begin update of PushButton to make it more generic
Eliminated constructor that had no pin parameter. Pin parameter is now always required. Since PushButton was not part of HomeSpan API, these changes should not impact any users.
This commit is contained in:
parent
57d791178c
commit
54b8374573
|
|
@ -191,7 +191,6 @@ class Span{
|
||||||
const char *defaultSetupCode=DEFAULT_SETUP_CODE; // Setup Code used for pairing
|
const char *defaultSetupCode=DEFAULT_SETUP_CODE; // Setup Code used for pairing
|
||||||
int statusPin=DEFAULT_STATUS_PIN; // pin for Status LED
|
int statusPin=DEFAULT_STATUS_PIN; // pin for Status LED
|
||||||
uint16_t autoOffLED=0; // automatic turn-off duration (in seconds) for Status LED
|
uint16_t autoOffLED=0; // automatic turn-off duration (in seconds) for Status LED
|
||||||
// int controlPin=DEFAULT_CONTROL_PIN; // pin for Control Pushbutton
|
|
||||||
uint8_t logLevel=DEFAULT_LOG_LEVEL; // level for writing out log messages to serial monitor
|
uint8_t logLevel=DEFAULT_LOG_LEVEL; // level for writing out log messages to serial monitor
|
||||||
uint8_t maxConnections=CONFIG_LWIP_MAX_SOCKETS-2; // maximum number of allowed simultaneous HAP connections
|
uint8_t maxConnections=CONFIG_LWIP_MAX_SOCKETS-2; // maximum number of allowed simultaneous HAP connections
|
||||||
uint8_t requestedMaxCon=CONFIG_LWIP_MAX_SOCKETS-2; // requested maximum number of simultaneous HAP connections
|
uint8_t requestedMaxCon=CONFIG_LWIP_MAX_SOCKETS-2; // requested maximum number of simultaneous HAP connections
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,6 @@
|
||||||
|
|
||||||
#define DEFAULT_QR_ID "HSPN" // change with homeSpan.setQRID(qrID);
|
#define DEFAULT_QR_ID "HSPN" // change with homeSpan.setQRID(qrID);
|
||||||
|
|
||||||
//#define DEFAULT_CONTROL_PIN -1 // change with homeSpan.setControlPin(pin)
|
|
||||||
#define DEFAULT_STATUS_PIN -1 // change with homeSpan.setStatusPin(pin)
|
#define DEFAULT_STATUS_PIN -1 // change with homeSpan.setStatusPin(pin)
|
||||||
|
|
||||||
#define DEFAULT_AP_SSID "HomeSpan-Setup" // change with homeSpan.setApSSID(ssid)
|
#define DEFAULT_AP_SSID "HomeSpan-Setup" // change with homeSpan.setApSSID(ssid)
|
||||||
|
|
|
||||||
|
|
@ -85,22 +85,9 @@ String Utils::mask(char *c, int n){
|
||||||
// PushButton //
|
// PushButton //
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
PushButton::PushButton(){}
|
|
||||||
|
|
||||||
//////////////////////////////////////
|
|
||||||
|
|
||||||
PushButton::PushButton(int pin){
|
PushButton::PushButton(int pin){
|
||||||
init(pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////
|
|
||||||
|
|
||||||
void PushButton::init(int pin){
|
|
||||||
|
|
||||||
this->pin=pin;
|
this->pin=pin;
|
||||||
if(pin<0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
status=0;
|
status=0;
|
||||||
doubleCheck=false;
|
doubleCheck=false;
|
||||||
pinMode(pin, INPUT_PULLUP);
|
pinMode(pin, INPUT_PULLUP);
|
||||||
|
|
@ -110,9 +97,6 @@ void PushButton::init(int pin){
|
||||||
|
|
||||||
boolean PushButton::triggered(uint16_t singleTime, uint16_t longTime, uint16_t doubleTime){
|
boolean PushButton::triggered(uint16_t singleTime, uint16_t longTime, uint16_t doubleTime){
|
||||||
|
|
||||||
if(pin<0)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
unsigned long cTime=millis();
|
unsigned long cTime=millis();
|
||||||
|
|
||||||
switch(status){
|
switch(status){
|
||||||
|
|
@ -190,9 +174,6 @@ boolean PushButton::triggered(uint16_t singleTime, uint16_t longTime, uint16_t d
|
||||||
|
|
||||||
boolean PushButton::primed(){
|
boolean PushButton::primed(){
|
||||||
|
|
||||||
if(pin<0)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
if(millis()>singleAlarm && status==1){
|
if(millis()>singleAlarm && status==1){
|
||||||
status=2;
|
status=2;
|
||||||
return(true);
|
return(true);
|
||||||
|
|
@ -210,10 +191,6 @@ int PushButton::type(){
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
void PushButton::wait(){
|
void PushButton::wait(){
|
||||||
|
|
||||||
if(pin<0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
while(!digitalRead(pin));
|
while(!digitalRead(pin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
17
src/Utils.h
17
src/Utils.h
|
|
@ -89,24 +89,9 @@ class PushButton{
|
||||||
LONG=2
|
LONG=2
|
||||||
};
|
};
|
||||||
|
|
||||||
PushButton();
|
|
||||||
PushButton(int pin);
|
PushButton(int pin);
|
||||||
|
|
||||||
// Creates generic pushbutton functionality on specified pin
|
// Creates generic pushbutton functionality on specified pin.
|
||||||
// that is wired to connect to ground when the button is pressed.
|
|
||||||
//
|
|
||||||
// In the first form, a PushButton is instantiated without specifying
|
|
||||||
// the pin. In this case the pin must be specified in a subsequent call
|
|
||||||
// to init() before the PushButton can be used.
|
|
||||||
//
|
|
||||||
// In the second form, a PushButton is instantiated and initialized with
|
|
||||||
// the specified pin, obviating the need for a separate call to init().
|
|
||||||
//
|
|
||||||
// pin: Pin mumber to which pushbutton connects to ground when pressed
|
|
||||||
|
|
||||||
void init(int pin);
|
|
||||||
|
|
||||||
// Initializes PushButton, if not configured during instantiation.
|
|
||||||
//
|
//
|
||||||
// pin: Pin mumber to which pushbutton connects to ground when pressed
|
// pin: Pin mumber to which pushbutton connects to ground when pressed
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue