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.cpp 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <Arduino.h>
  2. #include "config.h"
  3. #include "config_pins.h"
  4. #include "lcd.h"
  5. #include "states.h"
  6. State::State(State *_parent)
  7. : parent(_parent), child(NULL), title(""), heading(""), text("") {
  8. if (_parent != NULL) {
  9. _parent->setChild(this);
  10. }
  11. onEnterFunc = []() { };
  12. whenInFunc = [](StateMachineInput smi) {
  13. State *s = states_get();
  14. if (smi.click && (s != NULL)) {
  15. if (s->getChild() != NULL) {
  16. states_go_to(s->getChild());
  17. } else if (s->getParent() != NULL) {
  18. states_go_to(s->getParent());
  19. }
  20. }
  21. };
  22. }
  23. void State::updateText(void) {
  24. lcd_clear();
  25. if (heading != NULL) {
  26. lcd_set_heading(heading);
  27. } else if (getTitle() != NULL) {
  28. lcd_set_heading(getTitle());
  29. }
  30. if (text != NULL) {
  31. lcd_set_text(text);
  32. }
  33. }
  34. void State::enterState(void) {
  35. if (onEnterFunc != NULL) {
  36. onEnterFunc();
  37. }
  38. updateText();
  39. }
  40. void State::inState(struct StateMachineInput smi) {
  41. if (whenInFunc != NULL) {
  42. whenInFunc(smi);
  43. }
  44. }