From ff5a062ecdad4511a68020574454ff0d8151e4df Mon Sep 17 00:00:00 2001 From: Ard Kuijpers Date: Fri, 26 Jun 2020 17:14:48 +0200 Subject: [PATCH] Disabled button --- src/main.cpp | 144 +++++++++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 572cc21..ecae344 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,72 +1,72 @@ -#include - -#include "RelayNode.hpp" -#include "DHT22Node.hpp" -#include "ButtonNode.hpp" -#include "ContactNode.hpp" -#include "Heartbeater.hpp" -// #include "PingNode.hpp" -//const int trigPin = D1; -//const int echoPin = D2; -const int relayPin = D1; -const int contactPin = D2; -const int buttonPin = D6; -const int dhtPin = D7; ; -const int ledPin = LED_BUILTIN; -const int heartbeatPin = LED_BUILTIN; - -unsigned long TEMPERATURE_INTERVAL = 120; -unsigned long lastTemperatureUpdate = 0; -bool relayInverse = true; - -//PingNode obstacleNode("obstacle",trigPin,echoPin); -DHT22Node airNode("air",dhtPin,TEMPERATURE_INTERVAL); -RelayNode relayNode("relay",relayPin,ledPin,relayInverse); -ButtonNode buttonNode("button",buttonPin); -ContactNode contactNode("contact",contactPin); -Heartbeater heartbeater(heartbeatPin, heartbeatPin == LED_BUILTIN ? LOW : HIGH); - -void signal_led(bool on = true); - -void changeHandler() { - signal_led(); -} - -void buttonChangeHandler(bool down) { - Homie.getLogger() << "Button changing relay to " << (down ? "on" : "off") << endl; - relayNode.setRelay(down); -} - -void loopHandler() { - heartbeater.loop(); - // if (millis() - lastTemperatureUpdate > TEMPERATURE_INTERVAL * 1000UL || lastTemperatureUpdate == 0) { - // obstacleNode.setTemperature(airNode.getTemperature()); - // lastTemperatureUpdate = millis(); - // } -} - -void setup() { - Serial.begin(115200); - Serial << endl << endl; - randomSeed(analogRead(0)); - pinMode(ledPin, OUTPUT); - - Homie_setBrand("EtxeanIoT"); - Homie_setFirmware("etxean-garagesensor", "1.2.4"); - Homie.setLoopFunction(loopHandler); - // obstacleNode.setChangeHandler(changeHandler); - buttonNode.onChange(buttonChangeHandler); - Homie.setup(); -} - -void loop() { - Homie.loop(); -} - -const uint8_t TURN_ON = ledPin == LED_BUILTIN ? LOW : HIGH; -const uint8_t TURN_OFF = ledPin == LED_BUILTIN ? HIGH : LOW; - -void signal_led(bool on) -{ - digitalWrite(ledPin, on ? TURN_ON : TURN_OFF); -} +#include + +#include "RelayNode.hpp" +#include "DHT22Node.hpp" +#include "ButtonNode.hpp" +#include "ContactNode.hpp" +#include "Heartbeater.hpp" +// #include "PingNode.hpp" +//const int trigPin = D1; +//const int echoPin = D2; +const int relayPin = D1; +const int contactPin = D2; +// const int buttonPin = D6; +const int dhtPin = D7; ; +const int ledPin = LED_BUILTIN; +const int heartbeatPin = LED_BUILTIN; + +unsigned long TEMPERATURE_INTERVAL = 120; +unsigned long lastTemperatureUpdate = 0; +bool relayInverse = true; + +//PingNode obstacleNode("obstacle",trigPin,echoPin); +DHT22Node airNode("air",dhtPin,TEMPERATURE_INTERVAL); +RelayNode relayNode("relay",relayPin,ledPin,relayInverse); +// ButtonNode buttonNode("button",buttonPin); +ContactNode contactNode("contact",contactPin); +Heartbeater heartbeater(heartbeatPin, heartbeatPin == LED_BUILTIN ? LOW : HIGH); + +void signal_led(bool on = true); + +void changeHandler() { + signal_led(); +} + +// void buttonChangeHandler(bool down) { +// Homie.getLogger() << "Button changing relay to " << (down ? "on" : "off") << endl; +// relayNode.setRelay(down); +// } + +void loopHandler() { + heartbeater.loop(); + // if (millis() - lastTemperatureUpdate > TEMPERATURE_INTERVAL * 1000UL || lastTemperatureUpdate == 0) { + // obstacleNode.setTemperature(airNode.getTemperature()); + // lastTemperatureUpdate = millis(); + // } +} + +void setup() { + Serial.begin(115200); + Serial << endl << endl; + randomSeed(analogRead(0)); + pinMode(ledPin, OUTPUT); + + Homie_setBrand("EtxeanIoT"); + Homie_setFirmware("etxean-garagesensor", "1.3.0"); + Homie.setLoopFunction(loopHandler); + // obstacleNode.setChangeHandler(changeHandler); + // buttonNode.onChange(buttonChangeHandler); + Homie.setup(); +} + +void loop() { + Homie.loop(); +} + +const uint8_t TURN_ON = ledPin == LED_BUILTIN ? LOW : HIGH; +const uint8_t TURN_OFF = ledPin == LED_BUILTIN ? HIGH : LOW; + +void signal_led(bool on) +{ + digitalWrite(ledPin, on ? TURN_ON : TURN_OFF); +}