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
Diff: StateManager.h
- Revision:
- 4:d6661b976359
- Child:
- 5:100d960fc6d5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/StateManager.h Fri May 01 00:38:59 2015 +0000
@@ -0,0 +1,38 @@
+#ifndef STATE_MANAGER_H
+#define STATE_MANAGER_H
+
+#include "State.h"
+#include <map>
+
+// Main Finite State Machine - controls the flow between the main states
+class StateManager
+{
+ public:
+ StateManager(N5110 *lcd, InputManager* input)
+ : lcd(lcd), input(input){currentState = 0;}
+
+ void update(time_t dt);
+ void render();
+
+ template <typename T>
+ void changeState(MainState newState); // Deletes the current main state and creates a new one
+
+ private:
+ N5110 *lcd;
+ InputManager *input;
+ State* currentState; // Current state object
+};
+
+template <typename T>
+void StateManager::changeState(MainState newState)
+{
+ if (currentState != 0) // if a state exist
+ delete currentState; // clear allocated memory
+
+ // Create new state
+ currentState = new T(*this, lcd, input);
+
+ // TODO: Work on this
+}
+
+#endif STATE_MANAGER_H