1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #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("no title") {
- if (_parent != NULL) {
- _parent->setChild(this);
- }
- }
-
- // --------------------------------------
-
- StateText::StateText(State *_parent) : State(_parent) {
- heading = "";
- text = "";
- onEnterFunc = []() { };
- whenInFunc = [](StateMachineInput smi) {
- State *s = states_get();
- if (smi.click && (s != NULL) && (s->getChild() != NULL)) {
- states_go_to(s->getChild());
- }
- };
- }
-
- void StateText::setHeading(const char *_heading) {
- heading = _heading;
- }
-
- void StateText::setText(const char *_text) {
- text = _text;
- }
-
- void StateText::onEnter(EnterFuncPtr func) {
- onEnterFunc = func;
- }
-
- void StateText::whenIn(InFuncPtr func) {
- whenInFunc = func;
- }
-
- void StateText::enterState(void) {
- lcd_clear();
- lcd_set_heading(heading);
- lcd_set_text(text);
-
- onEnterFunc();
- }
-
- void StateText::inState(struct StateMachineInput smi) {
- whenInFunc(smi);
- }
-
- // --------------------------------------
-
- StateMenu::StateMenu(State *_parent) : State(_parent) {
- menuPos = 0;
- }
-
- void StateMenu::setChild(State *_child) {
- children.push_back(_child);
- }
-
- void StateMenu::addChild(State *_child, int pos) {
- if (pos < 0) {
- setChild(_child);
- } else {
- // TODO insert child at pos in children
- }
- }
-
- void StateMenu::enterState(void) {
- menuPos = 0;
- }
-
- void StateMenu::inState(struct StateMachineInput smi) {
-
- }
|