12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213 |
- /*
- * Copyright (c) 2021 Thomas Buck <thomas@xythobuz.de>
- *
- * This file is part of Giess-o-mat.
- *
- * Giess-o-mat is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Giess-o-mat is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Giess-o-mat. If not, see <https://www.gnu.org/licenses/>.
- */
-
- #include "wifi.h"
- #include "Plants.h"
- #include "DebugLog.h"
- #include "WifiStuff.h"
- #include "Statemachine.h"
- #include "config.h"
- #include "config_pins.h"
-
- #ifdef FUNCTION_CONTROL
-
- Statemachine::DigitBuffer::DigitBuffer(int _size) {
- size = _size;
- pos = 0;
- digits = new int[size];
- }
-
- Statemachine::DigitBuffer::~DigitBuffer() {
- delete digits;
- }
-
- bool Statemachine::DigitBuffer::spaceLeft(void) {
- return (pos < size);
- }
-
- bool Statemachine::DigitBuffer::hasDigits(void) {
- return (pos > 0);
- }
-
- int Statemachine::DigitBuffer::countDigits(void) {
- return pos;
- }
-
- void Statemachine::DigitBuffer::addDigit(int d) {
- if (spaceLeft()) {
- digits[pos] = d;
- pos++;
- }
- }
-
- void Statemachine::DigitBuffer::removeDigit(void) {
- if (hasDigits()) {
- pos--;
- }
- }
-
- void Statemachine::DigitBuffer::clear(void) {
- pos = 0;
- }
-
- uint32_t Statemachine::DigitBuffer::getNumber(void) {
- uint32_t fact = 1;
- uint32_t sum = 0;
- for (int i = (pos - 1); i >= 0; i--) {
- sum += digits[i] * fact;
- fact *= 10;
- }
- return sum;
- }
-
- static const char *state_names[] = {
- stringify(init),
- stringify(door_select),
- stringify(menu_a),
- stringify(menu_b),
- stringify(menu_c),
-
- stringify(auto_mode_a),
- stringify(auto_mode_b),
- stringify(auto_mode_c),
- stringify(auto_fert_a),
- stringify(auto_fert_b),
- stringify(auto_fert_run),
- stringify(auto_tank_run),
- stringify(auto_stirr_run),
- stringify(auto_plant),
- stringify(auto_plant_kickstart_run),
- stringify(auto_plant_run),
- stringify(auto_done),
-
- stringify(fillnwater_plant),
- stringify(fillnwater_tank_run),
- stringify(fillnwater_kickstart_run),
- stringify(fillnwater_plant_run),
-
- stringify(fullauto_fert),
- stringify(fullauto_plant),
- stringify(fullauto_stirr_run),
- stringify(fullauto_fert_run),
- stringify(fullauto_tank_run),
- stringify(fullauto_kickstart_run),
- stringify(fullauto_plant_run),
- stringify(fullauto_plant_overrun),
- stringify(fullauto_tank_purge_run),
- stringify(fullauto_kickstart_purge_run),
- stringify(fullauto_plant_purge_run),
- stringify(fullauto_plant_purge_overrun),
- stringify(fullauto_plant_purge_over_pump_run),
- stringify(fullauto_done),
-
- stringify(automation_mode),
-
- stringify(menu_pumps),
- stringify(menu_pumps_time),
- stringify(menu_pumps_go),
- stringify(menu_pumps_run),
- stringify(menu_pumps_done),
-
- stringify(menu_valves),
- stringify(menu_valves_time),
- stringify(menu_valves_go),
- stringify(menu_valves_run),
- stringify(menu_valves_done),
-
- stringify(menu_aux),
- stringify(menu_aux_time),
- stringify(menu_aux_go),
- stringify(menu_aux_run),
- stringify(menu_aux_done),
-
- stringify(error)
- };
-
- static int auto_pump_runtime[PUMP_COUNT] = AUTO_PUMP_RUNTIME;
-
- const char *Statemachine::getStateName(void) {
- return state_names[state];
- }
-
- bool Statemachine::isIdle(void) {
- return state == init;
- }
-
- Statemachine::Statemachine(print_fn _print, backspace_fn _backspace)
- : db(7), selected_plants(plants.countPlants()),
- selected_ferts(plants.countFertilizers()) {
- state = init;
- old_state = init;
- print = _print;
- backspace = _backspace;
-
- selected_id = 0;
- selected_time = 0;
- start_time = 0;
- stop_time = 0;
- last_animation_time = 0;
- error_condition = "";
- into_state_time = 0;
- filling_started_empty = false;
- watering_started_full = false;
- menu_entered_digits = "";
- }
-
- void Statemachine::begin(void) {
- switch_to(init);
- }
-
- #if defined(TELEGRAM_TOKEN) || defined(MQTT_HOST)
-
- void Statemachine::bot_abort(void) {
- plants.abort();
- stop_time = millis();
- switch_to(auto_done);
- }
-
- void Statemachine::bot_start_auto(BoolField &_ferts, BoolField &_plants) {
- selected_ferts.clear();
- for (int i = 0; i < plants.countFertilizers(); i++) {
- if (_ferts.isSet(i)) {
- selected_ferts.set(i);
- }
- }
-
- selected_plants.clear();
- for (int i = 0; i < plants.countPlants(); i++) {
- if (_plants.isSet(i)) {
- selected_plants.set(i);
- }
- }
-
- // check if we need to run fertilizers
- if (selected_ferts.countSet() > 0) {
- // stirr before pumping fertilizers
- for (int i = 0; i < STIRRER_COUNT; i++) {
- plants.startAux(i);
- }
- selected_id = 1;
- selected_time = AUTO_STIRR_RUNTIME;
- start_time = millis();
- switch_to(fullauto_stirr_run);
- } else {
- // immediately continue with filling tank
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- // if the waterlevel is currently empty, we
- // set a flag to record the time to fill
- filling_started_empty = (wl == Plants::empty);
-
- plants.openWaterInlet();
- selected_id = plants.countPlants() + 1;
- selected_time = MAX_TANK_FILL_TIME;
- start_time = millis();
- switch_to(fullauto_tank_run);
- } else if (wl == Plants::full) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- // for recording the flowrate
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- switch_to(fullauto_kickstart_run);
- } else {
- switch_to(fullauto_plant_run);
- }
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- }
- }
-
- #endif // TELEGRAM_TOKEN || MQTT_HOST
-
- void Statemachine::input(int n) {
- if (state == init) {
- #if (LOCK_COUNT > 0) && defined(DOOR_LOCK_PIN)
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- switch_to(menu_a);
- }
- } else if (n == -2) {
- switch_to(menu_a);
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- //menu_entered_digits += String(n);
- menu_entered_digits += String("*");
- switch_to(state);
- } else {
- backspace();
- }
-
- uint32_t n = db.getNumber();
- if (n == DOOR_LOCK_PIN) {
- db.clear();
- menu_entered_digits = "";
- selected_plants.clear();
- switch_to(door_select);
- } else if (db.countDigits() >= DOOR_LOCK_PIN_MAX_DIGITS) {
- db.clear();
- menu_entered_digits = "";
- switch_to(state);
- }
- }
- #else
- switch_to(menu_a);
- #endif
- } else if (state == door_select) {
- #if (LOCK_COUNT > 0)
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- switch_to(init);
- }
- } else if (n == -2) {
- if (!db.hasDigits()) {
- for (int i = 0; i < LOCK_COUNT; i++) {
- if (selected_plants.isSet(i)) {
- plants.startAux(STIRRER_COUNT + i);
- delay(DOOR_LOCK_ON_TIME);
- plants.stopAux(STIRRER_COUNT + i);
- delay(DOOR_LOCK_NEXT_DELAY);
- }
- }
- plants.stopAllAux();
- switch_to(menu_a);
- } else {
- selected_id = number_input();
- if ((selected_id <= 0) || (selected_id > LOCK_COUNT)) {
- error_condition = F("Invalid lock ID!");
- switch_to(error);
- } else {
- selected_plants.set(selected_id - 1);
- menu_entered_digits = "";
- switch_to(state);
- }
- }
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- menu_entered_digits += String(n);
- switch_to(state);
- } else {
- backspace();
- }
- }
- #else
- // should never be reached
- switch_to(menu_a);
- #endif
- } else if ((state == menu_a) || (state == menu_b) || (state == menu_c)) {
- if (n == 1) {
- switch_to(auto_mode_a);
- } else if (n == 2) {
- switch_to(automation_mode);
- } else if (n == 3) {
- switch_to(menu_pumps);
- } else if (n == 4) {
- switch_to(menu_valves);
- } else if (n == 5) {
- switch_to(menu_aux);
- #if (LOCK_COUNT > 0) && !defined(DOOR_LOCK_PIN)
- } else if (n == 6) {
- switch_to(door_select);
- #endif
- } else if (n == -1) {
- switch_to(init);
- } else if (n == -2) {
- switch_to((state == menu_a) ? menu_b : ((state == menu_b) ? menu_c : menu_a));
- }
- } else if (state == automation_mode) {
- // TODO
- switch_to(menu_a);
- } else if ((state == auto_mode_a) || (state == auto_mode_b) || (state == auto_mode_c)) {
- if (n == 1) {
- selected_ferts.clear();
- switch_to(fullauto_fert);
- } else if (n == 2) {
- switch_to(auto_fert_a);
- } else if (n == 3) {
- selected_plants.clear();
- switch_to(fillnwater_plant);
- } else if (n == 4) {
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- plants.openWaterInlet();
- selected_id = plants.countPlants() + 1;
- selected_time = MAX_TANK_FILL_TIME;
- start_time = millis();
- switch_to(auto_tank_run);
- } else if (wl == Plants::full) {
- stop_time = millis();
- switch_to(auto_mode_a);
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- } else if (n == 5) {
- selected_plants.clear();
- switch_to(auto_plant);
- } else if (n == -1) {
- switch_to(menu_a);
- } else if (n == -2) {
- switch_to((state == auto_mode_a) ? auto_mode_b : ((state == auto_mode_b) ? auto_mode_c : auto_mode_a));
- }
- } else if ((state == auto_fert_a) || (state == auto_fert_b)) {
- // TODO fertilizer number currently "hardcoded" to 3 in UI
- if ((n >= 1) && (n <= 3)) {
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- plants.startFertilizer(n - 1);
- selected_id = n;
- selected_time = auto_pump_runtime[n - 1];
- start_time = millis();
- switch_to(auto_fert_run);
- } else if (wl == Plants::full) {
- stop_time = millis();
- switch_to(auto_mode_a);
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- } else if (n == 4) {
- for (int i = 0; i < STIRRER_COUNT; i++) {
- plants.startAux(i);
- }
- selected_id = 1;
- selected_time = AUTO_STIRR_RUNTIME;
- start_time = millis();
- switch_to(auto_stirr_run);
- } else if (n == -1) {
- switch_to(auto_mode_a);
- } else if (n == -2) {
- switch_to((state == auto_fert_a) ? auto_fert_b : auto_fert_a);
- }
- } else if (state == fullauto_stirr_run) {
- // allow user to stop stirring and continue with fertilizers
- plants.abort();
- stop_time = millis();
- if (selected_ferts.countSet() > 0) {
- selected_time = auto_pump_runtime[0];
- for (int i = 0; i < plants.countFertilizers(); i++) {
- if (auto_pump_runtime[i] > selected_time) {
- selected_time = auto_pump_runtime[i];
- }
-
- if (selected_ferts.isSet(i)) {
- plants.startFertilizer(i);
- }
- }
-
- start_time = millis();
- switch_to(fullauto_fert_run);
- } else {
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- // if the waterlevel is currently empty, we
- // set a flag to record the time to fill
- filling_started_empty = (wl == Plants::empty);
-
- plants.openWaterInlet();
- selected_id = plants.countPlants() + 1;
- selected_time = MAX_TANK_FILL_TIME;
- start_time = millis();
- switch_to(fullauto_tank_run);
- } else if (wl == Plants::full) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- switch_to(fullauto_kickstart_run);
- } else {
- switch_to(fullauto_plant_run);
- }
- } else if (wl == Plants::invalid) {
- plants.abort();
- error_condition = F("Invalid sensor state");
- state = fullauto_fert;
- switch_to(error);
- }
- }
- } else if (state == fullauto_fert_run) {
- // allow user to stop fertizilers and continue with tank filling
- plants.abort();
- stop_time = millis();
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- // if the waterlevel is currently empty, we
- // set a flag to record the time to fill
- filling_started_empty = (wl == Plants::empty);
-
- plants.openWaterInlet();
- selected_id = plants.countPlants() + 1;
- selected_time = MAX_TANK_FILL_TIME;
- start_time = millis();
- switch_to(fullauto_tank_run);
- } else if (wl == Plants::full) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- switch_to(fullauto_kickstart_run);
- } else {
- switch_to(fullauto_plant_run);
- }
- } else if (wl == Plants::invalid) {
- plants.abort();
- error_condition = F("Invalid sensor state");
- state = fullauto_fert;
- switch_to(error);
- }
- } else if ((state == fullauto_tank_run)
- || (state == fullauto_tank_purge_run)) {
- // allow user to stop tank and continue with kickstart
- plants.abort();
- stop_time = millis();
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::empty) && (wl != Plants::invalid)) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- if (state == fullauto_tank_run) {
- switch_to(fullauto_kickstart_run);
- } else {
- switch_to(fullauto_kickstart_purge_run);
- }
- } else {
- if (state == fullauto_tank_run) {
- switch_to(fullauto_plant_run);
- } else {
- switch_to(fullauto_plant_purge_run);
- }
- }
- } else if (wl == Plants::empty) {
- stop_time = millis();
- switch_to(auto_done);
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- } else if ((state == fullauto_kickstart_run)
- || (state == fullauto_kickstart_purge_run)) {
- // allow user to stop kickstarting and continue with plants
- plants.abort();
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
-
- // start required valves
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, false);
- }
- }
-
- if (state == fullauto_kickstart_run) {
- switch_to(fullauto_plant_run);
- } else {
- switch_to(fullauto_plant_purge_run);
- }
- } else if ((state == auto_fert_run) || (state == auto_tank_run)
- || (state == auto_stirr_run) || (state == auto_plant_run)
- || (state == auto_plant_kickstart_run)
- || (state == fillnwater_kickstart_run)
- || (state == fullauto_plant_run)
- || (state == fullauto_plant_overrun)
- || (state == fullauto_plant_purge_run)
- || (state == fullauto_plant_purge_overrun)
- || (state == fullauto_plant_purge_over_pump_run)) {
- plants.abort();
- stop_time = millis();
- switch_to(auto_done);
- } else if (state == auto_plant) {
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- switch_to(auto_mode_b);
- }
- } else if (n == -2) {
- if (!db.hasDigits()) {
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::empty) && (wl != Plants::invalid)) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- switch_to(auto_plant_kickstart_run);
- } else {
- switch_to(auto_plant_run);
- }
- } else if (wl == Plants::empty) {
- stop_time = millis();
- switch_to(auto_mode_b);
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = auto_mode_b;
- switch_to(error);
- }
- } else {
- selected_id = number_input();
- if ((selected_id <= 0) || (selected_id > plants.countPlants())) {
- error_condition = F("Invalid plant ID!");
- switch_to(error);
- } else {
- selected_plants.set(selected_id - 1);
- menu_entered_digits = "";
- switch_to(auto_plant);
- }
- }
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- menu_entered_digits += String(n);
- switch_to(state);
- } else {
- backspace();
- }
- }
- } else if (state == fullauto_fert) {
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- switch_to(auto_mode_a);
- }
- } else if (n == -2) {
- if (!db.hasDigits()) {
- selected_plants.clear();
- switch_to(fullauto_plant);
- } else {
- selected_id = number_input();
- if ((selected_id <= 0) || (selected_id > plants.countFertilizers())) {
- error_condition = F("Invalid fert. ID!");
- switch_to(error);
- } else {
- selected_ferts.set(selected_id - 1);
- menu_entered_digits = "";
- switch_to(fullauto_fert);
- }
- }
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- menu_entered_digits += String(n);
- switch_to(state);
- } else {
- backspace();
- }
- }
- } else if (state == fullauto_plant) {
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- selected_ferts.clear();
- switch_to(fullauto_fert);
- }
- } else if (n == -2) {
- if (!db.hasDigits()) {
- if (selected_plants.countSet() <= 0) {
- // user has not selected a plant yet...
- return;
- }
-
- #ifdef FULLAUTO_MIN_PLANT_COUNT
- if (selected_plants.countSet() < FULLAUTO_MIN_PLANT_COUNT) {
- return;
- }
- #endif
-
- // check if we need to run fertilizers
- if (selected_ferts.countSet() > 0) {
- // stirr before pumping fertilizers
- for (int i = 0; i < STIRRER_COUNT; i++) {
- plants.startAux(i);
- }
- selected_id = 1;
- selected_time = AUTO_STIRR_RUNTIME;
- start_time = millis();
- switch_to(fullauto_stirr_run);
- } else {
- // immediately continue with filling tank
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- // if the waterlevel is currently empty, we
- // set a flag to record the time to fill
- filling_started_empty = (wl == Plants::empty);
-
- plants.openWaterInlet();
- selected_id = plants.countPlants() + 1;
- selected_time = MAX_TANK_FILL_TIME;
- start_time = millis();
- switch_to(fullauto_tank_run);
- } else if (wl == Plants::full) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- // for recording the flowrate
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- switch_to(fullauto_kickstart_run);
- } else {
- switch_to(fullauto_plant_run);
- }
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- }
- } else {
- selected_id = number_input();
- if ((selected_id <= 0) || (selected_id > plants.countPlants())) {
- error_condition = F("Invalid plant ID!");
- switch_to(error);
- } else {
- selected_plants.set(selected_id - 1);
- menu_entered_digits = "";
- switch_to(fullauto_plant);
- }
- }
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- menu_entered_digits += String(n);
- switch_to(state);
- } else {
- backspace();
- }
- }
- } else if ((state == auto_done) || (state == fullauto_done)) {
- switch_to(auto_mode_a);
- } else if (state == menu_pumps) {
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- switch_to(menu_b);
- }
- } else if (n == -2) {
- if (!db.hasDigits()) {
- return;
- }
-
- selected_id = number_input();
-
- if ((selected_id <= 0) || (selected_id > plants.countFertilizers())) {
- error_condition = F("Invalid pump ID!");
- switch_to(error);
- } else {
- switch_to(menu_pumps_time);
- }
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- menu_entered_digits += String(n);
- switch_to(state);
- } else {
- backspace();
- }
- }
- } else if (state == fillnwater_plant) {
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- switch_to(auto_mode_a);
- }
- } else if (n == -2) {
- if (!db.hasDigits()) {
- if (selected_plants.countSet() <= 0) {
- return;
- }
-
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- // if the waterlevel is currently empty, we
- // set a flag to record the time to fill
- filling_started_empty = (wl == Plants::empty);
-
- plants.openWaterInlet();
- selected_id = plants.countPlants() + 1;
- selected_time = MAX_TANK_FILL_TIME;
- start_time = millis();
- switch_to(fillnwater_tank_run);
- } else if (wl == Plants::full) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- // for recording the flowrate
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- switch_to(fillnwater_kickstart_run);
- } else {
- switch_to(fillnwater_plant_run);
- }
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- } else {
- selected_id = number_input();
- if ((selected_id <= 0) || (selected_id > plants.countPlants())) {
- error_condition = F("Invalid plant ID!");
- switch_to(error);
- } else {
- selected_plants.set(selected_id - 1);
- menu_entered_digits = "";
- switch_to(fillnwater_plant);
- }
- }
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- menu_entered_digits += String(n);
- switch_to(state);
- } else {
- backspace();
- }
- }
- } else if (state == fillnwater_tank_run) {
- plants.abort();
- stop_time = millis();
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::empty) && (wl != Plants::invalid)) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- switch_to(fillnwater_kickstart_run);
- } else {
- switch_to(fillnwater_plant_run);
- }
- } else if (wl == Plants::empty) {
- switch_to(auto_mode_a);
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- } else if (state == fillnwater_plant_run) {
- plants.abort();
- stop_time = millis();
- switch_to(auto_done);
- } else if (state == menu_pumps_time) {
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- switch_to(menu_pumps);
- }
- } else if (n == -2) {
- if (!db.hasDigits()) {
- return;
- }
-
- selected_time = number_input();
-
- if ((selected_time <= 0) || (selected_time > MAX_PUMP_RUNTIME)) {
- error_condition = F("Invalid time range!");
- switch_to(error);
- } else {
- switch_to(menu_pumps_go);
- }
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- menu_entered_digits += String(n);
- switch_to(state);
- } else {
- backspace();
- }
- }
- } else if (state == menu_pumps_go) {
- if (n == -2) {
- start_time = millis();
- last_animation_time = start_time;
-
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- plants.startFertilizer(selected_id - 1);
- switch_to(menu_pumps_run);
- } else if (wl == Plants::full) {
- stop_time = millis();
- switch_to(menu_pumps_done);
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = menu_pumps;
- switch_to(error);
- }
- } else {
- switch_to(menu_pumps_time);
- }
- } else if (state == menu_pumps_run) {
- plants.abort();
- stop_time = millis();
- switch_to(menu_pumps_done);
- } else if (state == menu_pumps_done) {
- switch_to(menu_b);
- } else if (state == menu_valves) {
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- switch_to(menu_b);
- }
- } else if (n == -2) {
- if (!db.hasDigits()) {
- return;
- }
-
- selected_id = number_input();
-
- if ((selected_id <= 0) || (selected_id > (plants.countPlants() + 1))) {
- error_condition = F("Invalid valve ID!");
- switch_to(error);
- } else {
- switch_to(menu_valves_time);
- }
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- menu_entered_digits += String(n);
- switch_to(state);
- } else {
- backspace();
- }
- }
- } else if (state == menu_valves_time) {
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- switch_to(menu_valves);
- }
- } else if (n == -2) {
- if (!db.hasDigits()) {
- return;
- }
-
- selected_time = number_input();
-
- if ((selected_time <= 0) || (selected_time > MAX_VALVE_RUNTIME)) {
- error_condition = F("Invalid time range!");
- switch_to(error);
- } else {
- switch_to(menu_valves_go);
- }
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- menu_entered_digits += String(n);
- switch_to(state);
- } else {
- backspace();
- }
- }
- } else if (state == menu_valves_go) {
- if (n == -2) {
- start_time = millis();
- last_animation_time = start_time;
-
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- if (selected_id >= (plants.countPlants() + 1)) {
- plants.openWaterInlet();
- } else {
- // TODO support testing kickstart
- plants.startPlant(selected_id - 1, false);
- }
-
- switch_to(menu_valves_run);
- } else if (wl == Plants::full) {
- stop_time = millis();
- switch_to(menu_valves_done);
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = menu_valves;
- switch_to(error);
- }
- } else {
- switch_to(menu_valves_time);
- }
- } else if (state == menu_valves_run) {
- plants.abort();
- stop_time = millis();
- switch_to(menu_valves_done);
- } else if (state == menu_valves_done) {
- switch_to(menu_b);
- } else if (state == menu_aux) {
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- switch_to(menu_c);
- }
- } else if (n == -2) {
- if (!db.hasDigits()) {
- return;
- }
-
- selected_id = number_input();
-
- if ((selected_id <= 0) || (selected_id > plants.countAux())) {
- error_condition = F("Invalid valve ID!");
- switch_to(error);
- } else {
- switch_to(menu_aux_time);
- }
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- menu_entered_digits += String(n);
- switch_to(state);
- } else {
- backspace();
- }
- }
- } else if (state == menu_aux_time) {
- if (n == -1) {
- if (db.hasDigits()) {
- backspace();
- db.removeDigit();
- if (menu_entered_digits.length() > 0) {
- menu_entered_digits.remove(menu_entered_digits.length() - 1);
- switch_to(state);
- }
- } else {
- switch_to(menu_aux);
- }
- } else if (n == -2) {
- if (!db.hasDigits()) {
- return;
- }
-
- selected_time = number_input();
-
- if ((selected_time <= 0) || (selected_time > MAX_AUX_RUNTIME)) {
- error_condition = F("Invalid time range!");
- switch_to(error);
- } else {
- switch_to(menu_aux_go);
- }
- } else {
- if (db.spaceLeft()) {
- db.addDigit(n);
- menu_entered_digits += String(n);
- switch_to(state);
- } else {
- backspace();
- }
- }
- } else if (state == menu_aux_go) {
- if (n == -2) {
- start_time = millis();
- last_animation_time = start_time;
- plants.startAux(selected_id - 1);
- switch_to(menu_aux_run);
- } else {
- switch_to(menu_aux_time);
- }
- } else if (state == menu_aux_run) {
- plants.abort();
- stop_time = millis();
- switch_to(menu_aux_done);
- } else if (state == menu_aux_done) {
- switch_to(menu_c);
- } else if (state == error) {
- if (old_state != error) {
- switch_to(old_state);
- } else {
- switch_to(menu_a);
- }
- }
- }
-
- uint32_t Statemachine::number_input(void) {
- for (int i = 0; i < db.countDigits(); i++) {
- backspace();
- }
-
- uint32_t n = db.getNumber();
- db.clear();
-
- debug.print("Whole number input: ");
- debug.println(n);
-
- return n;
- }
-
- void Statemachine::act(void) {
- if ((state == menu_pumps_run) || (state == menu_valves_run)
- || (state == menu_aux_run) || (state == fullauto_stirr_run)
- || (state == auto_stirr_run)) {
- unsigned long runtime = millis() - start_time;
- if ((runtime / 1000UL) >= selected_time) {
- // stop if timeout has been reached
- plants.abort();
- stop_time = millis();
- if (state == menu_pumps_run) {
- switch_to(menu_pumps_done);
- } else if (state == menu_valves_run) {
- switch_to(menu_valves_done);
- } else if (state == menu_aux_run) {
- switch_to(menu_aux_done);
- } else if (state == fullauto_stirr_run) {
- if (selected_ferts.countSet() > 0) {
- selected_time = auto_pump_runtime[0];
- for (int i = 0; i < plants.countFertilizers(); i++) {
- if (auto_pump_runtime[i] > selected_time) {
- selected_time = auto_pump_runtime[i];
- }
-
- if (selected_ferts.isSet(i)) {
- plants.startFertilizer(i);
- }
- }
-
- start_time = millis();
- switch_to(fullauto_fert_run);
- } else {
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- // if the waterlevel is currently empty, we
- // set a flag to record the time to fill
- filling_started_empty = (wl == Plants::empty);
-
- plants.openWaterInlet();
- selected_id = plants.countPlants() + 1;
- selected_time = MAX_TANK_FILL_TIME;
- start_time = millis();
- switch_to(fullauto_tank_run);
- } else if (wl == Plants::full) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- switch_to(fullauto_kickstart_run);
- } else {
- switch_to(fullauto_plant_run);
- }
- } else if (wl == Plants::invalid) {
- plants.abort();
- error_condition = F("Invalid sensor state");
- state = fullauto_fert;
- switch_to(error);
- }
- }
- } else {
- switch_to(auto_done);
- }
- } else if ((millis() - last_animation_time) >= 500) {
- // update animation if needed
- last_animation_time = millis();
- switch_to(state);
- }
- }
-
- #ifdef CHECK_SENSORS_VALVE_PUMP_MENU_FULL
- if ((state == menu_pumps_run) || ((state == menu_valves_run) && (selected_id == (plants.countPlants() + 1)))) {
- // check water level state
- auto wl = plants.getWaterlevel();
- if (wl == Plants::full) {
- plants.abort();
- stop_time = millis();
- switch_to((state == menu_pumps_run) ? menu_pumps_done : menu_valves_done);
- } else if (wl == Plants::invalid) {
- plants.abort();
- error_condition = F("Invalid sensor state");
- state = (state == menu_pumps_run) ? menu_pumps : menu_valves;
- switch_to(error);
- }
- }
- #endif // CHECK_SENSORS_VALVE_PUMP_MENU_FULL
-
- #ifdef CHECK_SENSORS_VALVE_PUMP_MENU_EMPTY
- if ((state == menu_valves_run) && (selected_id <= plants.countPlants())) {
- // check water level state
- auto wl = plants.getWaterlevel();
- if (wl == Plants::empty) {
- plants.abort();
- stop_time = millis();
- switch_to(menu_valves_done);
- } else if (wl == Plants::invalid) {
- plants.abort();
- error_condition = F("Invalid sensor state");
- state = menu_valves;
- switch_to(error);
- }
- }
- #endif // CHECK_SENSORS_VALVE_PUMP_MENU_EMPTY
-
- // kickstart states
- if ((state == auto_plant_kickstart_run) || (state == fillnwater_kickstart_run)
- || (state == fullauto_kickstart_run) || (state == fullauto_kickstart_purge_run)) {
- unsigned long runtime = millis() - start_time;
- if ((runtime / 1000UL) >= KICKSTART_RUNTIME) {
- // kickstart is done, switch over to valves
- plants.abort();
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
-
- // start required valves
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, false);
- }
- }
-
- if (state == auto_plant_kickstart_run) {
- switch_to(auto_plant_run);
- } else if (state == fillnwater_kickstart_run) {
- switch_to(fillnwater_plant_run);
- } else if (state == fullauto_kickstart_run) {
- switch_to(fullauto_plant_run);
- } else {
- switch_to(fullauto_plant_purge_run);
- }
- } else if ((millis() - last_animation_time) >= 500) {
- // update animation if needed
- last_animation_time = millis();
- switch_to(state);
- }
- }
-
- if (state == fullauto_fert_run) {
- unsigned long runtime = millis() - start_time;
- for (int i = 0; i < plants.countFertilizers(); i++) {
- if (selected_ferts.isSet(i)) {
- if ((runtime / 1000UL) >= auto_pump_runtime[i]) {
- plants.stopFertilizer(i);
- selected_ferts.set(i, false);
- }
- }
- }
-
- if ((millis() - last_animation_time) >= 500) {
- // update animation if needed
- last_animation_time = millis();
- switch_to(state);
- }
-
- if (selected_ferts.countSet() <= 0) {
- plants.abort();
-
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- // if the waterlevel is currently empty, we
- // set a flag to record the time to fill
- filling_started_empty = (wl == Plants::empty);
-
- plants.openWaterInlet();
- selected_id = plants.countPlants() + 1;
- selected_time = MAX_TANK_FILL_TIME;
- start_time = millis();
- switch_to(fullauto_tank_run);
- } else if (wl == Plants::full) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- // for recording the flowrate
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- switch_to(fullauto_kickstart_run);
- } else {
- switch_to(fullauto_plant_run);
- }
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- }
- }
-
- // states that fill the tank up
- if ((state == auto_fert_run) || (state == auto_tank_run)
- || (state == fullauto_tank_run) || (state == fullauto_tank_purge_run)
- || (state == fillnwater_tank_run)) {
- unsigned long runtime = millis() - start_time;
- if ((runtime / 1000UL) >= selected_time) {
- // stop if timeout has been reached
- plants.abort();
- stop_time = millis();
- if ((state == fillnwater_tank_run)
- || (state == fullauto_tank_run)
- || (state == fullauto_tank_purge_run)) {
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::empty) && (wl != Plants::invalid)) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- if (state == fillnwater_tank_run) {
- switch_to(fillnwater_kickstart_run);
- } else if (state == fullauto_tank_run) {
- switch_to(fullauto_kickstart_run);
- } else {
- switch_to(fullauto_kickstart_purge_run);
- }
- } else {
- if (state == fillnwater_tank_run) {
- switch_to(fillnwater_plant_run);
- } else if (state == fullauto_tank_run) {
- switch_to(fullauto_plant_run);
- } else {
- switch_to(fullauto_plant_purge_run);
- }
- }
- } else if (wl == Plants::empty) {
- stop_time = millis();
- switch_to(auto_done);
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- } else {
- switch_to(auto_done);
- }
- } else if ((millis() - last_animation_time) >= 500) {
- // update animation if needed
- last_animation_time = millis();
- switch_to(state);
- }
-
- // check water level state
- auto wl = plants.getWaterlevel();
- if (wl == Plants::full) {
- plants.abort();
- stop_time = millis();
- if ((state == fillnwater_tank_run)
- || (state == fullauto_tank_run)
- || (state == fullauto_tank_purge_run)) {
- // record time to fill here, if we started with
- // an empty tank at the start of filling
- if (filling_started_empty) {
- unsigned long time_to_fill = stop_time - start_time;
- debug.print("Filling tank took ");
- debug.print(String(time_to_fill));
- debug.println("ms");
-
- #if defined(PLATFORM_ESP)
- wifi_write_database(time_to_fill, "calibrated_filling", -1);
- #endif // PLATFORM_ESP
- }
-
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- if (state == fillnwater_tank_run) {
- switch_to(fillnwater_kickstart_run);
- } else if (state == fullauto_tank_run) {
- switch_to(fullauto_kickstart_run);
- } else {
- switch_to(fullauto_kickstart_purge_run);
- }
- } else {
- if (state == fillnwater_tank_run) {
- switch_to(fillnwater_plant_run);
- } else if (state == fullauto_tank_run) {
- switch_to(fullauto_plant_run);
- } else {
- switch_to(fullauto_plant_purge_run);
- }
- }
- } else {
- switch_to(auto_done);
- }
- } else if (wl == Plants::invalid) {
- plants.abort();
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- }
-
- // states that empty the tank
- if ((state == auto_plant_run) || (state == fillnwater_plant_run)
- || (state == fullauto_plant_run) || (state == fullauto_plant_overrun)
- || (state == fullauto_plant_purge_run)
- || (state == fullauto_plant_purge_overrun)
- || (state == fullauto_plant_purge_over_pump_run)) {
- unsigned long runtime = millis() - start_time;
- if ((runtime / 1000UL) >= selected_time) {
- if (state == fullauto_plant_run) {
- start_time = millis();
- selected_time = OVERRUN_RUNTIME;
- switch_to(fullauto_plant_overrun);
- } else if (state == fullauto_plant_overrun) {
- plants.abort();
- stop_time = millis();
- auto wl = plants.getWaterlevel();
- if ((wl != Plants::full) && (wl != Plants::invalid)) {
- // if the waterlevel is currently empty, we
- // set a flag to record the time to fill
- filling_started_empty = (wl == Plants::empty);
-
- plants.openWaterInlet();
- selected_id = plants.countPlants() + 1;
- selected_time = PURGE_FILL_RUNTIME;
- start_time = millis();
- switch_to(fullauto_tank_purge_run);
- } else if (wl == Plants::full) {
- // check if kickstart is required for this
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- // start kickstart/valve as needed
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, need_kickstart);
- }
- }
-
- // for recording the flowrate
- watering_started_full = (wl == Plants::full);
-
- selected_time = MAX_AUTO_PLANT_RUNTIME;
- start_time = millis();
- if (need_kickstart) {
- switch_to(fullauto_kickstart_purge_run);
- } else {
- switch_to(fullauto_plant_purge_run);
- }
- } else if (wl == Plants::invalid) {
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- } else if (state == fullauto_plant_purge_run) {
- start_time = millis();
- selected_time = OVERRUN_RUNTIME;
- switch_to(fullauto_plant_purge_overrun);
- } else if (state == fullauto_plant_purge_overrun) {
- plants.abort();
- stop_time = millis();
-
- bool need_kickstart = false;
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- if (plants.getKickstart()->getPinNumber(i) >= 0) {
- need_kickstart = true;
- }
- }
- }
-
- start_time = millis();
- selected_time = FULLAUTO_END_PUMP_TIME;
-
- if (need_kickstart) {
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- plants.startPlant(i, true);
- }
- }
-
- switch_to(fullauto_plant_purge_over_pump_run);
- } else {
- switch_to(fullauto_done);
- }
- } else if (state == fullauto_plant_purge_over_pump_run) {
- plants.abort();
- stop_time = millis();
- switch_to(fullauto_done);
- } else {
- plants.abort();
- stop_time = millis();
- switch_to(auto_done);
- }
- } else if ((millis() - last_animation_time) >= 500) {
- // update animation if needed
- last_animation_time = millis();
- switch_to(state);
- }
-
- if ((state == fullauto_plant_overrun)
- || (state == fullauto_plant_purge_overrun)
- || (state == fullauto_plant_purge_over_pump_run)) {
- // overrun should not exit when sensor returns empty
- return;
- }
-
- // check water level state
- auto wl = plants.getWaterlevel();
- if (wl == Plants::empty) {
- if ((state == auto_plant_run) || (state == fillnwater_plant_run)) {
- plants.abort();
- stop_time = millis();
- }
-
- if ((state == auto_plant_run) || (state == fillnwater_plant_run)
- || (state == fullauto_plant_run)) {
- // if we started watering with a full tank
- // and then finished watering when it was empty
- // and we were only watering a single plant
- // look at this as a "calibration run" and record
- // the time it took to empty the tank
- if (watering_started_full && (selected_plants.countSet() == 1)) {
- unsigned long time_to_water = stop_time - start_time;
- debug.print("Watering plant ");
- debug.print(selected_plants.getFirstSet() + 1);
- debug.print(" with the complete tank took ");
- debug.print(String(time_to_water));
- debug.println("ms");
-
- #if defined(PLATFORM_ESP)
- wifi_write_database(time_to_water, "calibrated_watering", selected_plants.getFirstSet() + 1);
- #endif // PLATFORM_ESP
- }
- }
-
- if ((state == auto_plant_run) || (state == fillnwater_plant_run)) {
- switch_to(auto_done);
- } else if (state == fullauto_plant_run) {
- start_time = millis();
- selected_time = OVERRUN_RUNTIME;
- switch_to(fullauto_plant_overrun);
- } else if (state == fullauto_plant_purge_run) {
- start_time = millis();
- selected_time = OVERRUN_RUNTIME;
- switch_to(fullauto_plant_purge_overrun);
- }
- } else if (wl == Plants::invalid) {
- plants.abort();
- error_condition = F("Invalid sensor state");
- state = auto_mode_a;
- switch_to(error);
- }
- }
-
- // timeout in user-input states
- if ((state == menu_a) || (state == menu_b) || (state == menu_c)
- || (state == automation_mode) || (state == auto_done)
- || (state == auto_mode_a) || (state == auto_mode_b)
- || (state == auto_fert_a) || (state == auto_fert_b)
- || (state == auto_plant) || (state == fillnwater_plant)
- || (state == menu_pumps) || (state == menu_pumps_time)
- || (state == menu_pumps_go) || (state == menu_pumps_done)
- || (state == menu_valves) || (state == menu_valves_time)
- || (state == menu_valves_go) || (state == menu_valves_done)
- || (state == menu_aux) || (state == menu_aux_time)
- || (state == menu_aux_go) || (state == menu_aux_done)
- || (state == fullauto_fert) || (state == fullauto_plant)
- || (state == fullauto_done)) {
- unsigned long runtime = millis() - into_state_time;
- if (runtime >= BACK_TO_IDLE_TIMEOUT) {
- debug.print("Idle timeout reached in state ");
- debug.println(state_names[state]);
- switch_to(init);
- }
- }
- }
-
- void Statemachine::switch_to(States s) {
- old_state = state;
- state = s;
- into_state_time = millis();
-
- if (old_state != state) {
- // don't spam log with every animation state "change"
- debug.print("switch_to ");
- debug.print(state_names[old_state]);
- debug.print(" --> ");
- debug.println(state_names[state]);
-
- menu_entered_digits = "";
-
- #ifdef PLATFORM_ESP
- wifi_broadcast_state_change(state_names[state]);
- #endif
- }
-
- if (s == init) {
- String a = String(F("- Giess-o-mat V")) + FIRMWARE_VERSION + String(F(" -"));
-
- #if (LOCK_COUNT > 0) && defined(DOOR_LOCK_PIN)
- String b = String(F("PIN: ")) + menu_entered_digits;
- print(a.c_str(),
- "* or # to enter menu",
- "Enter PIN for locks:",
- b.c_str(),
- 3);
- #else
- print(a.c_str(),
- "Usage: Enter number",
- "* Delete prev. digit",
- "# Execute input num.",
- -1);
- #endif
- } else if (s == door_select) {
- String a = String(F("(Input 1 to ")) + String(LOCK_COUNT) + String(F(")"));
- String b = String(F("Door: ")) + menu_entered_digits;
-
- print("- Select Door Lock -",
- "Leave empty if done!",
- a.c_str(),
- b.c_str(),
- 3);
- } else if (s == menu_a) {
- print("----- Menu 1/3 -----",
- "1: Manual Operation",
- "2: Automation",
- "#: Go to page 2/3...",
- -1);
- } else if (s == menu_b) {
- print("----- Menu 2/3 -----",
- "3: Fertilizer pumps",
- "4: Outlet valves",
- "#: Go to page 3/3...",
- -1);
- } else if (s == menu_c) {
- print("----- Menu 3/3 -----",
- "5: Aux. Outputs",
- #if (LOCK_COUNT > 0) && !defined(DOOR_LOCK_PIN)
- "6: Door Locks",
- #else
- "",
- #endif
- "#: Go to page 1/3...",
- -1);
- } else if (state == automation_mode) {
- // TODO
- print("---- Automation ----",
- "TODO NOT IMPLEMENTED",
- "TODO NOT IMPLEMENTED",
- "TODO NOT IMPLEMENTED",
- -1);
- } else if (s == auto_mode_a) {
- print("---- Manual 1/3 ----",
- "1: Full-Auto Mode",
- "2: Add Fertilizer",
- "#: Go to page 2/3...",
- -1);
- } else if (s == auto_mode_b) {
- print("---- Manual 2/3 ----",
- "3: Fill 'n' Water",
- "4: Fill Reservoir",
- "#: Go to page 3/3...",
- -1);
- } else if (s == auto_mode_c) {
- print("---- Manual 3/3 ----",
- "5: Water a plant",
- "",
- "#: Go to page 1/3...",
- -1);
- } else if (s == auto_fert_a) {
- print("-- Fertilizer 1/2 --",
- "1: Vegetation Phase",
- "2: Bloom Phase",
- "#: Go to page 2/2...",
- -1);
- } else if (s == auto_fert_b) {
- print("-- Fertilizer 2/2 --",
- "3: Special Fert.",
- "4: Run Stirrer",
- "#: Go to page 1/2...",
- -1);
- } else if ((s == auto_fert_run) || (s == fullauto_fert_run)) {
- unsigned long runtime = millis() - start_time;
- String a = String(F("Time: ")) + String(runtime / 1000UL) + String(F("s / ")) + String(selected_time) + String('s');
-
- unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
- String b;
- for (unsigned long i = 0; i < anim; i++) {
- b += '#';
- }
-
- print("---- Dispensing ----",
- a.c_str(),
- b.c_str(),
- "Hit any key to stop!",
- -1);
- } else if ((s == auto_stirr_run) || (s == fullauto_stirr_run)) {
- unsigned long runtime = millis() - start_time;
- String a = String(F("Time: ")) + String(runtime / 1000UL) + String(F("s / ")) + String(selected_time) + String('s');
-
- unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
- String b;
- for (unsigned long i = 0; i < anim; i++) {
- b += '#';
- }
-
- print("----- Stirring -----",
- a.c_str(),
- b.c_str(),
- "Hit any key to stop!",
- -1);
- } else if ((s == auto_tank_run) || (s == fillnwater_tank_run) || (s == fullauto_tank_run) || (s == fullauto_tank_purge_run)) {
- unsigned long runtime = millis() - start_time;
- String a = String(F("Time: ")) + String(runtime / 1000UL) + String(F("s / ")) + String(selected_time) + String('s');
-
- unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
- String b;
- for (unsigned long i = 0; i < anim; i++) {
- b += '#';
- }
-
- print("--- Filling Tank ---",
- a.c_str(),
- b.c_str(),
- "Hit any key to stop!",
- -1);
- } else if ((s == auto_plant) || (s == fillnwater_plant) || (s == fullauto_plant)) {
- String a = String(F("(Input 1 to ")) + String(plants.countPlants()) + String(F(")"));
- String b = String(F("Plant: ")) + menu_entered_digits;
-
- print("--- Select Plant ---",
- "Leave empty if done!",
- a.c_str(),
- b.c_str(),
- 3);
- } else if (s == fullauto_fert) {
- String a = String(F("(Input 1 to ")) + String(plants.countFertilizers()) + String(F(")"));
- String b = String(F("Fert.: ")) + menu_entered_digits;
-
- print("--- Select Fert. ---",
- "Leave empty if done!",
- a.c_str(),
- b.c_str(),
- 3);
- } else if ((s == auto_plant_kickstart_run) || (s == fillnwater_kickstart_run) || (s == fullauto_kickstart_run) || (s == fullauto_kickstart_purge_run)) {
- unsigned long runtime = millis() - start_time;
- String a = String(F("Time: ")) + String(runtime / 1000UL) + String(F("s / ")) + String(KICKSTART_RUNTIME) + String('s');
-
- unsigned long anim = runtime * 20UL / (KICKSTART_RUNTIME * 1000UL);
- String b;
- for (unsigned long i = 0; i < anim; i++) {
- b += '#';
- }
-
- print("---- Kick-Start ----",
- a.c_str(),
- b.c_str(),
- "Hit any key to stop!",
- -1);
- } else if ((s == auto_plant_run) || (s == fillnwater_plant_run) || (s == fullauto_plant_run) || (s == fullauto_plant_purge_run)) {
- unsigned long runtime = millis() - start_time;
- String a = String(F("Time: ")) + String(runtime / 1000UL) + String(F("s / ")) + String(selected_time) + String('s');
-
- unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
- String b;
- for (unsigned long i = 0; i < anim; i++) {
- b += '#';
- }
-
- print("----- Watering -----",
- a.c_str(),
- b.c_str(),
- "Hit any key to stop!",
- -1);
- } else if ((s == fullauto_plant_overrun)
- || (s == fullauto_plant_purge_overrun)
- || (s == fullauto_plant_purge_over_pump_run)) {
- unsigned long runtime = millis() - start_time;
- String a = String(F("Time: ")) + String(runtime / 1000UL) + String(F("s / ")) + String(selected_time) + String('s');
-
- unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
- String b;
- for (unsigned long i = 0; i < anim; i++) {
- b += '#';
- }
-
- print("-- Emptying lines --",
- a.c_str(),
- b.c_str(),
- "Hit any key to stop!",
- -1);
- } else if ((s == auto_done) || (s == fullauto_done)) {
- String a = String(F("after ")) + String((stop_time - start_time) / 1000UL) + String(F("s."));
-
- print("------- Done -------",
- "Dispensing finished",
- a.c_str(),
- "Hit any key for menu",
- -1);
-
- #if defined(PLATFORM_ESP)
- unsigned long runtime = stop_time - start_time;
- if ((old_state == auto_plant_run) || (old_state == fillnwater_plant_run)) {
- for (int i = 0; i < plants.countPlants(); i++) {
- if (selected_plants.isSet(i)) {
- wifi_write_database(runtime / 1000, "plant", i + 1);
- }
- }
- } else if (old_state == auto_fert_run) {
- wifi_write_database(runtime / 1000, "fertilizer", selected_id);
- }
- #endif // PLATFORM_ESP
- } else if (s == menu_pumps) {
- String a = String(F("(Input 1 to ")) + String(plants.countFertilizers()) + String(F(")"));
- String b = String(F("Pump: ")) + menu_entered_digits;
-
- print("------- Pump -------",
- "Please select pump",
- a.c_str(),
- b.c_str(),
- 3);
- } else if (s == menu_pumps_time) {
- String header = String(F("------ Pump ")) + String(selected_id) + String(F(" ------"));
- String b = String(F("Runtime: ")) + menu_entered_digits;
-
- print(header.c_str(),
- "Please set runtime",
- "(Input in seconds)",
- b.c_str(),
- 3);
- } else if (s == menu_pumps_go) {
- String a = String(F("Pump No. ")) + String(selected_id);
- String b = String(F("Runtime ")) + String(selected_time) + String('s');
-
- print("----- Confirm? -----",
- a.c_str(),
- b.c_str(),
- " # Confirm",
- -1);
- } else if (s == menu_pumps_run) {
- unsigned long runtime = millis() - start_time;
- String a = String(F("Time: ")) + String(runtime / 1000UL) + String(F("s / ")) + String(selected_time) + String('s');
-
- unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
- String b;
- for (unsigned long i = 0; i < anim; i++) {
- b += '#';
- }
-
- print("---- Dispensing ----",
- a.c_str(),
- b.c_str(),
- "Hit any key to stop!",
- -1);
- } else if (s == menu_pumps_done) {
- String a = String(F("after ")) + String((stop_time - start_time) / 1000UL) + String(F("s."));
-
- print("------- Done -------",
- "Dispensing finished",
- a.c_str(),
- "Hit any key for menu",
- -1);
-
- #if defined(PLATFORM_ESP)
- unsigned long runtime = stop_time - start_time;
- wifi_write_database(runtime / 1000, "fertilizer", selected_id);
- #endif // PLATFORM_ESP
- } else if (s == menu_valves) {
- String a = String(F("(Input 1 to ")) + String(plants.countPlants() + 1) + String(F(")"));
- String b = String(F("Valve: ")) + menu_entered_digits;
-
- print("------ Valves ------",
- "Please select valve",
- a.c_str(),
- b.c_str(),
- 3);
- } else if (s == menu_valves_time) {
- String header = String(F("----- Valve ")) + String(selected_id) + String(F(" -----"));
- String b = String(F("Runtime: ")) + menu_entered_digits;
-
- print(header.c_str(),
- "Please set runtime",
- "(Input in seconds)",
- b.c_str(),
- 3);
- } else if (s == menu_valves_go) {
- String a = String(F("Valve No. ")) + String(selected_id);
- String b = String(F("Runtime ")) + String(selected_time) + String('s');
-
- print("----- Confirm? -----",
- a.c_str(),
- b.c_str(),
- " # Confirm",
- -1);
- } else if (s == menu_valves_run) {
- unsigned long runtime = millis() - start_time;
- String a = String(F("Time: ")) + String(runtime / 1000UL) + String(F("s / ")) + String(selected_time) + String('s');
-
- unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
- String b;
- for (unsigned long i = 0; i <= anim; i++) {
- b += '#';
- }
-
- print("---- Dispensing ----",
- a.c_str(),
- b.c_str(),
- "Hit any key to stop!",
- -1);
- } else if (s == menu_valves_done) {
- String a = String(F("after ")) + String((stop_time - start_time) / 1000UL) + String(F("s."));
-
- print("------- Done -------",
- "Dispensing finished",
- a.c_str(),
- "Hit any key for menu",
- -1);
-
- #if defined(PLATFORM_ESP)
- unsigned long runtime = stop_time - start_time;
- if (selected_id <= plants.countPlants()) {
- wifi_write_database(runtime / 1000, "plant", selected_id);
- }
- #endif // PLATFORM_ESP
- } else if (s == menu_aux) {
- String a = String(F("(Input 1 to ")) + String(plants.countAux()) + String(F(")"));
- String b = String(F("Aux.: ")) + menu_entered_digits;
-
- print("------- Aux. -------",
- "Please select aux.",
- a.c_str(),
- b.c_str(),
- 3);
- } else if (s == menu_aux_time) {
- String header = String(F("------ Aux ")) + String(selected_id) + String(F(" ------"));
- String b = String(F("Runtime: ")) + menu_entered_digits;
-
- print(header.c_str(),
- "Please set runtime",
- "(Input in seconds)",
- b.c_str(),
- 3);
- } else if (s == menu_aux_go) {
- String a = String(F("Aux No. ")) + String(selected_id);
- String b = String(F("Runtime ")) + String(selected_time) + String('s');
-
- print("----- Confirm? -----",
- a.c_str(),
- b.c_str(),
- " # Confirm",
- -1);
- } else if (s == menu_aux_run) {
- unsigned long runtime = millis() - start_time;
- String a = String(F("Time: ")) + String(runtime / 1000UL) + String(F("s / ")) + String(selected_time) + String('s');
-
- unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
- String b;
- for (unsigned long i = 0; i <= anim; i++) {
- b += '#';
- }
-
- print("----- Stirring -----",
- a.c_str(),
- b.c_str(),
- "Hit any key to stop!",
- -1);
- } else if (s == menu_aux_done) {
- String a = String(F("after ")) + String((stop_time - start_time) / 1000UL) + String(F("s."));
-
- print("------- Done -------",
- "Aux. run finished",
- a.c_str(),
- "Hit any key for menu",
- -1);
- } else if (s == error) {
- print("------ Error! ------",
- "There is a problem:",
- error_condition.c_str(),
- " Press any key...",
- -1);
- } else {
- debug.print("Invalid state ");
- debug.println(s);
- }
- }
-
- #endif
|