188.1.17
by Selene Scriven
Added a ramping UI example. |
1 |
/*
|
2 |
* Ramping-UI: Ramping UI for SpaghettiMonster.
|
|
3 |
*
|
|
4 |
* Copyright (C) 2017 Selene Scriven
|
|
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 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18 |
*/
|
|
19 |
||
188.7.2
by Selene Scriven
Updated the rest of the FSM interfaces to use the new config file system. |
20 |
#include "hwdef-Emisar_D4.h" |
188.1.17
by Selene Scriven
Added a ramping UI example. |
21 |
#define USE_LVP
|
188.1.19
by Selene Scriven
Set default brightness to max 7135 level. |
22 |
#define USE_THERMAL_REGULATION
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
23 |
#define DEFAULT_THERM_CEIL 32
|
24 |
#define USE_DELAY_MS
|
|
25 |
#define USE_DELAY_ZERO
|
|
26 |
#define USE_RAMPING
|
|
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
27 |
#define USE_BATTCHECK
|
28 |
#define BATTCHECK_VpT
|
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
29 |
#define RAMP_LENGTH 150
|
30 |
#include "spaghetti-monster.h" |
|
31 |
||
32 |
// FSM states
|
|
188.6.6
by Selene Scriven
Updated most of the UIs to use the new event API. |
33 |
uint8_t off_state(Event event, uint16_t arg); |
34 |
uint8_t steady_state(Event event, uint16_t arg); |
|
35 |
uint8_t strobe_state(Event event, uint16_t arg); |
|
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
36 |
#ifdef USE_BATTCHECK
|
188.6.6
by Selene Scriven
Updated most of the UIs to use the new event API. |
37 |
uint8_t battcheck_state(Event event, uint16_t arg); |
38 |
uint8_t tempcheck_state(Event event, uint16_t arg); |
|
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
39 |
#endif
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
40 |
|
41 |
// brightness control
|
|
188.1.19
by Selene Scriven
Set default brightness to max 7135 level. |
42 |
uint8_t memorized_level = MAX_1x7135; |
188.1.18
by Selene Scriven
Made ramping UI able to toggle between smooth and discrete ramping with 4 clicks. |
43 |
// smooth vs discrete ramping
|
44 |
uint8_t ramp_step_size = 1; |
|
45 |
||
188.1.17
by Selene Scriven
Added a ramping UI example. |
46 |
#ifdef USE_THERMAL_REGULATION
|
188.1.18
by Selene Scriven
Made ramping UI able to toggle between smooth and discrete ramping with 4 clicks. |
47 |
// brightness before thermal step-down
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
48 |
uint8_t target_level = 0; |
49 |
#endif
|
|
50 |
||
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
51 |
// strobe timing
|
52 |
volatile uint8_t strobe_delay = 67; |
|
53 |
volatile uint8_t strobe_type = 0; // 0 == party strobe, 1 == tactical strobe |
|
54 |
||
55 |
||
188.6.6
by Selene Scriven
Updated most of the UIs to use the new event API. |
56 |
uint8_t off_state(Event event, uint16_t arg) { |
188.1.17
by Selene Scriven
Added a ramping UI example. |
57 |
// turn emitter off when entering state
|
58 |
if (event == EV_enter_state) { |
|
59 |
set_level(0); |
|
60 |
// sleep while off (lower power use)
|
|
188.1.69
by Selene Scriven
Got the 4th PWM channel to work, ish. (channel 4 is inverted though) |
61 |
go_to_standby = 1; |
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
62 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
63 |
}
|
64 |
// hold (initially): go to lowest level, but allow abort for regular click
|
|
65 |
else if (event == EV_click1_press) { |
|
66 |
set_level(1); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
67 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
68 |
}
|
69 |
// 1 click (before timeout): go to memorized level, but allow abort for double click
|
|
70 |
else if (event == EV_click1_release) { |
|
71 |
set_level(memorized_level); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
72 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
73 |
}
|
74 |
// 1 click: regular mode
|
|
75 |
else if (event == EV_1click) { |
|
76 |
set_state(steady_state, memorized_level); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
77 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
78 |
}
|
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
79 |
// 2 clicks (initial press): off, to prep for later events
|
80 |
else if (event == EV_click2_press) { |
|
81 |
set_level(0); |
|
82 |
return MISCHIEF_MANAGED; |
|
83 |
}
|
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
84 |
// 2 clicks: highest mode
|
85 |
else if (event == EV_2clicks) { |
|
86 |
set_state(steady_state, MAX_LEVEL); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
87 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
88 |
}
|
89 |
// 3 clicks: strobe mode
|
|
90 |
else if (event == EV_3clicks) { |
|
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
91 |
set_state(strobe_state, 0); |
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
92 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
93 |
}
|
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
94 |
#ifdef USE_BATTCHECK
|
95 |
// 4 clicks: battcheck mode
|
|
96 |
else if (event == EV_4clicks) { |
|
97 |
set_state(battcheck_state, 0); |
|
98 |
return MISCHIEF_MANAGED; |
|
99 |
}
|
|
100 |
#endif
|
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
101 |
// hold: go to lowest level
|
102 |
else if (event == EV_click1_hold) { |
|
103 |
// don't start ramping immediately;
|
|
104 |
// give the user time to release at moon level
|
|
105 |
if (arg >= HOLD_TIMEOUT) |
|
106 |
set_state(steady_state, 1); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
107 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
108 |
}
|
109 |
// hold, release quickly: go to lowest level
|
|
110 |
else if (event == EV_click1_hold_release) { |
|
111 |
set_state(steady_state, 1); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
112 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
113 |
}
|
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
114 |
// click, hold: go to highest level (for ramping down)
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
115 |
else if (event == EV_click2_hold) { |
116 |
set_state(steady_state, MAX_LEVEL); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
117 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
118 |
}
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
119 |
return EVENT_NOT_HANDLED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
120 |
}
|
121 |
||
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
122 |
|
188.6.6
by Selene Scriven
Updated most of the UIs to use the new event API. |
123 |
uint8_t steady_state(Event event, uint16_t arg) { |
188.1.17
by Selene Scriven
Added a ramping UI example. |
124 |
// turn LED on when we first enter the mode
|
125 |
if (event == EV_enter_state) { |
|
126 |
// remember this level, unless it's moon or turbo
|
|
127 |
if ((arg > 1) && (arg < MAX_LEVEL)) |
|
128 |
memorized_level = arg; |
|
129 |
// use the requested level even if not memorized
|
|
130 |
#ifdef USE_THERMAL_REGULATION
|
|
131 |
target_level = arg; |
|
132 |
#endif
|
|
133 |
set_level(arg); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
134 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
135 |
}
|
136 |
// 1 click: off
|
|
137 |
else if (event == EV_1click) { |
|
138 |
set_state(off_state, 0); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
139 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
140 |
}
|
141 |
// 2 clicks: go to/from highest level
|
|
142 |
else if (event == EV_2clicks) { |
|
143 |
if (actual_level < MAX_LEVEL) { |
|
144 |
memorized_level = actual_level; // in case we're on moon |
|
145 |
#ifdef USE_THERMAL_REGULATION
|
|
146 |
target_level = MAX_LEVEL; |
|
147 |
#endif
|
|
148 |
set_level(MAX_LEVEL); |
|
149 |
}
|
|
150 |
else { |
|
151 |
#ifdef USE_THERMAL_REGULATION
|
|
152 |
target_level = memorized_level; |
|
153 |
#endif
|
|
154 |
set_level(memorized_level); |
|
155 |
}
|
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
156 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
157 |
}
|
158 |
// 3 clicks: go to strobe modes
|
|
159 |
else if (event == EV_3clicks) { |
|
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
160 |
set_state(strobe_state, 0); |
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
161 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
162 |
}
|
188.1.18
by Selene Scriven
Made ramping UI able to toggle between smooth and discrete ramping with 4 clicks. |
163 |
// 4 clicks: toggle smooth vs discrete ramping
|
164 |
else if (event == EV_4clicks) { |
|
165 |
if (ramp_step_size == 1) ramp_step_size = MAX_LEVEL/6; |
|
166 |
else ramp_step_size = 1; |
|
167 |
set_level(0); |
|
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
168 |
delay_4ms(20/4); |
188.1.18
by Selene Scriven
Made ramping UI able to toggle between smooth and discrete ramping with 4 clicks. |
169 |
set_level(memorized_level); |
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
170 |
return MISCHIEF_MANAGED; |
188.1.18
by Selene Scriven
Made ramping UI able to toggle between smooth and discrete ramping with 4 clicks. |
171 |
}
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
172 |
// hold: change brightness (brighter)
|
173 |
else if (event == EV_click1_hold) { |
|
188.1.21
by Selene Scriven
Fixed repeating blinks at ends of ramp -- only blinks once now. |
174 |
// ramp slower in discrete mode
|
188.1.18
by Selene Scriven
Made ramping UI able to toggle between smooth and discrete ramping with 4 clicks. |
175 |
if (arg % ramp_step_size != 0) { |
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
176 |
return MISCHIEF_MANAGED; |
188.1.18
by Selene Scriven
Made ramping UI able to toggle between smooth and discrete ramping with 4 clicks. |
177 |
}
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
178 |
// FIXME: make it ramp down instead, if already at max
|
188.1.18
by Selene Scriven
Made ramping UI able to toggle between smooth and discrete ramping with 4 clicks. |
179 |
if (actual_level + ramp_step_size < MAX_LEVEL) |
180 |
memorized_level = actual_level + ramp_step_size; |
|
181 |
else memorized_level = MAX_LEVEL; |
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
182 |
#ifdef USE_THERMAL_REGULATION
|
183 |
target_level = memorized_level; |
|
184 |
#endif
|
|
188.1.21
by Selene Scriven
Fixed repeating blinks at ends of ramp -- only blinks once now. |
185 |
// only blink once for each threshold
|
186 |
if ((memorized_level != actual_level) |
|
187 |
&& ((memorized_level == MAX_1x7135) |
|
188 |
|| (memorized_level == MAX_LEVEL))) { |
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
189 |
set_level(0); |
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
190 |
delay_4ms(8/4); |
188.1.17
by Selene Scriven
Added a ramping UI example. |
191 |
}
|
192 |
set_level(memorized_level); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
193 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
194 |
}
|
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
195 |
// click, hold: change brightness (dimmer)
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
196 |
else if (event == EV_click2_hold) { |
188.1.21
by Selene Scriven
Fixed repeating blinks at ends of ramp -- only blinks once now. |
197 |
// ramp slower in discrete mode
|
188.1.18
by Selene Scriven
Made ramping UI able to toggle between smooth and discrete ramping with 4 clicks. |
198 |
if (arg % ramp_step_size != 0) { |
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
199 |
return MISCHIEF_MANAGED; |
188.1.18
by Selene Scriven
Made ramping UI able to toggle between smooth and discrete ramping with 4 clicks. |
200 |
}
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
201 |
// FIXME: make it ramp up instead, if already at min
|
188.1.18
by Selene Scriven
Made ramping UI able to toggle between smooth and discrete ramping with 4 clicks. |
202 |
if (actual_level > ramp_step_size) |
203 |
memorized_level = (actual_level-ramp_step_size); |
|
204 |
else
|
|
205 |
memorized_level = 1; |
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
206 |
#ifdef USE_THERMAL_REGULATION
|
207 |
target_level = memorized_level; |
|
208 |
#endif
|
|
188.1.21
by Selene Scriven
Fixed repeating blinks at ends of ramp -- only blinks once now. |
209 |
// only blink once for each threshold
|
210 |
if ((memorized_level != actual_level) |
|
211 |
&& ((memorized_level == MAX_1x7135) |
|
212 |
|| (memorized_level == 1))) { |
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
213 |
set_level(0); |
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
214 |
delay_4ms(8/4); |
188.1.17
by Selene Scriven
Added a ramping UI example. |
215 |
}
|
216 |
set_level(memorized_level); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
217 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
218 |
}
|
219 |
#ifdef USE_THERMAL_REGULATION
|
|
188.1.19
by Selene Scriven
Set default brightness to max 7135 level. |
220 |
// TODO: test this on a real light
|
221 |
// overheating: drop by an amount proportional to how far we are above the ceiling
|
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
222 |
else if (event == EV_temperature_high) { |
188.1.19
by Selene Scriven
Set default brightness to max 7135 level. |
223 |
if (actual_level > MAX_LEVEL/4) { |
224 |
uint8_t stepdown = actual_level - arg; |
|
225 |
if (stepdown < MAX_LEVEL/4) stepdown = MAX_LEVEL/4; |
|
226 |
set_level(stepdown); |
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
227 |
}
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
228 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
229 |
}
|
188.1.19
by Selene Scriven
Set default brightness to max 7135 level. |
230 |
// underheating: increase slowly if we're lower than the target
|
231 |
// (proportional to how low we are)
|
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
232 |
else if (event == EV_temperature_low) { |
233 |
if (actual_level < target_level) { |
|
188.1.19
by Selene Scriven
Set default brightness to max 7135 level. |
234 |
uint8_t stepup = actual_level + (arg>>1); |
235 |
if (stepup > target_level) stepup = target_level; |
|
236 |
set_level(stepup); |
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
237 |
}
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
238 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
239 |
}
|
240 |
#endif
|
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
241 |
return EVENT_NOT_HANDLED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
242 |
}
|
243 |
||
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
244 |
|
188.6.6
by Selene Scriven
Updated most of the UIs to use the new event API. |
245 |
uint8_t strobe_state(Event event, uint16_t arg) { |
188.1.17
by Selene Scriven
Added a ramping UI example. |
246 |
if (event == EV_enter_state) { |
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
247 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
248 |
}
|
249 |
// 1 click: off
|
|
250 |
else if (event == EV_1click) { |
|
251 |
set_state(off_state, 0); |
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
252 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
253 |
}
|
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
254 |
// 2 clicks: toggle party strobe vs tactical strobe
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
255 |
else if (event == EV_2clicks) { |
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
256 |
strobe_type ^= 1; |
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
257 |
return MISCHIEF_MANAGED; |
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
258 |
}
|
259 |
// 3 clicks: go back to regular modes
|
|
260 |
else if (event == EV_3clicks) { |
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
261 |
set_state(steady_state, memorized_level); |
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
262 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
263 |
}
|
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
264 |
// hold: change speed (go faster)
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
265 |
else if (event == EV_click1_hold) { |
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
266 |
if ((arg & 1) == 0) { |
267 |
if (strobe_delay > 8) strobe_delay --; |
|
268 |
}
|
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
269 |
return MISCHIEF_MANAGED; |
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
270 |
}
|
271 |
// click, hold: change speed (go slower)
|
|
272 |
else if (event == EV_click2_hold) { |
|
273 |
if ((arg & 1) == 0) { |
|
274 |
if (strobe_delay < 255) strobe_delay ++; |
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
275 |
}
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
276 |
return MISCHIEF_MANAGED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
277 |
}
|
188.1.23
by Selene Scriven
Started on some documentation, spaghetti-monster.txt. |
278 |
return EVENT_NOT_HANDLED; |
188.1.17
by Selene Scriven
Added a ramping UI example. |
279 |
}
|
280 |
||
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
281 |
|
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
282 |
#ifdef USE_BATTCHECK
|
188.6.6
by Selene Scriven
Updated most of the UIs to use the new event API. |
283 |
uint8_t battcheck_state(Event event, uint16_t arg) { |
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
284 |
// 1 click: off
|
285 |
if (event == EV_1click) { |
|
286 |
set_state(off_state, 0); |
|
287 |
return MISCHIEF_MANAGED; |
|
288 |
}
|
|
188.1.26
by Selene Scriven
Added a temperature check mode to ramping-ui, mostly for testing purposes. |
289 |
// 2 clicks: tempcheck mode
|
290 |
else if (event == EV_2clicks) { |
|
291 |
set_state(tempcheck_state, 0); |
|
292 |
return MISCHIEF_MANAGED; |
|
293 |
}
|
|
294 |
return EVENT_NOT_HANDLED; |
|
295 |
}
|
|
296 |
||
188.6.6
by Selene Scriven
Updated most of the UIs to use the new event API. |
297 |
uint8_t tempcheck_state(Event event, uint16_t arg) { |
188.1.26
by Selene Scriven
Added a temperature check mode to ramping-ui, mostly for testing purposes. |
298 |
// 1 click: off
|
299 |
if (event == EV_1click) { |
|
300 |
set_state(off_state, 0); |
|
301 |
return MISCHIEF_MANAGED; |
|
302 |
}
|
|
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
303 |
return EVENT_NOT_HANDLED; |
304 |
}
|
|
305 |
#endif
|
|
306 |
||
307 |
||
188.1.17
by Selene Scriven
Added a ramping UI example. |
308 |
void low_voltage() { |
309 |
// "step down" from strobe to something low
|
|
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
310 |
if (current_state == strobe_state) { |
188.1.17
by Selene Scriven
Added a ramping UI example. |
311 |
set_state(steady_state, RAMP_SIZE/6); |
312 |
}
|
|
313 |
// in normal mode, step down by half or turn off
|
|
314 |
else if (current_state == steady_state) { |
|
315 |
if (actual_level > 1) { |
|
316 |
set_level(actual_level >> 1); |
|
317 |
}
|
|
318 |
else { |
|
319 |
set_state(off_state, 0); |
|
320 |
}
|
|
321 |
}
|
|
188.1.25
by Selene Scriven
Made 4bar and 8bar battcheck styles work. |
322 |
// all other modes, just turn off when voltage is low
|
323 |
else { |
|
324 |
set_state(off_state, 0); |
|
325 |
}
|
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
326 |
}
|
327 |
||
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
328 |
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
329 |
void setup() { |
188.1.19
by Selene Scriven
Set default brightness to max 7135 level. |
330 |
set_level(RAMP_SIZE/8); |
331 |
delay_4ms(3); |
|
332 |
set_level(0); |
|
188.1.17
by Selene Scriven
Added a ramping UI example. |
333 |
|
334 |
push_state(off_state, 0); |
|
335 |
}
|
|
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
336 |
|
337 |
||
338 |
void loop() { |
|
339 |
if (current_state == strobe_state) { |
|
340 |
set_level(MAX_LEVEL); |
|
341 |
if (strobe_type == 0) { // party strobe |
|
342 |
if (strobe_delay < 30) delay_zero(); |
|
343 |
else delay_ms(1); |
|
344 |
} else { //tactical strobe |
|
345 |
nice_delay_ms(strobe_delay >> 1); |
|
346 |
}
|
|
347 |
set_level(0); |
|
348 |
nice_delay_ms(strobe_delay); |
|
349 |
}
|
|
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
350 |
#ifdef USE_BATTCHECK
|
351 |
else if (current_state == battcheck_state) { |
|
352 |
battcheck(); |
|
353 |
}
|
|
188.1.26
by Selene Scriven
Added a temperature check mode to ramping-ui, mostly for testing purposes. |
354 |
else if (current_state == tempcheck_state) { |
188.15.21
by Selene Scriven
fixed a few things in ramping-ui, rampingiosv3, and werner's UI |
355 |
blink_num(temperature); |
188.1.26
by Selene Scriven
Added a temperature check mode to ramping-ui, mostly for testing purposes. |
356 |
nice_delay_ms(1000); |
357 |
}
|
|
188.1.24
by Selene Scriven
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :( |
358 |
#endif
|
188.1.22
by Selene Scriven
Added loop() to API, executes constantly. |
359 |
}
|