From 7742747d5d7794fc8c6c4ee9f8a196dc9a2de263 Mon Sep 17 00:00:00 2001 From: Mykhailo Khulap Date: Thu, 27 Sep 2018 07:34:09 +0300 Subject: [PATCH] Add button support as input --- lighthub/inputs.cpp | 10 +++++++++- lighthub/inputs.h | 12 ++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lighthub/inputs.cpp b/lighthub/inputs.cpp index 365e7df..fc5bec1 100644 --- a/lighthub/inputs.cpp +++ b/lighthub/inputs.cpp @@ -306,7 +306,15 @@ void Input::contactPoll() { if (store->bounce) store->bounce = store->bounce - 1; else //confirmed change { - onContactChanged(currentInputState); + if (inType & IN_PUSH_TOGGLE) { + if (currentInputState) { //react on leading edge only (change from 0 to 1) + store->logicState = !store->logicState; + onContactChanged(store->logicState); + } + } else { + store->logicState = currentInputState; + onContactChanged(currentInputState); + } store->currentValue = currentInputState; } } else // no change diff --git a/lighthub/inputs.h b/lighthub/inputs.h index 4895b51..94bbf32 100644 --- a/lighthub/inputs.h +++ b/lighthub/inputs.h @@ -20,12 +20,12 @@ e-mail anklimov@gmail.com #include -#define IN_ACTIVE_HIGH 2 // High level = PUSHED/ CLOSED/ ON othervise :Low Level +#define IN_ACTIVE_HIGH 2 // High level = PUSHED/ CLOSED/ ON othervise :Low Level. Use INPUT mode instead of INPUT_PULLUP for digital pin #define IN_ANALOG 64 // Analog input #define IN_RE 32 // Rotary Encoder (for further use) #define IN_PUSH_ON 0 // PUSH - ON, Release - OFF (ovverrided by pcmd/rcmd) - DEFAULT -#define IN_PUSH_TOGGLE 1 // Every physicall push toggle logical switch on/off +#define IN_PUSH_TOGGLE 1 // Used for push buttons. Every physicall push toggle logical switch on/off. Toggle on leading edge #define IN_DHT22 4 #define IN_COUNTER 8 #define IN_UPTIME 16 @@ -41,14 +41,14 @@ e-mail anklimov@gmail.com // //Normal (not button) Switch (toggled mode) -//"pin": { "T":"1", "emit":"/light1", item:"light1", "scmd": "TOGGLE", "rcmd": "TOGGLE"} +//"pin": { "T":"0", "emit":"/light1", item:"light1", "scmd": "TOGGLE", "rcmd": "TOGGLE"} // or // "pin": { "T":"xx", "emit":"/light1", item:"light1"} -//Normal (not button) Switch -//"pin": { "T":"0", "emit":"/light1", item:"light1", "scmd": "ON", "rcmd": "OFF"} +//Use Button +//"pin": { "T":"1", "emit":"/light1", item:"light1", "scmd": "ON", "rcmd": "OFF"} // or -// "pin": { "T":"0", "emit":"/light1", item:"light1"} +// "pin": { "T":"1", "emit":"/light1", item:"light1"} //or // "pin": { "emit":"/light1", item:"light1"}