KeyboardManager: a class to manage the polling of a switch-matrix keyboard

Dependents:   KeyboardTest

Committer:
osmeest
Date:
Thu Feb 03 22:01:57 2011 +0000
Revision:
3:1310c57aca77
Parent:
2:eb4cc53ff33d
improve code structure, add key mapping and long key press handling

Who changed what in which revision?

UserRevisionLine numberNew contents of line
osmeest 3:1310c57aca77 1 #include "kbd_mgr/SingleKeyPressMonitor.h"
osmeest 3:1310c57aca77 2
osmeest 3:1310c57aca77 3 namespace kbd_mgr {
osmeest 3:1310c57aca77 4
osmeest 3:1310c57aca77 5 void SingleKeyPressMonitor::handleState(const KeyboardState &newState)
osmeest 3:1310c57aca77 6 {
osmeest 3:1310c57aca77 7 int key;
osmeest 3:1310c57aca77 8 if (newState.getKeyPressType(key) == KeyboardState::SingleKeyPress && this->lastReportedState.empty())
osmeest 3:1310c57aca77 9 {
osmeest 3:1310c57aca77 10 KeyEvent keyDown(key, KeyEvent::KeyDown);
osmeest 3:1310c57aca77 11 invokeHandler(keyDown);
osmeest 3:1310c57aca77 12
osmeest 3:1310c57aca77 13 this->lastReportedState = newState;
osmeest 3:1310c57aca77 14 this->lastReportedKey = key;
osmeest 3:1310c57aca77 15 }
osmeest 3:1310c57aca77 16 else if (!this->lastReportedState.empty() &&
osmeest 3:1310c57aca77 17 (newState & this->lastReportedState).empty())
osmeest 3:1310c57aca77 18 {
osmeest 3:1310c57aca77 19 KeyEvent keyUp(this->lastReportedKey, KeyEvent::KeyUp);
osmeest 3:1310c57aca77 20 invokeHandler(keyUp);
osmeest 3:1310c57aca77 21
osmeest 3:1310c57aca77 22 this->lastReportedState.clear();
osmeest 3:1310c57aca77 23 this->lastReportedKey = KeyEvent::NoKey;
osmeest 3:1310c57aca77 24 }
osmeest 3:1310c57aca77 25
osmeest 3:1310c57aca77 26 }
osmeest 3:1310c57aca77 27
osmeest 2:eb4cc53ff33d 28 } // kbd_mgr