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::checkNotifications();
|
||||||
HAPClient::checkTimedWrites();
|
HAPClient::checkTimedWrites();
|
||||||
|
|
||||||
if(controlButton.triggered(2000,10000)){
|
if(controlButton.primed()){
|
||||||
|
statusLED.start(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(controlButton.triggered(3000,10000)){
|
||||||
if(controlButton.longPress()){
|
if(controlButton.longPress()){
|
||||||
statusLED.start(200);
|
statusLED.start(200);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
processSerialCommand("W"); // Delete WiFi Data and Restart
|
statusLED.off();
|
||||||
|
ESP.restart();
|
||||||
|
processSerialCommand("W"); // DELETE WiFi Data and Restart
|
||||||
} else {
|
} else {
|
||||||
statusLED.off();
|
statusLED.off();
|
||||||
controlButton.reset();
|
controlButton.reset();
|
||||||
processSerialCommand("U"); // UPAIR Device
|
processSerialCommand("U"); // UNPAIR Device
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@
|
||||||
// DEFAULT SETTINGS
|
// DEFAULT SETTINGS
|
||||||
|
|
||||||
#define DEFAULT_SETUP_CODE "46637726" // changed during network setup or with 'S' command
|
#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_CONTROL_PIN 21 // change with homeSpan.setControlPin(pin)
|
||||||
#define DEFAULT_STATUS_PIN LED_BUILTIN // changed with homeSpan.setStatusPin(pin)
|
#define DEFAULT_STATUS_PIN LED_BUILTIN // change with homeSpan.setStatusPin(pin)
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
// Maximum number of simultaenous IP connections //
|
// Maximum number of simultaenous IP connections //
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ boolean PushButton::triggered(uint16_t shortTime, uint16_t longTime){
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
case 2:
|
||||||
if(digitalRead(pin)){ // button is released
|
if(digitalRead(pin)){ // button is released
|
||||||
status=0;
|
status=0;
|
||||||
if(millis()>shortAlarm){
|
if(millis()>shortAlarm){
|
||||||
|
|
@ -98,13 +99,13 @@ boolean PushButton::triggered(uint16_t shortTime, uint16_t longTime){
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if(millis()>longAlarm){ // button is long-pressed
|
if(millis()>longAlarm){ // button is long-pressed
|
||||||
status=2;
|
status=3;
|
||||||
isLongPress=true;
|
isLongPress=true;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 3:
|
||||||
if(digitalRead(pin)) // button has been released after a long press
|
if(digitalRead(pin)) // button has been released after a long press
|
||||||
status=0;
|
status=0;
|
||||||
break;
|
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(){
|
boolean PushButton::longPress(){
|
||||||
return(isLongPress);
|
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
|
// return false until there is a new trigger. After a Long Press, the button must be released to permit a subsequent
|
||||||
// trigger.
|
// 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();
|
boolean longPress();
|
||||||
|
|
||||||
// Returns true if last trigger event was a Long Press, or false if last trigger was a Short Press
|
// Returns true if last trigger event was a Long Press, or false if last trigger was a Short Press
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ void setup() {
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
homeSpan.setStatusPin(22);
|
|
||||||
|
|
||||||
homeSpan.begin(Category::Lighting,"HomeSpan Benchmark");
|
homeSpan.begin(Category::Lighting,"HomeSpan Benchmark");
|
||||||
|
|
||||||
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments
|
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue