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.
Dependencies: N5110 PinDetect PowerControl mbed
StateManager.h@4:d6661b976359, 2015-05-01 (annotated)
- Committer:
- Siriagus
- Date:
- Fri May 01 00:38:59 2015 +0000
- Revision:
- 4:d6661b976359
- Child:
- 5:100d960fc6d5
Started rewriting the main finite state machine - design in progress
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Siriagus | 4:d6661b976359 | 1 | #ifndef STATE_MANAGER_H |
| Siriagus | 4:d6661b976359 | 2 | #define STATE_MANAGER_H |
| Siriagus | 4:d6661b976359 | 3 | |
| Siriagus | 4:d6661b976359 | 4 | #include "State.h" |
| Siriagus | 4:d6661b976359 | 5 | #include <map> |
| Siriagus | 4:d6661b976359 | 6 | |
| Siriagus | 4:d6661b976359 | 7 | // Main Finite State Machine - controls the flow between the main states |
| Siriagus | 4:d6661b976359 | 8 | class StateManager |
| Siriagus | 4:d6661b976359 | 9 | { |
| Siriagus | 4:d6661b976359 | 10 | public: |
| Siriagus | 4:d6661b976359 | 11 | StateManager(N5110 *lcd, InputManager* input) |
| Siriagus | 4:d6661b976359 | 12 | : lcd(lcd), input(input){currentState = 0;} |
| Siriagus | 4:d6661b976359 | 13 | |
| Siriagus | 4:d6661b976359 | 14 | void update(time_t dt); |
| Siriagus | 4:d6661b976359 | 15 | void render(); |
| Siriagus | 4:d6661b976359 | 16 | |
| Siriagus | 4:d6661b976359 | 17 | template <typename T> |
| Siriagus | 4:d6661b976359 | 18 | void changeState(MainState newState); // Deletes the current main state and creates a new one |
| Siriagus | 4:d6661b976359 | 19 | |
| Siriagus | 4:d6661b976359 | 20 | private: |
| Siriagus | 4:d6661b976359 | 21 | N5110 *lcd; |
| Siriagus | 4:d6661b976359 | 22 | InputManager *input; |
| Siriagus | 4:d6661b976359 | 23 | State* currentState; // Current state object |
| Siriagus | 4:d6661b976359 | 24 | }; |
| Siriagus | 4:d6661b976359 | 25 | |
| Siriagus | 4:d6661b976359 | 26 | template <typename T> |
| Siriagus | 4:d6661b976359 | 27 | void StateManager::changeState(MainState newState) |
| Siriagus | 4:d6661b976359 | 28 | { |
| Siriagus | 4:d6661b976359 | 29 | if (currentState != 0) // if a state exist |
| Siriagus | 4:d6661b976359 | 30 | delete currentState; // clear allocated memory |
| Siriagus | 4:d6661b976359 | 31 | |
| Siriagus | 4:d6661b976359 | 32 | // Create new state |
| Siriagus | 4:d6661b976359 | 33 | currentState = new T(*this, lcd, input); |
| Siriagus | 4:d6661b976359 | 34 | |
| Siriagus | 4:d6661b976359 | 35 | // TODO: Work on this |
| Siriagus | 4:d6661b976359 | 36 | } |
| Siriagus | 4:d6661b976359 | 37 | |
| Siriagus | 4:d6661b976359 | 38 | #endif STATE_MANAGER_H |