Now capture transient events on GPIO inputs for JSON output
This commit is contained in:
parent
dafd7ba856
commit
cfdedc0d7c
|
@ -67,8 +67,24 @@ CGPIOin::begin(int pin1, int pin2, GPIOinModes mode, int activeState)
|
|||
uint8_t
|
||||
CGPIOin::getState(int channel)
|
||||
{
|
||||
int mask = 0x01 << (channel & 0x01);
|
||||
return (_Debounce.getState() & mask) != 0;
|
||||
uint8_t retval = 0;
|
||||
|
||||
if((channel & ~0x01) == 0) {
|
||||
// index is in bounds 0 or 1
|
||||
|
||||
// check for transient events
|
||||
if(_eventList[channel].empty()) {
|
||||
// read last actual state
|
||||
int mask = 0x01 << (channel & 0x01);
|
||||
retval = (_Debounce.getState() & mask) != 0;
|
||||
}
|
||||
else {
|
||||
// emit transient events if they occured
|
||||
retval = _eventList[channel].front() != 0;
|
||||
_eventList[channel].pop_front();
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
GPIOinModes CGPIOin::getMode() const
|
||||
|
@ -86,19 +102,12 @@ CGPIOin::manage()
|
|||
|
||||
if(keyChange) {
|
||||
simulateKey(newKey);
|
||||
/* switch (_Mode) {
|
||||
case GPIOinNone:
|
||||
break;
|
||||
case GPIOinOn1Off2:
|
||||
_doOn1Off2(newKey);
|
||||
break;
|
||||
case GPIOinOnHold1:
|
||||
_doOnHold1(newKey);
|
||||
break;
|
||||
case GPIOinOn1Off1:
|
||||
_doOn1Off1(newKey);
|
||||
break;
|
||||
}*/
|
||||
|
||||
// record possible sub sample transients - JSON usage especially
|
||||
if(keyChange & 0x01)
|
||||
_eventList[0].push_back(newKey & 0x01); // mask the channel bit
|
||||
if(keyChange & 0x02)
|
||||
_eventList[1].push_back(newKey & 0x02); // mask the channel bit
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <stdint.h>
|
||||
#include <driver/adc.h>
|
||||
#include "Debounce.h"
|
||||
#include <list>
|
||||
|
||||
extern const char* GPIOinNames[4];
|
||||
extern const char* GPIOoutNames[3];
|
||||
|
@ -61,14 +62,8 @@ struct sGPIOparams {
|
|||
class CGPIOin {
|
||||
GPIOinModes _Mode;
|
||||
CDebounce _Debounce;
|
||||
// int _pinActive;
|
||||
// int _pins[2];
|
||||
// uint8_t _prevPins;
|
||||
// uint8_t _debouncedPins;
|
||||
uint8_t _lastKey;
|
||||
// unsigned long _lastDebounceTime;
|
||||
// unsigned long _debounceDelay;
|
||||
// uint8_t _scanInputs();
|
||||
std::list<uint8_t> _eventList[2];
|
||||
void _doOn1Off2(uint8_t newKey);
|
||||
void _doOnHold1(uint8_t newKey);
|
||||
void _doOn1Off1(uint8_t newKey);
|
||||
|
|
Loading…
Reference in a new issue