COSA
An Object-Oriented Platform for Arduino Programming
Keypad Class Reference

#include <Keypad.hh>

Inheritance diagram for Keypad:
Inheritance graph
Collaboration diagram for Keypad:
Collaboration graph

Classes

class  Key
 

Public Member Functions

 Keypad (Job::Scheduler *scheduler, Board::AnalogPin pin, const uint16_t *map)
 
virtual void on_key_down (uint8_t nr)
 
virtual void on_key_up (uint8_t nr)
 
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 ()
 
Linkagesucc () const
 
Linkagepred () const
 
void attach (Linkage *pred)
 

Protected Member Functions

virtual void run ()
 
virtual void on_event (uint8_t type, uint16_t value)
 

Protected Attributes

Key m_key
 
uint32_t m_period
 
uint32_t m_expires
 
Schedulerm_scheduler
 
Linkagem_succ
 
Linkagem_pred
 

Static Protected Attributes

static const uint16_t SAMPLE_MS = 64
 

Detailed Description

Handling of keypad using resistor net and analog reading. Periodically samples the analog pin and maps to key code. Callback on_key() is called when a key down/up is detected.

Definition at line 33 of file Keypad.hh.

Constructor & Destructor Documentation

Keypad::Keypad ( Job::Scheduler scheduler,
Board::AnalogPin  pin,
const uint16_t *  map 
)
inline

Construct keypad handler with given analog pin and mapping. The mapping should be a decending sequence of thresholds and should be stored in program memory.

Parameters
[in]schedulerperiodic job handler.
[in]pinanalog pin.
[in]mapbetween analog value and key.

Definition at line 43 of file Keypad.hh.

Member Function Documentation

void Linkage::attach ( Linkage pred)
inlineinherited

Attach given linkage as predecessor. Will check and detach if already attached.

Parameters
[in]predlinkage to attach.
Note
atomic

Definition at line 71 of file Linkage.hh.

void Link::detach ( )
inlineinherited

Detach this link. Unlink from any list.

Definition at line 125 of file Linkage.hh.

void Job::expire_after ( uint32_t  time)
inlineinherited

Set expire time relative to latest expire time.

Parameters
[in]timeto add to latest expire time.

Definition at line 111 of file Job.hh.

int32_t Job::expire_after ( ) const
inlineinherited

Get time remaining before expired.

Returns
time.

Definition at line 129 of file Job.hh.

void Job::expire_at ( uint32_t  time)
inlineinherited

Set expire time. Absolute time in scheduler time unit.

Parameters
[in]timeto expire.

Definition at line 102 of file Job.hh.

uint32_t Job::expire_at ( ) const
inlineinherited

Get expire time.

Returns
time.

Definition at line 120 of file Job.hh.

bool Job::is_started ( ) const
inlineinherited

Return true(1) if the job is queued otherwise false(0).

Returns
bool.

Definition at line 149 of file Job.hh.

virtual void Periodic::on_event ( uint8_t  type,
uint16_t  value 
)
inlineprotectedvirtualinherited

Periodic event handler; dispatch the run() function on timeout events and reschedule the periodic job.

Parameters
[in]typethe type of event.
[in]valuethe event value.

Reimplemented from Job.

Definition at line 91 of file Periodic.hh.

virtual void Job::on_expired ( )
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.

Definition at line 185 of file Job.hh.

virtual void Keypad::on_key_down ( uint8_t  nr)
inlinevirtual

Callback method when a key down is detected. Must override.

Parameters
[in]nrkey number (index in map).

Reimplemented in Menu::KeypadController.

Definition at line 53 of file Keypad.hh.

virtual void Keypad::on_key_up ( uint8_t  nr)
inlinevirtual

Callback method when a key up is detected. Default is null function.

Parameters
[in]nrkey number (index in map).

Definition at line 64 of file Keypad.hh.

void Periodic::period ( uint32_t  time)
inlineinherited

Set timeout period.

Parameters
[in]timeperiod of timeout.

Definition at line 57 of file Periodic.hh.

uint32_t Periodic::period ( ) const
inlineinherited

Get timeout period.

Returns
period of timeout.

Definition at line 67 of file Periodic.hh.

Linkage* Linkage::pred ( ) const
inlineinherited

Return predecessor in sequence.

Returns
predecessor linkage.

Definition at line 60 of file Linkage.hh.

void Periodic::reschedule ( )
inlineinherited

Reschedule after a new period.

Definition at line 76 of file Periodic.hh.

void Keypad::run ( )
protectedvirtual

Periodic sampling of analog pin.

Reimplemented from Job.

Definition at line 37 of file Keypad.cpp.

bool Job::start ( )
inlineinherited

Start the job. Returns true(1) if scheduled otherwise false(0).

Returns
bool.

Definition at line 159 of file Job.hh.

bool Job::stop ( )
inlineinherited

Stop the job. Returns true(1) if scheduled otherwise false(0).

Returns
bool.

Definition at line 169 of file Job.hh.

Linkage* Linkage::succ ( ) const
inlineinherited

Return successor in sequence.

Returns
successor linkage.

Definition at line 51 of file Linkage.hh.

uint32_t Job::time ( ) const
inlineinherited

Get current scheduler time. May be used to set relative expire time.

Returns
time.

Definition at line 139 of file Job.hh.

Member Data Documentation

uint32_t Job::m_expires
protectedinherited

Expire time. Scale (us, ms, s) depends on scheduler.

Definition at line 214 of file Job.hh.

Key Keypad::m_key
protected

The key sampler and mapper.

Definition at line 106 of file Keypad.hh.

uint32_t Periodic::m_period
protectedinherited

Time period. Time unit is defined by the scheduler.

Definition at line 100 of file Periodic.hh.

Linkage* Linkage::m_pred
protectedinherited

Definition at line 94 of file Linkage.hh.

Scheduler* Job::m_scheduler
protectedinherited

Job scheduler.

Definition at line 217 of file Job.hh.

Linkage* Linkage::m_succ
protectedinherited

Double linked list pointers.

Definition at line 93 of file Linkage.hh.

const uint16_t Keypad::SAMPLE_MS = 64
staticprotected

Keypad sample rate.

Definition at line 103 of file Keypad.hh.


The documentation for this class was generated from the following files: