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.5KB

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