123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #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;
- };
-
- class StateDynamicMenu : public State {
- public:
- StateDynamicMenu(State *_parent = NULL);
-
- typedef int(*CountFuncPtr)(void);
- typedef const char *(*GetFuncPtr)(int);
- typedef void(*CallFuncPtr)(int);
-
- void dataCount(CountFuncPtr count);
- void dataGet(GetFuncPtr get);
- void dataCall(CallFuncPtr call);
-
- virtual void enterState(void);
- virtual void inState(StateMachineInput smi);
-
- private:
- void display(void);
-
- CountFuncPtr countFunc;
- GetFuncPtr getFunc;
- CallFuncPtr callFunc;
-
- int count;
- Array<const char *, 42> contents;
- };
-
- #endif // _STATE_MACHINE_H_
|