Disabled button

This commit is contained in:
Ard Kuijpers
2020-06-26 17:14:48 +02:00
parent ea7246e7c3
commit ff5a062ecd

View File

@@ -1,72 +1,72 @@
#include <Homie.h> #include <Homie.h>
#include "RelayNode.hpp" #include "RelayNode.hpp"
#include "DHT22Node.hpp" #include "DHT22Node.hpp"
#include "ButtonNode.hpp" #include "ButtonNode.hpp"
#include "ContactNode.hpp" #include "ContactNode.hpp"
#include "Heartbeater.hpp" #include "Heartbeater.hpp"
// #include "PingNode.hpp" // #include "PingNode.hpp"
//const int trigPin = D1; //const int trigPin = D1;
//const int echoPin = D2; //const int echoPin = D2;
const int relayPin = D1; const int relayPin = D1;
const int contactPin = D2; const int contactPin = D2;
const int buttonPin = D6; // const int buttonPin = D6;
const int dhtPin = D7; ; const int dhtPin = D7; ;
const int ledPin = LED_BUILTIN; const int ledPin = LED_BUILTIN;
const int heartbeatPin = LED_BUILTIN; const int heartbeatPin = LED_BUILTIN;
unsigned long TEMPERATURE_INTERVAL = 120; unsigned long TEMPERATURE_INTERVAL = 120;
unsigned long lastTemperatureUpdate = 0; unsigned long lastTemperatureUpdate = 0;
bool relayInverse = true; bool relayInverse = true;
//PingNode obstacleNode("obstacle",trigPin,echoPin); //PingNode obstacleNode("obstacle",trigPin,echoPin);
DHT22Node airNode("air",dhtPin,TEMPERATURE_INTERVAL); DHT22Node airNode("air",dhtPin,TEMPERATURE_INTERVAL);
RelayNode relayNode("relay",relayPin,ledPin,relayInverse); RelayNode relayNode("relay",relayPin,ledPin,relayInverse);
ButtonNode buttonNode("button",buttonPin); // ButtonNode buttonNode("button",buttonPin);
ContactNode contactNode("contact",contactPin); ContactNode contactNode("contact",contactPin);
Heartbeater heartbeater(heartbeatPin, heartbeatPin == LED_BUILTIN ? LOW : HIGH); Heartbeater heartbeater(heartbeatPin, heartbeatPin == LED_BUILTIN ? LOW : HIGH);
void signal_led(bool on = true); void signal_led(bool on = true);
void changeHandler() { void changeHandler() {
signal_led(); signal_led();
} }
void buttonChangeHandler(bool down) { // void buttonChangeHandler(bool down) {
Homie.getLogger() << "Button changing relay to " << (down ? "on" : "off") << endl; // Homie.getLogger() << "Button changing relay to " << (down ? "on" : "off") << endl;
relayNode.setRelay(down); // relayNode.setRelay(down);
} // }
void loopHandler() { void loopHandler() {
heartbeater.loop(); heartbeater.loop();
// if (millis() - lastTemperatureUpdate > TEMPERATURE_INTERVAL * 1000UL || lastTemperatureUpdate == 0) { // if (millis() - lastTemperatureUpdate > TEMPERATURE_INTERVAL * 1000UL || lastTemperatureUpdate == 0) {
// obstacleNode.setTemperature(airNode.getTemperature()); // obstacleNode.setTemperature(airNode.getTemperature());
// lastTemperatureUpdate = millis(); // lastTemperatureUpdate = millis();
// } // }
} }
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
Serial << endl << endl; Serial << endl << endl;
randomSeed(analogRead(0)); randomSeed(analogRead(0));
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
Homie_setBrand("EtxeanIoT"); Homie_setBrand("EtxeanIoT");
Homie_setFirmware("etxean-garagesensor", "1.2.4"); Homie_setFirmware("etxean-garagesensor", "1.3.0");
Homie.setLoopFunction(loopHandler); Homie.setLoopFunction(loopHandler);
// obstacleNode.setChangeHandler(changeHandler); // obstacleNode.setChangeHandler(changeHandler);
buttonNode.onChange(buttonChangeHandler); // buttonNode.onChange(buttonChangeHandler);
Homie.setup(); Homie.setup();
} }
void loop() { void loop() {
Homie.loop(); Homie.loop();
} }
const uint8_t TURN_ON = ledPin == LED_BUILTIN ? LOW : HIGH; const uint8_t TURN_ON = ledPin == LED_BUILTIN ? LOW : HIGH;
const uint8_t TURN_OFF = ledPin == LED_BUILTIN ? HIGH : LOW; const uint8_t TURN_OFF = ledPin == LED_BUILTIN ? HIGH : LOW;
void signal_led(bool on) void signal_led(bool on)
{ {
digitalWrite(ledPin, on ? TURN_ON : TURN_OFF); digitalWrite(ledPin, on ? TURN_ON : TURN_OFF);
} }