COSA
An Object-Oriented Platform for Arduino Programming
|
#include <Button.hh>
Public Types | |
enum | Mode { ON_FALLING_MODE = 0, ON_RISING_MODE = 1, ON_CHANGE_MODE = 2 } |
enum | Direction { MSB_FIRST = 0, LSB_FIRST = 1 } |
Public Member Functions | |
Button (Job::Scheduler *scheduler, Board::DigitalPin pin, Mode mode=ON_CHANGE_MODE) | |
virtual void | on_change (uint8_t type)=0 |
Mode | mode () const |
uint8_t | pin () const |
bool | is_set () const |
bool | is_high () const |
bool | is_on () const |
bool | is_clear () const |
bool | is_low () const |
bool | is_off () const |
bool | read () const |
uint8_t | read (OutputPin &clk, Direction order=MSB_FIRST) const |
operator bool () const | |
Pin & | operator>> (uint8_t &var) |
void | period (uint32_t time) |
uint32_t | period () const |
void | reschedule () |
void | expire_at (uint32_t time) |
uint32_t | expire_at () const |
void | expire_after (uint32_t time) |
int32_t | expire_after () const |
uint32_t | time () const |
bool | is_started () const |
bool | start () |
bool | stop () |
virtual void | on_expired () |
void | detach () |
Linkage * | succ () const |
Linkage * | pred () const |
void | attach (Linkage *pred) |
Static Public Member Functions | |
static void | mode (Board::DigitalPin pin, Mode mode) |
static Mode | mode (Board::DigitalPin pin) |
static uint8_t | MASK (uint8_t pin) |
static volatile uint8_t * | PIN (uint8_t pin) |
static volatile uint8_t * | DDR (uint8_t pin) |
static volatile uint8_t * | PORT (uint8_t pin) |
static bool | read (Board::DigitalPin pin) |
Protected Member Functions | |
virtual void | run () |
volatile uint8_t * | PIN () const |
volatile uint8_t * | DDR () const |
volatile uint8_t * | PORT () const |
volatile uint8_t * | PCIMR () const |
virtual void | on_event (uint8_t type, uint16_t value) |
Protected Attributes | |
const Mode | MODE |
uint8_t | m_state |
volatile uint8_t *const | m_sfr |
const uint8_t | m_mask |
const uint8_t | m_pin |
uint32_t | m_period |
uint32_t | m_expires |
Scheduler * | m_scheduler |
Linkage * | m_succ |
Linkage * | m_pred |
Static Protected Attributes | |
static const uint16_t | SAMPLE_MS = 64 |
Debounded Button; Sampled input pin (with internal pullup resistor). Uses a periodic function with timout of 64 ms for sampling and on change calls an event action. Subclass Button and implement the virtual on_change() method. Use the subclass for any state needed for the action function. Connect button/switch from pin to ground. Internal pull-up resistor is activated.
Button toggle faster than sample period may be missed. This is the case when connecting to a Rotary Encoder.
The Button event handler requires the usage of an event dispatch or implementing the virtual member function Job::on_expired() to call run() and reschedule(). See Event.hh.
|
inherited |
enum Button::Mode |
|
inline |
Construct a button connected to the given pin and with the given change detection mode. The scheduler should allow periodic jobs with a time unit of milli-seconds (e.g. Watchdog::Scheduler).
[in] | scheduler | for periodic job. |
[in] | pin | number. |
[in] | mode | change detection mode. |
|
inlineinherited |
Attach given linkage as predecessor. Will check and detach if already attached.
[in] | pred | linkage to attach. |
Definition at line 71 of file Linkage.hh.
|
inlinestaticinherited |
|
inlineprotectedinherited |
|
inlineinherited |
Detach this link. Unlink from any list.
Definition at line 125 of file Linkage.hh.
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlinestaticinherited |
|
inlineinherited |
|
inlinestaticinherited |
Set input pin to given mode.
[in] | pin | number. |
[in] | mode | pin mode. |
Definition at line 64 of file InputPin.hh.
|
inlinestaticinherited |
Get input pin mode.
[in] | pin | number. |
Definition at line 80 of file InputPin.hh.
|
pure virtual |
The button change handler. Called when a change corresponding to the mode has been detected. Event types are; Event::FALLING_TYPE, Event::RISING_TYPE, and Event::CHANGE_TYPE. Sub-class must override this method.
[in] | type | event type. |
|
inlineprotectedvirtualinherited |
Periodic event handler; dispatch the run() function on timeout events and reschedule the periodic job.
[in] | type | the type of event. |
[in] | value | the event value. |
Reimplemented from Job.
Definition at line 91 of file Periodic.hh.
|
inlinevirtualinherited |
Job member function that is called Scheduler::dispatch() when the job time has expired. This function is normally called from an interrupt service routine. The default implementation will push a timeout event with the job as target. The default event handler will call the job run() virtual member function. Override this function if the job should be executed during the interrupt service routine.
|
inlineinherited |
|
inlineinherited |
|
inlineprotectedinherited |
|
inlineinherited |
Set timeout period.
[in] | time | period of timeout. |
Definition at line 57 of file Periodic.hh.
|
inlineinherited |
|
inlinestaticinherited |
|
inlineinherited |
|
inlineprotectedinherited |
|
inlinestaticinherited |
|
inlineprotectedinherited |
|
inlineinherited |
Return predecessor in sequence.
Definition at line 60 of file Linkage.hh.
|
inlineinherited |
|
inlinestaticinherited |
|
inlineinherited |
Reschedule after a new period.
Definition at line 76 of file Periodic.hh.
|
inlineprotectedvirtual |
Button periodic function. Called by job scheduler on timeout. Samples the attached pin and calls the pin change handler, on_change().
Reimplemented from Job.
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
Time period. Time unit is defined by the scheduler.
Definition at line 100 of file Periodic.hh.
|
protectedinherited |
Definition at line 94 of file Linkage.hh.
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
Double linked list pointers.
Definition at line 93 of file Linkage.hh.
|
staticprotected |