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
=== modified file 'ToyKeeper/spaghetti-monster/anduril/load-save-config-fsm.h'
--- ToyKeeper/spaghetti-monster/anduril/load-save-config-fsm.h 2021-08-23 10:24:08 +0000
+++ ToyKeeper/spaghetti-monster/anduril/load-save-config-fsm.h 2021-08-30 11:26:43 +0000
@@ -82,6 +82,9 @@
82 #ifdef USE_AUTOLOCK82 #ifdef USE_AUTOLOCK
83 autolock_time_e,83 autolock_time_e,
84 #endif84 #endif
85 #ifdef USE_2C_STYLE_CONFIG
86 use_2c_max_turbo_e,
87 #endif
85 eeprom_indexes_e_END88 eeprom_indexes_e_END
86} eeprom_indexes_e;89} eeprom_indexes_e;
87#define EEPROM_BYTES eeprom_indexes_e_END90#define EEPROM_BYTES eeprom_indexes_e_END
8891
=== modified file 'ToyKeeper/spaghetti-monster/anduril/load-save-config.c'
--- ToyKeeper/spaghetti-monster/anduril/load-save-config.c 2021-08-23 10:24:08 +0000
+++ ToyKeeper/spaghetti-monster/anduril/load-save-config.c 2021-08-30 11:26:43 +0000
@@ -82,6 +82,9 @@
82 #ifdef USE_AUTOLOCK82 #ifdef USE_AUTOLOCK
83 autolock_time = eeprom[autolock_time_e];83 autolock_time = eeprom[autolock_time_e];
84 #endif84 #endif
85 #ifdef USE_2C_STYLE_CONFIG
86 use_2c_max_turbo = eeprom[use_2c_max_turbo_e];
87 #endif
85 }88 }
86 #ifdef START_AT_MEMORIZED_LEVEL89 #ifdef START_AT_MEMORIZED_LEVEL
87 if (load_eeprom_wl()) {90 if (load_eeprom_wl()) {
@@ -148,6 +151,9 @@
148 #ifdef USE_AUTOLOCK151 #ifdef USE_AUTOLOCK
149 eeprom[autolock_time_e] = autolock_time;152 eeprom[autolock_time_e] = autolock_time;
150 #endif153 #endif
154 #ifdef USE_2C_STYLE_CONFIG
155 eeprom[use_2c_max_turbo_e] = use_2c_max_turbo,
156 #endif
151157
152 save_eeprom();158 save_eeprom();
153}159}
154160
=== modified file 'ToyKeeper/spaghetti-monster/anduril/ramp-mode.c'
--- ToyKeeper/spaghetti-monster/anduril/ramp-mode.c 2021-08-23 10:24:08 +0000
+++ ToyKeeper/spaghetti-monster/anduril/ramp-mode.c 2021-08-30 11:26:43 +0000
@@ -101,7 +101,7 @@
101 // 2 clicks: go to/from highest level101 // 2 clicks: go to/from highest level
102 else if (event == EV_2clicks) {102 else if (event == EV_2clicks) {
103 uint8_t turbo_level;103 uint8_t turbo_level;
104 #ifdef USE_2C_MAX_TURBO104 if (use_2c_max_turbo) {
105 // simple UI: to/from ceiling105 // simple UI: to/from ceiling
106 // full UI: to/from turbo (Anduril1 behavior)106 // full UI: to/from turbo (Anduril1 behavior)
107 #ifdef USE_SIMPLE_UI107 #ifdef USE_SIMPLE_UI
@@ -109,7 +109,7 @@
109 else109 else
110 #endif110 #endif
111 turbo_level = MAX_LEVEL;111 turbo_level = MAX_LEVEL;
112 #else112 } else {
113 // simple UI: to/from ceiling113 // simple UI: to/from ceiling
114 // full UI: to/from ceiling if mem < ceiling,114 // full UI: to/from ceiling if mem < ceiling,
115 // or to/from turbo if mem >= ceiling115 // or to/from turbo if mem >= ceiling
@@ -119,7 +119,7 @@
119 #endif119 #endif
120 ) { turbo_level = mode_max; }120 ) { turbo_level = mode_max; }
121 else { turbo_level = MAX_LEVEL; }121 else { turbo_level = MAX_LEVEL; }
122 #endif122 }
123123
124 if (actual_level < turbo_level) {124 if (actual_level < turbo_level) {
125 set_level_and_therm_target(turbo_level);125 set_level_and_therm_target(turbo_level);
@@ -475,19 +475,32 @@
475475
476#ifdef USE_GLOBALS_CONFIG476#ifdef USE_GLOBALS_CONFIG
477void globals_config_save(uint8_t step, uint8_t value) {477void globals_config_save(uint8_t step, uint8_t value) {
478 uint8_t step_index = 0;
478 if (0) {}479 if (0) {}
479 #ifdef USE_2C_STYLE_CONFIG480 #ifdef USE_2C_STYLE_CONFIG
480 // TODO: make double-click style configurable (turbo or ceil)481 else if (++step_index == step) {
481 else if (1 == step) {}482 if (value > 0) {
483 use_2c_max_turbo = (value == 1);
484 }
485 }
482 #endif486 #endif
483 #ifdef USE_JUMP_START487 #ifdef USE_JUMP_START
484 else { jump_start_level = value; }488 else if (++step_index == step) {
489 jump_start_level = value;
490 }
485 #endif491 #endif
486}492}
487493
488uint8_t globals_config_state(Event event, uint16_t arg) {494uint8_t globals_config_state(Event event, uint16_t arg) {
489 // TODO: set number of steps based on how many configurable options495 const uint8_t step_count = 0
490 return config_state_base(event, arg, 1, globals_config_save);496 #ifdef USE_2C_STYLE_CONFIG
497 +1
498 #endif
499 #ifdef USE_JUMP_START
500 +1
501 #endif
502 ;
503 return config_state_base(event, arg, step_count, globals_config_save);
491}504}
492#endif505#endif
493506
494507
=== modified file 'ToyKeeper/spaghetti-monster/anduril/ramp-mode.h'
--- ToyKeeper/spaghetti-monster/anduril/ramp-mode.h 2021-08-23 10:24:08 +0000
+++ ToyKeeper/spaghetti-monster/anduril/ramp-mode.h 2021-08-30 11:26:43 +0000
@@ -197,5 +197,11 @@
197uint8_t globals_config_state(Event event, uint16_t arg);197uint8_t globals_config_state(Event event, uint16_t arg);
198#endif198#endif
199199
200#ifdef USE_2C_MAX_TURBO
201uint8_t use_2c_max_turbo = 1;
202#else
203uint8_t use_2c_max_turbo = 0;
204#endif
205
200206
201#endif207#endif

Subscribers

People subscribed via source and target branches

to status/vote changes: