-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSpecificSensors.cpp
113 lines (96 loc) · 1.74 KB
/
SpecificSensors.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* SpecificSensors.cpp
*
* Created on: 28 ÿíâ. 2016 ã.
* Author: Anakod
*/
#include <user_config.h>
#include <SmingCore/SmingCore.h>
#include "SpecificSensors.h"
#include <Libraries/DHT/DHT.h>
#include <Libraries/DS18S20/ds18s20.h>
SensorDHT::SensorDHT(String type) :
Sensor(0)
{
type.toLowerCase();
if (type == "dht11")
this->type = DHT11;
else if (type == "dht21" || type == "am2301")
this->type = DHT21;
else if (type == "dht22")
this->type = DHT22;
else
debugf("UNK DHT!");
}
SensorDHT::~SensorDHT()
{
delete dht;
}
void SensorDHT::onLoad(JsonObject& data)
{
dht = new DHT(pins[DFNAME], type);
}
void SensorDHT::onBegin()
{
//if (!initialized)
{
dht->begin();
initialized = true;
}
TempAndHumidity result;
bool ok = dht->readTempAndHumidity(result);
if (ok)
{
store("temperature", result.temp);
store("humidity", result.humid);
}
else
{
debugf("failed read DHT sensor");
//dht->begin();
}
}
/////////
void SensorAnalogReader::onBegin()
{
//int pin = pins[DFNAME];
store(analogRead(A0));
}
/////////
void SensorButton::onLoad(JsonObject& data)
{
//auto cb = &SensorButton::onRrepeat;
//attachInterrupt(pins[DFNAME], Delegate<void()>(cb, (WorkingObject*)this), CHANGE);
}
void SensorButton::onFinish()
{
int pin = pins[DFNAME];
bool state = digitalRead(pin);
store(state);
}
/////////
SensorDS1820::~SensorDS1820()
{
delete ds;
}
void SensorDS1820::onLoad(JsonObject& data)
{
int pin = pins[DFNAME];
ds = new DS18S20();
ds->Init(pin);
}
void SensorDS1820::onBegin()
{
ds->StartMeasure();
}
void SensorDS1820::onFinish()
{
if (ds->GetSensorsCount() == 0)
{
debugf("DS1820 not found");
}
if (ds->IsValidTemperature(0))
store(ds->GetCelsius(0));
else
debugf("DS1820 temperature not valid");
}