rename methods
This commit is contained in:
parent
aed5ff152b
commit
c145154f3b
@ -4,9 +4,9 @@
|
|||||||
class Device {
|
class Device {
|
||||||
public:
|
public:
|
||||||
// purely virtual functions, need to be implemented
|
// purely virtual functions, need to be implemented
|
||||||
virtual void setup() = 0;
|
virtual void deviceSetup() = 0;
|
||||||
virtual void homieRegister() = 0;
|
virtual void deviceRegister() = 0;
|
||||||
virtual void loop() = 0;
|
virtual void deviceLoop() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,9 +11,9 @@ class DeviceDht : public Device {
|
|||||||
pin = dhtPin;
|
pin = dhtPin;
|
||||||
type = dhtType;
|
type = dhtType;
|
||||||
}
|
}
|
||||||
virtual void setup();
|
virtual void deviceSetup();
|
||||||
virtual void homieRegister();
|
virtual void deviceRegister();
|
||||||
virtual void loop();
|
virtual void deviceLoop();
|
||||||
private:
|
private:
|
||||||
byte pin;
|
byte pin;
|
||||||
byte type;
|
byte type;
|
||||||
@ -27,12 +27,12 @@ class DeviceDht : public Device {
|
|||||||
HomieNode heatindexNode{"heatindex", "heatindex"};
|
HomieNode heatindexNode{"heatindex", "heatindex"};
|
||||||
};
|
};
|
||||||
|
|
||||||
void DeviceDht::setup() {
|
void DeviceDht::deviceSetup() {
|
||||||
pinMode(pin, INPUT);
|
pinMode(pin, INPUT);
|
||||||
dht.begin();
|
dht.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceDht::homieRegister() {
|
void DeviceDht::deviceRegister() {
|
||||||
Homie.registerNode(humidityNode);
|
Homie.registerNode(humidityNode);
|
||||||
Homie.registerNode(temperatureNode);
|
Homie.registerNode(temperatureNode);
|
||||||
Homie.registerNode(heatindexNode);
|
Homie.registerNode(heatindexNode);
|
||||||
@ -43,7 +43,7 @@ bool isEqual(float a, float b, float epsilon=0.001) {
|
|||||||
return fabs(a - b) <= epsilon * fabs(a);
|
return fabs(a - b) <= epsilon * fabs(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceDht::loop() {
|
void DeviceDht::deviceLoop() {
|
||||||
if (millis() - lastSentDHT >= INTERVAL_DHT * 1000UL || lastSentDHT == 0) {
|
if (millis() - lastSentDHT >= INTERVAL_DHT * 1000UL || lastSentDHT == 0) {
|
||||||
float previousHumidity = humidity;
|
float previousHumidity = humidity;
|
||||||
float previousTemperature = temperature;
|
float previousTemperature = temperature;
|
||||||
|
@ -9,9 +9,9 @@ class DeviceLdr : public Device {
|
|||||||
inline DeviceLdr(byte ldrPin) {
|
inline DeviceLdr(byte ldrPin) {
|
||||||
pin = ldrPin;
|
pin = ldrPin;
|
||||||
}
|
}
|
||||||
virtual void setup();
|
virtual void deviceSetup();
|
||||||
virtual void homieRegister();
|
virtual void deviceRegister();
|
||||||
virtual void loop();
|
virtual void deviceLoop();
|
||||||
private:
|
private:
|
||||||
byte pin;
|
byte pin;
|
||||||
const int INTERVAL_LDR = 60;
|
const int INTERVAL_LDR = 60;
|
||||||
@ -20,15 +20,15 @@ class DeviceLdr : public Device {
|
|||||||
HomieNode ldrNode = HomieNode("ldr", "ldr");
|
HomieNode ldrNode = HomieNode("ldr", "ldr");
|
||||||
};
|
};
|
||||||
|
|
||||||
void DeviceLdr::setup() {
|
void DeviceLdr::deviceSetup() {
|
||||||
pinMode(pin, INPUT);
|
pinMode(pin, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceLdr::homieRegister() {
|
void DeviceLdr::deviceRegister() {
|
||||||
Homie.registerNode(ldrNode);
|
Homie.registerNode(ldrNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceLdr::loop() {
|
void DeviceLdr::deviceLoop() {
|
||||||
if (millis() - lastSentLDR >= INTERVAL_LDR * 1000UL || lastSentLDR == 0) {
|
if (millis() - lastSentLDR >= INTERVAL_LDR * 1000UL || lastSentLDR == 0) {
|
||||||
int ldr_new = analogRead(pin);
|
int ldr_new = analogRead(pin);
|
||||||
if (ldr_new != ldr) {
|
if (ldr_new != ldr) {
|
||||||
|
@ -11,9 +11,9 @@ class DeviceLed : public Device {
|
|||||||
pinGreen = ledGreen;
|
pinGreen = ledGreen;
|
||||||
pinBlue = ledBlue;
|
pinBlue = ledBlue;
|
||||||
}
|
}
|
||||||
virtual void setup();
|
virtual void deviceSetup();
|
||||||
virtual void homieRegister();
|
virtual void deviceRegister();
|
||||||
virtual void loop();
|
virtual void deviceLoop();
|
||||||
private:
|
private:
|
||||||
byte pinRed;
|
byte pinRed;
|
||||||
byte pinGreen;
|
byte pinGreen;
|
||||||
@ -26,7 +26,7 @@ class DeviceLed : public Device {
|
|||||||
HomieNode ledNode{"led", "rgb"};
|
HomieNode ledNode{"led", "rgb"};
|
||||||
};
|
};
|
||||||
|
|
||||||
void DeviceLed::setup() {
|
void DeviceLed::deviceSetup() {
|
||||||
pinMode(pinRed, OUTPUT);
|
pinMode(pinRed, OUTPUT);
|
||||||
pinMode(pinGreen, OUTPUT);
|
pinMode(pinGreen, OUTPUT);
|
||||||
pinMode(pinBlue, OUTPUT);
|
pinMode(pinBlue, OUTPUT);
|
||||||
@ -87,13 +87,13 @@ bool DeviceLed::ledColorHandler(String message) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceLed::homieRegister() {
|
void DeviceLed::deviceRegister() {
|
||||||
ledNode.subscribe("on", [this](String value) { return ledOnHandler(value); });
|
ledNode.subscribe("on", [this](String value) { return ledOnHandler(value); });
|
||||||
ledNode.subscribe("color", [this](String value) { return ledColorHandler(value); });
|
ledNode.subscribe("color", [this](String value) { return ledColorHandler(value); });
|
||||||
Homie.registerNode(ledNode);
|
Homie.registerNode(ledNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceLed::loop() {
|
void DeviceLed::deviceLoop() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,13 +23,13 @@ Device * devices[3];
|
|||||||
|
|
||||||
void setupHandler() {
|
void setupHandler() {
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
devices[i]->setup();
|
devices[i]->deviceSetup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loopHandler() {
|
void loopHandler() {
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
devices[i]->loop();
|
devices[i]->deviceLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ void setup() {
|
|||||||
devices[1] = &deviceLdr;
|
devices[1] = &deviceLdr;
|
||||||
//devices[2] = &deviceDht;
|
//devices[2] = &deviceDht;
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
devices[i]->homieRegister();
|
devices[i]->deviceRegister();
|
||||||
}
|
}
|
||||||
Homie.setSetupFunction(setupHandler);
|
Homie.setSetupFunction(setupHandler);
|
||||||
Homie.setLoopFunction(loopHandler);
|
Homie.setLoopFunction(loopHandler);
|
||||||
|
Loading…
Reference in New Issue
Block a user