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_settings.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * state_settings.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 "log.h"
  22. #include "menu.h"
  23. #include "mem.h"
  24. #include "state.h"
  25. #include "state_value.h"
  26. #include "state_workflow.h"
  27. #include "state_settings.h"
  28. static void enter_cb(int selection) {
  29. switch (selection) {
  30. case 0:
  31. // Auto Connect
  32. state_value_set(&mem_data()->wf_auto_connect,
  33. sizeof(mem_data()->wf_auto_connect),
  34. 0, 1, VAL_STEP_INCREMENT, 1);
  35. state_value_return(STATE_SETTINGS);
  36. state_switch(STATE_VALUE);
  37. break;
  38. case 1:
  39. // Brightness
  40. state_value_set(&mem_data()->backlight,
  41. sizeof(mem_data()->backlight),
  42. 0x00FF, 0xFF00, VAL_STEP_SHIFT, 1);
  43. state_value_return(STATE_SETTINGS);
  44. state_switch(STATE_VALUE);
  45. break;
  46. case 2:
  47. // Workflows
  48. state_wf_edit(true);
  49. state_switch(STATE_WORKFLOW);
  50. break;
  51. case 3:
  52. // Reset
  53. mem_load_defaults();
  54. break;
  55. }
  56. }
  57. static void exit_cb(void) {
  58. state_switch(STATE_SCAN);
  59. }
  60. void state_settings_enter(void) {
  61. menu_init(enter_cb, NULL, NULL, exit_cb);
  62. }
  63. void state_settings_exit(void) {
  64. menu_deinit();
  65. mem_write();
  66. }
  67. static void draw(struct menu_state *menu) {
  68. int pos = 0;
  69. menu->length = 0;
  70. ADD_STATIC_ELEMENT("Auto Connect");
  71. ADD_STATIC_ELEMENT("Brightness");
  72. ADD_STATIC_ELEMENT("Workflows");
  73. ADD_STATIC_ELEMENT("Reset");
  74. if (menu->selection < 0) {
  75. menu->selection = 0;
  76. }
  77. }
  78. void state_settings_run(void) {
  79. menu_run(draw, false);
  80. }