Kaynağa Gözat

can edit settings now

Thomas Buck 6 ay önce
ebeveyn
işleme
b2eeca99b9

+ 1
- 0
CMakeLists.txt Dosyayı Görüntüle

92
     src/workflow_default.c
92
     src/workflow_default.c
93
     src/state_settings.c
93
     src/state_settings.c
94
     src/state_about.c
94
     src/state_about.c
95
+    src/state_value.c
95
 
96
 
96
     ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ff.c
97
     ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ff.c
97
     ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ffunicode.c
98
     ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ffunicode.c

+ 3
- 7
include/config.h Dosyayı Görüntüle

25
 #define MENU_PREFER_VOLCANO
25
 #define MENU_PREFER_VOLCANO
26
 //#define MENU_PREFER_CRAFTY
26
 //#define MENU_PREFER_CRAFTY
27
 
27
 
28
+#define VOLCANO_AUTO_CONNECT_TIMEOUT_MS 2000
29
+#define VOLCANO_AUTO_CONNECT_WITHIN_MS 10000
30
+
28
 #ifdef NDEBUG
31
 #ifdef NDEBUG
29
 // Release build
32
 // Release build
30
-
31
 #define AUTO_MOUNT_MASS_STORAGE
33
 #define AUTO_MOUNT_MASS_STORAGE
32
 #define AUTO_LOG_ON_MASS_STORAGE
34
 #define AUTO_LOG_ON_MASS_STORAGE
33
 #define DEBUG_DISK_WRITE_SOURCES
35
 #define DEBUG_DISK_WRITE_SOURCES
34
-
35
-#ifdef MENU_PREFER_VOLCANO
36
-#define VOLCANO_AUTO_CONNECT_TIMEOUT_MS 2000
37
-#define VOLCANO_AUTO_CONNECT_WITHIN_MS 10000
38
-#endif // MENU_PREFER_VOLCANO
39
-
40
 #endif // NDEBUG
36
 #endif // NDEBUG
41
 
37
 
42
 #define WATCHDOG_PERIOD_MS 1000
38
 #define WATCHDOG_PERIOD_MS 1000

+ 0
- 2
include/menu.h Dosyayı Görüntüle

39
 
39
 
40
 void menu_run(void (*cb)(struct menu_state *), bool centered);
40
 void menu_run(void (*cb)(struct menu_state *), bool centered);
41
 
41
 
42
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
43
 extern bool menu_got_input;
42
 extern bool menu_got_input;
44
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
45
 
43
 
46
 #define ADD_STATIC_ELEMENT(name) {\
44
 #define ADD_STATIC_ELEMENT(name) {\
47
     menu->length += 1; \
45
     menu->length += 1; \

+ 1
- 0
include/state.h Dosyayı Görüntüle

28
     STATE_EDIT_WORKFLOW,
28
     STATE_EDIT_WORKFLOW,
29
     STATE_SETTINGS,
29
     STATE_SETTINGS,
30
     STATE_ABOUT,
30
     STATE_ABOUT,
31
+    STATE_VALUE,
31
 
32
 
32
     STATE_INVALID,
33
     STATE_INVALID,
33
 };
34
 };

+ 39
- 0
include/state_value.h Dosyayı Görüntüle

1
+/*
2
+ * state_value.h
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
+
19
+#ifndef __STATE_VALUE_H__
20
+#define __STATE_VALUE_H__
21
+
22
+#include <sys/types.h>
23
+#include "state.h"
24
+
25
+enum value_step_mode {
26
+    VAL_STEP_INCREMENT = 0,
27
+    VAL_STEP_SHIFT,
28
+};
29
+
30
+void state_value_set(void *value, size_t length,
31
+                     ssize_t min, ssize_t max,
32
+                     enum value_step_mode mode, ssize_t step);
33
+void state_value_return(enum system_state state);
34
+
35
+void state_value_enter(void);
36
+void state_value_exit(void);
37
+void state_value_run(void);
38
+
39
+#endif // __STATE_VALUE_H__

+ 2
- 0
include/text.h Dosyayı Görüntüle

20
 #define __TEXT_H__
20
 #define __TEXT_H__
21
 
21
 
22
 #include "mcufont.h"
22
 #include "mcufont.h"
23
+#include "menu.h"
23
 
24
 
24
 #define TEXT_BG_NONE -1
25
 #define TEXT_BG_NONE -1
26
+#define TEXT_BOX_HEIGHT(font, space) ((MENU_MAX_LINES * font) + ((MENU_MAX_LINES - 1) * space))
25
 
27
 
26
 struct text_font {
28
 struct text_font {
27
     const char *fontname;
29
     const char *fontname;

+ 4
- 0
src/main.c Dosyayı Görüntüle

44
     usb_run();
44
     usb_run();
45
     serial_run();
45
     serial_run();
46
     heartbeat_run();
46
     heartbeat_run();
47
+
48
+    if (lcd_get_backlight() != mem_data()->backlight) {
49
+        lcd_set_backlight(mem_data()->backlight);
50
+    }
47
 }
51
 }
48
 
52
 
49
 int main(void) {
53
 int main(void) {

+ 2
- 24
src/menu.c Dosyayı Görüntüle

22
 #include "buttons.h"
22
 #include "buttons.h"
23
 #include "text.h"
23
 #include "text.h"
24
 #include "lcd.h"
24
 #include "lcd.h"
25
-#include "mem.h"
26
 #include "menu.h"
25
 #include "menu.h"
27
 
26
 
28
 static char prev_buff[MENU_MAX_LEN] = {0};
27
 static char prev_buff[MENU_MAX_LEN] = {0};
32
 static void (*down_callback)(int) = NULL;
31
 static void (*down_callback)(int) = NULL;
33
 static void (*exit_callback)(void) = NULL;
32
 static void (*exit_callback)(void) = NULL;
34
 
33
 
35
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
36
 bool menu_got_input = false;
34
 bool menu_got_input = false;
37
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
38
 
35
 
39
 static void menu_buttons(enum buttons btn, bool state) {
36
 static void menu_buttons(enum buttons btn, bool state) {
40
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
41
     menu_got_input = true;
37
     menu_got_input = true;
42
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
43
 
38
 
44
-    if (state && (btn == BTN_LEFT)) {
45
-        uint16_t backlight_value = lcd_get_backlight();
46
-        if (backlight_value > 0x00FF) {
47
-            backlight_value = backlight_value >> 1;
48
-        }
49
-        lcd_set_backlight(backlight_value);
50
-        mem_data()->backlight = backlight_value;
51
-        return;
52
-    } else if (state && (btn == BTN_RIGHT)) {
53
-        uint16_t backlight_value = lcd_get_backlight();
54
-        if (backlight_value < 0xFF00) {
55
-            backlight_value = backlight_value << 1;
56
-        }
57
-        lcd_set_backlight(backlight_value);
58
-        mem_data()->backlight = backlight_value;
59
-        return;
60
-    } else if (state && ((btn == BTN_ENTER) || (btn == BTN_A))) {
39
+    if (state && ((btn == BTN_ENTER) || (btn == BTN_A))) {
61
         if (enter_callback) {
40
         if (enter_callback) {
62
             enter_callback(menu.selection);
41
             enter_callback(menu.selection);
63
         }
42
         }
127
 
106
 
128
 void menu_deinit(void) {
107
 void menu_deinit(void) {
129
     buttons_callback(NULL);
108
     buttons_callback(NULL);
130
-    mem_write();
131
 }
109
 }
132
 
110
 
133
 void menu_run(void (*draw)(struct menu_state *), bool centered) {
111
 void menu_run(void (*draw)(struct menu_state *), bool centered) {
140
         text_box(menu.buff, centered,
118
         text_box(menu.buff, centered,
141
                  "fixed_10x20",
119
                  "fixed_10x20",
142
                  0, LCD_WIDTH,
120
                  0, LCD_WIDTH,
143
-                 50, (MENU_MAX_LINES * 20) + ((MENU_MAX_LINES - 1) * 2),
121
+                 50, TEXT_BOX_HEIGHT(20, 2),
144
                  0);
122
                  0);
145
     }
123
     }
146
 }
124
 }

+ 6
- 0
src/state.c Dosyayı Görüntüle

25
 #include "state_edit_workflow.h"
25
 #include "state_edit_workflow.h"
26
 #include "state_settings.h"
26
 #include "state_settings.h"
27
 #include "state_about.h"
27
 #include "state_about.h"
28
+#include "state_value.h"
28
 #include "state.h"
29
 #include "state.h"
29
 
30
 
30
 #define stringify(name) # name
31
 #define stringify(name) # name
78
         .exit = state_about_exit,
79
         .exit = state_about_exit,
79
         .run = state_about_run,
80
         .run = state_about_run,
80
     }, {
81
     }, {
82
+        .name = stringify(STATE_VALUE),
83
+        .enter = state_value_enter,
84
+        .exit = state_value_exit,
85
+        .run = state_value_run,
86
+    }, {
81
         .name = stringify(STATE_INVALID),
87
         .name = stringify(STATE_INVALID),
82
         .enter = NULL,
88
         .enter = NULL,
83
         .exit = NULL,
89
         .exit = NULL,

+ 1
- 1
src/state_about.c Dosyayı Görüntüle

68
 ;
68
 ;
69
 
69
 
70
 static const uint16_t step_size = 10;
70
 static const uint16_t step_size = 10;
71
-static const uint16_t max_height = (MENU_MAX_LINES * 20) + ((MENU_MAX_LINES - 1) * 2);
71
+static const uint16_t max_height = TEXT_BOX_HEIGHT(20, 2);
72
 
72
 
73
 static uint16_t off = 0;
73
 static uint16_t off = 0;
74
 static bool held_up = false;
74
 static bool held_up = false;

+ 6
- 25
src/state_scan.c Dosyayı Görüntüle

24
 #include "config.h"
24
 #include "config.h"
25
 #include "ble.h"
25
 #include "ble.h"
26
 #include "models.h"
26
 #include "models.h"
27
+#include "mem.h"
27
 #include "menu.h"
28
 #include "menu.h"
28
 #include "state.h"
29
 #include "state.h"
29
 #include "state_workflow.h"
30
 #include "state_workflow.h"
33
 
34
 
34
 static struct ble_scan_result results[BLE_MAX_SCAN_RESULTS] = {0};
35
 static struct ble_scan_result results[BLE_MAX_SCAN_RESULTS] = {0};
35
 static int result_count = 0;
36
 static int result_count = 0;
36
-
37
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
38
 static uint32_t auto_connect_time = 0;
37
 static uint32_t auto_connect_time = 0;
39
 static int auto_connect_idx = 0;
38
 static int auto_connect_idx = 0;
40
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
41
 
39
 
42
 static void enter_cb(int selection) {
40
 static void enter_cb(int selection) {
43
     int devs = 0;
41
     int devs = 0;
67
     }
65
     }
68
 }
66
 }
69
 
67
 
70
-static void edit_cb(int selection) {
71
-    UNUSED(selection);
72
-
73
-    state_wf_edit(true);
74
-    state_switch(STATE_WORKFLOW);
75
-}
76
-
77
 void state_scan_enter(void) {
68
 void state_scan_enter(void) {
78
-    menu_init(enter_cb, edit_cb, NULL, NULL);
69
+    menu_init(enter_cb, NULL, NULL, NULL);
79
     ble_scan(BLE_SCAN_ON);
70
     ble_scan(BLE_SCAN_ON);
80
 }
71
 }
81
 
72
 
107
             if (dev == DEV_VOLCANO) {
98
             if (dev == DEV_VOLCANO) {
108
                 menu->selection = devs - 1;
99
                 menu->selection = devs - 1;
109
 
100
 
110
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
111
-#ifdef VOLCANO_AUTO_CONNECT_WITHIN_MS
112
                 if (to_ms_since_boot(get_absolute_time()) <= VOLCANO_AUTO_CONNECT_WITHIN_MS) {
101
                 if (to_ms_since_boot(get_absolute_time()) <= VOLCANO_AUTO_CONNECT_WITHIN_MS) {
113
-#endif // VOLCANO_AUTO_CONNECT_WITHIN_MS
114
-                    auto_connect_time = to_ms_since_boot(get_absolute_time());
115
-                    auto_connect_idx = i;
116
-#ifdef VOLCANO_AUTO_CONNECT_WITHIN_MS
102
+                    if (mem_data()->wf_auto_connect) {
103
+                        auto_connect_time = to_ms_since_boot(get_absolute_time());
104
+                        auto_connect_idx = i;
105
+                    }
117
                 }
106
                 }
118
-#endif // VOLCANO_AUTO_CONNECT_WITHIN_MS
119
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
120
             }
107
             }
121
 #endif // MENU_PREFER_VOLCANO
108
 #endif // MENU_PREFER_VOLCANO
122
 #ifdef MENU_PREFER_CRAFTY
109
 #ifdef MENU_PREFER_CRAFTY
128
 #endif // defined(MENU_PREFER_VOLCANO) || defined(MENU_PREFER_CRAFTY)
115
 #endif // defined(MENU_PREFER_VOLCANO) || defined(MENU_PREFER_CRAFTY)
129
 
116
 
130
         if ((devs - 1) == menu->selection) {
117
         if ((devs - 1) == menu->selection) {
131
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
132
             if ((auto_connect_time != 0) && (!menu_got_input)) {
118
             if ((auto_connect_time != 0) && (!menu_got_input)) {
133
                 uint32_t now = to_ms_since_boot(get_absolute_time());
119
                 uint32_t now = to_ms_since_boot(get_absolute_time());
134
                 uint32_t diff = now - auto_connect_time;
120
                 uint32_t diff = now - auto_connect_time;
136
                                 "%ld ",
122
                                 "%ld ",
137
                                 (VOLCANO_AUTO_CONNECT_TIMEOUT_MS / 1000) - (diff / 1000));
123
                                 (VOLCANO_AUTO_CONNECT_TIMEOUT_MS / 1000) - (diff / 1000));
138
             } else {
124
             } else {
139
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
140
                 pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "> ");
125
                 pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "> ");
141
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
142
             }
126
             }
143
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
144
         } else {
127
         } else {
145
             pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "  ");
128
             pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "  ");
146
         }
129
         }
174
 void state_scan_run(void) {
157
 void state_scan_run(void) {
175
     menu_run(draw, false);
158
     menu_run(draw, false);
176
 
159
 
177
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
178
     if ((auto_connect_time != 0) && (!menu_got_input)) {
160
     if ((auto_connect_time != 0) && (!menu_got_input)) {
179
         uint32_t now = to_ms_since_boot(get_absolute_time());
161
         uint32_t now = to_ms_since_boot(get_absolute_time());
180
         if ((now - auto_connect_time) >= VOLCANO_AUTO_CONNECT_TIMEOUT_MS) {
162
         if ((now - auto_connect_time) >= VOLCANO_AUTO_CONNECT_TIMEOUT_MS) {
186
             auto_connect_time = 0;
168
             auto_connect_time = 0;
187
         }
169
         }
188
     }
170
     }
189
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
190
 }
171
 }

+ 15
- 0
src/state_settings.c Dosyayı Görüntüle

24
 #include "menu.h"
24
 #include "menu.h"
25
 #include "mem.h"
25
 #include "mem.h"
26
 #include "state.h"
26
 #include "state.h"
27
+#include "state_value.h"
28
+#include "state_workflow.h"
27
 #include "state_settings.h"
29
 #include "state_settings.h"
28
 
30
 
29
 static void enter_cb(int selection) {
31
 static void enter_cb(int selection) {
30
     switch (selection) {
32
     switch (selection) {
31
     case 0:
33
     case 0:
32
         // Auto Connect
34
         // Auto Connect
35
+        state_value_set(&mem_data()->wf_auto_connect,
36
+                        sizeof(mem_data()->wf_auto_connect),
37
+                        0, 1, VAL_STEP_INCREMENT, 1);
38
+        state_value_return(STATE_SETTINGS);
39
+        state_switch(STATE_VALUE);
33
         break;
40
         break;
34
 
41
 
35
     case 1:
42
     case 1:
36
         // Brightness
43
         // Brightness
44
+        state_value_set(&mem_data()->backlight,
45
+                        sizeof(mem_data()->backlight),
46
+                        0x00FF, 0xFF00, VAL_STEP_SHIFT, 1);
47
+        state_value_return(STATE_SETTINGS);
48
+        state_switch(STATE_VALUE);
37
         break;
49
         break;
38
 
50
 
39
     case 2:
51
     case 2:
40
         // Workflows
52
         // Workflows
53
+        state_wf_edit(true);
54
+        state_switch(STATE_WORKFLOW);
41
         break;
55
         break;
42
 
56
 
43
     case 3:
57
     case 3:
57
 
71
 
58
 void state_settings_exit(void) {
72
 void state_settings_exit(void) {
59
     menu_deinit();
73
     menu_deinit();
74
+    mem_write();
60
 }
75
 }
61
 
76
 
62
 static void draw(struct menu_state *menu) {
77
 static void draw(struct menu_state *menu) {

+ 169
- 0
src/state_value.c Dosyayı Görüntüle

1
+/*
2
+ * state_value.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
+
19
+#include <stdio.h>
20
+
21
+#include "config.h"
22
+#include "buttons.h"
23
+#include "log.h"
24
+#include "lcd.h"
25
+#include "text.h"
26
+#include "state_value.h"
27
+
28
+static void *val_p = NULL;
29
+static size_t val_len = 0;
30
+static ssize_t val_min = 0;
31
+static ssize_t val_max = 0;
32
+static ssize_t val_step = 0;
33
+
34
+static enum value_step_mode val_mode = VAL_STEP_INCREMENT;
35
+static enum system_state val_ret_state = STATE_SCAN;
36
+
37
+static ssize_t val = 0;
38
+
39
+void state_value_set(void *value, size_t length,
40
+                     ssize_t min, ssize_t max,
41
+                     enum value_step_mode mode, ssize_t step) {
42
+    val_p = value;
43
+    val_len = length;
44
+    val_min = min;
45
+    val_max = max;
46
+    val_mode = mode;
47
+    val_step = step;
48
+}
49
+
50
+void state_value_return(enum system_state state) {
51
+    val_ret_state = state;
52
+}
53
+
54
+static void draw(void) {
55
+    static char buff[100];
56
+    static size_t pos = 0;
57
+
58
+    if ((val_p == NULL) || (val_len <= 0)) {
59
+        pos += snprintf(buff, sizeof(buff),
60
+                        "error");
61
+    } else {
62
+        pos += snprintf(buff, sizeof(buff),
63
+                        "%d", val);
64
+    }
65
+
66
+    text_box(buff, false,
67
+             "fixed_10x20",
68
+             0, LCD_WIDTH,
69
+             50, TEXT_BOX_HEIGHT(20, 2),
70
+             0);
71
+}
72
+
73
+static void write(void) {
74
+    if ((val_p == NULL) || (val_len <= 0)) {
75
+        debug("invalid params");
76
+        return;
77
+    }
78
+
79
+    switch (val_len) {
80
+    case 1:
81
+        *((uint8_t *)val_p) = val;
82
+        break;
83
+
84
+    case 2:
85
+        *((uint16_t *)val_p) = val;
86
+        break;
87
+
88
+    case 4:
89
+        *((uint32_t *)val_p) = val;
90
+        break;
91
+
92
+    default:
93
+        debug("invalid len %d", val_len);
94
+        return;
95
+    }
96
+}
97
+
98
+static void step(ssize_t v) {
99
+    if ((val_p == NULL) || (val_len <= 0)) {
100
+        debug("invalid params");
101
+        return;
102
+    }
103
+
104
+    if (((v > 0) && (val >= val_max))
105
+        || ((v < 0) && (val <= val_min))) {
106
+        debug("val=%d v=%d", val, v);
107
+        return;
108
+    }
109
+
110
+    switch (val_mode) {
111
+    case VAL_STEP_INCREMENT:
112
+        val += v * val_step;
113
+        break;
114
+
115
+    case VAL_STEP_SHIFT:
116
+        if ((val_step * v) > 0) {
117
+            val <<= val_step;
118
+        } else {
119
+            val >>= val_step;
120
+        }
121
+        break;
122
+    }
123
+
124
+    // apply new value while editing
125
+    write();
126
+}
127
+
128
+static void value_buttons(enum buttons btn, bool state) {
129
+    if (state && (btn == BTN_Y)) {
130
+        state_switch(val_ret_state);
131
+    } else if (state && (btn == BTN_LEFT)) {
132
+        step(-1);
133
+        draw();
134
+    } else if (state && (btn == BTN_RIGHT)) {
135
+        step(1);
136
+        draw();
137
+    }
138
+}
139
+
140
+void state_value_enter(void) {
141
+    buttons_callback(value_buttons);
142
+
143
+    switch (val_len) {
144
+    case 1:
145
+        val = *((uint8_t *)val_p);
146
+        break;
147
+
148
+    case 2:
149
+        val = *((uint16_t *)val_p);
150
+        break;
151
+
152
+    case 4:
153
+        val = *((uint32_t *)val_p);
154
+        break;
155
+
156
+    default:
157
+        debug("invalid len %d", val_len);
158
+        return;
159
+    }
160
+
161
+    draw();
162
+}
163
+
164
+void state_value_exit(void) {
165
+    buttons_callback(NULL);
166
+    write();
167
+}
168
+
169
+void state_value_run(void) { }

+ 9
- 13
src/state_workflow.c Dosyayı Görüntüle

22
 #include "pico/stdlib.h"
22
 #include "pico/stdlib.h"
23
 
23
 
24
 #include "config.h"
24
 #include "config.h"
25
+#include "mem.h"
25
 #include "menu.h"
26
 #include "menu.h"
26
 #include "workflow.h"
27
 #include "workflow.h"
27
 #include "state.h"
28
 #include "state.h"
30
 #include "state_workflow.h"
31
 #include "state_workflow.h"
31
 
32
 
32
 static bool edit_mode = false;
33
 static bool edit_mode = false;
33
-
34
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
35
 static uint32_t auto_connect_time = 0;
34
 static uint32_t auto_connect_time = 0;
36
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
37
 
35
 
38
 static void enter_cb(int selection) {
36
 static void enter_cb(int selection) {
39
     if ((selection >= 0) && (selection < wf_count())) {
37
     if ((selection >= 0) && (selection < wf_count())) {
68
 }
66
 }
69
 
67
 
70
 static void exit_cb(void) {
68
 static void exit_cb(void) {
71
-    state_switch(STATE_SCAN);
69
+    if (edit_mode) {
70
+        state_switch(STATE_SETTINGS);
71
+    } else {
72
+        state_switch(STATE_SCAN);
73
+    }
72
 }
74
 }
73
 
75
 
74
 void state_wf_edit(bool edit) {
76
 void state_wf_edit(bool edit) {
82
         menu_init(enter_cb, NULL, NULL, exit_cb);
84
         menu_init(enter_cb, NULL, NULL, exit_cb);
83
     }
85
     }
84
 
86
 
85
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
86
-    auto_connect_time = to_ms_since_boot(get_absolute_time());
87
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
87
+    if (mem_data()->wf_auto_connect) {
88
+        auto_connect_time = to_ms_since_boot(get_absolute_time());
89
+    }
88
 }
90
 }
89
 
91
 
90
 void state_wf_exit(void) {
92
 void state_wf_exit(void) {
102
         }
104
         }
103
 
105
 
104
         if (i == menu->selection) {
106
         if (i == menu->selection) {
105
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
106
             if ((auto_connect_time != 0) && (!menu_got_input) && (!edit_mode)) {
107
             if ((auto_connect_time != 0) && (!menu_got_input) && (!edit_mode)) {
107
                 uint32_t now = to_ms_since_boot(get_absolute_time());
108
                 uint32_t now = to_ms_since_boot(get_absolute_time());
108
                 uint32_t diff = now - auto_connect_time;
109
                 uint32_t diff = now - auto_connect_time;
110
                                 "%ld ",
111
                                 "%ld ",
111
                                 (VOLCANO_AUTO_CONNECT_TIMEOUT_MS / 1000) - (diff / 1000));
112
                                 (VOLCANO_AUTO_CONNECT_TIMEOUT_MS / 1000) - (diff / 1000));
112
             } else {
113
             } else {
113
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
114
                 pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "> ");
114
                 pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "> ");
115
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
116
             }
115
             }
117
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
118
         } else {
116
         } else {
119
             pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "  ");
117
             pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "  ");
120
         }
118
         }
135
 void state_wf_run(void) {
133
 void state_wf_run(void) {
136
     menu_run(draw, false);
134
     menu_run(draw, false);
137
 
135
 
138
-#ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
139
     if ((auto_connect_time != 0) && (!menu_got_input) && (!edit_mode)) {
136
     if ((auto_connect_time != 0) && (!menu_got_input) && (!edit_mode)) {
140
         uint32_t now = to_ms_since_boot(get_absolute_time());
137
         uint32_t now = to_ms_since_boot(get_absolute_time());
141
         if ((now - auto_connect_time) >= VOLCANO_AUTO_CONNECT_TIMEOUT_MS) {
138
         if ((now - auto_connect_time) >= VOLCANO_AUTO_CONNECT_TIMEOUT_MS) {
146
             menu_got_input = true;
143
             menu_got_input = true;
147
         }
144
         }
148
     }
145
     }
149
-#endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
150
 }
146
 }

Loading…
İptal
Kaydet