aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2021-08-31 13:43:43 -0600
committerSelene ToyKeeper2021-08-31 13:43:43 -0600
commita0b0a0af03d0c80d15d27ea02c8d3d7209dfdd01 (patch)
treebd9169843b8b01cdff32bc1a8e4136d004f15ebf /spaghetti-monster
parentmade it possible to use autolock in simple UI (diff)
downloadanduril-a0b0a0af03d0c80d15d27ea02c8d3d7209dfdd01.tar.gz
anduril-a0b0a0af03d0c80d15d27ea02c8d3d7209dfdd01.tar.bz2
anduril-a0b0a0af03d0c80d15d27ea02c8d3d7209dfdd01.zip
added runtime config option for smooth ramp speed
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/anduril/config-default.h3
-rw-r--r--spaghetti-monster/anduril/load-save-config-fsm.h15
-rw-r--r--spaghetti-monster/anduril/load-save-config.c30
-rw-r--r--spaghetti-monster/anduril/ramp-mode.c26
-rw-r--r--spaghetti-monster/anduril/ramp-mode.h8
5 files changed, 61 insertions, 21 deletions
diff --git a/spaghetti-monster/anduril/config-default.h b/spaghetti-monster/anduril/config-default.h
index a50be5d..1043253 100644
--- a/spaghetti-monster/anduril/config-default.h
+++ b/spaghetti-monster/anduril/config-default.h
@@ -68,6 +68,9 @@
// default ramp style: 0 = smooth, 1 = stepped
#define RAMP_STYLE 0
+// smooth ramp speed: 1, 2, 3, 4, ... for 1X speed, 1/2, 1/3rd, 1/4th, ...
+#define USE_RAMP_SPEED_CONFIG
+
// short blip when crossing from "click" to "hold" from off
// (helps the user hit moon mode exactly, instead of holding too long
// or too short)
diff --git a/spaghetti-monster/anduril/load-save-config-fsm.h b/spaghetti-monster/anduril/load-save-config-fsm.h
index 343c6ff..edd4ed5 100644
--- a/spaghetti-monster/anduril/load-save-config-fsm.h
+++ b/spaghetti-monster/anduril/load-save-config-fsm.h
@@ -27,10 +27,19 @@ typedef enum {
#ifdef USE_RAMP_CONFIG
ramp_smooth_floor_e,
ramp_smooth_ceil_e,
+ #ifdef USE_RAMP_SPEED_CONFIG
+ ramp_speed_e,
+ #endif
ramp_discrete_floor_e,
ramp_discrete_ceil_e,
ramp_discrete_steps_e,
#endif
+ #ifdef USE_SIMPLE_UI
+ simple_ui_floor_e,
+ simple_ui_ceil_e,
+ simple_ui_steps_e,
+ simple_ui_active_e,
+ #endif
#ifdef USE_MANUAL_MEMORY
manual_memory_e,
#ifdef USE_MANUAL_MEMORY_TIMER
@@ -59,12 +68,6 @@ typedef enum {
#ifdef USE_BEACON_MODE
beacon_seconds_e,
#endif
- #ifdef USE_SIMPLE_UI
- simple_ui_active_e,
- simple_ui_floor_e,
- simple_ui_ceil_e,
- simple_ui_steps_e,
- #endif
#ifdef USE_THERMAL_REGULATION
therm_ceil_e,
therm_cal_offset_e,
diff --git a/spaghetti-monster/anduril/load-save-config.c b/spaghetti-monster/anduril/load-save-config.c
index cd29ca5..57638d6 100644
--- a/spaghetti-monster/anduril/load-save-config.c
+++ b/spaghetti-monster/anduril/load-save-config.c
@@ -29,10 +29,19 @@ void load_config() {
#ifdef USE_RAMP_CONFIG
ramp_floors[0] = eeprom[ramp_smooth_floor_e];
ramp_ceils[0] = eeprom[ramp_smooth_ceil_e];
+ #ifdef USE_RAMP_SPEED_CONFIG
+ ramp_speed = eeprom[ramp_speed_e];
+ #endif
ramp_floors[1] = eeprom[ramp_discrete_floor_e];
ramp_ceils[1] = eeprom[ramp_discrete_ceil_e];
ramp_stepss[1] = eeprom[ramp_discrete_steps_e];
#endif
+ #ifdef USE_SIMPLE_UI
+ ramp_floors[2] = eeprom[simple_ui_floor_e];
+ ramp_ceils[2] = eeprom[simple_ui_ceil_e];
+ ramp_stepss[2] = eeprom[simple_ui_steps_e];
+ simple_ui_active = eeprom[simple_ui_active_e];
+ #endif
#ifdef USE_MANUAL_MEMORY
manual_memory = eeprom[manual_memory_e];
#ifdef USE_MANUAL_MEMORY_TIMER
@@ -59,12 +68,6 @@ void load_config() {
#ifdef USE_BEACON_MODE
beacon_seconds = eeprom[beacon_seconds_e];
#endif
- #ifdef USE_SIMPLE_UI
- simple_ui_active = eeprom[simple_ui_active_e];
- ramp_floors[2] = eeprom[simple_ui_floor_e];
- ramp_ceils[2] = eeprom[simple_ui_ceil_e];
- ramp_stepss[2] = eeprom[simple_ui_steps_e];
- #endif
#ifdef USE_THERMAL_REGULATION
therm_ceil = eeprom[therm_ceil_e];
therm_cal_offset = eeprom[therm_cal_offset_e];
@@ -95,10 +98,19 @@ void save_config() {
#ifdef USE_RAMP_CONFIG
eeprom[ramp_smooth_floor_e] = ramp_floors[0];
eeprom[ramp_smooth_ceil_e] = ramp_ceils[0];
+ #ifdef USE_RAMP_SPEED_CONFIG
+ eeprom[ramp_speed_e] = ramp_speed;
+ #endif
eeprom[ramp_discrete_floor_e] = ramp_floors[1];
eeprom[ramp_discrete_ceil_e] = ramp_ceils[1];
eeprom[ramp_discrete_steps_e] = ramp_stepss[1];
#endif
+ #ifdef USE_SIMPLE_UI
+ eeprom[simple_ui_floor_e] = ramp_floors[2];
+ eeprom[simple_ui_ceil_e] = ramp_ceils[2];
+ eeprom[simple_ui_steps_e] = ramp_stepss[2];
+ eeprom[simple_ui_active_e] = simple_ui_active;
+ #endif
#ifdef USE_MANUAL_MEMORY
eeprom[manual_memory_e] = manual_memory;
#ifdef USE_MANUAL_MEMORY_TIMER
@@ -125,12 +137,6 @@ void save_config() {
#ifdef USE_BEACON_MODE
eeprom[beacon_seconds_e] = beacon_seconds;
#endif
- #ifdef USE_SIMPLE_UI
- eeprom[simple_ui_active_e] = simple_ui_active;
- eeprom[simple_ui_floor_e] = ramp_floors[2];
- eeprom[simple_ui_ceil_e] = ramp_ceils[2];
- eeprom[simple_ui_steps_e] = ramp_stepss[2];
- #endif
#ifdef USE_THERMAL_REGULATION
eeprom[therm_ceil_e] = therm_ceil;
eeprom[therm_cal_offset_e] = therm_cal_offset;
diff --git a/spaghetti-monster/anduril/ramp-mode.c b/spaghetti-monster/anduril/ramp-mode.c
index e16a7b9..2508d52 100644
--- a/spaghetti-monster/anduril/ramp-mode.c
+++ b/spaghetti-monster/anduril/ramp-mode.c
@@ -149,6 +149,12 @@ uint8_t steady_state(Event event, uint16_t arg) {
if (ramp_style && (arg % HOLD_TIMEOUT != 0)) {
return MISCHIEF_MANAGED;
}
+ #ifdef USE_RAMP_SPEED_CONFIG
+ // ramp slower if user configured things that way
+ if ((! ramp_style) && (arg % ramp_speed)) {
+ return MISCHIEF_MANAGED;
+ }
+ #endif
// fix ramp direction on first frame if necessary
if (!arg) {
// click, hold should always go down if possible
@@ -160,12 +166,24 @@ uint8_t steady_state(Event event, uint16_t arg) {
else if (actual_level <= mode_min) { ramp_direction = 1; }
}
// if the button is stuck, err on the side of safety and ramp down
- else if ((arg > TICKS_PER_SECOND * 5) && (actual_level >= mode_max)) {
+ else if ((arg > TICKS_PER_SECOND * 5
+ #ifdef USE_RAMP_SPEED_CONFIG
+ // FIXME: count from time actual_level hits mode_max,
+ // not from beginning of button hold
+ * ramp_speed
+ #endif
+ ) && (actual_level >= mode_max)) {
ramp_direction = -1;
}
#ifdef USE_LOCKOUT_MODE
// if the button is still stuck, lock the light
- else if ((arg > TICKS_PER_SECOND * 10) && (actual_level <= mode_min)) {
+ else if ((arg > TICKS_PER_SECOND * 10
+ #ifdef USE_RAMP_SPEED_CONFIG
+ // FIXME: count from time actual_level hits mode_min,
+ // not from beginning of button hold
+ * ramp_speed
+ #endif
+ ) && (actual_level <= mode_min)) {
blink_once();
set_state(lockout_state, 0);
}
@@ -445,7 +463,11 @@ void ramp_config_save(uint8_t step, uint8_t value) {
}
uint8_t ramp_config_state(Event event, uint16_t arg) {
+ #ifdef USE_RAMP_SPEED_CONFIG
+ const uint8_t num_config_steps = 3;
+ #else
uint8_t num_config_steps = ramp_style + 2;
+ #endif
return config_state_base(event, arg,
num_config_steps, ramp_config_save);
}
diff --git a/spaghetti-monster/anduril/ramp-mode.h b/spaghetti-monster/anduril/ramp-mode.h
index 7fb704a..7c8b014 100644
--- a/spaghetti-monster/anduril/ramp-mode.h
+++ b/spaghetti-monster/anduril/ramp-mode.h
@@ -75,6 +75,9 @@
#ifndef RAMP_STYLE
#define RAMP_STYLE 0 // smooth default
#endif
+#ifndef DEFAULT_RAMP_SPEED
+#define DEFAULT_RAMP_SPEED 1 // WDT ticks per "frame", must be 1 or more
+#endif
#ifndef RAMP_SMOOTH_FLOOR
#define RAMP_SMOOTH_FLOOR 1
#endif
@@ -165,6 +168,9 @@ uint8_t simple_ui_active = SIMPLE_UI_ACTIVE;
#endif
// smooth vs discrete ramping
uint8_t ramp_style = RAMP_STYLE; // 0 = smooth, 1 = discrete
+#ifdef USE_RAMP_SPEED_CONFIG
+#define ramp_speed (ramp_stepss[0])
+#endif
// current values, regardless of style
uint8_t ramp_floor = RAMP_SMOOTH_FLOOR;
uint8_t ramp_ceil = RAMP_SMOOTH_CEIL;
@@ -184,7 +190,7 @@ uint8_t ramp_ceils[] = {
#endif
};
uint8_t ramp_stepss[] = {
- 0,
+ DEFAULT_RAMP_SPEED,
RAMP_DISCRETE_STEPS,
#ifdef USE_SIMPLE_UI
SIMPLE_UI_STEPS,