Browse Source

add basics of settings menu, about screen.

Thomas Buck 6 months ago
parent
commit
7a045d33cd
12 changed files with 284 additions and 6 deletions
  1. 2
    0
      CMakeLists.txt
  2. 3
    0
      include/config.h
  3. 7
    2
      include/mem.h
  4. 13
    0
      include/menu.h
  5. 2
    0
      include/state.h
  6. 26
    0
      include/state_about.h
  7. 26
    0
      include/state_settings.h
  8. 1
    1
      src/mem.c
  9. 12
    0
      src/state.c
  10. 121
    0
      src/state_about.c
  11. 8
    3
      src/state_scan.c
  12. 63
    0
      src/state_settings.c

+ 2
- 0
CMakeLists.txt View File

90
     src/mem.c
90
     src/mem.c
91
     src/state_edit_workflow.c
91
     src/state_edit_workflow.c
92
     src/workflow_default.c
92
     src/workflow_default.c
93
+    src/state_settings.c
94
+    src/state_about.c
93
 
95
 
94
     ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ff.c
96
     ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ff.c
95
     ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ffunicode.c
97
     ${CMAKE_CURRENT_BINARY_DIR}/fatfs/ffunicode.c

+ 3
- 0
include/config.h View File

19
 #ifndef __CONFIG_H__
19
 #ifndef __CONFIG_H__
20
 #define __CONFIG_H__
20
 #define __CONFIG_H__
21
 
21
 
22
+#define APP_VERSION_MAJOR 0
23
+#define APP_VERSION_MINOR 1
24
+
22
 #define MENU_PREFER_VOLCANO
25
 #define MENU_PREFER_VOLCANO
23
 //#define MENU_PREFER_CRAFTY
26
 //#define MENU_PREFER_CRAFTY
24
 
27
 

+ 7
- 2
include/mem.h View File

20
 #define __MEM_H__
20
 #define __MEM_H__
21
 
21
 
22
 #include <stdint.h>
22
 #include <stdint.h>
23
+#include <stdbool.h>
24
+
23
 #include "workflow.h"
25
 #include "workflow.h"
24
 
26
 
25
-#define MEM_VERSION 0x02
27
+// to migrate settings when struct changes between releases
28
+#define MEM_VERSION 0
26
 
29
 
27
 struct mem_data {
30
 struct mem_data {
28
     uint16_t backlight;
31
     uint16_t backlight;
32
+    bool wf_auto_connect;
29
 
33
 
30
     uint16_t wf_count;
34
     uint16_t wf_count;
31
     struct workflow wf[WF_MAX_FLOWS];
35
     struct workflow wf[WF_MAX_FLOWS];
32
-} __attribute__((packed));
36
+};
33
 
37
 
34
 // wf and wf_count are assigned in mem_init()
38
 // wf and wf_count are assigned in mem_init()
35
 #define MEM_DATA_INIT {           \
39
 #define MEM_DATA_INIT {           \
36
     .backlight = (0xFF00 >> 1),   \
40
     .backlight = (0xFF00 >> 1),   \
41
+    .wf_auto_connect = false,     \
37
 }
42
 }
38
 
43
 
39
 void mem_init(void);
44
 void mem_init(void);

+ 13
- 0
include/menu.h View File

43
 extern bool menu_got_input;
43
 extern bool menu_got_input;
44
 #endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
44
 #endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
45
 
45
 
46
+#define ADD_STATIC_ELEMENT(name) {\
47
+    menu->length += 1; \
48
+    if (((menu->length - 1) >= menu->off) \
49
+        && ((menu->length - 1 - menu->off) < MENU_MAX_LINES)) { \
50
+        if ((menu->length - 1) == menu->selection) { \
51
+            pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "> "); \
52
+        } else { \
53
+            pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "  "); \
54
+        } \
55
+        pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, name "\n"); \
56
+    } \
57
+}
58
+
46
 #endif // __MENU_H__
59
 #endif // __MENU_H__

+ 2
- 0
include/state.h View File

26
     STATE_VOLCANO_RUN,
26
     STATE_VOLCANO_RUN,
27
     STATE_CRAFTY,
27
     STATE_CRAFTY,
28
     STATE_EDIT_WORKFLOW,
28
     STATE_EDIT_WORKFLOW,
29
+    STATE_SETTINGS,
30
+    STATE_ABOUT,
29
 
31
 
30
     STATE_INVALID,
32
     STATE_INVALID,
31
 };
33
 };

+ 26
- 0
include/state_about.h View File

1
+/*
2
+ * state_about.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_ABOUT_H__
20
+#define __STATE_ABOUT_H__
21
+
22
+void state_about_enter(void);
23
+void state_about_exit(void);
24
+void state_about_run(void);
25
+
26
+#endif // __STATE_ABOUT_H__

+ 26
- 0
include/state_settings.h View File

1
+/*
2
+ * state_settings.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_SETTINGS_H__
20
+#define __STATE_SETTINGS_H__
21
+
22
+void state_settings_enter(void);
23
+void state_settings_exit(void);
24
+void state_settings_run(void);
25
+
26
+#endif // __STATE_SETTINGS_H__

+ 1
- 1
src/mem.c View File

40
     uint32_t checksum;
40
     uint32_t checksum;
41
 
41
 
42
     struct mem_data data;
42
     struct mem_data data;
43
-} __attribute__((packed));
43
+};
44
 
44
 
45
 #define MEM_CONTENTS_INIT { \
45
 #define MEM_CONTENTS_INIT { \
46
     .version = MEM_VERSION, \
46
     .version = MEM_VERSION, \

+ 12
- 0
src/state.c View File

23
 #include "state_volcano_run.h"
23
 #include "state_volcano_run.h"
24
 #include "state_crafty.h"
24
 #include "state_crafty.h"
25
 #include "state_edit_workflow.h"
25
 #include "state_edit_workflow.h"
26
+#include "state_settings.h"
27
+#include "state_about.h"
26
 #include "state.h"
28
 #include "state.h"
27
 
29
 
28
 #define stringify(name) # name
30
 #define stringify(name) # name
66
         .exit = state_edit_wf_exit,
68
         .exit = state_edit_wf_exit,
67
         .run = state_edit_wf_run,
69
         .run = state_edit_wf_run,
68
     }, {
70
     }, {
71
+        .name = stringify(STATE_SETTINGS),
72
+        .enter = state_settings_enter,
73
+        .exit = state_settings_exit,
74
+        .run = state_settings_run,
75
+    }, {
76
+        .name = stringify(STATE_ABOUT),
77
+        .enter = state_about_enter,
78
+        .exit = state_about_exit,
79
+        .run = state_about_run,
80
+    }, {
69
         .name = stringify(STATE_INVALID),
81
         .name = stringify(STATE_INVALID),
70
         .enter = NULL,
82
         .enter = NULL,
71
         .exit = NULL,
83
         .exit = NULL,

+ 121
- 0
src/state_about.c View File

1
+/*
2
+ * state_about.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
+#include <string.h>
21
+
22
+#include "config.h"
23
+#include "buttons.h"
24
+#include "log.h"
25
+#include "lcd.h"
26
+#include "text.h"
27
+#include "menu.h"
28
+#include "state.h"
29
+#include "state_about.h"
30
+
31
+#define xstr(s) str(s)
32
+#define str(s) #s
33
+
34
+static const char *about_text =
35
+    "Volcano RC Gadget\n"
36
+    "by xythobuz\n"
37
+    "Licensed as GPLv3\n"
38
+    "\n"
39
+
40
+    "V" xstr(APP_VERSION_MAJOR) "." xstr(APP_VERSION_MINOR) "\n"
41
+#ifdef NDEBUG
42
+    "Release Build\n"
43
+#else // NDEBUG
44
+    "Debug Build\n"
45
+#endif // NDEBUG
46
+    __DATE__ " " __TIME__ "\n"
47
+    "\n"
48
+
49
+    "Included libs:\n"
50
+    "hathach/tinyusb\n"
51
+    "abbrev/fatfs\n"
52
+    "bluekitchen/btstack\n"
53
+    "mcufont/mcufont\n"
54
+    "hepingood/st7789\n"
55
+    "\n"
56
+
57
+    "This program is free software: you can redistribute it and/or modify "
58
+    "it under the terms of the GNU General Public License as published by "
59
+    "the Free Software Foundation, either version 3 of the License, or "
60
+    "(at your option) any later version.\n"
61
+    "\n"
62
+    "This program is distributed in the hope that it will be useful, "
63
+    "but WITHOUT ANY WARRANTY; without even the implied warranty of "
64
+    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the "
65
+    "GNU General Public License for more details.\n"
66
+    "\n"
67
+    "See <http://www.gnu.org/licenses/>.\n"
68
+;
69
+
70
+static const uint16_t step_size = 10;
71
+static const uint16_t max_height = (MENU_MAX_LINES * 20) + ((MENU_MAX_LINES - 1) * 2);
72
+
73
+static uint16_t off = 0;
74
+static bool held_up = false;
75
+static bool held_down = false;
76
+static int16_t last_draw_off = 0;
77
+
78
+static void draw(void) {
79
+    int16_t r;
80
+    r = text_box(about_text, false,
81
+                 "DejaVuSerif16",
82
+                 0, LCD_WIDTH,
83
+                 50, max_height,
84
+                 -off);
85
+    last_draw_off = r;
86
+}
87
+
88
+static void about_buttons(enum buttons btn, bool state) {
89
+    if (state && (btn == BTN_Y)) {
90
+        state_switch(STATE_SCAN);
91
+    } else if (btn == BTN_UP) {
92
+        held_up = state;
93
+    } else if (btn == BTN_DOWN) {
94
+        held_down = state;
95
+    }
96
+}
97
+
98
+void state_about_enter(void) {
99
+    buttons_callback(about_buttons);
100
+    off = 0;
101
+    draw();
102
+}
103
+
104
+void state_about_exit(void) {
105
+    buttons_callback(NULL);
106
+}
107
+
108
+void state_about_run(void) {
109
+    if (held_up) {
110
+        if (off >= step_size) {
111
+            off -= step_size;
112
+            draw();
113
+        }
114
+    }
115
+    if (held_down) {
116
+        if (last_draw_off >= max_height) {
117
+            off += step_size;
118
+            draw();
119
+        }
120
+    }
121
+}

+ 8
- 3
src/state_scan.c View File

59
             return;
59
             return;
60
         }
60
         }
61
     }
61
     }
62
+
63
+    if (selection == devs) {
64
+        state_switch(STATE_SETTINGS);
65
+    } else if (selection == (devs + 1)) {
66
+        state_switch(STATE_ABOUT);
67
+    }
62
 }
68
 }
63
 
69
 
64
 static void edit_cb(int selection) {
70
 static void edit_cb(int selection) {
161
     }
167
     }
162
 #endif // !defined(MENU_PREFER_VOLCANO) && !defined(MENU_PREFER_CRAFTY)
168
 #endif // !defined(MENU_PREFER_VOLCANO) && !defined(MENU_PREFER_CRAFTY)
163
 
169
 
164
-    if (menu->length == 0) {
165
-        strncpy(menu->buff, "NONE", MENU_MAX_LEN);
166
-    }
170
+    ADD_STATIC_ELEMENT("Settings");
171
+    ADD_STATIC_ELEMENT("About");
167
 }
172
 }
168
 
173
 
169
 void state_scan_run(void) {
174
 void state_scan_run(void) {

+ 63
- 0
src/state_settings.c View File

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
+
19
+#include <stdio.h>
20
+#include <string.h>
21
+
22
+#include "config.h"
23
+#include "log.h"
24
+#include "menu.h"
25
+#include "state.h"
26
+#include "state_settings.h"
27
+
28
+static void enter_cb(int selection) {
29
+    switch (selection) {
30
+    case 0:
31
+        // Auto Connect
32
+
33
+    }
34
+}
35
+
36
+static void exit_cb(void) {
37
+    state_switch(STATE_SCAN);
38
+}
39
+
40
+void state_settings_enter(void) {
41
+    menu_init(enter_cb, NULL, NULL, exit_cb);
42
+}
43
+
44
+void state_settings_exit(void) {
45
+    menu_deinit();
46
+}
47
+
48
+static void draw(struct menu_state *menu) {
49
+    int pos = 0;
50
+    menu->length = 0;
51
+
52
+    ADD_STATIC_ELEMENT("Auto Connect");
53
+    ADD_STATIC_ELEMENT("Brightness");
54
+    ADD_STATIC_ELEMENT("Workflows");
55
+
56
+    if (menu->selection < 0) {
57
+        menu->selection = 0;
58
+    }
59
+}
60
+
61
+void state_settings_run(void) {
62
+    menu_run(draw, false);
63
+}

Loading…
Cancel
Save