No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

statemachine.h 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef _STATE_MACHINE_H_
  2. #define _STATE_MACHINE_H_
  3. #include <Array.h>
  4. struct StateMachineInput {
  5. StateMachineInput(int c, int e, int k, int m)
  6. : click(c), encoder(e), kill(k), motors_done(m) { };
  7. int click;
  8. int encoder;
  9. int kill;
  10. int motors_done;
  11. };
  12. class State {
  13. public:
  14. State(State *_parent = NULL);
  15. State *getParent(void) { return parent; }
  16. virtual void setChild(State *_child) { child = _child; }
  17. State *getChild(void) { return child; }
  18. void setTitle(const char *_title) { title = _title; }
  19. const char *getTitle(void) { return title; }
  20. virtual void enterState(void) = 0;
  21. virtual void inState(StateMachineInput smi) = 0;
  22. private:
  23. State *parent;
  24. State *child;
  25. const char *title;
  26. };
  27. class StateText : public State {
  28. public:
  29. StateText(State *_parent = NULL);
  30. void setHeading(const char *_heading);
  31. void setText(const char *_text);
  32. typedef void(*EnterFuncPtr)(void);
  33. typedef void(*InFuncPtr)(StateMachineInput smi);
  34. void onEnter(EnterFuncPtr func);
  35. void whenIn(InFuncPtr func);
  36. virtual void enterState(void);
  37. virtual void inState(StateMachineInput smi);
  38. private:
  39. const char *heading;
  40. const char *text;
  41. EnterFuncPtr onEnterFunc;
  42. InFuncPtr whenInFunc;
  43. };
  44. class StateMenu : public State {
  45. public:
  46. StateMenu(State *_parent = NULL);
  47. virtual void setChild(State *_child);
  48. void addChild(State *_child, int pos = -1);
  49. virtual void enterState(void);
  50. virtual void inState(StateMachineInput smi);
  51. private:
  52. int menuPos;
  53. Array<State *, 42> children;
  54. };
  55. #endif // _STATE_MACHINE_H_