KeyboardManager: a class to manage the polling of a switch-matrix keyboard
kbd_mgr/KeyboardStateEventServer.h@3:1310c57aca77, 2011-02-03 (annotated)
- Committer:
- osmeest
- Date:
- Thu Feb 03 22:01:57 2011 +0000
- Revision:
- 3:1310c57aca77
improve code structure, add key mapping and long key press handling
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
osmeest | 3:1310c57aca77 | 1 | #ifndef KEYBOARD_STATE_EVENT_SERVER_H_ |
osmeest | 3:1310c57aca77 | 2 | #define KEYBOARD_STATE_EVENT_SERVER_H_ |
osmeest | 3:1310c57aca77 | 3 | |
osmeest | 3:1310c57aca77 | 4 | #include "kbd_mgr/KeyboardEventServer.h" |
osmeest | 3:1310c57aca77 | 5 | #include "kbd_mgr/KeyboardStateHandler.h" |
osmeest | 3:1310c57aca77 | 6 | |
osmeest | 3:1310c57aca77 | 7 | namespace kbd_mgr { |
osmeest | 3:1310c57aca77 | 8 | |
osmeest | 3:1310c57aca77 | 9 | /** |
osmeest | 3:1310c57aca77 | 10 | * @brief A keyboard state handler that reports only state changes. |
osmeest | 3:1310c57aca77 | 11 | */ |
osmeest | 3:1310c57aca77 | 12 | class KeyboardStateEventServer : public KeyboardEventServer<KeyboardStateHandler> { |
osmeest | 3:1310c57aca77 | 13 | public: |
osmeest | 3:1310c57aca77 | 14 | /** |
osmeest | 3:1310c57aca77 | 15 | * @brief Attaches the monitor to a function. |
osmeest | 3:1310c57aca77 | 16 | * @param fn Event handler called to report keyboard state change. |
osmeest | 3:1310c57aca77 | 17 | */ |
osmeest | 3:1310c57aca77 | 18 | void attach(FunctionKeyboardStateHandler::HandlerFunction fn) { |
osmeest | 3:1310c57aca77 | 19 | setHandler(new FunctionKeyboardStateHandler(fn)); |
osmeest | 3:1310c57aca77 | 20 | } |
osmeest | 3:1310c57aca77 | 21 | |
osmeest | 3:1310c57aca77 | 22 | /** |
osmeest | 3:1310c57aca77 | 23 | * @brief Attaches the monitor to a method of an object. |
osmeest | 3:1310c57aca77 | 24 | * @param obj Event handler object |
osmeest | 3:1310c57aca77 | 25 | * @param fn Event handler method called to report keyboard state after each complete scan. |
osmeest | 3:1310c57aca77 | 26 | */ |
osmeest | 3:1310c57aca77 | 27 | template <class T> |
osmeest | 3:1310c57aca77 | 28 | void attach(T *obj, typename MemberKeyboardStateHandler<T>::MemberFunction fn) { |
osmeest | 3:1310c57aca77 | 29 | setHandler(new MemberKeyboardStateHandler<T>(obj, fn)); |
osmeest | 3:1310c57aca77 | 30 | } |
osmeest | 3:1310c57aca77 | 31 | |
osmeest | 3:1310c57aca77 | 32 | using KeyboardEventServer<KeyboardStateHandler>::attach; |
osmeest | 3:1310c57aca77 | 33 | |
osmeest | 3:1310c57aca77 | 34 | void invokeHandler(const KeyboardState &state) { |
osmeest | 3:1310c57aca77 | 35 | if (this->hasHandler()) { |
osmeest | 3:1310c57aca77 | 36 | this->handler()->handleState(state); |
osmeest | 3:1310c57aca77 | 37 | } |
osmeest | 3:1310c57aca77 | 38 | } |
osmeest | 3:1310c57aca77 | 39 | }; |
osmeest | 3:1310c57aca77 | 40 | |
osmeest | 3:1310c57aca77 | 41 | } // kbd_mgr |
osmeest | 3:1310c57aca77 | 42 | |
osmeest | 3:1310c57aca77 | 43 | #endif // KEYBOARD_STATE_EVENT_SERVER_H_ |