finally a working modularized version
This commit is contained in:
parent
73395170ac
commit
52c4648c02
@ -7,7 +7,7 @@
|
||||
|
||||
class DeviceDht : public Device {
|
||||
public:
|
||||
inline DeviceDht(byte dhtPin, byte dhtType) {
|
||||
inline DeviceDht(byte dhtPin, byte dhtType):dht(dhtPin, dhtType) {
|
||||
pin = dhtPin;
|
||||
type = dhtType;
|
||||
}
|
||||
@ -17,9 +17,7 @@ class DeviceDht : public Device {
|
||||
private:
|
||||
byte pin;
|
||||
byte type;
|
||||
// TODO configuration via constructor doesn't work yet
|
||||
//DHT dht{pin, type};
|
||||
DHT dht{D4, DHT22};
|
||||
DHT dht;
|
||||
const int INTERVAL_DHT = 60;
|
||||
unsigned long lastSentDHT = 0;
|
||||
float humidity, temperature; // raw values from the sensor
|
||||
|
@ -17,7 +17,7 @@ class DeviceLdr : public Device {
|
||||
const int INTERVAL_LDR = 60;
|
||||
unsigned long lastSentLDR = 0;
|
||||
int ldr = 0;
|
||||
HomieNode ldrNode{"ldr", "ldr"};
|
||||
HomieNode ldrNode = HomieNode("ldr", "ldr");
|
||||
};
|
||||
|
||||
void DeviceLdr::setup() {
|
||||
|
@ -88,9 +88,8 @@ bool DeviceLed::ledColorHandler(String message) {
|
||||
}
|
||||
|
||||
void DeviceLed::homieRegister() {
|
||||
// TODO this doesn't work :-(
|
||||
//ledNode.subscribe("on", &DeviceLed::ledOnHandler());
|
||||
//ledNode.subscribe("color", &DeviceLed::ledColorHandler());
|
||||
ledNode.subscribe("on", [this](String value) { return ledOnHandler(value); });
|
||||
ledNode.subscribe("color", std::bind(&DeviceLed::ledColorHandler, this, std::placeholders::_1));
|
||||
Homie.registerNode(ledNode);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user