Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed_keyboard_manager.cpp
00001 #include "mbed_keyboard_manager.hpp" 00002 #include <iostream> 00003 00004 using namespace kbd_mgr; 00005 00006 namespace { 00007 PinName outPinsArray[4] = { p8, p7, p6, p5 }; 00008 KeyboardMonitor::OutPinsSet outPins(&outPinsArray[0], &outPinsArray[4]); 00009 00010 00011 KeyMap makeKeymap() 00012 { 00013 KeyMap keymap("123A456B789C*0#D"); 00014 keymap(kbd_mgr::KeyEvent::LongKeyPress, 12, '@') 00015 (kbd_mgr::KeyEvent::LongKeyPress, 14, '$'); 00016 return keymap; 00017 } 00018 00019 } 00020 00021 MbedKeyboardManager::MbedKeyboardManager() : 00022 keyMonitor(Port0, 4, 15, outPins), changeMonitor(), keyPressMonitor(), 00023 longKeyPressMonitor(), keyMapper(makeKeymap()) 00024 { 00025 std::cout << "Init Keyboard" << "\r" << std::endl; 00026 longKeyPressMonitor.autoRepeat(0.500,0.250)(0,15); 00027 longKeyPressMonitor.longKeyPress(0.500)(12)(14); 00028 } 00029 00030 void MbedKeyboardManager::attach(KeyHandler *handler) 00031 { 00032 std::cout << "Attach Keyboard" << "\r" << std::endl; 00033 00034 this->handler = handler; 00035 00036 keyMapper.attach(this); 00037 longKeyPressMonitor.attach(keyMapper); 00038 keyPressMonitor.attach(longKeyPressMonitor); 00039 changeMonitor.attach(keyPressMonitor); 00040 keyMonitor.attach(changeMonitor); 00041 00042 keyMonitor.start(); 00043 } 00044 00045 void MbedKeyboardManager::detach() 00046 { 00047 std::cout << "Detach Keyboard" << "\r" << std::endl; 00048 00049 keyMonitor.stop(); 00050 00051 keyMapper.detach(); 00052 longKeyPressMonitor.detach(); 00053 changeMonitor.detach(); 00054 keyMonitor.detach(); 00055 } 00056 00057 void MbedKeyboardManager::handleKeyPress(const KeyEvent &keypress) 00058 { 00059 if (keypress.event != KeyEvent::KeyPress && keypress.event != KeyEvent::RepeatedKeyPress && keypress.event != KeyEvent::LongKeyPress) { 00060 return; 00061 } 00062 00063 if (keypress.keyChar != 0) { 00064 std::cout << "Handle Key '" << keypress.keyChar << "'\r" << std::endl; 00065 this->handler->handleKey(keypress.keyChar); 00066 } 00067 }
Generated on Wed Jul 13 2022 16:23:43 by
1.7.2