COSA
An Object-Oriented Platform for Arduino Programming
IR.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_IR_HH
22 #define COSA_IR_HH
23 
25 #include "Cosa/Periodic.hh"
26 #include "Cosa/IOStream.hh"
27 
44 class IR {
45 public:
46 
47  class Receiver : private ExternalInterrupt, public Job {
48  public:
53  struct keymap_t {
54  uint16_t code;
55  char key;
56  };
57  typedef const keymap_t* keymap_P;
58 
67  virtual void on_interrupt(uint16_t arg = 0);
68 
69  public:
85  uint8_t max, uint32_t threshold,
86  Job::Scheduler* scheduler,
87  keymap_P keymap = NULL, uint8_t keys = 0,
88  uint16_t* sample = NULL) :
90  Job(scheduler),
91  m_threshold(threshold),
92  m_sample(sample),
93  m_start(0),
94  m_code(0),
95  m_ix(0),
96  m_max(max),
97  m_keymap(keymap),
98  m_keys(keys)
99  {}
100 
104  void reset();
105 
111  int lookup(uint16_t code);
112 
113  private:
114  static const uint16_t TIMEOUT = 512;
115  volatile uint32_t m_threshold;
116  volatile uint16_t* m_sample;
117  volatile uint32_t m_start;
118  volatile uint32_t m_code;
119  volatile uint8_t m_ix;
120  const uint8_t m_max;
121  const keymap_P m_keymap;
122  const uint8_t m_keys;
123 
130  friend IOStream& operator<<(IOStream& outs, Receiver& receiver);
131  };
132 };
133 
134 #endif
135 
virtual void on_interrupt(uint16_t arg=0)
Definition: IR.cpp:26
Definition: IR.hh:44
uint8_t pin() const
Definition: Pin.hh:103
#define NULL
Definition: Types.h:101
Definition: Job.hh:33
int lookup(uint16_t code)
Definition: IR.cpp:80
friend IOStream & operator<<(IOStream &outs, Receiver &receiver)
Definition: IR.cpp:89
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)
Definition: IR.hh:84
const keymap_t * keymap_P
Definition: IR.hh:57
ExternalInterruptPin
Definition: ATmega1284P.hh:190
void reset()
Definition: IR.cpp:65
uint16_t code
Definition: IR.hh:54