Merge lp:~sammyshp/flashlight-firmware/moon-dont-ramp-up into lp:~toykeeper/flashlight-firmware/anduril2

Proposed by Sven Greiner
Status: Needs review
Proposed branch: lp:~sammyshp/flashlight-firmware/moon-dont-ramp-up
Merge into: lp:~toykeeper/flashlight-firmware/anduril2
Diff against target: 225 lines (+75/-11)
9 files modified
ToyKeeper/spaghetti-monster/anduril/anduril-manual.txt (+9/-1)
ToyKeeper/spaghetti-monster/anduril/config-default.h (+5/-0)
ToyKeeper/spaghetti-monster/anduril/load-save-config-fsm.h (+6/-0)
ToyKeeper/spaghetti-monster/anduril/load-save-config.c (+12/-0)
ToyKeeper/spaghetti-monster/anduril/off-mode.c (+1/-1)
ToyKeeper/spaghetti-monster/anduril/off-mode.h (+6/-0)
ToyKeeper/spaghetti-monster/anduril/ramp-mode-fsm.h (+1/-1)
ToyKeeper/spaghetti-monster/anduril/ramp-mode.c (+29/-8)
ToyKeeper/spaghetti-monster/anduril/ramp-mode.h (+6/-0)
To merge this branch: bzr merge lp:~sammyshp/flashlight-firmware/moon-dont-ramp-up
Reviewer Review Type Date Requested Status
Selene ToyKeeper Pending
Review via email: mp+407834@code.launchpad.net

Description of the change

Add option to stop ramping up from moon

With `#undef MOON_START_RAMPING` entering moon from off by holding the switch will not automatically start ramping up. This ensures that moon is entered reliably when the switch is held long enough.

Timings still apply (you can release the switch when the light turns on or when it blips, depending on the configured timing).

With `#define USE_MOON_START_RAMPING_CONFIG` this can be configured during runtime with the global configuration menu.

This contains the changes of lp:~sammyshp/flashlight-firmware/2c-turbo-config because they were necessary for the configuration menu.

To post a comment you must log in.
Revision history for this message
Selene ToyKeeper (toykeeper) wrote :

We took very similar approaches here, mostly differing in whether the boolean means "ramp" or "don't ramp". Also, yours has the nice property that the user can select either behavior at compile time, or add a menu item... while mine only offers the old behavior or a menu item.

I'm hoping to merge other branches at the moment, but I left a note in the code pointing back to this as a possible improvement for later, because it's a good idea.

Unmerged revisions

621. By Sven Greiner

Make moon ramping behavior configurable during runtime

620. By Sven Greiner

Add option to stop ramping up from moon

With `#undef MOON_START_RAMPING` entering moon from off by holding the
switch will not automatically start ramping up. This ensures that moon
is entered reliably when the switch is held long enough.

Timings still apply (you can release the switch when the light turns on
or when it blips, depending on the configured timing).

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/anduril-manual.txt'
2--- ToyKeeper/spaghetti-monster/anduril/anduril-manual.txt 2021-08-23 10:37:15 +0000
3+++ ToyKeeper/spaghetti-monster/anduril/anduril-manual.txt 2021-08-30 13:29:06 +0000
4@@ -645,7 +645,7 @@
5 Some models may have an extra config menu for settings which don't fit
6 anywhere else. These settings are, in order:
7
8- - 2C style: (not yet implemented)
9+ - 2C style:
10
11 1: 2C goes to turbo (Anduril V1 style)
12 2: 2C goes to ramp ceiling (Anduril V2 style)
13@@ -659,6 +659,14 @@
14
15 The value can be from 1 to 150, but is usually between 10 and 30.
16
17+ - Start ramping up from moon:
18+
19+ When entering moon from off by holding the button and then keep
20+ holding it ...
21+
22+ 0: stay at moon
23+ 1: start to ramp up
24+
25 Some settings are hardware-specific and may not be present on all
26 lights. The number of settings in the global menu depends on the
27 hardware model and the firmware version.
28
29=== modified file 'ToyKeeper/spaghetti-monster/anduril/config-default.h'
30--- ToyKeeper/spaghetti-monster/anduril/config-default.h 2021-07-13 23:44:08 +0000
31+++ ToyKeeper/spaghetti-monster/anduril/config-default.h 2021-08-30 13:29:06 +0000
32@@ -106,6 +106,11 @@
33 // timer is available in regular ramp mode and candle mode
34 #define USE_SUNSET_TIMER
35
36+// automatically start ramping up when entering moon from off
37+#define MOON_START_RAMPING
38+// make this configurable at runtime
39+//#define USE_MOON_START_RAMPING_CONFIG
40+
41
42 ///// What to do when power is connected /////
43 // factory reset function erases user's runtime configuration in eeprom
44
45=== modified file 'ToyKeeper/spaghetti-monster/anduril/load-save-config-fsm.h'
46--- ToyKeeper/spaghetti-monster/anduril/load-save-config-fsm.h 2021-08-23 10:24:08 +0000
47+++ ToyKeeper/spaghetti-monster/anduril/load-save-config-fsm.h 2021-08-30 13:29:06 +0000
48@@ -82,6 +82,12 @@
49 #ifdef USE_AUTOLOCK
50 autolock_time_e,
51 #endif
52+ #ifdef USE_2C_STYLE_CONFIG
53+ use_2c_max_turbo_e,
54+ #endif
55+ #ifdef USE_MOON_START_RAMPING_CONFIG
56+ moon_start_ramping_e,
57+ #endif
58 eeprom_indexes_e_END
59 } eeprom_indexes_e;
60 #define EEPROM_BYTES eeprom_indexes_e_END
61
62=== modified file 'ToyKeeper/spaghetti-monster/anduril/load-save-config.c'
63--- ToyKeeper/spaghetti-monster/anduril/load-save-config.c 2021-08-23 10:24:08 +0000
64+++ ToyKeeper/spaghetti-monster/anduril/load-save-config.c 2021-08-30 13:29:06 +0000
65@@ -82,6 +82,12 @@
66 #ifdef USE_AUTOLOCK
67 autolock_time = eeprom[autolock_time_e];
68 #endif
69+ #ifdef USE_2C_STYLE_CONFIG
70+ use_2c_max_turbo = eeprom[use_2c_max_turbo_e];
71+ #endif
72+ #ifdef USE_MOON_START_RAMPING_CONFIG
73+ moon_start_ramping = eeprom[moon_start_ramping_e];
74+ #endif
75 }
76 #ifdef START_AT_MEMORIZED_LEVEL
77 if (load_eeprom_wl()) {
78@@ -148,6 +154,12 @@
79 #ifdef USE_AUTOLOCK
80 eeprom[autolock_time_e] = autolock_time;
81 #endif
82+ #ifdef USE_2C_STYLE_CONFIG
83+ eeprom[use_2c_max_turbo_e] = use_2c_max_turbo,
84+ #endif
85+ #ifdef USE_MOON_START_RAMPING_CONFIG
86+ eeprom[moon_start_ramping_e] = moon_start_ramping;
87+ #endif
88
89 save_eeprom();
90 }
91
92=== modified file 'ToyKeeper/spaghetti-monster/anduril/off-mode.c'
93--- ToyKeeper/spaghetti-monster/anduril/off-mode.c 2021-08-27 13:33:01 +0000
94+++ ToyKeeper/spaghetti-monster/anduril/off-mode.c 2021-08-30 13:29:06 +0000
95@@ -109,7 +109,7 @@
96 // don't start ramping immediately;
97 // give the user time to release at moon level
98 //if (arg >= HOLD_TIMEOUT) { // smaller
99- if (arg >= (!ramp_style) * HOLD_TIMEOUT) { // more consistent
100+ if (moon_start_ramping && arg >= (!ramp_style) * HOLD_TIMEOUT) { // more consistent
101 set_state(steady_state, 1);
102 }
103 return MISCHIEF_MANAGED;
104
105=== modified file 'ToyKeeper/spaghetti-monster/anduril/off-mode.h'
106--- ToyKeeper/spaghetti-monster/anduril/off-mode.h 2020-07-22 22:50:22 +0000
107+++ ToyKeeper/spaghetti-monster/anduril/off-mode.h 2021-08-30 13:29:06 +0000
108@@ -23,5 +23,11 @@
109 // when the light is "off" or in standby
110 uint8_t off_state(Event event, uint16_t arg);
111
112+#ifdef MOON_START_RAMPING
113+uint8_t moon_start_ramping = 1;
114+#else
115+uint8_t moon_start_ramping = 0;
116+#endif
117+
118
119 #endif
120
121=== modified file 'ToyKeeper/spaghetti-monster/anduril/ramp-mode-fsm.h'
122--- ToyKeeper/spaghetti-monster/anduril/ramp-mode-fsm.h 2021-08-23 10:24:08 +0000
123+++ ToyKeeper/spaghetti-monster/anduril/ramp-mode-fsm.h 2021-08-30 13:29:06 +0000
124@@ -47,7 +47,7 @@
125 #endif
126
127 // include an extra config mode for random stuff which doesn't fit elsewhere
128-#if defined(USE_JUMP_START) || defined(USE_2C_STYLE_CONFIG)
129+#if defined(USE_JUMP_START) || defined(USE_2C_STYLE_CONFIG) || defined(USE_MOON_START_RAMPING_CONFIG)
130 #define USE_GLOBALS_CONFIG
131 #endif
132
133
134=== modified file 'ToyKeeper/spaghetti-monster/anduril/ramp-mode.c'
135--- ToyKeeper/spaghetti-monster/anduril/ramp-mode.c 2021-08-23 10:24:08 +0000
136+++ ToyKeeper/spaghetti-monster/anduril/ramp-mode.c 2021-08-30 13:29:06 +0000
137@@ -101,7 +101,7 @@
138 // 2 clicks: go to/from highest level
139 else if (event == EV_2clicks) {
140 uint8_t turbo_level;
141- #ifdef USE_2C_MAX_TURBO
142+ if (use_2c_max_turbo) {
143 // simple UI: to/from ceiling
144 // full UI: to/from turbo (Anduril1 behavior)
145 #ifdef USE_SIMPLE_UI
146@@ -109,7 +109,7 @@
147 else
148 #endif
149 turbo_level = MAX_LEVEL;
150- #else
151+ } else {
152 // simple UI: to/from ceiling
153 // full UI: to/from ceiling if mem < ceiling,
154 // or to/from turbo if mem >= ceiling
155@@ -119,7 +119,7 @@
156 #endif
157 ) { turbo_level = mode_max; }
158 else { turbo_level = MAX_LEVEL; }
159- #endif
160+ }
161
162 if (actual_level < turbo_level) {
163 set_level_and_therm_target(turbo_level);
164@@ -475,19 +475,40 @@
165
166 #ifdef USE_GLOBALS_CONFIG
167 void globals_config_save(uint8_t step, uint8_t value) {
168+ uint8_t step_index = 0;
169 if (0) {}
170 #ifdef USE_2C_STYLE_CONFIG
171- // TODO: make double-click style configurable (turbo or ceil)
172- else if (1 == step) {}
173+ else if (++step_index == step) {
174+ if (value > 0) {
175+ use_2c_max_turbo = (value == 1);
176+ }
177+ }
178 #endif
179 #ifdef USE_JUMP_START
180- else { jump_start_level = value; }
181+ else if (++step_index == step) {
182+ jump_start_level = value;
183+ }
184+ #endif
185+ #ifdef USE_MOON_START_RAMPING_CONFIG
186+ else if (++step_index == step) {
187+ moon_start_ramping = value;
188+ }
189 #endif
190 }
191
192 uint8_t globals_config_state(Event event, uint16_t arg) {
193- // TODO: set number of steps based on how many configurable options
194- return config_state_base(event, arg, 1, globals_config_save);
195+ const uint8_t step_count = 0
196+ #ifdef USE_2C_STYLE_CONFIG
197+ +1
198+ #endif
199+ #ifdef USE_JUMP_START
200+ +1
201+ #endif
202+ #ifdef USE_MOON_START_RAMPING_CONFIG
203+ +1
204+ #endif
205+ ;
206+ return config_state_base(event, arg, step_count, globals_config_save);
207 }
208 #endif
209
210
211=== modified file 'ToyKeeper/spaghetti-monster/anduril/ramp-mode.h'
212--- ToyKeeper/spaghetti-monster/anduril/ramp-mode.h 2021-08-23 10:24:08 +0000
213+++ ToyKeeper/spaghetti-monster/anduril/ramp-mode.h 2021-08-30 13:29:06 +0000
214@@ -197,5 +197,11 @@
215 uint8_t globals_config_state(Event event, uint16_t arg);
216 #endif
217
218+#ifdef USE_2C_MAX_TURBO
219+uint8_t use_2c_max_turbo = 1;
220+#else
221+uint8_t use_2c_max_turbo = 0;
222+#endif
223+
224
225 #endif

Subscribers

People subscribed via source and target branches

to status/vote changes: