blob: 797961aa368e5a2be48c1b40c0790bb996be9d92 (
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);
~DhtTemperatureSensor();
GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override;
TemperatureError GetLatestTemperature(float& t, uint8_t outputNumber = 0) override;
const uint8_t GetNumAdditionalOutputs() const override { return 1; }
void Poll() override;
bool PollInTask() override;
void Interrupt();
void TakeReading();
TemperatureError ProcessReadings(float& t, float& h);
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);
~DhtHumiditySensor();
static constexpr const char *TypeName = "dhthumidity";
};
#endif
#endif /* SRC_HEATING_SENSORS_DHTSENSOR_H_ */
|