-
Notifications
You must be signed in to change notification settings - Fork 2
/
strobe-modes.c
731 lines (668 loc) · 22.3 KB
/
strobe-modes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
/*
* strobe-modes.c: Strobe modes for Anduril.
*
* Copyright (C) 2017 Selene Scriven
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STROBE_MODES_C
#define STROBE_MODES_C
#include "strobe-modes.h"
#ifdef USE_STROBE_STATE
#ifdef USE_TINT_RAMPING
// for accessing tint
#include "fsm-ramping.h"
// the tint will be changed in some cases here. This is for restoring the original tint
uint8_t saved_tint = 128;
// when user is about to exit the strobe mode, let's stop updating tint after restored saved tint
uint8_t tint_locked = 0;
#endif
// enable static PWM
static inline void set_static_pwm() {
#ifdef USE_DYN_PWM
use_static_pwm = 1;
#endif
}
// restore tint to the original tint when entering strobe mode
static inline void restore_tint() {
#ifdef USE_TINT_RAMPING
tint = saved_tint;
tint_locked = 1;
#endif
}
// unset static PWM and restore tint
static inline void undo_global_setting() {
#ifdef USE_DYN_PWM
use_static_pwm = 0;
#elif defined(PWM1_TOP)
// when not using USE_DYN_PWM, we must revert the TOP back to default
PWM1_TOP = PWM_TOP;
#endif
restore_tint();
// always reset aux LED (default behaviour)
#if defined(USE_AUX_RGB_LEDS) || defined(USE_INDICATOR_LED)
aux_led_reset = 1;
#endif
}
// for some strobe modes we need to enable/disable some global settings:
// tint or dynamic PWM
static void strobe_global_setup(strobe_mode_te type) {
switch(type) {
#ifdef USE_CANDLE_MODE
case candle_mode_e:
set_static_pwm();
#if defined(PWM1_TOP) && defined(PWM_TOP_CANDLE)
PWM1_TOP = PWM_TOP_CANDLE;
#endif
restore_tint();
// aux LED will not be reset in each set_level in candle mode
#if defined(USE_AUX_RGB_LEDS) || defined(USE_INDICATOR_LED)
aux_led_reset = 0;
#endif
#ifdef USE_INDICATOR_LED
indicator_led(candle_indicator_mode);
#endif
break;
#endif
#ifdef USE_FIREWORK_MODE
case firework_mode_e:
set_static_pwm();
#if defined(PWM1_TOP) && defined(PWM_TOP_FIREWORK)
PWM1_TOP = PWM_TOP_FIREWORK;
#endif
#ifdef USE_TINT_RAMPING
tint_locked = 0;
#endif
#if defined(USE_AUX_RGB_LEDS) || defined(USE_INDICATOR_LED)
aux_led_reset = 1;
#endif
break;
#endif
#ifdef USE_TINT_RAMPING
case tint_alternating_strobe_e:
case tint_smooth_ramp_e:
tint_locked = 0;
#if defined(USE_AUX_RGB_LEDS) || defined(USE_INDICATOR_LED)
aux_led_reset = 1;
#endif
break;
#endif
default:
undo_global_setting();
}
}
uint8_t strobe_state(Event event, uint16_t arg) {
static int8_t ramp_direction = 1;
// 'st' reduces ROM size slightly
strobe_mode_te st = strobe_type;
#ifdef USE_MOMENTARY_MODE
momentary_mode = 1; // 0 = ramping, 1 = strobes
#endif
if (event == EV_enter_state) {
#ifdef USE_TINT_RAMPING
saved_tint = tint;
#endif
strobe_global_setup(st);
}
#ifdef USE_CANDLE_MODE
// pass all events to candle mode, when it's active
// (the code is in its own pseudo-state to keep things cleaner)
if (st == candle_mode_e) {
candle_mode_state(event, arg);
}
#endif
if (0) {} // placeholder
// init anything which needs to be initialized
else if (event == EV_enter_state) {
ramp_direction = 1;
return MISCHIEF_MANAGED;
}
// 1 click: off
else if (event == EV_1click) {
set_state(off_state, 0);
undo_global_setting();
return MISCHIEF_MANAGED;
}
// 2 clicks: rotate through strobe/flasher modes
else if (event == EV_2clicks) {
strobe_type = (st + 1) % NUM_STROBES;
save_config();
strobe_global_setup(strobe_type);
return MISCHIEF_MANAGED;
}
// 3 clicks: rotate back through strobe/flasher modes
else if (event == EV_3clicks) {
strobe_type = (st - 1 + NUM_STROBES) % NUM_STROBES;
save_config();
strobe_global_setup(strobe_type);
return MISCHIEF_MANAGED;
}
// hold: change speed (go faster)
// or change brightness (brighter)
else if (event == EV_click1_hold) {
if (0) {} // placeholder
// party / tactical strobe faster
#if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
#ifdef USE_TACTICAL_STROBE_MODE
else if (st <= tactical_strobe_e) {
#else
else if (st == party_strobe_e) {
#endif
if ((arg & 1) == 0) {
uint8_t d = strobe_delays[st];
d -= ramp_direction;
if (d < 8) d = 8;
else if (d > 254) d = 254;
strobe_delays[st] = d;
}
}
#endif
// lightning has no adjustments
//else if (st == lightning_storm_e) {}
// biking mode brighter
#ifdef USE_BIKE_FLASHER_MODE
else if (st == bike_flasher_e) {
bike_flasher_brightness += ramp_direction;
if (bike_flasher_brightness < 2) bike_flasher_brightness = 2;
else if (bike_flasher_brightness > MAX_BIKING_LEVEL) bike_flasher_brightness = MAX_BIKING_LEVEL;
set_level(bike_flasher_brightness);
}
#endif
#ifdef USE_BAD_FLUORESCENT_MODE
else if (st == bad_fluorescent_mode_e) {
fluoresent_brightness += ramp_direction;
if (fluoresent_brightness < 1) fluoresent_brightness = 1;
else if (fluoresent_brightness > MAX_LEVEL) fluoresent_brightness = MAX_LEVEL;
}
#endif
#ifdef USE_TINT_RAMPING
else if (st == tint_alternating_strobe_e) {
tint_alt_brightness += ramp_direction;
if (tint_alt_brightness < 2) tint_alt_brightness = 2;
else if (tint_alt_brightness > RAMP_SMOOTH_CEIL) tint_alt_brightness = RAMP_SMOOTH_CEIL;
set_level(tint_alt_brightness);
}
else if (st == tint_smooth_ramp_e) {
tint_smooth_brightness += ramp_direction;
if (tint_smooth_brightness < 2) tint_smooth_brightness = 2;
else if (tint_smooth_brightness > RAMP_SMOOTH_CEIL) tint_smooth_brightness = RAMP_SMOOTH_CEIL;
set_level(tint_smooth_brightness);
}
#endif
return MISCHIEF_MANAGED;
}
// reverse ramp direction on hold release
// ... and save new strobe settings
else if (event == EV_click1_hold_release) {
ramp_direction = -ramp_direction;
save_config();
return MISCHIEF_MANAGED;
}
// click, hold: change speed (go slower)
// or change brightness (dimmer)
else if (event == EV_click2_hold) {
ramp_direction = 1;
if (0) {} // placeholder
// party / tactical strobe slower
#if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
#ifdef USE_TACTICAL_STROBE_MODE
else if (st <= tactical_strobe_e) {
#else
else if (st == party_strobe_e) {
#endif
if ((arg & 1) == 0) {
if (strobe_delays[st] < 255) strobe_delays[st] ++;
}
}
#endif
// lightning has no adjustments
//else if (st == lightning_storm_e) {}
// biking mode dimmer
#ifdef USE_BIKE_FLASHER_MODE
else if (st == bike_flasher_e) {
if (bike_flasher_brightness > 2)
bike_flasher_brightness --;
set_level(bike_flasher_brightness);
}
#endif
#ifdef USE_BAD_FLUORESCENT_MODE
else if (st == bad_fluorescent_mode_e) {
if (fluoresent_brightness > 1)
fluoresent_brightness--;
}
#endif
#ifdef USE_TINT_RAMPING
else if (st == tint_alternating_strobe_e) {
if (tint_alt_brightness > 2)
tint_alt_brightness--;
set_level(tint_alt_brightness);
}
else if (st == tint_smooth_ramp_e) {
if (tint_smooth_brightness > 2)
tint_smooth_brightness--;
set_level(tint_smooth_brightness);
}
#endif
return MISCHIEF_MANAGED;
}
// release hold: save new strobe settings
else if (event == EV_click2_hold_release) {
save_config();
return MISCHIEF_MANAGED;
}
#ifdef USE_MOMENTARY_MODE
// 8 clicks: go to momentary mode (momentary strobe)
else if (event == EV_8clicks) {
set_state(momentary_state, 0);
set_level(0);
return MISCHIEF_MANAGED;
}
#endif
#if defined(USE_LIGHTNING_MODE) || defined(USE_CANDLE_MODE)
// clock tick: bump the random seed
else if (event == EV_tick) {
// un-reverse after 1 second
if (arg == AUTO_REVERSE_TIME) ramp_direction = 1;
pseudo_rand_seed += arg;
return MISCHIEF_MANAGED;
}
// 4C: turning down busy factor (less busy) of lightning mode,
// or turning down firework brightness by 12,
// or decrease tint alternating interval by 0.5 second
// or decrease lighthouse delay by 1 sec
else if (event == EV_4clicks) {
if (0) {} // placeholder
#ifdef USE_LIGHTNING_MODE
else if (st == lightning_storm_e) {
lightning_busy_factor++;
if (lightning_busy_factor > LIGHTNING_BUSY_FACTOR_MAX)
lightning_busy_factor = LIGHTNING_BUSY_FACTOR_MAX;
save_config();
blink_once();
}
#endif
#ifdef USE_FIREWORK_MODE
else if (st == firework_mode_e) {
firework_brightness -= 12;
if (firework_brightness < MIN_FIREWORK_LEVEL)
firework_brightness = MIN_FIREWORK_LEVEL;
save_config();
blink_once();
}
#endif
#ifdef USE_LIGHTHOUSE_MODE
else if (st == lighthouse_mode_e) {
if (lighthouse_delay > LIGHTHOUSE_MIN_DELAY)
lighthouse_delay--;
save_config();
blink_once();
}
#endif
#ifdef USE_TINT_RAMPING
else if (st == tint_alternating_strobe_e) {
if (tint_alt_interval > TINT_ALT_MIN_INTERVAL)
tint_alt_interval--;
save_config();
blink_once();
}
else if (st == tint_smooth_ramp_e) {
if (tint_smooth_pause > TINT_SMOOTH_MIN_PAUSE)
tint_smooth_pause -= 2;
save_config();
blink_once();
}
#endif
return MISCHIEF_MANAGED;
}
// 5C: turning up busy factor (busier) of lightning mode,
// or turning up firework brightness by 12,
// or increasing tint alternating interval by 0.5 second
// or increasing lighthouse delay by 1 sec
else if (event == EV_5clicks) {
if (0) {} // placeholder
#ifdef USE_LIGHTNING_MODE
else if (st == lightning_storm_e) {
lightning_busy_factor--;
if (lightning_busy_factor < LIGHTNING_BUSY_FACTOR_MIN)
lightning_busy_factor = LIGHTNING_BUSY_FACTOR_MIN;
save_config();
blink_once();
}
#endif
#ifdef USE_FIREWORK_MODE
else if (st == firework_mode_e) {
firework_brightness += 12;
if (firework_brightness > MAX_LEVEL)
firework_brightness = MAX_LEVEL;
save_config();
blink_once();
}
#endif
#ifdef USE_LIGHTHOUSE_MODE
else if (st == lighthouse_mode_e) {
if (lighthouse_delay < LIGHTHOUSE_MAX_DELAY)
lighthouse_delay++;
save_config();
blink_once();
}
#endif
#ifdef USE_TINT_RAMPING
else if (st == tint_alternating_strobe_e) {
if (tint_alt_interval < TINT_ALT_MAX_INTERVAL)
tint_alt_interval++;
save_config();
blink_once();
}
else if (st == tint_smooth_ramp_e) {
if (tint_smooth_pause < TINT_SMOOTH_MAX_PAUSE)
tint_smooth_pause += 2;
save_config();
blink_once();
}
#endif
return MISCHIEF_MANAGED;
}
// 6C: reset lightning busy factor to default,
// or reset firework brightness to default
// or reset lighthouse delay to default
else if (event == EV_6clicks) {
if (0) {} // placeholder
#ifdef USE_LIGHTNING_MODE
else if (st == lightning_storm_e) {
lightning_busy_factor = LIGHTNING_BUSY_FACTOR;
save_config();
blink_once();
}
#endif
#ifdef USE_FIREWORK_MODE
else if (st == firework_mode_e) {
firework_brightness = RAMP_SMOOTH_CEIL;
}
#endif
#ifdef USE_LIGHTHOUSE_MODE
else if (st == lighthouse_mode_e) {
lighthouse_delay = LIGHTHOUSE_DELAY_DEFAULT;
}
#endif
return MISCHIEF_MANAGED;
}
#endif
return EVENT_NOT_HANDLED;
}
// runs repeatedly in FSM loop() whenever UI is in strobe_state or momentary strobe
inline void strobe_state_iter() {
uint8_t st = strobe_type; // can't use switch() on an enum
switch(st) {
#if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
#ifdef USE_PARTY_STROBE_MODE
case party_strobe_e:
#endif
#ifdef USE_TACTICAL_STROBE_MODE
case tactical_strobe_e:
#endif
party_tactical_strobe_mode_iter(st);
break;
#endif
#ifdef USE_LIGHTNING_MODE
case lightning_storm_e:
lightning_storm_iter();
break;
#endif
#ifdef USE_BIKE_FLASHER_MODE
case bike_flasher_e:
bike_flasher_iter();
break;
#endif
#ifdef USE_FIREWORK_MODE
case firework_mode_e:
firework_iter();
break;
#endif
#ifdef USE_LIGHTHOUSE_MODE
case lighthouse_mode_e:
lighthouse_iter();
break;
#endif
#ifdef USE_BAD_FLUORESCENT_MODE
case bad_fluorescent_mode_e:
bad_fluorescent_iter();
break;
#endif
#ifdef USE_TINT_RAMPING
case tint_alternating_strobe_e:
tint_alt_iter();
break;
case tint_smooth_ramp_e:
tint_smooth_ramp_iter();
#endif
}
}
#endif // ifdef USE_STROBE_STATE
#if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
inline void party_tactical_strobe_mode_iter(uint8_t st) {
// one iteration of main loop()
uint8_t del = strobe_delays[st];
// TODO: make tac strobe brightness configurable?
set_level(STROBE_BRIGHTNESS);
if (0) {} // placeholde0
#ifdef USE_PARTY_STROBE_MODE
else if (st == party_strobe_e) { // party strobe
#ifdef PARTY_STROBE_ONTIME
nice_delay_ms(PARTY_STROBE_ONTIME);
#else
if (del < 42) delay_zero();
else nice_delay_ms(1);
#endif
}
#endif
#ifdef USE_TACTICAL_STROBE_MODE
else { //tactical strobe
nice_delay_ms(del >> 1);
}
#endif
set_level(STROBE_OFF_LEVEL);
nice_delay_ms(del); // no return check necessary on final delay
}
#endif
#ifdef USE_LIGHTNING_MODE
inline void lightning_storm_iter() {
// one iteration of main loop()
int16_t brightness;
uint16_t rand_time;
// turn the emitter on at a random level,
// for a random amount of time between 1ms and 32ms
//rand_time = 1 << (pseudo_rand() % 7);
rand_time = pseudo_rand() & 63;
brightness = 1 << (pseudo_rand() % 7); // 1, 2, 4, 8, 16, 32, 64
brightness += 1 << (pseudo_rand() % 5); // 2 to 80 now
brightness += pseudo_rand() % brightness; // 2 to 159 now (w/ low bias)
if (brightness > MAX_LEVEL) brightness = MAX_LEVEL;
set_level(brightness);
nice_delay_ms(rand_time);
// decrease the brightness somewhat more gradually, like lightning
uint8_t stepdown = brightness >> 3;
if (stepdown < 1) stepdown = 1;
while(brightness > 1) {
nice_delay_ms(rand_time);
brightness -= stepdown;
if (brightness < 0) brightness = 0;
set_level(brightness);
/*
if ((brightness < MAX_LEVEL/2) && (! (pseudo_rand() & 15))) {
brightness <<= 1;
set_level(brightness);
}
*/
if (! (pseudo_rand() & 3)) {
nice_delay_ms(rand_time);
set_level(brightness>>1);
}
}
// turn the emitter off,
// for a random amount of time between 1ms and 8192ms (default busy factor)
// (with a low bias)
rand_time = 1 << (pseudo_rand() % lightning_busy_factor);
rand_time += pseudo_rand() % rand_time;
set_level(0);
nice_delay_ms(rand_time); // no return check necessary on final delay
}
#endif
#ifdef USE_BIKE_FLASHER_MODE
inline void bike_flasher_iter() {
// one iteration of main loop()
uint8_t burst = bike_flasher_brightness << 1;
if (burst > MAX_LEVEL) burst = MAX_LEVEL;
for(uint8_t i=0; i<4; i++) {
set_level(burst);
nice_delay_ms(5);
set_level(bike_flasher_brightness);
nice_delay_ms(65);
}
nice_delay_ms(720); // no return check necessary on final delay
set_level(0);
}
#endif
#ifdef USE_FIREWORK_MODE
#define FIREWORK_DEFAULT_STAGE_COUNT 64
#define FIREWORK_DEFAULT_INTERVAL (2500/FIREWORK_DEFAULT_STAGE_COUNT)
uint8_t firework_stage = 0;
uint8_t firework_stage_count = FIREWORK_DEFAULT_STAGE_COUNT;
uint8_t step_interval = FIREWORK_DEFAULT_INTERVAL;
#ifdef USE_TINT_RAMPING
uint8_t tint_mode = 0; // 0: alternate, 1: channel 1 only, 2: channel 2 only, 3: random tint
uint8_t chosen_tint = 127; // for tint_mode = 3
#endif
inline static void update_firework_tint(uint8_t stage) {
#ifdef USE_TINT_RAMPING
if (tint_locked) return;
switch (tint_mode) {
// alternate both channels
case 0:
if (stage % 5 == 0)
tint = (tint == 1) ? 254 : 1;
break;
// channel 1 only
case 1:
tint = 1;
break;
// channel 2 only
case 2:
tint = 254;
break;
// random tint
case 3:
tint = chosen_tint;
break;
}
#endif
}
// code is copied and modified from factory-reset.c
inline void firework_iter() {
if (firework_stage == firework_stage_count) {
// explode, and reset stage
firework_stage = 0;
for (uint8_t brightness = firework_brightness; brightness > 0; brightness--) {
update_firework_tint(firework_stage);
set_level(brightness);
nice_delay_ms(step_interval/4);
set_level((uint16_t)brightness*7/8);
nice_delay_ms(step_interval/(1+(pseudo_rand()%5)));
}
// off for 1 to 5 seconds
set_level(0);
nice_delay_ms(1000 + (pseudo_rand() % 5) * 1000);
#ifdef USE_TINT_RAMPING
// randomly set a tint mode for the next firework show
tint_mode = pseudo_rand() % 4;
if (tint_mode == 3) chosen_tint = pseudo_rand() % 254 + 1;
update_firework_tint(firework_stage);
#endif
// set next stage count (16 to 64 in increment of 8)
firework_stage_count = 16 + 8 * (pseudo_rand() % 7);
return;
}
// wind up to explode
set_level(firework_stage);
nice_delay_ms(step_interval/3);
set_level((uint16_t)firework_stage*2/3);
nice_delay_ms(step_interval/3);
firework_stage++;
// we've reached our max brightness for firework mode, let's explode in the next iteration
if (firework_stage > firework_brightness)
firework_stage = firework_stage_count;
}
#endif
#ifdef USE_LIGHTHOUSE_MODE
// phase is between 0~255, returns MAX_LEVEL at 128 and 1 at both ends
uint8_t lighthouse_intensity(uint8_t phase) {
if (phase > 127)
phase = 256 - phase;
const uint64_t maxOutput = MAX_LEVEL - 1;
// power of 4 (quartic function)
return (uint8_t)(maxOutput * phase / 128 * phase / 128 * phase / 128 * phase / 128) + 1;
}
inline void lighthouse_iter() {
uint8_t brightness = lighthouse_intensity(lighthouse_phase++);
set_level(brightness);
if (lighthouse_phase == 0) {
set_level(0);
nice_delay_ms(1000 * lighthouse_delay);
} else
nice_delay_ms(10 + lighthouse_delay);
}
#endif
#ifdef USE_BAD_FLUORESCENT_MODE
inline void bad_fluorescent_iter() {
// broken fluorescent
// even index: light off, odd index: light on
// unit: 10ms or -1 means random number (10~500ms) generated at boot
static const int8_t fluorescent_pattern[] = {1,4, -1,2, 5,3, -1,5, 7,27, 1,5, 3,10, -1,20, 3,-1, 2,-1, 10,-1, -1,-1, 1};
fluoresent_ramp_up_increment++;
if ((fluorescent_pattern[fluoresent_flicker_index] == -1 && fluoresent_ramp_up_increment == fluoresent_flicker_random) ||
(fluorescent_pattern[fluoresent_flicker_index] == fluoresent_ramp_up_increment)) {
fluoresent_flicker_index++;
fluoresent_ramp_up_increment = 0;
set_level(fluoresent_flicker_index & 1 ? fluoresent_brightness >> (pseudo_rand()&1): 0);
}
if (fluoresent_flicker_index == sizeof(fluorescent_pattern)) {
fluoresent_flicker_index = 0;
fluoresent_flicker_random = pseudo_rand()%50 + 1;
}
nice_delay_ms(10);
}
#endif
#ifdef USE_TINT_RAMPING
inline void tint_alt_iter() {
if (tint_locked) return;
tint = (tint == 1) ? 254 : 1;
set_level(tint_alt_brightness);
nice_delay_ms(500 * tint_alt_interval);
}
inline void tint_smooth_ramp_iter() {
if (tint_locked) return;
static uint8_t tint_step = 1;
if (tint == 254) tint_step = -1;
else if (tint == 1) tint_step = 1;
tint += tint_step;
set_level(tint_smooth_brightness);
nice_delay_ms(tint_smooth_pause);
}
#endif
#ifdef USE_CANDLE_MODE
#include "candle-mode.c"
#endif
#ifdef USE_BORING_STROBE_STATE
#include "ff-strobe-modes.c"
#endif
#endif