Update Utils.h

Added comments for new toggled() functionality
This commit is contained in:
Gregg 2023-01-30 07:56:46 -06:00
parent 1a3887b6cf
commit 232362c807
1 changed files with 27 additions and 18 deletions

View File

@ -100,11 +100,11 @@ class PushButton{
public: public:
enum { enum {
SINGLE=0, SINGLE=0, // applicable only for push button
DOUBLE=1, DOUBLE=1, // applicable only for push button
LONG=2, LONG=2, // applicable only for push button
ON=3, ON=3, // applicable only for toggle switch
OFF=4 OFF=4 // applicable only for toggle switch
}; };
static boolean TRIGGER_ON_LOW(int pin){return(!digitalRead(pin));} static boolean TRIGGER_ON_LOW(int pin){return(!digitalRead(pin));}
@ -120,19 +120,19 @@ class PushButton{
PushButton(int pin, triggerType_t triggerType=TRIGGER_ON_LOW); PushButton(int pin, triggerType_t triggerType=TRIGGER_ON_LOW);
// Creates pushbutton of specified type on specified pin // Creates a push-button/toggle-switch of specified type on specified pin
// //
// pin: pin number to which the button is connected // pin: pin number to which the button is connected
// triggerType: a function of of the form 'boolean f(int)' that is passed // triggerType: a function of of the form 'boolean f(int)' that is passed
// the parameter *pin* and returns TRUE if the button associated // the parameter *pin* and returns TRUE if the button associated
// with *pin* is pressed, or FALSE if not. Can choose from 3 pre-specifed // with *pin* is pressed/on, or FALSE if not. Can choose from 3 pre-specifed
// triggerType_t functions (TRIGGER_ON_LOW, TRIGGER_ON_HIGH, and TRIGGER_ON_TOUCH), or write your // triggerType_t functions (TRIGGER_ON_LOW, TRIGGER_ON_HIGH, and TRIGGER_ON_TOUCH),
// own custom handler // or write your own custom handler
void reset(); void reset();
// Resets state of PushButton. Should be called once before any loops that will // Resets state of PushButton. Should be called once before any loops that will
// repeatedly check the button for a trigger event. // repeatedly check the button for a trigger() event.
boolean triggered(uint16_t singleTime, uint16_t longTime, uint16_t doubleTime=0); boolean triggered(uint16_t singleTime, uint16_t longTime, uint16_t doubleTime=0);
@ -161,7 +161,10 @@ class PushButton{
int type(); int type();
// Returns 0=Single Press, 1=Double Press, or 2=Long Press // Returns the press type based on the whether triggered() or toggled() is called:
// * For a push button, returns the last trigger event: 0=Single Press, 1=Double Press, 2=Long Press
// * For a toggle switch, returns the current state of the switch: 4=ON, 5=OFF
void wait(); void wait();
@ -169,6 +172,12 @@ class PushButton{
boolean toggled(uint16_t toggleTime); boolean toggled(uint16_t toggleTime);
// Returns true if switch has been toggled, where
// toggleTime: the minimum time (in milliseconds) a switch needs to be ON to register a toggle event
// Once toggled() returns true, if will subsequently return false until the switch is toggled again.
int getPin(){return(pin);} int getPin(){return(pin);}
// Returns pin number // Returns pin number