From c145154f3bfad064f1cc22bdb84311ff361c380d Mon Sep 17 00:00:00 2001 From: Ronald Schaten Date: Mon, 11 Apr 2016 00:29:05 +0200 Subject: [PATCH] rename methods --- things/Device.h | 6 +++--- things/DeviceDht.h | 12 ++++++------ things/DeviceLdr.h | 12 ++++++------ things/DeviceLed.h | 12 ++++++------ things/things.ino | 6 +++--- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/things/Device.h b/things/Device.h index decfd91..6c72aef 100644 --- a/things/Device.h +++ b/things/Device.h @@ -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 diff --git a/things/DeviceDht.h b/things/DeviceDht.h index a33c983..20668cf 100644 --- a/things/DeviceDht.h +++ b/things/DeviceDht.h @@ -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; diff --git a/things/DeviceLdr.h b/things/DeviceLdr.h index c070287..37d8af3 100644 --- a/things/DeviceLdr.h +++ b/things/DeviceLdr.h @@ -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) { diff --git a/things/DeviceLed.h b/things/DeviceLed.h index 7149f67..cc5434c 100644 --- a/things/DeviceLed.h +++ b/things/DeviceLed.h @@ -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; } diff --git a/things/things.ino b/things/things.ino index 01dd9d3..38a44b1 100644 --- a/things/things.ino +++ b/things/things.ino @@ -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);