Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DhtSensor.h « Sensors « Heating « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5cf86c0d8332989b9d4109e7f1fec36b2f807e26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * DhtSensor.h
 *
 *  Created on: 15 Sep 2017
 *      Author: Christian
 */

#ifndef SRC_HEATING_SENSORS_DHTSENSOR_H_
#define SRC_HEATING_SENSORS_DHTSENSOR_H_

#include "RepRapFirmware.h"

#if SUPPORT_DHT_SENSOR

# include "AdditionalOutputSensor.h"
# include "SensorWithPort.h"
# include "RTOSIface/RTOSIface.h"

enum class DhtSensorType
{
	Dht11,
	Dht21,
	Dht22
};


// This class represents a DHT temperature sensor
class DhtTemperatureSensor : public SensorWithPort
{
public:
	DhtTemperatureSensor(unsigned int sensorNum, DhtSensorType type) noexcept;
	~DhtTemperatureSensor() noexcept;

	GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override;
	TemperatureError GetLatestTemperature(float& t, uint8_t outputNumber = 0) noexcept override;
	const uint8_t GetNumAdditionalOutputs() const noexcept override { return 1; }

	void Poll() noexcept override;
	bool PollInTask() noexcept override;

	void Interrupt() noexcept;
	void TakeReading() noexcept;
	TemperatureError ProcessReadings(float& t, float& h) noexcept;

	static constexpr const char *TypeNameDht11 = "dht11";
	static constexpr const char *TypeNameDht21 = "dht21";
	static constexpr const char *TypeNameDht22 = "dht22";

private:
	DhtSensorType type;

	float lastHumidity;
	uint8_t badTemperatureCount;

	uint32_t lastReadTime;
	volatile uint16_t lastPulseTime;
	volatile uint8_t numPulses;
	uint16_t pulses[41];			// 1 start bit + 40 data bits
};

// This class represents a DHT humidity sensor
class DhtHumiditySensor : public AdditionalOutputSensor
{
public:
	DhtHumiditySensor(unsigned int sensorNum) noexcept;
	~DhtHumiditySensor() noexcept;

	static constexpr const char *TypeName = "dhthumidity";
};

#endif

#endif /* SRC_HEATING_SENSORS_DHTSENSOR_H_ */