COSA
An Object-Oriented Platform for Arduino Programming
IR::Receiver Class Reference

#include <IR.hh>

Inheritance diagram for IR::Receiver:
Inheritance graph
Collaboration diagram for IR::Receiver:
Collaboration graph

Classes

struct  keymap_t
 

Public Types

typedef const keymap_tkeymap_P
 

Public Member Functions

virtual void on_interrupt (uint16_t arg=0)
 
 Receiver (Board::ExternalInterruptPin pin, uint8_t max, uint32_t threshold, Job::Scheduler *scheduler, keymap_P keymap=NULL, uint8_t keys=0, uint16_t *sample=NULL)
 
void reset ()
 
int lookup (uint16_t code)
 
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 ()
 
virtual void on_event (uint8_t type, uint16_t value)
 
virtual void run ()
 
void detach ()
 
Linkagesucc () const
 
Linkagepred () const
 
void attach (Linkage *pred)
 

Protected Attributes

uint32_t m_expires
 
Schedulerm_scheduler
 
Linkagem_succ
 
Linkagem_pred
 

Private Types

enum  InterruptMode { ON_LOW_LEVEL_MODE = 0, ON_CHANGE_MODE = _BV(ISC00), ON_FALLING_MODE = _BV(ISC01), ON_RISING_MODE = (_BV(ISC01) | _BV(ISC00)) }
 
enum  Mode { OUTPUT_MODE = 0, INPUT_MODE = 1 }
 
enum  Direction { MSB_FIRST = 0, LSB_FIRST = 1 }
 

Private Member Functions

virtual void enable ()
 
virtual void disable ()
 
virtual void clear ()
 
void clear () const
 
void mode (Mode mode)
 
Mode mode () const
 
void _set () const
 
void _set (int value) const
 
void set () const
 
void set (int value) const
 
void high () const
 
void on () const
 
void _clear () const
 
void low () const
 
void off () const
 
void _toggle () const
 
void toggle () const
 
void _write (int value) const
 
void write (int value) const
 
void write (uint8_t value, OutputPin &clk, Direction order=MSB_FIRST) const
 
void write (uint16_t value, uint8_t bits, uint16_t us) const
 
OutputPinoperator<< (int value)
 
void pulse (uint16_t us) const
 
volatile uint8_t * PIN () const
 
volatile uint8_t * DDR () const
 
volatile uint8_t * PORT () 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
 
Pinoperator>> (uint8_t &var)
 
volatile uint8_t * PCIMR () const
 

Static Private Member Functions

static void mode (Board::DigitalPin pin, Mode mode)
 
static Mode mode (Board::DigitalPin pin)
 
static void mode (Board::DigitalPin pin, uint8_t initial=0)
 
static void toggle (Board::DigitalPin pin)
 
static void _write (Board::DigitalPin pin, uint8_t value)
 
static void write (Board::DigitalPin pin, int value)
 
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)
 

Private Attributes

volatile uint8_t *const m_sfr
 
const uint8_t m_mask
 
const uint8_t m_pin
 

Friends

IOStreamoperator<< (IOStream &outs, Receiver &receiver)
 

Detailed Description

Definition at line 47 of file IR.hh.

Member Typedef Documentation

Definition at line 57 of file IR.hh.

Constructor & Destructor Documentation

IR::Receiver::Receiver ( Board::ExternalInterruptPin  pin,
uint8_t  max,
uint32_t  threshold,
Job::Scheduler scheduler,
keymap_P  keymap = NULL,
uint8_t  keys = 0,
uint16_t *  sample = NULL 
)
inline

Construct an IR::Receiver connected to the given interrupt pin, capture given max number of samples, and decode to binary with the given threshold. A key map may be provided; pointer to vector in program memory and size of vector. To collect the time period samples provide a storage vector.

Parameters
[in]pininterrupt pin (Board::EXTn).
[in]maxnumber of samples.
[in]thresholdlevel for mapping to binary.
[in]schedulerfor timeout.
[in]keymapmapping table from code to key.
[in]keysnumber of members in keymap.
[in]samplevector for samples[max].

Definition at line 84 of file IR.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.

int IR::Receiver::lookup ( uint16_t  code)

Lookup given code and return key or EOF(-1).

Parameters
[in]codeto lookup in key map.
Returns
key or EOF(-1).

Definition at line 80 of file IR.cpp.

virtual void Job::on_event ( uint8_t  type,
uint16_t  value 
)
inlinevirtualinherited

Default job event handler; execute the run() virtual member function on timeout event. Event is pushed by on_expired().

Parameters
[in]typethe type of event (Typically TIMEOUT_TYPE).
[in]valuethe event value.

Reimplemented from Event::Handler.

Reimplemented in ProtoThread, and Periodic.

Definition at line 197 of file Job.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.

void IR::Receiver::on_interrupt ( uint16_t  arg = 0)
virtual

Interrupt pin handler: Measure time periods of pulses in sequence from IR receiver circuit. Push an event when a full sequence has been recieved; READ_COMPLETED(this, code) where the code is the recieved binary code or key if a key map was provided.

Parameters
[in]argargument from interrupt service routine.

Reimplemented from ExternalInterrupt.

Definition at line 26 of file IR.cpp.

Linkage* Linkage::pred ( ) const
inlineinherited

Return predecessor in sequence.

Returns
predecessor linkage.

Definition at line 60 of file Linkage.hh.

void IR::Receiver::reset ( )

Reset the receiver for the next code sequence.

Definition at line 65 of file IR.cpp.

virtual void Job::run ( )
inlinevirtualinherited

The job run() virtual member function; sub-class should define. Called by the scheduler (via event handler) when the time expires. May set an new expire time and start the job again, or even start other jobs.

Reimplemented in Button, Keypad, and Touch.

Definition at line 210 of file Job.hh.

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.

Friends And Related Function Documentation

IOStream& operator<< ( IOStream outs,
IR::Receiver receiver 
)
friend

Print the captured samples to the given output stream.

Parameters
[in]outsstream.
[in]receiversamples to print.
Returns
iostream.

Definition at line 89 of file IR.cpp.

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.

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.


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