#include #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); } }