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.
Diff: FSM.cpp
- Revision:
- 0:091e1a699d64
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/FSM.cpp Mon Jan 07 10:58:16 2019 +0000
@@ -0,0 +1,45 @@
+#include "FSM.h"
+#include "HMI.h"
+#include "LinkedList.h"
+
+FSM::FSM(size_t num_state)
+{
+ _index_state = 0;
+ _num_state = num_state;
+ states = new struct MachineState[num_state];
+ if(states == NULL)
+ pc.printf("FSM - assignment failed.\r\n");
+}
+
+FSM::~FSM()
+{
+ delete[] states;
+}
+void FSM::addState(unsigned int uid,unsigned int (*state)(void))
+{
+ struct MachineState ms;
+ ms.uid = uid;
+ ms.state = state;
+ states[_index_state++] = ms;
+}
+
+void FSM::addTransition(int from, int to)
+{
+ trans.append(new Transition(from, to));
+}
+void FSM::setInitialState(unsigned int uid)
+{
+ _uid_zero = uid;
+ _cur_state = _uid_zero;
+}
+void FSM::execute()
+{
+ unsigned int next_uid = 0;
+ next_uid = states[_cur_state].state();
+ for (int i = 0; i < _num_state; i++) {
+ if(next_uid == states[i].uid) {
+ _cur_state = i;
+ }
+ }
+}
+