S&B Volcano vaporizer remote control with Pi Pico W
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

state.c 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * state.c
  3. *
  4. * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
  5. *
  6. * This program 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. * This program 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. * See <http://www.gnu.org/licenses/>.
  17. */
  18. #include "config.h"
  19. #include "log.h"
  20. #include "state_scan.h"
  21. #include "state_volcano_workflow.h"
  22. #include "state.h"
  23. static enum system_state state = STATE_INIT;
  24. void state_switch(enum system_state next) {
  25. if (state == next) {
  26. return;
  27. }
  28. // clean up old state when leaving it
  29. switch (state) {
  30. case STATE_SCAN:
  31. debug("leaving STATE_SCAN");
  32. state_scan_exit();
  33. break;
  34. case STATE_VOLCANO_WORKFLOW:
  35. debug("leaving STATE_VOLCANO_WORKFLOW");
  36. state_volcano_wf_exit();
  37. break;
  38. default:
  39. break;
  40. }
  41. // prepare new state on entering
  42. switch (next) {
  43. case STATE_SCAN:
  44. debug("entering STATE_SCAN");
  45. state_scan_enter();
  46. break;
  47. case STATE_VOLCANO_WORKFLOW:
  48. debug("entering STATE_VOLCANO_WORKFLOW");
  49. state_volcano_wf_enter();
  50. break;
  51. default:
  52. break;
  53. }
  54. state = next;
  55. }
  56. void state_run(void) {
  57. switch (state) {
  58. case STATE_INIT:
  59. break;
  60. case STATE_SCAN:
  61. state_scan_run();
  62. break;
  63. case STATE_VOLCANO_WORKFLOW:
  64. state_volcano_wf_run();
  65. break;
  66. default:
  67. debug("invalid main state %d", state);
  68. state_switch(STATE_SCAN);
  69. break;
  70. }
  71. }