KeyboardManager: a class to manage the polling of a switch-matrix keyboard
SingleKeyPressMonitor.cpp@2:eb4cc53ff33d, 2011-01-23 (annotated)
- Committer:
- osmeest
- Date:
- Sun Jan 23 23:15:36 2011 +0000
- Revision:
- 2:eb4cc53ff33d
- Child:
- 3:1310c57aca77
Thorough split of the code to have one responsibility per class. Generalisation of the keyboard layout (not limited to 4x4 anymore). Introduction of the kbd_mgr namespace (also apparent in header filenames).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
osmeest | 2:eb4cc53ff33d | 1 | #include "kbd_mgr/SingleKeyPressMonitor.h" |
osmeest | 2:eb4cc53ff33d | 2 | |
osmeest | 2:eb4cc53ff33d | 3 | namespace kbd_mgr { |
osmeest | 2:eb4cc53ff33d | 4 | |
osmeest | 2:eb4cc53ff33d | 5 | void SingleKeyPressMonitor::operator()(const KeyboardState &newState) |
osmeest | 2:eb4cc53ff33d | 6 | { |
osmeest | 2:eb4cc53ff33d | 7 | int key; |
osmeest | 2:eb4cc53ff33d | 8 | if (newState.getKeyPressType(key) == KeyboardState::SingleKeyPress && this->lastReportedState.empty()) |
osmeest | 2:eb4cc53ff33d | 9 | { |
osmeest | 2:eb4cc53ff33d | 10 | if (this->handler) { |
osmeest | 2:eb4cc53ff33d | 11 | (*this->handler)(key, true); |
osmeest | 2:eb4cc53ff33d | 12 | } |
osmeest | 2:eb4cc53ff33d | 13 | |
osmeest | 2:eb4cc53ff33d | 14 | this->lastReportedState = newState; |
osmeest | 2:eb4cc53ff33d | 15 | this->lastReportedKey = key; |
osmeest | 2:eb4cc53ff33d | 16 | } |
osmeest | 2:eb4cc53ff33d | 17 | else if (!this->lastReportedState.empty() && |
osmeest | 2:eb4cc53ff33d | 18 | (newState & this->lastReportedState).empty()) |
osmeest | 2:eb4cc53ff33d | 19 | { |
osmeest | 2:eb4cc53ff33d | 20 | if (this->handler) { |
osmeest | 2:eb4cc53ff33d | 21 | (*this->handler)(this->lastReportedKey, false); |
osmeest | 2:eb4cc53ff33d | 22 | } |
osmeest | 2:eb4cc53ff33d | 23 | |
osmeest | 2:eb4cc53ff33d | 24 | this->lastReportedState.clear(); |
osmeest | 2:eb4cc53ff33d | 25 | this->lastReportedKey = KeyPressEventHandler::NoKey; |
osmeest | 2:eb4cc53ff33d | 26 | } |
osmeest | 2:eb4cc53ff33d | 27 | |
osmeest | 2:eb4cc53ff33d | 28 | } |
osmeest | 2:eb4cc53ff33d | 29 | |
osmeest | 2:eb4cc53ff33d | 30 | } // kbd_mgr |