From 53215abb11d66f53fb079e64a4c83d07e5cbedf8 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 22 Jul 2020 16:14:14 -0600 Subject: renamed lockout.* -> lockout-mode.*, moved user-configurable lockout options to config-default.h --- spaghetti-monster/anduril/anduril.c | 4 +- spaghetti-monster/anduril/config-default.h | 6 + spaghetti-monster/anduril/lockout-mode.c | 169 +++++++++++++++++++++++++++++ spaghetti-monster/anduril/lockout-mode.h | 27 +++++ spaghetti-monster/anduril/lockout.c | 169 ----------------------------- spaghetti-monster/anduril/lockout.h | 31 ------ 6 files changed, 204 insertions(+), 202 deletions(-) create mode 100644 spaghetti-monster/anduril/lockout-mode.c create mode 100644 spaghetti-monster/anduril/lockout-mode.h delete mode 100644 spaghetti-monster/anduril/lockout.c delete mode 100644 spaghetti-monster/anduril/lockout.h diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 11bfa4a..d508b3b 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -115,7 +115,7 @@ #endif #ifdef USE_LOCKOUT_MODE -#include "lockout.h" +#include "lockout-mode.h" #endif #ifdef USE_MOMENTARY_MODE @@ -231,7 +231,7 @@ uint8_t rgb_led_lockout_mode = RGB_LED_LOCKOUT_DEFAULT; #endif #ifdef USE_LOCKOUT_MODE -#include "lockout.c" +#include "lockout-mode.c" #endif #ifdef USE_MOMENTARY_MODE diff --git a/spaghetti-monster/anduril/config-default.h b/spaghetti-monster/anduril/config-default.h index 3576566..f055425 100644 --- a/spaghetti-monster/anduril/config-default.h +++ b/spaghetti-monster/anduril/config-default.h @@ -26,6 +26,8 @@ * These settings can be overridden per build target, in cfg-*.h files... * ... but most are not. So changing one here will make it change in * almost every build target. + * + * Some configurable settings are also in other *.h files. */ /********* User-configurable options *********/ @@ -111,6 +113,10 @@ // enable a mode for locking the light for safe carry #define USE_LOCKOUT_MODE +// should lockout mode function as a momentary moon mode? +#define MOON_DURING_LOCKOUT_MODE +// if enabled, 2nd lockout click goes to the other ramp's floor level +#define LOCKOUT_MOON_FANCY // enable momentary mode #define USE_MOMENTARY_MODE diff --git a/spaghetti-monster/anduril/lockout-mode.c b/spaghetti-monster/anduril/lockout-mode.c new file mode 100644 index 0000000..14739fe --- /dev/null +++ b/spaghetti-monster/anduril/lockout-mode.c @@ -0,0 +1,169 @@ +/* + * lockout-mode.c: Lockout mode for Anduril. + * + * Copyright (C) 2017 Selene ToyKeeper + * + * 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 . + */ + +#ifndef LOCKOUT_MODE_C +#define LOCKOUT_MODE_C + +#include "lockout-mode.h" + +uint8_t lockout_state(Event event, uint16_t arg) { + #ifdef MOON_DURING_LOCKOUT_MODE + // momentary(ish) moon mode during lockout + // button is being held + #ifdef USE_AUX_RGB_LEDS + // don't turn on during RGB aux LED configuration + if (event == EV_click3_hold) { set_level(0); } else + #endif + if ((event & (B_CLICK | B_PRESS)) == (B_CLICK | B_PRESS)) { + #ifdef LOCKOUT_MOON_LOWEST + // Use lowest moon configured + uint8_t lvl = ramp_floors[0]; + if (ramp_floors[1] < lvl) lvl = ramp_floors[1]; + set_level(lvl); + #elif defined(LOCKOUT_MOON_FANCY) + if ((event & 0x0f) == 2) { + set_level(ramp_floors[ramp_style^1]); + } else { + set_level(ramp_floors[ramp_style]); + } + #else + // Use moon from current ramp + set_level(nearest_level(1)); + #endif + } + // button was released + else if ((event & (B_CLICK | B_PRESS)) == (B_CLICK)) { + set_level(0); + } + #endif + + // regular event handling + // conserve power while locked out + // (allow staying awake long enough to exit, but otherwise + // be persistent about going back to sleep every few seconds + // even if the user keeps pressing the button) + #ifdef USE_INDICATOR_LED + if (event == EV_enter_state) { + indicator_led(indicator_led_mode >> 2); + } else + #elif defined(USE_AUX_RGB_LEDS) + if (event == EV_enter_state) { + rgb_led_update(rgb_led_lockout_mode, 0); + } else + #endif + if (event == EV_tick) { + if (arg > HOLD_TIMEOUT) { + go_to_standby = 1; + #ifdef USE_INDICATOR_LED + indicator_led(indicator_led_mode >> 2); + #elif defined(USE_AUX_RGB_LEDS) + rgb_led_update(rgb_led_lockout_mode, arg); + #endif + } + return MISCHIEF_MANAGED; + } + #if defined(TICK_DURING_STANDBY) && (defined(USE_INDICATOR_LED) || defined(USE_AUX_RGB_LEDS)) + else if (event == EV_sleep_tick) { + #if defined(USE_INDICATOR_LED) + if ((indicator_led_mode & 0b00001100) == 0b00001100) { + indicator_blink(arg); + } + #elif defined(USE_AUX_RGB_LEDS) + rgb_led_update(rgb_led_lockout_mode, arg); + #endif + return MISCHIEF_MANAGED; + } + #endif + // 4 clicks: exit and turn on + else if (event == EV_4clicks) { + blink_confirm(1); + set_state(steady_state, memorized_level); + return MISCHIEF_MANAGED; + } + // 4 clicks, but hold last: exit and start at floor + else if (event == EV_click4_hold) { + blink_confirm(1); + set_state(steady_state, 1); + return MISCHIEF_MANAGED; + } + + ////////// Every action below here is blocked in the simple UI ////////// + #ifdef USE_SIMPLE_UI + if (simple_ui_active) { + return EVENT_NOT_HANDLED; + } + #endif + + #if defined(USE_INDICATOR_LED) + // 7 clicks: rotate through indicator LED modes (lockout mode) + else if (event == EV_7clicks) { + #if defined(USE_INDICATOR_LED) + uint8_t mode = indicator_led_mode >> 2; + #ifdef TICK_DURING_STANDBY + mode = (mode + 1) & 3; + #else + mode = (mode + 1) % 3; + #endif + #ifdef INDICATOR_LED_SKIP_LOW + if (mode == 1) { mode ++; } + #endif + indicator_led_mode = (mode << 2) + (indicator_led_mode & 0x03); + indicator_led(mode); + #elif defined(USE_AUX_RGB_LEDS) + #endif + save_config(); + return MISCHIEF_MANAGED; + } + #elif defined(USE_AUX_RGB_LEDS) + // 7 clicks: change RGB aux LED pattern + else if (event == EV_7clicks) { + uint8_t mode = (rgb_led_lockout_mode >> 4) + 1; + mode = mode % RGB_LED_NUM_PATTERNS; + rgb_led_lockout_mode = (mode << 4) | (rgb_led_lockout_mode & 0x0f); + rgb_led_update(rgb_led_lockout_mode, 0); + save_config(); + blink_confirm(1); + return MISCHIEF_MANAGED; + } + // 7H: change RGB aux LED color + else if (event == EV_click7_hold) { + setting_rgb_mode_now = 1; + if (0 == (arg & 0x3f)) { + uint8_t mode = (rgb_led_lockout_mode & 0x0f) + 1; + mode = mode % RGB_LED_NUM_COLORS; + rgb_led_lockout_mode = mode | (rgb_led_lockout_mode & 0xf0); + //save_config(); + } + rgb_led_update(rgb_led_lockout_mode, arg); + return MISCHIEF_MANAGED; + } + // 7H, release: save new color + else if (event == EV_click7_hold_release) { + setting_rgb_mode_now = 0; + save_config(); + return MISCHIEF_MANAGED; + } + #endif + + return EVENT_NOT_HANDLED; +} + + +#endif + diff --git a/spaghetti-monster/anduril/lockout-mode.h b/spaghetti-monster/anduril/lockout-mode.h new file mode 100644 index 0000000..c933b30 --- /dev/null +++ b/spaghetti-monster/anduril/lockout-mode.h @@ -0,0 +1,27 @@ +/* + * lockout-mode.h: Lockout mode for Anduril. + * + * Copyright (C) 2017 Selene ToyKeeper + * + * 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 . + */ + +#ifndef LOCKOUT_MODE_H +#define LOCKOUT_MODE_H + +// soft lockout +uint8_t lockout_state(Event event, uint16_t arg); + + +#endif diff --git a/spaghetti-monster/anduril/lockout.c b/spaghetti-monster/anduril/lockout.c deleted file mode 100644 index 56b1051..0000000 --- a/spaghetti-monster/anduril/lockout.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * lockout.c: Lockout mode for Anduril. - * - * Copyright (C) 2017 Selene ToyKeeper - * - * 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 . - */ - -#ifndef LOCKOUT_C -#define LOCKOUT_C - -#include "lockout.h" - -uint8_t lockout_state(Event event, uint16_t arg) { - #ifdef MOON_DURING_LOCKOUT_MODE - // momentary(ish) moon mode during lockout - // button is being held - #ifdef USE_AUX_RGB_LEDS - // don't turn on during RGB aux LED configuration - if (event == EV_click3_hold) { set_level(0); } else - #endif - if ((event & (B_CLICK | B_PRESS)) == (B_CLICK | B_PRESS)) { - #ifdef LOCKOUT_MOON_LOWEST - // Use lowest moon configured - uint8_t lvl = ramp_floors[0]; - if (ramp_floors[1] < lvl) lvl = ramp_floors[1]; - set_level(lvl); - #elif defined(LOCKOUT_MOON_FANCY) - if ((event & 0x0f) == 2) { - set_level(ramp_floors[ramp_style^1]); - } else { - set_level(ramp_floors[ramp_style]); - } - #else - // Use moon from current ramp - set_level(nearest_level(1)); - #endif - } - // button was released - else if ((event & (B_CLICK | B_PRESS)) == (B_CLICK)) { - set_level(0); - } - #endif - - // regular event handling - // conserve power while locked out - // (allow staying awake long enough to exit, but otherwise - // be persistent about going back to sleep every few seconds - // even if the user keeps pressing the button) - #ifdef USE_INDICATOR_LED - if (event == EV_enter_state) { - indicator_led(indicator_led_mode >> 2); - } else - #elif defined(USE_AUX_RGB_LEDS) - if (event == EV_enter_state) { - rgb_led_update(rgb_led_lockout_mode, 0); - } else - #endif - if (event == EV_tick) { - if (arg > HOLD_TIMEOUT) { - go_to_standby = 1; - #ifdef USE_INDICATOR_LED - indicator_led(indicator_led_mode >> 2); - #elif defined(USE_AUX_RGB_LEDS) - rgb_led_update(rgb_led_lockout_mode, arg); - #endif - } - return MISCHIEF_MANAGED; - } - #if defined(TICK_DURING_STANDBY) && (defined(USE_INDICATOR_LED) || defined(USE_AUX_RGB_LEDS)) - else if (event == EV_sleep_tick) { - #if defined(USE_INDICATOR_LED) - if ((indicator_led_mode & 0b00001100) == 0b00001100) { - indicator_blink(arg); - } - #elif defined(USE_AUX_RGB_LEDS) - rgb_led_update(rgb_led_lockout_mode, arg); - #endif - return MISCHIEF_MANAGED; - } - #endif - // 4 clicks: exit and turn on - else if (event == EV_4clicks) { - blink_confirm(1); - set_state(steady_state, memorized_level); - return MISCHIEF_MANAGED; - } - // 4 clicks, but hold last: exit and start at floor - else if (event == EV_click4_hold) { - blink_confirm(1); - set_state(steady_state, 1); - return MISCHIEF_MANAGED; - } - - ////////// Every action below here is blocked in the simple UI ////////// - #ifdef USE_SIMPLE_UI - if (simple_ui_active) { - return EVENT_NOT_HANDLED; - } - #endif - - #if defined(USE_INDICATOR_LED) - // 7 clicks: rotate through indicator LED modes (lockout mode) - else if (event == EV_7clicks) { - #if defined(USE_INDICATOR_LED) - uint8_t mode = indicator_led_mode >> 2; - #ifdef TICK_DURING_STANDBY - mode = (mode + 1) & 3; - #else - mode = (mode + 1) % 3; - #endif - #ifdef INDICATOR_LED_SKIP_LOW - if (mode == 1) { mode ++; } - #endif - indicator_led_mode = (mode << 2) + (indicator_led_mode & 0x03); - indicator_led(mode); - #elif defined(USE_AUX_RGB_LEDS) - #endif - save_config(); - return MISCHIEF_MANAGED; - } - #elif defined(USE_AUX_RGB_LEDS) - // 7 clicks: change RGB aux LED pattern - else if (event == EV_7clicks) { - uint8_t mode = (rgb_led_lockout_mode >> 4) + 1; - mode = mode % RGB_LED_NUM_PATTERNS; - rgb_led_lockout_mode = (mode << 4) | (rgb_led_lockout_mode & 0x0f); - rgb_led_update(rgb_led_lockout_mode, 0); - save_config(); - blink_confirm(1); - return MISCHIEF_MANAGED; - } - // 7H: change RGB aux LED color - else if (event == EV_click7_hold) { - setting_rgb_mode_now = 1; - if (0 == (arg & 0x3f)) { - uint8_t mode = (rgb_led_lockout_mode & 0x0f) + 1; - mode = mode % RGB_LED_NUM_COLORS; - rgb_led_lockout_mode = mode | (rgb_led_lockout_mode & 0xf0); - //save_config(); - } - rgb_led_update(rgb_led_lockout_mode, arg); - return MISCHIEF_MANAGED; - } - // 7H, release: save new color - else if (event == EV_click7_hold_release) { - setting_rgb_mode_now = 0; - save_config(); - return MISCHIEF_MANAGED; - } - #endif - - return EVENT_NOT_HANDLED; -} - - -#endif - diff --git a/spaghetti-monster/anduril/lockout.h b/spaghetti-monster/anduril/lockout.h deleted file mode 100644 index 4268595..0000000 --- a/spaghetti-monster/anduril/lockout.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * lockout.h: Lockout mode for Anduril. - * - * Copyright (C) 2017 Selene ToyKeeper - * - * 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 . - */ - -#ifndef LOCKOUT_H -#define LOCKOUT_H - -// should lockout mode function as a momentary moon mode? -#define MOON_DURING_LOCKOUT_MODE -// if enabled, 2nd lockout click goes to the other ramp's floor level -#define LOCKOUT_MOON_FANCY -// soft lockout -uint8_t lockout_state(Event event, uint16_t arg); - - -#endif -- cgit v1.2.3