Merge lp:~sammyshp/flashlight-firmware/2c-turbo-config into lp:~toykeeper/flashlight-firmware/anduril2

Proposed by Sven Greiner
Status: Needs review
Proposed branch: lp:~sammyshp/flashlight-firmware/2c-turbo-config
Merge into: lp:~toykeeper/flashlight-firmware/anduril2
Diff against target: 122 lines (+36/-8)
4 files modified
ToyKeeper/spaghetti-monster/anduril/load-save-config-fsm.h (+3/-0)
ToyKeeper/spaghetti-monster/anduril/load-save-config.c (+6/-0)
ToyKeeper/spaghetti-monster/anduril/ramp-mode.c (+21/-8)
ToyKeeper/spaghetti-monster/anduril/ramp-mode.h (+6/-0)
To merge this branch: bzr merge lp:~sammyshp/flashlight-firmware/2c-turbo-config
Reviewer Review Type Date Requested Status
Selene ToyKeeper Pending
Review via email: mp+407822@code.launchpad.net

Description of the change

Add runtime configuration of 2C turbo style

This adds a new configuration option to the global configuration menu if `USE_2C_STYLE_CONFIG` is defined. The user can select between 0 (no change), 1 (Anduril 1 behavior) and 2 (Anduril 2) behavior. The default is taken from `USE_2C_MAX_TURBO` if it is defined.

If `USE_2C_STYLE_CONFIG` is not defined, this creates the same output as before (no increase in code size).

Also add dynamic setup of the global configuration menu.

To post a comment you must log in.
619. By Sven Greiner

Add runtime configuration of 2C turbo style

This adds a new configuration option to the global configuration menu if
`USE_2C_STYLE_CONFIG` is defined. The user can select between 0 (no
change), 1 (Anduril 1 behavior) and 2 (Anduril 2) behavior. The default
is taken from `USE_2C_MAX_TURBO` if it is defined.

If `USE_2C_STYLE_CONFIG` is not defined, this creates the same output as
before (no increase in code size).

Also add dynamic setup of the global configuration menu.

Revision history for this message
Selene ToyKeeper (toykeeper) wrote :

Looks like we were working on the same thing at similar times.

I used a somewhat different approach though...

- retained the USE_2C_MAX_TURBO compile option, for backward compatibility and a smaller binary
- made turbo config apply to more places, not just double-click-from-ramp
- made simple and advanced modes use independent turbo configs
- added a third style: no turbo (to retain simple UI's no-turbo policy)
- put the turbo config into ramp menus instead of the misc/globals menu

It'd be nice to remove some of the older code at some point, but for now it's still available as a compile option.

I really like the tricks you did to handle counting depending on which options are compiled in, and will have to keep it in mind for cases where it's needed. I'm debating how to handle variable features in menus though, since things get confusing when the UI has different items at different menu indexes in different builds. So for now I've tried to keep the menu item number consistent, even if prior items were compiled out. On the one hand, this leaves a gap in the menu where the user can change a setting but it has no effect. On the other hand, it means the documentation can give accurate info about which item is which, even when some items are missing.

Also, you make a good point about being able to use global variables instead of preprocessor symbols sometimes... since the compiler can detect when it never gets changed, and compile it out. I'm hoping to replace the entire set of config vars with a struct though, and I'm not sure yet if the same method will work there. Will have to test if the compiler can retain the same granular detection, or if it leaves redundant vars in since the container struct gets modified. Regardless, refactoring the config vars is going to be a bit messy, and requires some deeper changes, so I'm putting it off for now.

Unmerged revisions

619. By Sven Greiner

Add runtime configuration of 2C turbo style

This adds a new configuration option to the global configuration menu if
`USE_2C_STYLE_CONFIG` is defined. The user can select between 0 (no
change), 1 (Anduril 1 behavior) and 2 (Anduril 2) behavior. The default
is taken from `USE_2C_MAX_TURBO` if it is defined.

If `USE_2C_STYLE_CONFIG` is not defined, this creates the same output as
before (no increase in code size).

Also add dynamic setup of the global configuration menu.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ToyKeeper/spaghetti-monster/anduril/load-save-config-fsm.h'
2--- ToyKeeper/spaghetti-monster/anduril/load-save-config-fsm.h 2021-08-23 10:24:08 +0000
3+++ ToyKeeper/spaghetti-monster/anduril/load-save-config-fsm.h 2021-08-30 11:26:43 +0000
4@@ -82,6 +82,9 @@
5 #ifdef USE_AUTOLOCK
6 autolock_time_e,
7 #endif
8+ #ifdef USE_2C_STYLE_CONFIG
9+ use_2c_max_turbo_e,
10+ #endif
11 eeprom_indexes_e_END
12 } eeprom_indexes_e;
13 #define EEPROM_BYTES eeprom_indexes_e_END
14
15=== modified file 'ToyKeeper/spaghetti-monster/anduril/load-save-config.c'
16--- ToyKeeper/spaghetti-monster/anduril/load-save-config.c 2021-08-23 10:24:08 +0000
17+++ ToyKeeper/spaghetti-monster/anduril/load-save-config.c 2021-08-30 11:26:43 +0000
18@@ -82,6 +82,9 @@
19 #ifdef USE_AUTOLOCK
20 autolock_time = eeprom[autolock_time_e];
21 #endif
22+ #ifdef USE_2C_STYLE_CONFIG
23+ use_2c_max_turbo = eeprom[use_2c_max_turbo_e];
24+ #endif
25 }
26 #ifdef START_AT_MEMORIZED_LEVEL
27 if (load_eeprom_wl()) {
28@@ -148,6 +151,9 @@
29 #ifdef USE_AUTOLOCK
30 eeprom[autolock_time_e] = autolock_time;
31 #endif
32+ #ifdef USE_2C_STYLE_CONFIG
33+ eeprom[use_2c_max_turbo_e] = use_2c_max_turbo,
34+ #endif
35
36 save_eeprom();
37 }
38
39=== modified file 'ToyKeeper/spaghetti-monster/anduril/ramp-mode.c'
40--- ToyKeeper/spaghetti-monster/anduril/ramp-mode.c 2021-08-23 10:24:08 +0000
41+++ ToyKeeper/spaghetti-monster/anduril/ramp-mode.c 2021-08-30 11:26:43 +0000
42@@ -101,7 +101,7 @@
43 // 2 clicks: go to/from highest level
44 else if (event == EV_2clicks) {
45 uint8_t turbo_level;
46- #ifdef USE_2C_MAX_TURBO
47+ if (use_2c_max_turbo) {
48 // simple UI: to/from ceiling
49 // full UI: to/from turbo (Anduril1 behavior)
50 #ifdef USE_SIMPLE_UI
51@@ -109,7 +109,7 @@
52 else
53 #endif
54 turbo_level = MAX_LEVEL;
55- #else
56+ } else {
57 // simple UI: to/from ceiling
58 // full UI: to/from ceiling if mem < ceiling,
59 // or to/from turbo if mem >= ceiling
60@@ -119,7 +119,7 @@
61 #endif
62 ) { turbo_level = mode_max; }
63 else { turbo_level = MAX_LEVEL; }
64- #endif
65+ }
66
67 if (actual_level < turbo_level) {
68 set_level_and_therm_target(turbo_level);
69@@ -475,19 +475,32 @@
70
71 #ifdef USE_GLOBALS_CONFIG
72 void globals_config_save(uint8_t step, uint8_t value) {
73+ uint8_t step_index = 0;
74 if (0) {}
75 #ifdef USE_2C_STYLE_CONFIG
76- // TODO: make double-click style configurable (turbo or ceil)
77- else if (1 == step) {}
78+ else if (++step_index == step) {
79+ if (value > 0) {
80+ use_2c_max_turbo = (value == 1);
81+ }
82+ }
83 #endif
84 #ifdef USE_JUMP_START
85- else { jump_start_level = value; }
86+ else if (++step_index == step) {
87+ jump_start_level = value;
88+ }
89 #endif
90 }
91
92 uint8_t globals_config_state(Event event, uint16_t arg) {
93- // TODO: set number of steps based on how many configurable options
94- return config_state_base(event, arg, 1, globals_config_save);
95+ const uint8_t step_count = 0
96+ #ifdef USE_2C_STYLE_CONFIG
97+ +1
98+ #endif
99+ #ifdef USE_JUMP_START
100+ +1
101+ #endif
102+ ;
103+ return config_state_base(event, arg, step_count, globals_config_save);
104 }
105 #endif
106
107
108=== modified file 'ToyKeeper/spaghetti-monster/anduril/ramp-mode.h'
109--- ToyKeeper/spaghetti-monster/anduril/ramp-mode.h 2021-08-23 10:24:08 +0000
110+++ ToyKeeper/spaghetti-monster/anduril/ramp-mode.h 2021-08-30 11:26:43 +0000
111@@ -197,5 +197,11 @@
112 uint8_t globals_config_state(Event event, uint16_t arg);
113 #endif
114
115+#ifdef USE_2C_MAX_TURBO
116+uint8_t use_2c_max_turbo = 1;
117+#else
118+uint8_t use_2c_max_turbo = 0;
119+#endif
120+
121
122 #endif

Subscribers

People subscribed via source and target branches

to status/vote changes: