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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 exit_cb(void) {
  30. state_switch(STATE_SCAN);
  31. }
  32. static void enter_cb(int selection) {
  33. switch (selection) {
  34. case 0:
  35. // Auto Connect
  36. state_value_set(&mem_data()->wf_auto_connect,
  37. sizeof(mem_data()->wf_auto_connect),
  38. 0, 1, VAL_STEP_INCREMENT, 1,
  39. "Auto Connect");
  40. state_value_return(STATE_SETTINGS);
  41. state_switch(STATE_VALUE);
  42. break;
  43. case 1:
  44. // Brightness
  45. state_value_set(&mem_data()->backlight,
  46. sizeof(mem_data()->backlight),
  47. 0x00FF, 0xFF00, VAL_STEP_SHIFT, 1,
  48. "Brightness");
  49. state_value_return(STATE_SETTINGS);
  50. state_switch(STATE_VALUE);
  51. break;
  52. case 2:
  53. // Edit Workflows
  54. state_wf_edit(true);
  55. state_switch(STATE_WORKFLOW);
  56. break;
  57. case 3:
  58. // Enable WiFi
  59. state_value_set(&mem_data()->enable_wifi,
  60. sizeof(mem_data()->enable_wifi),
  61. 0, 1, VAL_STEP_INCREMENT, 1,
  62. "Enable WiFi");
  63. state_value_return(STATE_SETTINGS);
  64. state_switch(STATE_VALUE);
  65. break;
  66. case 4:
  67. // WiFi Networks
  68. state_switch(STATE_WIFI_NETS);
  69. break;
  70. case 5:
  71. // Factory Reset
  72. mem_load_defaults();
  73. break;
  74. case 6:
  75. // OTA Update
  76. picowota_reboot(true);
  77. break;
  78. default:
  79. exit_cb();
  80. break;
  81. }
  82. }
  83. void state_settings_enter(void) {
  84. menu_init(enter_cb, NULL, NULL, exit_cb);
  85. }
  86. void state_settings_exit(void) {
  87. menu_deinit();
  88. mem_write();
  89. // apply changed wifi state
  90. if (mem_data()->enable_wifi) {
  91. if (!wifi_initialized()) {
  92. wifi_init();
  93. }
  94. } else {
  95. if (wifi_initialized()) {
  96. wifi_deinit();
  97. }
  98. }
  99. }
  100. static void draw(struct menu_state *menu) {
  101. int pos = 0;
  102. menu->length = 0;
  103. ADD_STATIC_ELEMENT("Auto Connect (%d)", mem_data()->wf_auto_connect);
  104. ADD_STATIC_ELEMENT("Brightness (%d)", __builtin_ffs(mem_data()->backlight));
  105. ADD_STATIC_ELEMENT("Edit Workflows");
  106. ADD_STATIC_ELEMENT("Enable WiFi (%d)", mem_data()->enable_wifi);
  107. ADD_STATIC_ELEMENT("WiFi Networks");
  108. ADD_STATIC_ELEMENT("Factory Reset");
  109. ADD_STATIC_ELEMENT("OTA Update");
  110. ADD_STATIC_ELEMENT("... go back");
  111. if (menu->selection < 0) {
  112. menu->selection = 0;
  113. }
  114. }
  115. void state_settings_run(void) {
  116. menu_run(draw, false);
  117. }