123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include <Arduino.h>
-
- #include "config.h"
- #include "config_pins.h"
- #include "lcd.h"
- #include "states.h"
-
- State::State(State *_parent)
- : parent(_parent), child(NULL), title(""), heading(""), text("") {
- if (_parent != NULL) {
- _parent->setChild(this);
- }
-
- onEnterFunc = []() { };
-
- whenInFunc = [](StateMachineInput smi) {
- State *s = states_get();
- if (smi.click && (s != NULL)) {
- if (s->getChild() != NULL) {
- states_go_to(s->getChild());
- } else if (s->getParent() != NULL) {
- states_go_to(s->getParent());
- }
- }
- };
- }
-
- void State::updateText(void) {
- lcd_clear();
-
- if ((heading != NULL) && (strlen(heading) > 0)) {
- lcd_set_heading(heading);
- } else if ((getTitle() != NULL) && (strlen(getTitle()) > 0)) {
- lcd_set_heading(getTitle());
- }
-
- if ((text != NULL) && (strlen(text) > 0)) {
- lcd_set_text(text);
- }
- }
-
- void State::enterState(void) {
- if (onEnterFunc != NULL) {
- onEnterFunc();
- }
-
- updateText();
- }
-
- void State::inState(struct StateMachineInput smi) {
- if (whenInFunc != NULL) {
- whenInFunc(smi);
- }
- }
|