S&B Volcano vaporizer remote control with Pi Pico W
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * state_edit_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. // TODO adding and removing whole steps
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include "config.h"
  22. #include "mem.h"
  23. #include "menu.h"
  24. #include "workflow.h"
  25. #include "state.h"
  26. #include "state_value.h"
  27. #include "state_edit_workflow.h"
  28. static uint16_t wf_index = 0;
  29. static void exit_cb(void) {
  30. state_switch(STATE_WORKFLOW);
  31. }
  32. static void enter_cb(int selection) {
  33. static char buff[20];
  34. if ((selection >= 0) && (selection < wf_steps(wf_index))) {
  35. struct wf_step *step = wf_get_step(wf_index, selection);
  36. switch (step->op) {
  37. case OP_SET_TEMPERATURE:
  38. case OP_WAIT_TEMPERATURE:
  39. snprintf(buff, sizeof(buff),
  40. "%s Temp.",
  41. step->op == OP_WAIT_TEMPERATURE ? "Wait" : "Set");
  42. state_value_set(&step->val,
  43. sizeof(step->val),
  44. 400, 2300, VAL_STEP_INCREMENT, 10,
  45. buff);
  46. break;
  47. case OP_WAIT_TIME:
  48. case OP_PUMP_TIME:
  49. snprintf(buff, sizeof(buff),
  50. "%s Time",
  51. step->op == OP_WAIT_TIME ? "Wait" : "Pump");
  52. state_value_set(&step->val,
  53. sizeof(step->val),
  54. 0, 60000, VAL_STEP_INCREMENT, 1000,
  55. buff);
  56. break;
  57. }
  58. state_value_return(STATE_EDIT_WORKFLOW);
  59. state_switch(STATE_VALUE);
  60. } else {
  61. exit_cb();
  62. }
  63. }
  64. static void lower_cb(int selection) {
  65. if ((selection > 0) && (selection < wf_steps(wf_index))) {
  66. wf_move_step_down(wf_index, selection);
  67. }
  68. }
  69. static void upper_cb(int selection) {
  70. if ((selection >= 0) && (selection < (wf_steps(wf_index) - 1))) {
  71. wf_move_step_up(wf_index, selection);
  72. }
  73. }
  74. void state_edit_wf_index(uint16_t index) {
  75. wf_index = index;
  76. }
  77. void state_edit_wf_enter(void) {
  78. menu_init(enter_cb, lower_cb, upper_cb, exit_cb);
  79. }
  80. void state_edit_wf_exit(void) {
  81. menu_deinit();
  82. }
  83. static void draw(struct menu_state *menu) {
  84. menu->length = wf_steps(wf_index);
  85. int pos = 0;
  86. for (uint16_t i = 0; i < menu->length; i++) {
  87. if ((i < menu->off)
  88. || ((i - menu->off) >= MENU_MAX_LINES)) {
  89. continue;
  90. }
  91. if (i == menu->selection) {
  92. pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "> ");
  93. } else {
  94. pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, " ");
  95. }
  96. struct wf_step *step = wf_get_step(wf_index, i);
  97. pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
  98. "% 2d: %s\n", i, wf_step_str(step));
  99. }
  100. ADD_STATIC_ELEMENT("... go back");
  101. if (menu->selection < 0) {
  102. menu->selection = 0;
  103. }
  104. }
  105. void state_edit_wf_run(void) {
  106. menu_run(draw, false);
  107. }