Olivier Smeesters
/
DtmfKit
A DTMF sequence editor and player for HAM radio equipment command & control.
system_states.hpp@0:1324e7d9d471, 2011-03-07 (annotated)
- Committer:
- osmeest
- Date:
- Mon Mar 07 22:51:19 2011 +0000
- Revision:
- 0:1324e7d9d471
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
osmeest | 0:1324e7d9d471 | 1 | #ifndef _SYSTEM_STATES_HPP |
osmeest | 0:1324e7d9d471 | 2 | #define _SYSTEM_STATES_HPP |
osmeest | 0:1324e7d9d471 | 3 | |
osmeest | 0:1324e7d9d471 | 4 | #include "state.hpp" |
osmeest | 0:1324e7d9d471 | 5 | #include "system.hpp" // for System::StateId |
osmeest | 0:1324e7d9d471 | 6 | |
osmeest | 0:1324e7d9d471 | 7 | #include "mbed.h" // for Timeout |
osmeest | 0:1324e7d9d471 | 8 | |
osmeest | 0:1324e7d9d471 | 9 | class StateBase : public State { |
osmeest | 0:1324e7d9d471 | 10 | protected: |
osmeest | 0:1324e7d9d471 | 11 | StateBase(System::StateId id, System *system); |
osmeest | 0:1324e7d9d471 | 12 | virtual ~StateBase(); |
osmeest | 0:1324e7d9d471 | 13 | |
osmeest | 0:1324e7d9d471 | 14 | public: |
osmeest | 0:1324e7d9d471 | 15 | System * system() const { return this->system_; } |
osmeest | 0:1324e7d9d471 | 16 | |
osmeest | 0:1324e7d9d471 | 17 | private: |
osmeest | 0:1324e7d9d471 | 18 | System *system_; |
osmeest | 0:1324e7d9d471 | 19 | }; |
osmeest | 0:1324e7d9d471 | 20 | |
osmeest | 0:1324e7d9d471 | 21 | class InitState : public StateBase { |
osmeest | 0:1324e7d9d471 | 22 | public: |
osmeest | 0:1324e7d9d471 | 23 | InitState(System *system) : StateBase(System::Init, system) { } |
osmeest | 0:1324e7d9d471 | 24 | |
osmeest | 0:1324e7d9d471 | 25 | virtual void enterState(); |
osmeest | 0:1324e7d9d471 | 26 | virtual void exitState(); |
osmeest | 0:1324e7d9d471 | 27 | }; |
osmeest | 0:1324e7d9d471 | 28 | |
osmeest | 0:1324e7d9d471 | 29 | class InteractiveState : public StateBase { |
osmeest | 0:1324e7d9d471 | 30 | public: |
osmeest | 0:1324e7d9d471 | 31 | InteractiveState(System::StateId id, System *system) : StateBase(id, system) { } |
osmeest | 0:1324e7d9d471 | 32 | |
osmeest | 0:1324e7d9d471 | 33 | protected: |
osmeest | 0:1324e7d9d471 | 34 | void updateText() const; |
osmeest | 0:1324e7d9d471 | 35 | void updateCursor() const; |
osmeest | 0:1324e7d9d471 | 36 | }; |
osmeest | 0:1324e7d9d471 | 37 | |
osmeest | 0:1324e7d9d471 | 38 | class EditState : public InteractiveState { |
osmeest | 0:1324e7d9d471 | 39 | public: |
osmeest | 0:1324e7d9d471 | 40 | EditState(System *system) : InteractiveState(System::Edit, system) { } |
osmeest | 0:1324e7d9d471 | 41 | |
osmeest | 0:1324e7d9d471 | 42 | virtual void enterState(); |
osmeest | 0:1324e7d9d471 | 43 | |
osmeest | 0:1324e7d9d471 | 44 | virtual void handleKey(char key); |
osmeest | 0:1324e7d9d471 | 45 | |
osmeest | 0:1324e7d9d471 | 46 | private: |
osmeest | 0:1324e7d9d471 | 47 | void handleSymbol(char ch) const; |
osmeest | 0:1324e7d9d471 | 48 | }; |
osmeest | 0:1324e7d9d471 | 49 | |
osmeest | 0:1324e7d9d471 | 50 | class CommandState : public InteractiveState { |
osmeest | 0:1324e7d9d471 | 51 | public: |
osmeest | 0:1324e7d9d471 | 52 | CommandState(System *system) : InteractiveState(System::Command, system) { } |
osmeest | 0:1324e7d9d471 | 53 | |
osmeest | 0:1324e7d9d471 | 54 | virtual void enterState(); |
osmeest | 0:1324e7d9d471 | 55 | virtual void exitState(); |
osmeest | 0:1324e7d9d471 | 56 | |
osmeest | 0:1324e7d9d471 | 57 | virtual void handleKey(char key); |
osmeest | 0:1324e7d9d471 | 58 | |
osmeest | 0:1324e7d9d471 | 59 | private: |
osmeest | 0:1324e7d9d471 | 60 | void handleLeft() const; |
osmeest | 0:1324e7d9d471 | 61 | void handleRight() const; |
osmeest | 0:1324e7d9d471 | 62 | void handleHome() const; |
osmeest | 0:1324e7d9d471 | 63 | void handleEnd() const; |
osmeest | 0:1324e7d9d471 | 64 | void handleDelete() const; |
osmeest | 0:1324e7d9d471 | 65 | void handleBackSpace() const; |
osmeest | 0:1324e7d9d471 | 66 | void handleClear() const; |
osmeest | 0:1324e7d9d471 | 67 | void handleSend() const; |
osmeest | 0:1324e7d9d471 | 68 | void handleHelp(); |
osmeest | 0:1324e7d9d471 | 69 | |
osmeest | 0:1324e7d9d471 | 70 | void showNextStatusMsg(); |
osmeest | 0:1324e7d9d471 | 71 | void showStatusMsg(int index); |
osmeest | 0:1324e7d9d471 | 72 | |
osmeest | 0:1324e7d9d471 | 73 | int statusMsgIndex; |
osmeest | 0:1324e7d9d471 | 74 | Timeout statusMsgTimeout; |
osmeest | 0:1324e7d9d471 | 75 | }; |
osmeest | 0:1324e7d9d471 | 76 | |
osmeest | 0:1324e7d9d471 | 77 | class SendingState : public StateBase { |
osmeest | 0:1324e7d9d471 | 78 | public: |
osmeest | 0:1324e7d9d471 | 79 | SendingState(System *system) : StateBase(System::Sending, system) { } |
osmeest | 0:1324e7d9d471 | 80 | |
osmeest | 0:1324e7d9d471 | 81 | virtual void enterState(); |
osmeest | 0:1324e7d9d471 | 82 | |
osmeest | 0:1324e7d9d471 | 83 | virtual void handleKey(char key); |
osmeest | 0:1324e7d9d471 | 84 | |
osmeest | 0:1324e7d9d471 | 85 | private: |
osmeest | 0:1324e7d9d471 | 86 | void playSymbol(); |
osmeest | 0:1324e7d9d471 | 87 | void endSymbol(); |
osmeest | 0:1324e7d9d471 | 88 | void nextSymbol(); |
osmeest | 0:1324e7d9d471 | 89 | |
osmeest | 0:1324e7d9d471 | 90 | static float ToneTime; |
osmeest | 0:1324e7d9d471 | 91 | static float PauseTime; |
osmeest | 0:1324e7d9d471 | 92 | |
osmeest | 0:1324e7d9d471 | 93 | Timeout timer; |
osmeest | 0:1324e7d9d471 | 94 | }; |
osmeest | 0:1324e7d9d471 | 95 | |
osmeest | 0:1324e7d9d471 | 96 | #endif |