1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #ifndef _STATE_MACHINE_H_
- #define _STATE_MACHINE_H_
-
- #include <Array.h>
-
- struct StateMachineInput {
- StateMachineInput(int c, int e, int k, int m)
- : click(c), encoder(e), kill(k), motors_done(m) { };
-
- int click;
- int encoder;
- int kill;
- int motors_done;
- };
-
- class State {
- public:
- State(State *_parent = NULL);
- State *getParent(void) { return parent; }
-
- virtual void setChild(State *_child) { child = _child; }
- State *getChild(void) { return child; }
-
- void setTitle(const char *_title) { title = _title; }
- const char *getTitle(void) { return title; }
-
- virtual void enterState(void) = 0;
- virtual void inState(StateMachineInput smi) = 0;
-
- private:
- State *parent;
- State *child;
- const char *title;
- };
-
- class StateText : public State {
- public:
- StateText(State *_parent = NULL);
-
- void setHeading(const char *_heading);
- void setText(const char *_text);
-
- typedef void(*EnterFuncPtr)(void);
- typedef void(*InFuncPtr)(StateMachineInput smi);
-
- void onEnter(EnterFuncPtr func);
- void whenIn(InFuncPtr func);
-
- virtual void enterState(void);
- virtual void inState(StateMachineInput smi);
-
- private:
- const char *heading;
- const char *text;
- EnterFuncPtr onEnterFunc;
- InFuncPtr whenInFunc;
- };
-
- class StateMenu : public State {
- public:
- StateMenu(State *_parent = NULL);
- virtual void setChild(State *_child);
-
- void addChild(State *_child, int pos = -1);
-
- virtual void enterState(void);
- virtual void inState(StateMachineInput smi);
-
- private:
- int menuPos;
- Array<State *, 42> children;
- };
-
- #endif // _STATE_MACHINE_H_
|