KeyboardTest: a test program for KeyboardManager lib
Dependencies: mbed KeyboardManager
Revision 4:392068d3f56d, committed 2011-02-03
- Comitter:
- osmeest
- Date:
- Thu Feb 03 22:03:24 2011 +0000
- Parent:
- 3:c20e3d23ce5f
- Commit message:
- adapt to latest improvements in the lib
Changed in this revision
KeyboardManager.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c20e3d23ce5f -r 392068d3f56d KeyboardManager.lib --- a/KeyboardManager.lib Sun Jan 23 23:15:56 2011 +0000 +++ b/KeyboardManager.lib Thu Feb 03 22:03:24 2011 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/osmeest/code/KeyboardManager/#eb4cc53ff33d +http://mbed.org/users/osmeest/code/KeyboardManager/#1310c57aca77
diff -r c20e3d23ce5f -r 392068d3f56d main.cpp --- a/main.cpp Sun Jan 23 23:15:56 2011 +0000 +++ b/main.cpp Thu Feb 03 22:03:24 2011 +0000 @@ -5,25 +5,61 @@ using namespace std; using namespace kbd_mgr; -class KeyHandler : public KeyPressEventHandler { -public: - virtual void operator()(int key, bool state) { - cout << "Key state change: " << key << " " << (state ? "Down" : "Up") << "\r" << endl; +void handleKeyPress(const KeyEvent &keypress) { + char ch = (keypress.keyChar >= 32 && keypress.keyChar < 127 ? keypress.keyChar : '?'); + + std::string eventName; + switch (keypress.event) { + case KeyEvent::KeyDown: + eventName = "Down"; + break; + case KeyEvent::KeyUp: + eventName = "Up"; + break; + case KeyEvent::KeyPress: + eventName = "Press"; + break; + case KeyEvent::RepeatedKeyPress: + eventName = "RepeatedPress"; + break; + case KeyEvent::LongKeyPress: + eventName = "LongPress"; + break; + default: + eventName = "???"; + break; } -}; + + cout << "Key state change: " << keypress.keyCode << " '" << ch << "' " << eventName << "\r" << endl; +} int main() { cout << "\n\r\nKeyboardTest " __DATE__ "-" __TIME__ "\r" << endl; PinName outPinsArray[] = { p8, p7, p6, p5 }; - KeyboardManager::OutPinsSet outPins(&outPinsArray[0], &outPinsArray[4]); - KeyHandler handler; + KeyboardMonitor::OutPinsSet outPins(&outPinsArray[0], &outPinsArray[4]); + + KeyMap keyMap("123A456B789C*0#D"); + keyMap(KeyEvent::LongKeyPress, 12, '@')(KeyEvent::LongKeyPress, 14, '$'); + + KeyboardMonitor kbdMonitor(Port0, 4, 15, outPins); + KeyboardStateChangeMonitor changeMonitor; + SingleKeyPressMonitor keyPressMonitor; + LongKeyPressMonitor longKeyPressMonitor; + KeyMapper keyMapper(keyMap); - KeyboardManager kbd(Port0, 4, 15, outPins, &handler); + longKeyPressMonitor.autoRepeat(0.500,0.250)(0,15); + longKeyPressMonitor.longKeyPress(0.500)(12)(14); - kbd.start(); - - while(1) { + keyMapper.attach(handleKeyPress); + longKeyPressMonitor.attach(keyMapper); + keyPressMonitor.attach(longKeyPressMonitor); + changeMonitor.attach(keyPressMonitor); + kbdMonitor.attach(changeMonitor); + + kbdMonitor.start(); + + while (1) { wait(10); } }