123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #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) {
-
- }
-
- // --------------------------------------
-
- StateDynamicMenu::StateDynamicMenu(State *_parent = NULL) : State(_parent) { }
-
- void StateDynamicMenu::dataCount(CountFuncPtr count) {
- countFunc = count;
- }
-
- void StateDynamicMenu::dataGet(GetFuncPtr get) {
- getFunc = get;
- }
-
- void StateDynamicMenu::dataCall(CallFuncPtr call) {
- callFunc = call;
- }
-
- void StateDynamicMenu::display(void) {
-
- }
-
- void StateDynamicMenu::enterState(void) {
- // cache all entries on entering state
- count = countFunc();
- contents.clear();
- for (int i = 0; i < count; i++) {
- contents.push_back(getFunc(i));
- }
-
- display();
- }
-
- void StateDynamicMenu::inState(StateMachineInput smi) {
-
- }
|