From 782750a1e45acce104748c2aba8a04454cfc3448 Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Fri, 25 Dec 2020 16:15:21 +0100 Subject: [PATCH] Feature: do output action on input trigger --- src/main.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 878afa5..32173f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ const char *postboxFlapTopic = "postboxFlap"; const char *postboxDoorTopic = "postboxDoor"; const char *doorBellTriggerSoundTopic = "doorBellTrigger"; const char *postboxLightTopic = "postboxLight"; +const char *doorLightRequestTopic = "doorLightRequest"; EthernetClient ethClient; EthernetServer server(80); @@ -24,21 +25,26 @@ PubSubClient mqttClient(ethClient); #define DOOR_BELL_BUTTON_PIN 7 #define POSTBOX_FLAP_PIN 5 #define POSTBOX_DOOR_PIN 3 +#define LIGHT_REQUEST_BUTTON_PIN 2 // Output pins #define LED_PIN 13 #define DOOR_BELL_BUZZER_PIN 6 #define POSTBOX_LIGHT_PIN 4 +#define OUTPUT_NONE 0xff + struct { const uint8_t pin; const unsigned long quietAfterTriggerFor_ms; unsigned long lastTrigger_ts; bool isTriggered; const char *topic; + const uint8_t triggerOutputPin; } myInputs[] = { - { DOOR_BELL_BUTTON_PIN, 500, 0 , false, doorBellTopic }, - { POSTBOX_FLAP_PIN, 1000, 0, false, postboxFlapTopic }, - { POSTBOX_DOOR_PIN, 1000, 0, false, postboxDoorTopic } + { DOOR_BELL_BUTTON_PIN, 500, 0 , false, doorBellTopic, DOOR_BELL_BUZZER_PIN }, + { LIGHT_REQUEST_BUTTON_PIN, 500, 0 , false, doorLightRequestTopic, POSTBOX_LIGHT_PIN }, + { POSTBOX_FLAP_PIN, 1000, 0, false, postboxFlapTopic, OUTPUT_NONE }, + { POSTBOX_DOOR_PIN, 1000, 0, false, postboxDoorTopic, OUTPUT_NONE } }; #define NUM_INPUTS (sizeof(myInputs) / sizeof(myInputs[0])) int ledState = LOW; @@ -55,6 +61,15 @@ struct { }; #define NUM_OUTPUTS (sizeof(myOutputs) / sizeof(myOutputs[0])) +uint8_t getOutputIndexByPin(uint8_t pin) { + for (unsigned int i=0; i