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