Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- === modified file 'ToyKeeper/spaghetti-monster/anduril/anduril.c'
- --- ToyKeeper/spaghetti-monster/anduril/anduril.c 2018-05-06 23:51:39 +0000
- +++ ToyKeeper/spaghetti-monster/anduril/anduril.c 2018-06-16 21:06:14 +0000
- @@ -20,8 +20,8 @@
- /********* User-configurable options *********/
- // Physical driver type
- -#define FSM_EMISAR_D4_DRIVER
- -//#define FSM_BLF_Q8_DRIVER
- +//#define FSM_EMISAR_D4_DRIVER
- +#define FSM_BLF_Q8_DRIVER
- //#define FSM_FW3A_DRIVER
- //#define FSM_BLF_GT_DRIVER
- @@ -150,6 +150,8 @@
- #endif
- // 1-hour ramp down from low, then automatic off
- uint8_t goodnight_state(EventPtr event, uint16_t arg);
- +// off for configurable then ramp up
- +uint8_t alarmclock_state(EventPtr event, uint16_t arg);
- // beacon mode and its related config mode
- uint8_t beacon_state(EventPtr event, uint16_t arg);
- uint8_t beacon_config_state(EventPtr event, uint16_t arg);
- @@ -897,9 +899,9 @@
- set_state(off_state, 0);
- return MISCHIEF_MANAGED;
- }
- - // 2 clicks: beacon mode
- + // 2 clicks: alarm mode
- else if (event == EV_2clicks) {
- - set_state(beacon_state, 0);
- + set_state(alarmclock_state, 0);
- return MISCHIEF_MANAGED;
- }
- // tick: step down (maybe) or off (maybe)
- @@ -922,6 +924,60 @@
- }
- +uint8_t alarmclock_state(EventPtr event, uint16_t arg) {
- + static uint8_t hours;
- + static uint8_t ten_minutes;
- + static uint16_t ticks_since_start = 0;
- + static uint16_t alarmclock_ticks = 0;
- +
- + // start
- + if (event == EV_enter_state) {
- + ticks_since_start = 0;
- + hours = 255;
- +
- + // enter config to ask for hours
- + push_state(number_entry_state, 0);
- +
- + // TODO moonlight or indicator light
- + return MISCHIEF_MANAGED;
- + }
- + // an option was set (return from number_entry_state)
- + else if (event == EV_reenter_state) {
- + blink_confirm(1);
- + if (hours == 255) {
- + hours = number_entry_value;
- + // enter config again to ask for ten_minutes
- + push_state(number_entry_state, 0);
- + } else {
- + ten_minutes = number_entry_value;
- + alarmclock_ticks = (hours * 60 + ten_minutes * 10) * TICKS_PER_SECOND * 60;
- + }
- +
- + return MISCHIEF_MANAGED;
- + }
- + // 1 click: off
- + else if (event == EV_1click) {
- + set_state(off_state, 0);
- + return MISCHIEF_MANAGED;
- + }
- + // 2 clicks: beacon mode
- + else if (event == EV_2clicks) {
- + set_state(beacon_state, 0);
- + return MISCHIEF_MANAGED;
- + }
- + // tick: wait ramp up
- + else if (event == EV_tick) {
- + // ramp up
- + if (++ticks_since_start > alarmclock_ticks) {
- + long level = (ticks_since_start - alarmclock_ticks) / TICKS_PER_SECOND;
- + set_level(level < ramp_smooth_ceil ? level : ramp_smooth_ceil);
- + }
- + return MISCHIEF_MANAGED;
- + }
- + return EVENT_NOT_HANDLED;
- +}
- +
- +
- uint8_t lockout_state(EventPtr event, uint16_t arg) {
- #ifdef MOON_DURING_LOCKOUT_MODE
- // momentary(ish) moon mode during lockout
- @@ -1553,7 +1609,9 @@
- else if ( (state == steady_state)
- || (state == off_state)
- || (state == lockout_state)
- - || (state == goodnight_state) ) {
- + || (state == goodnight_state)
- + || (state == alarmclock_state)
- + ) {
- // doze until next clock tick
- idle_mode();
- }
Advertisement
Add Comment
Please, Sign In to add comment