Add button support as input

This commit is contained in:
Mykhailo Khulap
2018-09-27 07:34:09 +03:00
parent ae2187de84
commit 7742747d5d
2 changed files with 15 additions and 7 deletions

View File

@@ -306,7 +306,15 @@ void Input::contactPoll() {
if (store->bounce) store->bounce = store->bounce - 1; if (store->bounce) store->bounce = store->bounce - 1;
else //confirmed change 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; store->currentValue = currentInputState;
} }
} else // no change } else // no change

View File

@@ -20,12 +20,12 @@ e-mail anklimov@gmail.com
#include <aJSON.h> #include <aJSON.h>
#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_ANALOG 64 // Analog input
#define IN_RE 32 // Rotary Encoder (for further use) #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_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_DHT22 4
#define IN_COUNTER 8 #define IN_COUNTER 8
#define IN_UPTIME 16 #define IN_UPTIME 16
@@ -41,14 +41,14 @@ e-mail anklimov@gmail.com
// //
//Normal (not button) Switch (toggled mode) //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 // or
// "pin": { "T":"xx", "emit":"/light1", item:"light1"} // "pin": { "T":"xx", "emit":"/light1", item:"light1"}
//Normal (not button) Switch //Use Button
//"pin": { "T":"0", "emit":"/light1", item:"light1", "scmd": "ON", "rcmd": "OFF"} //"pin": { "T":"1", "emit":"/light1", item:"light1", "scmd": "ON", "rcmd": "OFF"}
// or // or
// "pin": { "T":"0", "emit":"/light1", item:"light1"} // "pin": { "T":"1", "emit":"/light1", item:"light1"}
//or //or
// "pin": { "emit":"/light1", item:"light1"} // "pin": { "emit":"/light1", item:"light1"}