-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSensor.h
More file actions
54 lines (42 loc) · 1.22 KB
/
Sensor.h
File metadata and controls
54 lines (42 loc) · 1.22 KB
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
//
// Sensor.h - Library for handling readings from the temp sensor.
//
#ifndef Sensor_h
#define Sensor_h
#define DHT_DEBUG
#include <DHT.h>
#include "defaults.h"
#include "Config.h"
#define SENSOR_POLL_INTERVAL 10 // Seconds
#define SENSOR_RESET_INTERVAL 60 // Reset the sensor if it's been at least this many
// seconds since we last got a successful reading
//
// Sensor Library Class
class Sensor
{
public:
Sensor(uint8_t pin, uint8_t type): _dht(pin, type) { };
void begin( Config *config );
void loop();
void sensor_on();
void read_sensor();
void read_analog();
void reset_sensor();
float get_temp();
float get_humidity();
float get_hindex();
float get_analog();
float get_pressure();
private:
Config *_config;
DHT _dht;
// DHT _dht(DHTPIN, DHTTYPE);
int _poll_sensor_interval = SENSOR_POLL_INTERVAL * 1000; // Read the sensors every 10 seconds
int _next_sensor_poll = _poll_sensor_interval;
unsigned long _last_sensor_read = 0;
float _cur_temp = NAN;
float _cur_humidity = NAN;
float _cur_hindex = NAN;
float _cur_analog = NAN;
};
#endif