123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
-
-
- #include <stdio.h>
- #include <string.h>
-
- #include "picowota/reboot.h"
-
- #include "config.h"
- #include "log.h"
- #include "main.h"
- #include "menu.h"
- #include "mem.h"
- #include "state.h"
- #include "state_value.h"
- #include "state_workflow.h"
- #include "state_settings.h"
-
- static void exit_cb(void) {
- state_switch(STATE_SCAN);
- }
-
- static void enter_cb(int selection) {
- switch (selection) {
- case 0:
-
- state_value_set(&mem_data()->wf_auto_connect,
- sizeof(mem_data()->wf_auto_connect),
- 0, 1, VAL_STEP_INCREMENT, 1,
- "Auto Connect");
- state_value_return(STATE_SETTINGS);
- state_switch(STATE_VALUE);
- break;
-
- case 1:
-
- state_value_set(&mem_data()->backlight,
- sizeof(mem_data()->backlight),
- 0x00FF, 0xFF00, VAL_STEP_SHIFT, 1,
- "Brightness");
- state_value_return(STATE_SETTINGS);
- state_switch(STATE_VALUE);
- break;
-
- case 2:
-
- state_wf_edit(true);
- state_switch(STATE_WORKFLOW);
- break;
-
- case 3:
-
- state_value_set(&mem_data()->enable_wifi,
- sizeof(mem_data()->enable_wifi),
- 0, 1, VAL_STEP_INCREMENT, 1,
- "Enable WiFi");
- state_value_return(STATE_SETTINGS);
- state_switch(STATE_VALUE);
- break;
-
- case 4:
-
- state_switch(STATE_WIFI_NETS);
- break;
-
- case 5:
-
- mem_load_defaults();
- break;
-
- case 6:
-
- picowota_reboot(true);
- break;
-
- default:
- exit_cb();
- break;
- }
- }
-
- void state_settings_enter(void) {
- menu_init(enter_cb, NULL, NULL, exit_cb);
- }
-
- void state_settings_exit(void) {
- menu_deinit();
- mem_write();
-
-
- if (mem_data()->enable_wifi) {
- if (!wifi_initialized()) {
- networking_init();
- }
- } else {
- if (wifi_initialized()) {
- networking_deinit();
- }
- }
- }
-
- static void draw(struct menu_state *menu) {
- int pos = 0;
- menu->length = 0;
-
- ADD_STATIC_ELEMENT("Auto Connect (%d)", mem_data()->wf_auto_connect);
- ADD_STATIC_ELEMENT("Brightness (%d)", __builtin_ffs(mem_data()->backlight));
- ADD_STATIC_ELEMENT("Edit Workflows");
- ADD_STATIC_ELEMENT("Enable WiFi (%d)", mem_data()->enable_wifi);
- ADD_STATIC_ELEMENT("WiFi Networks");
- ADD_STATIC_ELEMENT("Factory Reset");
- ADD_STATIC_ELEMENT("OTA Update");
-
- ADD_STATIC_ELEMENT("... go back");
-
- if (menu->selection < 0) {
- menu->selection = 0;
- }
- }
-
- void state_settings_run(void) {
- menu_run(draw, false);
- }
|