DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Statemachine.cpp 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /*
  2. * Copyright (c) 2021 Thomas Buck <thomas@xythobuz.de>
  3. *
  4. * This file is part of Giess-o-mat.
  5. *
  6. * Giess-o-mat is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Giess-o-mat is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Giess-o-mat. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #include "Plants.h"
  20. #include "DebugLog.h"
  21. #include "Statemachine.h"
  22. #include "config.h"
  23. Statemachine::DigitBuffer::DigitBuffer(int _size) {
  24. size = _size;
  25. pos = 0;
  26. digits = new int[size];
  27. }
  28. Statemachine::DigitBuffer::~DigitBuffer() {
  29. delete digits;
  30. }
  31. bool Statemachine::DigitBuffer::spaceLeft(void) {
  32. return (pos < size);
  33. }
  34. bool Statemachine::DigitBuffer::hasDigits(void) {
  35. return (pos > 0);
  36. }
  37. int Statemachine::DigitBuffer::countDigits(void) {
  38. return pos;
  39. }
  40. void Statemachine::DigitBuffer::addDigit(int d) {
  41. if (spaceLeft()) {
  42. digits[pos] = d;
  43. pos++;
  44. }
  45. }
  46. void Statemachine::DigitBuffer::removeDigit(void) {
  47. if (hasDigits()) {
  48. pos--;
  49. }
  50. }
  51. void Statemachine::DigitBuffer::clear(void) {
  52. pos = 0;
  53. }
  54. uint32_t Statemachine::DigitBuffer::getNumber(void) {
  55. uint32_t fact = 1;
  56. uint32_t sum = 0;
  57. for (int i = (pos - 1); i >= 0; i--) {
  58. sum += digits[i] * fact;
  59. fact *= 10;
  60. }
  61. return sum;
  62. }
  63. static const char *state_names[] = {
  64. stringify(init),
  65. stringify(menu),
  66. stringify(auto_mode),
  67. stringify(auto_fert),
  68. stringify(auto_fert_run),
  69. stringify(auto_tank_run),
  70. stringify(auto_plant),
  71. stringify(auto_plant_run),
  72. stringify(auto_done),
  73. stringify(menu_pumps),
  74. stringify(menu_pumps_time),
  75. stringify(menu_pumps_go),
  76. stringify(menu_pumps_run),
  77. stringify(menu_pumps_done),
  78. stringify(menu_valves),
  79. stringify(menu_valves_time),
  80. stringify(menu_valves_go),
  81. stringify(menu_valves_run),
  82. stringify(menu_valves_done),
  83. stringify(error)
  84. };
  85. const char *Statemachine::getStateName(void) {
  86. return state_names[state];
  87. }
  88. Statemachine::Statemachine(print_fn _print, backspace_fn _backspace)
  89. : db(7) {
  90. state = init;
  91. old_state = init;
  92. print = _print;
  93. backspace = _backspace;
  94. selected_id = 0;
  95. selected_time = 0;
  96. start_time = 0;
  97. stop_time = 0;
  98. last_animation_time = 0;
  99. error_condition = "";
  100. }
  101. void Statemachine::begin(void) {
  102. switch_to(init);
  103. }
  104. void Statemachine::input(int n) {
  105. if (state == init) {
  106. switch_to(menu);
  107. } else if (state == menu) {
  108. if (n == 1) {
  109. switch_to(auto_mode);
  110. } else if (n == 2) {
  111. switch_to(menu_pumps);
  112. } else if (n == 3) {
  113. switch_to(menu_valves);
  114. } else if ((n == -1) || (n == -2)) {
  115. switch_to(init);
  116. }
  117. } else if (state == auto_mode) {
  118. if (n == 1) {
  119. switch_to(auto_fert);
  120. } else if (n == 2) {
  121. auto wl = plants.getWaterlevel();
  122. if ((wl != Plants::full) && (wl != Plants::invalid)) {
  123. plants.openWaterInlet();
  124. selected_id = plants.countPlants() + 1;
  125. selected_time = MAX_TANK_FILL_TIME;
  126. start_time = millis();
  127. switch_to(auto_tank_run);
  128. } else if (wl == Plants::full) {
  129. stop_time = millis();
  130. switch_to(auto_mode);
  131. } else if (wl == Plants::invalid) {
  132. error_condition = "Invalid sensor state";
  133. state = auto_mode;
  134. switch_to(error);
  135. }
  136. } else if (n == 3) {
  137. switch_to(auto_plant);
  138. } else if ((n == -1) || (n == -2)) {
  139. switch_to(menu);
  140. }
  141. } else if (state == auto_fert) {
  142. if ((n >= 1) && (n <= 3)) {
  143. auto wl = plants.getWaterlevel();
  144. if ((wl != Plants::full) && (wl != Plants::invalid)) {
  145. plants.startFertilizer(n - 1);
  146. selected_id = n;
  147. selected_time = AUTO_PUMP_RUNTIME;
  148. start_time = millis();
  149. switch_to(auto_fert_run);
  150. } else if (wl == Plants::full) {
  151. stop_time = millis();
  152. switch_to(auto_mode);
  153. } else if (wl == Plants::invalid) {
  154. error_condition = "Invalid sensor state";
  155. state = auto_mode;
  156. switch_to(error);
  157. }
  158. } else if ((n == -1) || (n == -2)) {
  159. switch_to(auto_mode);
  160. }
  161. } else if (state == auto_fert_run) {
  162. plants.abort();
  163. stop_time = millis();
  164. switch_to(auto_done);
  165. } else if (state == auto_tank_run) {
  166. plants.abort();
  167. stop_time = millis();
  168. switch_to(auto_done);
  169. } else if (state == auto_plant) {
  170. if (n == -1) {
  171. if (db.hasDigits()) {
  172. backspace();
  173. db.removeDigit();
  174. } else {
  175. switch_to(auto_mode);
  176. }
  177. } else if (n == -2) {
  178. if (!db.hasDigits()) {
  179. return;
  180. }
  181. selected_id = number_input();
  182. if ((selected_id <= 0) || (selected_id > plants.countPlants())) {
  183. error_condition = "Invalid plant ID!";
  184. switch_to(error);
  185. } else {
  186. auto wl = plants.getWaterlevel();
  187. if ((wl != Plants::empty) && (wl != Plants::invalid)) {
  188. plants.startPlant(selected_id - 1);
  189. selected_time = MAX_AUTO_PLANT_RUNTIME;
  190. start_time = millis();
  191. switch_to(auto_plant_run);
  192. } else if (wl == Plants::empty) {
  193. stop_time = millis();
  194. switch_to(auto_mode);
  195. } else if (wl == Plants::invalid) {
  196. error_condition = "Invalid sensor state";
  197. state = auto_mode;
  198. switch_to(error);
  199. }
  200. }
  201. } else {
  202. if (db.spaceLeft()) {
  203. db.addDigit(n);
  204. } else {
  205. backspace();
  206. }
  207. }
  208. } else if (state == auto_plant_run) {
  209. plants.abort();
  210. stop_time = millis();
  211. switch_to(auto_done);
  212. } else if (state == auto_done) {
  213. switch_to(auto_mode);
  214. } else if (state == menu_pumps) {
  215. if (n == -1) {
  216. if (db.hasDigits()) {
  217. backspace();
  218. db.removeDigit();
  219. } else {
  220. switch_to(menu);
  221. }
  222. } else if (n == -2) {
  223. if (!db.hasDigits()) {
  224. return;
  225. }
  226. selected_id = number_input();
  227. if ((selected_id <= 0) || (selected_id > plants.countFertilizers())) {
  228. error_condition = "Invalid pump ID!";
  229. switch_to(error);
  230. } else {
  231. switch_to(menu_pumps_time);
  232. }
  233. } else {
  234. if (db.spaceLeft()) {
  235. db.addDigit(n);
  236. } else {
  237. backspace();
  238. }
  239. }
  240. } else if (state == menu_pumps_time) {
  241. if (n == -1) {
  242. if (db.hasDigits()) {
  243. backspace();
  244. db.removeDigit();
  245. } else {
  246. switch_to(menu_pumps);
  247. }
  248. } else if (n == -2) {
  249. if (!db.hasDigits()) {
  250. return;
  251. }
  252. selected_time = number_input();
  253. if ((selected_time <= 0) || (selected_time > MAX_PUMP_RUNTIME)) {
  254. error_condition = "Invalid time range!";
  255. switch_to(error);
  256. } else {
  257. switch_to(menu_pumps_go);
  258. }
  259. } else {
  260. if (db.spaceLeft()) {
  261. db.addDigit(n);
  262. } else {
  263. backspace();
  264. }
  265. }
  266. } else if (state == menu_pumps_go) {
  267. if (n == -2) {
  268. start_time = millis();
  269. last_animation_time = start_time;
  270. auto wl = plants.getWaterlevel();
  271. if ((wl != Plants::full) && (wl != Plants::invalid)) {
  272. plants.startFertilizer(selected_id - 1);
  273. switch_to(menu_pumps_run);
  274. } else if (wl == Plants::full) {
  275. stop_time = millis();
  276. switch_to(menu_pumps_done);
  277. } else if (wl == Plants::invalid) {
  278. error_condition = "Invalid sensor state";
  279. state = menu_pumps;
  280. switch_to(error);
  281. }
  282. } else {
  283. switch_to(menu_pumps_time);
  284. }
  285. } else if (state == menu_pumps_run) {
  286. plants.abort();
  287. stop_time = millis();
  288. switch_to(menu_pumps_done);
  289. } else if (state == menu_pumps_done) {
  290. switch_to(menu);
  291. } else if (state == menu_valves) {
  292. if (n == -1) {
  293. if (db.hasDigits()) {
  294. backspace();
  295. db.removeDigit();
  296. } else {
  297. switch_to(menu);
  298. }
  299. } else if (n == -2) {
  300. if (!db.hasDigits()) {
  301. return;
  302. }
  303. selected_id = number_input();
  304. if ((selected_id <= 0) || (selected_id > (plants.countPlants() + 1))) {
  305. error_condition = "Invalid valve ID!";
  306. switch_to(error);
  307. } else {
  308. switch_to(menu_valves_time);
  309. }
  310. } else {
  311. if (db.spaceLeft()) {
  312. db.addDigit(n);
  313. } else {
  314. backspace();
  315. }
  316. }
  317. } else if (state == menu_valves_time) {
  318. if (n == -1) {
  319. if (db.hasDigits()) {
  320. backspace();
  321. db.removeDigit();
  322. } else {
  323. switch_to(menu_valves);
  324. }
  325. } else if (n == -2) {
  326. if (!db.hasDigits()) {
  327. return;
  328. }
  329. selected_time = number_input();
  330. if ((selected_time <= 0) || (selected_time > MAX_VALVE_RUNTIME)) {
  331. error_condition = "Invalid time range!";
  332. switch_to(error);
  333. } else {
  334. switch_to(menu_valves_go);
  335. }
  336. } else {
  337. if (db.spaceLeft()) {
  338. db.addDigit(n);
  339. } else {
  340. backspace();
  341. }
  342. }
  343. } else if (state == menu_valves_go) {
  344. if (n == -2) {
  345. start_time = millis();
  346. last_animation_time = start_time;
  347. auto wl = plants.getWaterlevel();
  348. if ((wl != Plants::full) && (wl != Plants::invalid)) {
  349. if (selected_id >= (plants.countPlants() + 1)) {
  350. plants.openWaterInlet();
  351. } else {
  352. plants.startPlant(selected_id - 1);
  353. }
  354. switch_to(menu_valves_run);
  355. } else if (wl == Plants::full) {
  356. stop_time = millis();
  357. switch_to(menu_valves_done);
  358. } else if (wl == Plants::invalid) {
  359. error_condition = "Invalid sensor state";
  360. state = menu_valves;
  361. switch_to(error);
  362. }
  363. } else {
  364. switch_to(menu_valves_time);
  365. }
  366. } else if (state == menu_valves_run) {
  367. plants.abort();
  368. stop_time = millis();
  369. switch_to(menu_valves_done);
  370. } else if (state == menu_valves_done) {
  371. switch_to(menu);
  372. } else if (state == error) {
  373. if (old_state != error) {
  374. switch_to(old_state);
  375. } else {
  376. switch_to(menu);
  377. }
  378. }
  379. }
  380. uint32_t Statemachine::number_input(void) {
  381. for (int i = 0; i < db.countDigits(); i++) {
  382. backspace();
  383. }
  384. uint32_t n = db.getNumber();
  385. db.clear();
  386. debug.print("Whole number input: ");
  387. debug.println(n);
  388. return n;
  389. }
  390. void Statemachine::act(void) {
  391. if ((state == menu_pumps_run) || (state == menu_valves_run)) {
  392. unsigned long runtime = millis() - start_time;
  393. if ((runtime / 1000UL) >= selected_time) {
  394. // stop if timeout has been reached
  395. plants.abort();
  396. stop_time = millis();
  397. switch_to((state == menu_pumps_run) ? menu_pumps_done : menu_valves_done);
  398. } else if ((millis() - last_animation_time) >= 500) {
  399. // update animation if needed
  400. last_animation_time = millis();
  401. switch_to(state);
  402. }
  403. }
  404. #ifdef CHECK_SENSORS_VALVE_PUMP_MENU_FULL
  405. if ((state == menu_pumps_run) || ((state == menu_valves_run) && (selected_id == (plants.countPlants() + 1)))) {
  406. // check water level state
  407. auto wl = plants.getWaterlevel();
  408. if (wl == Plants::full) {
  409. plants.abort();
  410. stop_time = millis();
  411. switch_to((state == menu_pumps_run) ? menu_pumps_done : menu_valves_done);
  412. } else if (wl == Plants::invalid) {
  413. plants.abort();
  414. error_condition = "Invalid sensor state";
  415. state = (state == menu_pumps_run) ? menu_pumps : menu_valves;
  416. switch_to(error);
  417. }
  418. }
  419. #endif // CHECK_SENSORS_VALVE_PUMP_MENU_FULL
  420. #ifdef CHECK_SENSORS_VALVE_PUMP_MENU_EMPTY
  421. if ((state == menu_valves_run) && (selected_id <= plants.countPlants())) {
  422. // check water level state
  423. auto wl = plants.getWaterlevel();
  424. if (wl == Plants::empty) {
  425. plants.abort();
  426. stop_time = millis();
  427. switch_to(menu_valves_done);
  428. } else if (wl == Plants::invalid) {
  429. plants.abort();
  430. error_condition = "Invalid sensor state";
  431. state = menu_valves;
  432. switch_to(error);
  433. }
  434. }
  435. #endif // CHECK_SENSORS_VALVE_PUMP_MENU_EMPTY
  436. if ((state == auto_fert_run) || (state == auto_tank_run)) {
  437. unsigned long runtime = millis() - start_time;
  438. if ((runtime / 1000UL) >= selected_time) {
  439. // stop if timeout has been reached
  440. plants.abort();
  441. stop_time = millis();
  442. switch_to(auto_done);
  443. } else if ((millis() - last_animation_time) >= 500) {
  444. // update animation if needed
  445. last_animation_time = millis();
  446. switch_to(state);
  447. }
  448. // check water level state
  449. auto wl = plants.getWaterlevel();
  450. if (wl == Plants::full) {
  451. plants.abort();
  452. stop_time = millis();
  453. switch_to(auto_done);
  454. } else if (wl == Plants::invalid) {
  455. plants.abort();
  456. error_condition = "Invalid sensor state";
  457. state = auto_mode;
  458. switch_to(error);
  459. }
  460. }
  461. if (state == auto_plant_run) {
  462. unsigned long runtime = millis() - start_time;
  463. if ((runtime / 1000UL) >= selected_time) {
  464. // stop if timeout has been reached
  465. plants.abort();
  466. stop_time = millis();
  467. switch_to(auto_done);
  468. } else if ((millis() - last_animation_time) >= 500) {
  469. // update animation if needed
  470. last_animation_time = millis();
  471. switch_to(state);
  472. }
  473. // check water level state
  474. auto wl = plants.getWaterlevel();
  475. if (wl == Plants::empty) {
  476. plants.abort();
  477. stop_time = millis();
  478. switch_to(auto_done);
  479. } else if (wl == Plants::invalid) {
  480. plants.abort();
  481. error_condition = "Invalid sensor state";
  482. state = auto_mode;
  483. switch_to(error);
  484. }
  485. }
  486. }
  487. void Statemachine::switch_to(States s) {
  488. old_state = state;
  489. state = s;
  490. if (s == init) {
  491. String a = String("- Giess-o-mat V") + FIRMWARE_VERSION + String(" -");
  492. print(a.c_str(),
  493. "Usage: Enter number",
  494. "* Delete prev. digit",
  495. "# Execute input num.",
  496. -1);
  497. } else if (s == menu) {
  498. print("------- Menu -------",
  499. "1: Automatic program",
  500. "2: Fertilizer pumps",
  501. "3: Outlet valves",
  502. -1);
  503. } else if (s == auto_mode) {
  504. print("------- Auto -------",
  505. "1: Add Fertilizer",
  506. "2: Fill Reservoir",
  507. "3: Water a plant",
  508. -1);
  509. } else if (s == auto_fert) {
  510. print("---- Fertilizer ----",
  511. "1: Vegetation Phase",
  512. "2: Bloom Phase",
  513. "3: Special",
  514. -1);
  515. } else if (s == auto_fert_run) {
  516. unsigned long runtime = millis() - start_time;
  517. String a = String("Runtime: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
  518. unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
  519. String b;
  520. for (unsigned long i = 0; i < anim; i++) {
  521. b += '#';
  522. }
  523. print("---- Dispensing ----",
  524. a.c_str(),
  525. b.c_str(),
  526. "Hit any key to stop!",
  527. -1);
  528. } else if (s == auto_tank_run) {
  529. unsigned long runtime = millis() - start_time;
  530. String a = String("Runtime: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
  531. unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
  532. String b;
  533. for (unsigned long i = 0; i < anim; i++) {
  534. b += '#';
  535. }
  536. print("--- Filling Tank ---",
  537. a.c_str(),
  538. b.c_str(),
  539. "Hit any key to stop!",
  540. -1);
  541. } else if (s == auto_plant) {
  542. String a = String("(Input 1 to ") + String(plants.countPlants()) + String(")");
  543. print("--- Select Plant ---",
  544. "Which plant to water",
  545. a.c_str(),
  546. "Plant: ",
  547. 3);
  548. } else if (s == auto_plant_run) {
  549. unsigned long runtime = millis() - start_time;
  550. String a = String("Runtime: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
  551. unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
  552. String b;
  553. for (unsigned long i = 0; i < anim; i++) {
  554. b += '#';
  555. }
  556. print("----- Watering -----",
  557. a.c_str(),
  558. b.c_str(),
  559. "Hit any key to stop!",
  560. -1);
  561. } else if (s == auto_done) {
  562. String a = String("after ") + String((stop_time - start_time) / 1000UL) + String("s.");
  563. print("------- Done -------",
  564. "Dispensing finished",
  565. a.c_str(),
  566. "Hit any key for menu",
  567. -1);
  568. } else if (s == menu_pumps) {
  569. String a = String("(Input 1 to ") + String(plants.countFertilizers()) + String(")");
  570. print("------- Pump -------",
  571. "Please select pump",
  572. a.c_str(),
  573. "Pump: ",
  574. 3);
  575. } else if (s == menu_pumps_time) {
  576. String header = String("------ Pump ") + String(selected_id) + String(" ------");
  577. print(header.c_str(),
  578. "Please set runtime",
  579. "(Input in seconds)",
  580. "Runtime: ",
  581. 3);
  582. } else if (s == menu_pumps_go) {
  583. String a = String("Pump No. ") + String(selected_id);
  584. String b = String("Runtime ") + String(selected_time) + String('s');
  585. print("----- Confirm? -----",
  586. a.c_str(),
  587. b.c_str(),
  588. " # Confirm",
  589. -1);
  590. } else if (s == menu_pumps_run) {
  591. unsigned long runtime = millis() - start_time;
  592. String a = String("Runtime: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
  593. unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
  594. String b;
  595. for (unsigned long i = 0; i < anim; i++) {
  596. b += '#';
  597. }
  598. print("---- Dispensing ----",
  599. a.c_str(),
  600. b.c_str(),
  601. "Hit any key to stop!",
  602. -1);
  603. } else if (s == menu_pumps_done) {
  604. String a = String("after ") + String((stop_time - start_time) / 1000UL) + String("s.");
  605. print("------- Done -------",
  606. "Dispensing finished",
  607. a.c_str(),
  608. "Hit any key for menu",
  609. -1);
  610. } else if (s == menu_valves) {
  611. String a = String("(Input 1 to ") + String(plants.countPlants() + 1) + String(")");
  612. print("------ Valves ------",
  613. "Please select valve",
  614. a.c_str(),
  615. "Valve: ",
  616. 3);
  617. } else if (s == menu_valves_time) {
  618. String header = String("----- Valve ") + String(selected_id) + String(" -----");
  619. print(header.c_str(),
  620. "Please set runtime",
  621. "(Input in seconds)",
  622. "Runtime: ",
  623. 3);
  624. } else if (s == menu_valves_go) {
  625. String a = String("Valve No. ") + String(selected_id);
  626. String b = String("Runtime ") + String(selected_time) + String('s');
  627. print("----- Confirm? -----",
  628. a.c_str(),
  629. b.c_str(),
  630. " # Confirm",
  631. -1);
  632. } else if (s == menu_valves_run) {
  633. unsigned long runtime = millis() - start_time;
  634. String a = String("Runtime: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
  635. unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
  636. String b;
  637. for (unsigned long i = 0; i <= anim; i++) {
  638. b += '#';
  639. }
  640. print("---- Dispensing ----",
  641. a.c_str(),
  642. b.c_str(),
  643. "Hit any key to stop!",
  644. -1);
  645. } else if (s == menu_valves_done) {
  646. String a = String("after ") + String((stop_time - start_time) / 1000UL) + String("s.");
  647. print("------- Done -------",
  648. "Dispensing finished",
  649. a.c_str(),
  650. "Hit any key for menu",
  651. -1);
  652. } else if (s == error) {
  653. print("------ Error! ------",
  654. "There is a problem:",
  655. error_condition.c_str(),
  656. " Press any key...",
  657. -1);
  658. }
  659. }