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.
FSM.cpp
00001 #include "FSM.h" 00002 #include "HMI.h" 00003 #include "LinkedList.h" 00004 00005 FSM::FSM(size_t num_state) 00006 { 00007 _index_state = 0; 00008 _num_state = num_state; 00009 states = new struct MachineState[num_state]; 00010 if(states == NULL) 00011 pc.printf("FSM - assignment failed.\r\n"); 00012 } 00013 00014 FSM::~FSM() 00015 { 00016 delete[] states; 00017 } 00018 void FSM::addState(unsigned int uid,unsigned int (*state)(void)) 00019 { 00020 struct MachineState ms; 00021 ms.uid = uid; 00022 ms.state = state; 00023 states[_index_state++] = ms; 00024 } 00025 00026 void FSM::addTransition(int from, int to) 00027 { 00028 trans.append(new Transition(from, to)); 00029 } 00030 void FSM::setInitialState(unsigned int uid) 00031 { 00032 _uid_zero = uid; 00033 _cur_state = _uid_zero; 00034 } 00035 void FSM::execute() 00036 { 00037 unsigned int next_uid = 0; 00038 next_uid = states[_cur_state].state(); 00039 for (int i = 0; i < _num_state; i++) { 00040 if(next_uid == states[i].uid) { 00041 _cur_state = i; 00042 } 00043 } 00044 } 00045
Generated on Wed Aug 17 2022 05:29:14 by
 1.7.2