Skip to content

Commit

Permalink
startup mode: add old fluorescent and lighter flicker ramp
Browse files Browse the repository at this point in the history
Startup mode:
0: instant on (default)
1: quickly ramp up to memorized level
2: old fluorescent light flickering
3: lighter flickering and slowly ramp up
  • Loading branch information
starryalley committed Jul 23, 2022
1 parent 383e8b8 commit 09bd7fd
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
5 changes: 1 addition & 4 deletions spaghetti-monster/anduril/config-default.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@
// those oscillations
//#define USE_LOWPASS_WHILE_ASLEEP

// when in off mode and single click to turn on the light, use can configure different start up behaviour:
// 0: instant on (default)
// 1: quickly ramp up to the level (~0.5s or so)
// 2: fluorescent startup flicker
// when in off mode and single click to turn on the light, user can configure different start up behaviour
#define USE_RAMP_START_MODE
#endif
65 changes: 58 additions & 7 deletions spaghetti-monster/anduril/startup_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,31 @@ void ramp_up_level(uint8_t lvl) {
if (ramp_start_mode == 1) {
ramp_up_target = lvl;
ramp_up_increment = ramp_up_target / (TICKS_PER_SECOND/4) + 1;
} else if (ramp_start_mode == 2) {
// TODO: set additional parameter for fluorescent startup flickering
set_level_and_therm_target(lvl);
} else if (ramp_start_mode == 2 || ramp_start_mode == 3) {
ramp_up_target = lvl;
flicker_random = pseudo_rand()%20 + 1;
ramp_up_increment = 0;
flicker_index = 0;
} else {
// 0 or else: default behaviour: instant on
set_level_and_therm_target(lvl);
}
}

void ramp_up_tick() {
if (ramp_start_mode == 1) {
if (ramp_up_target > 0 && ramp_up_target > actual_level) {
if (ramp_up_target == 0) return;

// even index: light off, odd index: light on
// unit: tick (1/62s) or -1 means random number (1~30 ticks) generated at boot
static const int8_t fluorescent_pattern[] = {-1,2, 5,3, -1,1, -1,2, -1,5, 14,-1, /*6*/-1};
// more broken fluorescent
//static const int8_t fluorescent_pattern[] = {1,4, -1,2, 5,3, -1,5, 7,27, -1,5, 5,10, -1,20, 34,-1, 2};
// lighter
static const int8_t lighter_pattern[] = {5,2, 12,2, -1,1};

switch(ramp_start_mode) {
case 1:
if (ramp_up_target > actual_level) {
if (actual_level+ramp_up_increment >= ramp_up_target) {
set_level(ramp_up_target);
// we're done now
Expand All @@ -46,8 +59,46 @@ void ramp_up_tick() {
set_level(actual_level + ramp_up_increment);
}
}
} else if (ramp_start_mode == 2) {
// TODO: fluorescent startup flickering
break;
case 2:
// fluorescent startup flickering
ramp_up_increment++;
if ((fluorescent_pattern[flicker_index] == -1 && ramp_up_increment == flicker_random) ||
(fluorescent_pattern[flicker_index] == ramp_up_increment)) {
flicker_index++;
ramp_up_increment = 0;
set_level(flicker_index & 1 ? ramp_up_target>>1: 0);
}
if (flicker_index == sizeof(fluorescent_pattern)) {
// we're done now
set_level(ramp_up_target);
ramp_up_target = 0;
flicker_index = 0;
}
break;
case 3:
// lighter flickering
ramp_up_increment++;
// step 1: flicker a bit
if (flicker_index < sizeof(lighter_pattern) && (
(lighter_pattern[flicker_index] == -1 && ramp_up_increment == flicker_random) ||
(lighter_pattern[flicker_index] == ramp_up_increment))) {
flicker_index++;
ramp_up_increment = 0;
set_level(flicker_index & 1 ? ramp_up_target>>1: 0);
}
// step 2: ramp up slowly to target
if (flicker_index == sizeof(lighter_pattern)) {
// ramp up slowly now
set_level(actual_level + 2);
if (actual_level >= ramp_up_target) {
// all done
set_level(ramp_up_target);
ramp_up_target = 0;
flicker_index = 0;
}
}
break;
}
}

Expand Down
9 changes: 7 additions & 2 deletions spaghetti-monster/anduril/startup_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
#ifndef DEFAULT_RAMP_START_MODE
#define DEFAULT_RAMP_START_MODE 0
#endif
// 0: instant on, 1: ramp up to memorized level, 2: fluorescent startup flicker

// 0: instant on (default)
// 1: ramp up to memorized level within 0.5sec
// 2: old fluorescent light flicker
// 3: lighter flicker and slowly ramp up
uint8_t ramp_start_mode = DEFAULT_RAMP_START_MODE;
uint8_t ramp_up_target = 0;
uint8_t ramp_up_increment = 1;

uint8_t flicker_random = 1;
uint8_t flicker_index = 0;
void ramp_up_level(uint8_t lvl);
void ramp_up_tick();

Expand Down

0 comments on commit 09bd7fd

Please sign in to comment.