COSA
An Object-Oriented Platform for Arduino Programming
Keypad.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_KEYPAD_HH
22 #define COSA_KEYPAD_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/AnalogPin.hh"
26 #include "Cosa/Periodic.hh"
27 
33 class Keypad : public Periodic {
34 public:
43  Keypad(Job::Scheduler* scheduler, Board::AnalogPin pin, const uint16_t* map) :
44  Periodic(scheduler, SAMPLE_MS),
45  m_key(pin, this, map)
46  {}
47 
53  virtual void on_key_down(uint8_t nr)
54  {
55  UNUSED(nr);
56  }
57 
64  virtual void on_key_up(uint8_t nr)
65  {
66  UNUSED(nr);
67  }
68 
69 protected:
74  class Key : public AnalogPin {
75  public:
82  Key(Board::AnalogPin pin, Keypad* keypad, const uint16_t* map) :
83  AnalogPin(pin),
84  m_keypad(keypad),
85  m_map(map),
86  m_latest(0)
87  {}
88 
89  private:
90  Keypad* m_keypad;
91  const uint16_t* m_map;
92  uint8_t m_latest;
93 
99  virtual void on_change(uint16_t value);
100  };
101 
103  static const uint16_t SAMPLE_MS = 64;
104 
107 
112  virtual void run();
113 };
114 
115 #endif
Board::AnalogPin pin() const
Definition: AnalogPin.hh:69
virtual void on_key_up(uint8_t nr)
Definition: Keypad.hh:64
Key m_key
Definition: Keypad.hh:106
Definition: Keypad.hh:33
Keypad(Job::Scheduler *scheduler, Board::AnalogPin pin, const uint16_t *map)
Definition: Keypad.hh:43
virtual void run()
Definition: Keypad.cpp:37
virtual void on_key_down(uint8_t nr)
Definition: Keypad.hh:53
#define UNUSED(x)
Definition: ATmega328P.hh:31
static const uint16_t SAMPLE_MS
Definition: Keypad.hh:103
Key(Board::AnalogPin pin, Keypad *keypad, const uint16_t *map)
Definition: Keypad.hh:82
T map(T x)
Definition: Math.hh:106
uint16_t value() const
Definition: AnalogPin.hh:79