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