Added PushButton::primed()
Allows you to determine if short-press has occured but button not yet released.
This commit is contained in:
parent
a40447b8f8
commit
538a3a9531
|
|
@ -155,15 +155,21 @@ void Span::poll() {
|
|||
HAPClient::checkNotifications();
|
||||
HAPClient::checkTimedWrites();
|
||||
|
||||
if(controlButton.triggered(2000,10000)){
|
||||
if(controlButton.primed()){
|
||||
statusLED.start(500);
|
||||
}
|
||||
|
||||
if(controlButton.triggered(3000,10000)){
|
||||
if(controlButton.longPress()){
|
||||
statusLED.start(200);
|
||||
delay(2000);
|
||||
processSerialCommand("W"); // Delete WiFi Data and Restart
|
||||
statusLED.off();
|
||||
ESP.restart();
|
||||
processSerialCommand("W"); // DELETE WiFi Data and Restart
|
||||
} else {
|
||||
statusLED.off();
|
||||
controlButton.reset();
|
||||
processSerialCommand("U"); // UPAIR Device
|
||||
processSerialCommand("U"); // UNPAIR Device
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -470,7 +476,7 @@ void Span::processSerialCommand(char *c){
|
|||
break;
|
||||
|
||||
case 'W': {
|
||||
|
||||
|
||||
nvs_erase_all(HAPClient::wifiNVS);
|
||||
nvs_commit(HAPClient::wifiNVS);
|
||||
Serial.print("\n** WIFI Network Data DELETED **\n** Restarting...\n\n");
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
// DEFAULT SETTINGS
|
||||
|
||||
#define DEFAULT_SETUP_CODE "46637726" // changed during network setup or with 'S' command
|
||||
#define DEFAULT_CONTROL_PIN 21 // changed with homeSpan.setControlPin(pin)
|
||||
#define DEFAULT_STATUS_PIN LED_BUILTIN // changed with homeSpan.setStatusPin(pin)
|
||||
#define DEFAULT_CONTROL_PIN 21 // change with homeSpan.setControlPin(pin)
|
||||
#define DEFAULT_STATUS_PIN LED_BUILTIN // change with homeSpan.setStatusPin(pin)
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Maximum number of simultaenous IP connections //
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ boolean PushButton::triggered(uint16_t shortTime, uint16_t longTime){
|
|||
break;
|
||||
|
||||
case 1:
|
||||
case 2:
|
||||
if(digitalRead(pin)){ // button is released
|
||||
status=0;
|
||||
if(millis()>shortAlarm){
|
||||
|
|
@ -98,13 +99,13 @@ boolean PushButton::triggered(uint16_t shortTime, uint16_t longTime){
|
|||
} else
|
||||
|
||||
if(millis()>longAlarm){ // button is long-pressed
|
||||
status=2;
|
||||
status=3;
|
||||
isLongPress=true;
|
||||
return(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
if(digitalRead(pin)) // button has been released after a long press
|
||||
status=0;
|
||||
break;
|
||||
|
|
@ -116,6 +117,18 @@ boolean PushButton::triggered(uint16_t shortTime, uint16_t longTime){
|
|||
|
||||
//////////////////////////////////////
|
||||
|
||||
boolean PushButton::primed(){
|
||||
|
||||
if(millis()>shortAlarm && status==1){
|
||||
status=2;
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
boolean PushButton::longPress(){
|
||||
return(isLongPress);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,11 @@ class PushButton{
|
|||
// return false until there is a new trigger. After a Long Press, the button must be released to permit a subsequent
|
||||
// trigger.
|
||||
|
||||
boolean primed();
|
||||
|
||||
// Returns true if button has been pressed and held for greater than shortTime, but has not yet been released.
|
||||
// After returning true, subsequent calls will always return false until the button has been released and reset.
|
||||
|
||||
boolean longPress();
|
||||
|
||||
// Returns true if last trigger event was a Long Press, or false if last trigger was a Short Press
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@
|
|||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
homeSpan.setStatusPin(22);
|
||||
|
||||
homeSpan.begin(Category::Lighting,"HomeSpan Benchmark");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue