KeyboardManager: a class to manage the polling of a switch-matrix keyboard
Diff: SingleKeyPressMonitor.cpp
- Revision:
- 3:1310c57aca77
- Parent:
- 2:eb4cc53ff33d
diff -r eb4cc53ff33d -r 1310c57aca77 SingleKeyPressMonitor.cpp --- a/SingleKeyPressMonitor.cpp Sun Jan 23 23:15:36 2011 +0000 +++ b/SingleKeyPressMonitor.cpp Thu Feb 03 22:01:57 2011 +0000 @@ -1,30 +1,28 @@ -#include "kbd_mgr/SingleKeyPressMonitor.h" - -namespace kbd_mgr { - -void SingleKeyPressMonitor::operator()(const KeyboardState &newState) -{ - int key; - if (newState.getKeyPressType(key) == KeyboardState::SingleKeyPress && this->lastReportedState.empty()) - { - if (this->handler) { - (*this->handler)(key, true); - } - - this->lastReportedState = newState; - this->lastReportedKey = key; - } - else if (!this->lastReportedState.empty() && - (newState & this->lastReportedState).empty()) - { - if (this->handler) { - (*this->handler)(this->lastReportedKey, false); - } - - this->lastReportedState.clear(); - this->lastReportedKey = KeyPressEventHandler::NoKey; - } - -} - +#include "kbd_mgr/SingleKeyPressMonitor.h" + +namespace kbd_mgr { + +void SingleKeyPressMonitor::handleState(const KeyboardState &newState) +{ + int key; + if (newState.getKeyPressType(key) == KeyboardState::SingleKeyPress && this->lastReportedState.empty()) + { + KeyEvent keyDown(key, KeyEvent::KeyDown); + invokeHandler(keyDown); + + this->lastReportedState = newState; + this->lastReportedKey = key; + } + else if (!this->lastReportedState.empty() && + (newState & this->lastReportedState).empty()) + { + KeyEvent keyUp(this->lastReportedKey, KeyEvent::KeyUp); + invokeHandler(keyUp); + + this->lastReportedState.clear(); + this->lastReportedKey = KeyEvent::NoKey; + } + +} + } // kbd_mgr \ No newline at end of file