A DTMF sequence editor and player for HAM radio equipment command & control.

Dependencies:   mbed ExtTextLCD

Committer:
osmeest
Date:
Mon Mar 07 22:51:19 2011 +0000
Revision:
0:1324e7d9d471

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
osmeest 0:1324e7d9d471 1 #include "mbed_keyboard_manager.hpp"
osmeest 0:1324e7d9d471 2 #include <iostream>
osmeest 0:1324e7d9d471 3
osmeest 0:1324e7d9d471 4 using namespace kbd_mgr;
osmeest 0:1324e7d9d471 5
osmeest 0:1324e7d9d471 6 namespace {
osmeest 0:1324e7d9d471 7 PinName outPinsArray[4] = { p8, p7, p6, p5 };
osmeest 0:1324e7d9d471 8 KeyboardMonitor::OutPinsSet outPins(&outPinsArray[0], &outPinsArray[4]);
osmeest 0:1324e7d9d471 9
osmeest 0:1324e7d9d471 10
osmeest 0:1324e7d9d471 11 KeyMap makeKeymap()
osmeest 0:1324e7d9d471 12 {
osmeest 0:1324e7d9d471 13 KeyMap keymap("123A456B789C*0#D");
osmeest 0:1324e7d9d471 14 keymap(kbd_mgr::KeyEvent::LongKeyPress, 12, '@')
osmeest 0:1324e7d9d471 15 (kbd_mgr::KeyEvent::LongKeyPress, 14, '$');
osmeest 0:1324e7d9d471 16 return keymap;
osmeest 0:1324e7d9d471 17 }
osmeest 0:1324e7d9d471 18
osmeest 0:1324e7d9d471 19 }
osmeest 0:1324e7d9d471 20
osmeest 0:1324e7d9d471 21 MbedKeyboardManager::MbedKeyboardManager() :
osmeest 0:1324e7d9d471 22 keyMonitor(Port0, 4, 15, outPins), changeMonitor(), keyPressMonitor(),
osmeest 0:1324e7d9d471 23 longKeyPressMonitor(), keyMapper(makeKeymap())
osmeest 0:1324e7d9d471 24 {
osmeest 0:1324e7d9d471 25 std::cout << "Init Keyboard" << "\r" << std::endl;
osmeest 0:1324e7d9d471 26 longKeyPressMonitor.autoRepeat(0.500,0.250)(0,15);
osmeest 0:1324e7d9d471 27 longKeyPressMonitor.longKeyPress(0.500)(12)(14);
osmeest 0:1324e7d9d471 28 }
osmeest 0:1324e7d9d471 29
osmeest 0:1324e7d9d471 30 void MbedKeyboardManager::attach(KeyHandler *handler)
osmeest 0:1324e7d9d471 31 {
osmeest 0:1324e7d9d471 32 std::cout << "Attach Keyboard" << "\r" << std::endl;
osmeest 0:1324e7d9d471 33
osmeest 0:1324e7d9d471 34 this->handler = handler;
osmeest 0:1324e7d9d471 35
osmeest 0:1324e7d9d471 36 keyMapper.attach(this);
osmeest 0:1324e7d9d471 37 longKeyPressMonitor.attach(keyMapper);
osmeest 0:1324e7d9d471 38 keyPressMonitor.attach(longKeyPressMonitor);
osmeest 0:1324e7d9d471 39 changeMonitor.attach(keyPressMonitor);
osmeest 0:1324e7d9d471 40 keyMonitor.attach(changeMonitor);
osmeest 0:1324e7d9d471 41
osmeest 0:1324e7d9d471 42 keyMonitor.start();
osmeest 0:1324e7d9d471 43 }
osmeest 0:1324e7d9d471 44
osmeest 0:1324e7d9d471 45 void MbedKeyboardManager::detach()
osmeest 0:1324e7d9d471 46 {
osmeest 0:1324e7d9d471 47 std::cout << "Detach Keyboard" << "\r" << std::endl;
osmeest 0:1324e7d9d471 48
osmeest 0:1324e7d9d471 49 keyMonitor.stop();
osmeest 0:1324e7d9d471 50
osmeest 0:1324e7d9d471 51 keyMapper.detach();
osmeest 0:1324e7d9d471 52 longKeyPressMonitor.detach();
osmeest 0:1324e7d9d471 53 changeMonitor.detach();
osmeest 0:1324e7d9d471 54 keyMonitor.detach();
osmeest 0:1324e7d9d471 55 }
osmeest 0:1324e7d9d471 56
osmeest 0:1324e7d9d471 57 void MbedKeyboardManager::handleKeyPress(const KeyEvent &keypress)
osmeest 0:1324e7d9d471 58 {
osmeest 0:1324e7d9d471 59 if (keypress.event != KeyEvent::KeyPress && keypress.event != KeyEvent::RepeatedKeyPress && keypress.event != KeyEvent::LongKeyPress) {
osmeest 0:1324e7d9d471 60 return;
osmeest 0:1324e7d9d471 61 }
osmeest 0:1324e7d9d471 62
osmeest 0:1324e7d9d471 63 if (keypress.keyChar != 0) {
osmeest 0:1324e7d9d471 64 std::cout << "Handle Key '" << keypress.keyChar << "'\r" << std::endl;
osmeest 0:1324e7d9d471 65 this->handler->handleKey(keypress.keyChar);
osmeest 0:1324e7d9d471 66 }
osmeest 0:1324e7d9d471 67 }