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 "system_states.hpp"
osmeest 0:1324e7d9d471 2 #include "system.hpp"
osmeest 0:1324e7d9d471 3 #include "display_manager.hpp"
osmeest 0:1324e7d9d471 4
osmeest 0:1324e7d9d471 5 const char *statusMsg[] = {
osmeest 0:1324e7d9d471 6 //234567890123456
osmeest 0:1324e7d9d471 7 "Cmd: [5]Help",
osmeest 0:1324e7d9d471 8 "Cmd: [0]Send",
osmeest 0:1324e7d9d471 9 "Cmd: 1<-4-+-6->3",
osmeest 0:1324e7d9d471 10 "Cmd: [7]BS[8]Del",
osmeest 0:1324e7d9d471 11 "Cmd: [9]Clear",
osmeest 0:1324e7d9d471 12 "Cmd: <*>Edit",
osmeest 0:1324e7d9d471 13 NULL
osmeest 0:1324e7d9d471 14 };
osmeest 0:1324e7d9d471 15
osmeest 0:1324e7d9d471 16 enum {
osmeest 0:1324e7d9d471 17 HelpTimeout = 2
osmeest 0:1324e7d9d471 18 };
osmeest 0:1324e7d9d471 19
osmeest 0:1324e7d9d471 20 void CommandState::enterState() {
osmeest 0:1324e7d9d471 21 DisplayManager *display = system()->display();
osmeest 0:1324e7d9d471 22 display->hideCursor();
osmeest 0:1324e7d9d471 23 showStatusMsg(0);
osmeest 0:1324e7d9d471 24 updateText();
osmeest 0:1324e7d9d471 25 }
osmeest 0:1324e7d9d471 26
osmeest 0:1324e7d9d471 27 void CommandState::exitState() {
osmeest 0:1324e7d9d471 28 this->statusMsgTimeout.detach();
osmeest 0:1324e7d9d471 29 }
osmeest 0:1324e7d9d471 30
osmeest 0:1324e7d9d471 31 void CommandState::handleKey(char key)
osmeest 0:1324e7d9d471 32 {
osmeest 0:1324e7d9d471 33 switch(key) {
osmeest 0:1324e7d9d471 34 case '5':
osmeest 0:1324e7d9d471 35 handleHelp(); break;
osmeest 0:1324e7d9d471 36 case '1':
osmeest 0:1324e7d9d471 37 handleHome(); break;
osmeest 0:1324e7d9d471 38 case '3':
osmeest 0:1324e7d9d471 39 handleEnd(); break;
osmeest 0:1324e7d9d471 40 case '4':
osmeest 0:1324e7d9d471 41 handleLeft(); break;
osmeest 0:1324e7d9d471 42 case '6':
osmeest 0:1324e7d9d471 43 handleRight(); break;
osmeest 0:1324e7d9d471 44 case '7':
osmeest 0:1324e7d9d471 45 handleBackSpace(); break;
osmeest 0:1324e7d9d471 46 case '8':
osmeest 0:1324e7d9d471 47 handleDelete(); break;
osmeest 0:1324e7d9d471 48 case '9':
osmeest 0:1324e7d9d471 49 handleClear(); break;
osmeest 0:1324e7d9d471 50 case '0':
osmeest 0:1324e7d9d471 51 handleSend(); break;
osmeest 0:1324e7d9d471 52 case '@':
osmeest 0:1324e7d9d471 53 system()->setState(System::Edit);
osmeest 0:1324e7d9d471 54 break;
osmeest 0:1324e7d9d471 55 default:
osmeest 0:1324e7d9d471 56 break;
osmeest 0:1324e7d9d471 57 }
osmeest 0:1324e7d9d471 58 }
osmeest 0:1324e7d9d471 59
osmeest 0:1324e7d9d471 60 void CommandState::handleHome() const {
osmeest 0:1324e7d9d471 61 system()->moveCursorTo(0);
osmeest 0:1324e7d9d471 62 updateCursor();
osmeest 0:1324e7d9d471 63 }
osmeest 0:1324e7d9d471 64
osmeest 0:1324e7d9d471 65 void CommandState::handleEnd() const {
osmeest 0:1324e7d9d471 66 system()->moveCursorTo(-1);
osmeest 0:1324e7d9d471 67 updateCursor();
osmeest 0:1324e7d9d471 68 }
osmeest 0:1324e7d9d471 69
osmeest 0:1324e7d9d471 70 void CommandState::handleLeft() const {
osmeest 0:1324e7d9d471 71 system()->moveCursorBy(-1);
osmeest 0:1324e7d9d471 72 updateCursor();
osmeest 0:1324e7d9d471 73 }
osmeest 0:1324e7d9d471 74
osmeest 0:1324e7d9d471 75 void CommandState::handleRight() const {
osmeest 0:1324e7d9d471 76 system()->moveCursorBy(+1);
osmeest 0:1324e7d9d471 77 updateCursor();
osmeest 0:1324e7d9d471 78 }
osmeest 0:1324e7d9d471 79
osmeest 0:1324e7d9d471 80 void CommandState::handleDelete() const {
osmeest 0:1324e7d9d471 81 system()->deleteCurrentSymbol();
osmeest 0:1324e7d9d471 82 updateText();
osmeest 0:1324e7d9d471 83 }
osmeest 0:1324e7d9d471 84
osmeest 0:1324e7d9d471 85 void CommandState::handleBackSpace() const {
osmeest 0:1324e7d9d471 86 system()->moveCursorBy(-1);
osmeest 0:1324e7d9d471 87 system()->deleteCurrentSymbol();
osmeest 0:1324e7d9d471 88 updateText();
osmeest 0:1324e7d9d471 89 }
osmeest 0:1324e7d9d471 90
osmeest 0:1324e7d9d471 91 void CommandState::handleClear() const {
osmeest 0:1324e7d9d471 92 system()->clearText();
osmeest 0:1324e7d9d471 93 updateText();
osmeest 0:1324e7d9d471 94 }
osmeest 0:1324e7d9d471 95
osmeest 0:1324e7d9d471 96 void CommandState::handleSend() const {
osmeest 0:1324e7d9d471 97 if (system()->text_size() > 0) {
osmeest 0:1324e7d9d471 98 system()->setState(System::Sending);
osmeest 0:1324e7d9d471 99 }
osmeest 0:1324e7d9d471 100 }
osmeest 0:1324e7d9d471 101
osmeest 0:1324e7d9d471 102 void CommandState::handleHelp() {
osmeest 0:1324e7d9d471 103 this->statusMsgTimeout.detach();
osmeest 0:1324e7d9d471 104 showNextStatusMsg();
osmeest 0:1324e7d9d471 105 }
osmeest 0:1324e7d9d471 106
osmeest 0:1324e7d9d471 107 void CommandState::showNextStatusMsg() {
osmeest 0:1324e7d9d471 108 int msg = this->statusMsgIndex+1;
osmeest 0:1324e7d9d471 109 if (statusMsg[msg] == NULL) {
osmeest 0:1324e7d9d471 110 msg = 0;
osmeest 0:1324e7d9d471 111 }
osmeest 0:1324e7d9d471 112 showStatusMsg(msg);
osmeest 0:1324e7d9d471 113 }
osmeest 0:1324e7d9d471 114
osmeest 0:1324e7d9d471 115 void CommandState::showStatusMsg(int index) {
osmeest 0:1324e7d9d471 116 this->statusMsgIndex = index;
osmeest 0:1324e7d9d471 117 DisplayManager *display = system()->display();
osmeest 0:1324e7d9d471 118 display->writeStatus(statusMsg[index]);
osmeest 0:1324e7d9d471 119 this->statusMsgTimeout.attach(this, &CommandState::showNextStatusMsg, HelpTimeout * 1.0);
osmeest 0:1324e7d9d471 120 }