S&B Volcano vaporizer remote control with Pi Pico W
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.

state_volcano_workflow.c 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * state_volcano_workflow.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 <stdio.h>
  19. #include <string.h>
  20. #include "config.h"
  21. #include "menu.h"
  22. #include "workflow.h"
  23. #include "state.h"
  24. #include "state_volcano_run.h"
  25. #include "state_edit_workflow.h"
  26. #include "state_volcano_workflow.h"
  27. static bool edit_mode = false;
  28. static void enter_cb(int selection) {
  29. if ((selection >= 0) && (selection < wf_count())) {
  30. if (edit_mode) {
  31. state_edit_wf_index(selection);
  32. state_switch(STATE_EDIT_WORKFLOW);
  33. } else {
  34. state_volcano_run_index(selection);
  35. state_switch(STATE_VOLCANO_RUN);
  36. }
  37. }
  38. }
  39. static void lower_cb(int selection) {
  40. if (!edit_mode) {
  41. return;
  42. }
  43. if ((selection > 0) && (selection < wf_count())) {
  44. wf_move_down(selection);
  45. }
  46. }
  47. static void upper_cb(int selection) {
  48. if (!edit_mode) {
  49. return;
  50. }
  51. if ((selection >= 0) && (selection < (wf_count() - 1))) {
  52. wf_move_up(selection);
  53. }
  54. }
  55. static void exit_cb(void) {
  56. state_switch(STATE_SCAN);
  57. }
  58. void state_volcano_wf_edit(bool edit) {
  59. edit_mode = edit;
  60. }
  61. void state_volcano_wf_enter(void) {
  62. if (edit_mode) {
  63. menu_init(enter_cb, lower_cb, upper_cb, exit_cb);
  64. } else {
  65. menu_init(enter_cb, NULL, NULL, exit_cb);
  66. }
  67. }
  68. void state_volcano_wf_exit(void) {
  69. menu_deinit();
  70. }
  71. static void draw(struct menu_state *menu) {
  72. menu->length = wf_count();
  73. int pos = 0;
  74. for (uint16_t i = 0; i < menu->length; i++) {
  75. if ((i < menu->off)
  76. || ((i - menu->off) >= MENU_MAX_LINES)) {
  77. continue;
  78. }
  79. if (i == menu->selection) {
  80. pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "> ");
  81. } else {
  82. pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, " ");
  83. }
  84. pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
  85. "'%s' by %s\n", wf_name(i), wf_author(i));
  86. }
  87. if ((menu->selection < 0) && (menu->length > 0)) {
  88. menu->selection = 0;
  89. }
  90. if (menu->length == 0) {
  91. strncpy(menu->buff, "NONE", MENU_MAX_LEN);
  92. }
  93. }
  94. void state_volcano_wf_run(void) {
  95. menu_run(draw, false);
  96. }