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
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 #ifndef KEYPRESS_EVENT_SERVER_H_
osmeest 3:1310c57aca77 2 #define KEYPRESS_EVENT_SERVER_H_
osmeest 3:1310c57aca77 3
osmeest 3:1310c57aca77 4 #include "kbd_mgr/KeyboardEventServer.h"
osmeest 3:1310c57aca77 5 #include "kbd_mgr/KeyPressEventHandler.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 base class for monitors that report keypresses.
osmeest 3:1310c57aca77 11 */
osmeest 3:1310c57aca77 12 class KeyPressEventServer : public KeyboardEventServer<KeyPressEventHandler> {
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(FunctionKeyPressEventHandler::HandlerFunction fn) {
osmeest 3:1310c57aca77 19 setHandler(new FunctionKeyPressEventHandler(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 MemberKeyPressEventHandler<T>::MemberFunction fn) {
osmeest 3:1310c57aca77 29 setHandler(new MemberKeyPressEventHandler<T>(obj, fn));
osmeest 3:1310c57aca77 30 }
osmeest 3:1310c57aca77 31
osmeest 3:1310c57aca77 32 using KeyboardEventServer<KeyPressEventHandler>::attach;
osmeest 3:1310c57aca77 33
osmeest 3:1310c57aca77 34 void invokeHandler(const KeyEvent &keypress) {
osmeest 3:1310c57aca77 35 if (this->hasHandler()) {
osmeest 3:1310c57aca77 36 this->handler()->handleKeyPress(keypress);
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 // KEYPRESS_EVENT_SERVER_H_