Added PushButton::primed()

Allows you to determine if short-press has occured but button not yet released.
This commit is contained in:
Gregg 2020-09-27 14:33:38 -05:00
parent a40447b8f8
commit 538a3a9531
5 changed files with 32 additions and 10 deletions

View File

@ -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
}
}

View File

@ -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 //

View File

@ -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);
}

View File

@ -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

View File

@ -8,8 +8,6 @@ void setup() {
Serial.begin(115200);
homeSpan.setStatusPin(22);
homeSpan.begin(Category::Lighting,"HomeSpan Benchmark");
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments