Last active
June 16, 2019 12:49
-
-
Save SammysHP/15304ddbabce4eb80d012b08e5ddb8dd to your computer and use it in GitHub Desktop.
Anduril – Delay ramp after blip()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=== modified file 'ToyKeeper/spaghetti-monster/anduril/anduril.c' | |
--- ToyKeeper/spaghetti-monster/anduril/anduril.c 2019-06-02 06:51:53 +0000 | |
+++ ToyKeeper/spaghetti-monster/anduril/anduril.c 2019-06-16 12:42:40 +0000 | |
@@ -37,6 +37,7 @@ | |
//#define BLINK_AT_RAMP_FLOOR | |
#define BLINK_AT_RAMP_CEILING | |
//#define BLINK_AT_STEPS // whenever a discrete ramp mode is passed in smooth mode | |
+#define BLINK_AT_RAMP_MIDDLE_DELAY | |
// ramp down via regular button hold if a ramp-up ended <1s ago | |
// ("hold, release, hold" ramps down instead of up) | |
@@ -337,6 +338,10 @@ | |
#define BLINK_AT_RAMP_MIDDLE_1 MAX_1x7135 | |
#endif | |
#endif | |
+#else | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ #undef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ #endif | |
#endif | |
// brightness control | |
@@ -616,6 +621,9 @@ | |
// and this stores the level to return to | |
static uint8_t level_before_off = 0; | |
#endif | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ static uint8_t middle_delay_time = 0; | |
+ #endif | |
if (ramp_style) { | |
mode_min = ramp_discrete_floor; | |
mode_max = ramp_discrete_ceil; | |
@@ -715,6 +723,15 @@ | |
if (ramp_style && (arg % HOLD_TIMEOUT != 0)) { | |
return MISCHIEF_MANAGED; | |
} | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ if (arg && !ramp_style && middle_delay_time) { | |
+ --middle_delay_time; | |
+ return MISCHIEF_MANAGED; | |
+ } | |
+ else { | |
+ middle_delay_time = 0; | |
+ } | |
+ #endif | |
#ifdef USE_REVERSING | |
// fix ramp direction on first frame if necessary | |
if (!arg) { | |
@@ -750,6 +767,9 @@ | |
#endif | |
)) { | |
blip(); | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ middle_delay_time = HOLD_TIMEOUT; | |
+ #endif | |
} | |
#endif | |
#if defined(BLINK_AT_STEPS) | |
@@ -790,6 +810,15 @@ | |
if (ramp_style && (arg % HOLD_TIMEOUT != 0)) { | |
return MISCHIEF_MANAGED; | |
} | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ if (arg && !ramp_style && middle_delay_time) { | |
+ --middle_delay_time; | |
+ return MISCHIEF_MANAGED; | |
+ } | |
+ else { | |
+ middle_delay_time = 0; | |
+ } | |
+ #endif | |
// TODO? make it ramp up instead, if already at min? | |
memorized_level = nearest_level((int16_t)actual_level - ramp_step_size); | |
#ifdef USE_THERMAL_REGULATION | |
@@ -810,6 +839,9 @@ | |
#endif | |
)) { | |
blip(); | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ middle_delay_time = HOLD_TIMEOUT; | |
+ #endif | |
} | |
#endif | |
#if defined(BLINK_AT_STEPS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=== modified file 'ToyKeeper/spaghetti-monster/anduril/anduril.c' | |
--- ToyKeeper/spaghetti-monster/anduril/anduril.c 2019-06-02 06:51:53 +0000 | |
+++ ToyKeeper/spaghetti-monster/anduril/anduril.c 2019-06-16 12:46:17 +0000 | |
@@ -37,6 +37,7 @@ | |
//#define BLINK_AT_RAMP_FLOOR | |
#define BLINK_AT_RAMP_CEILING | |
//#define BLINK_AT_STEPS // whenever a discrete ramp mode is passed in smooth mode | |
+#define BLINK_AT_RAMP_MIDDLE_DELAY | |
// ramp down via regular button hold if a ramp-up ended <1s ago | |
// ("hold, release, hold" ramps down instead of up) | |
@@ -337,6 +338,10 @@ | |
#define BLINK_AT_RAMP_MIDDLE_1 MAX_1x7135 | |
#endif | |
#endif | |
+#else | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ #undef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ #endif | |
#endif | |
// brightness control | |
@@ -616,6 +621,9 @@ | |
// and this stores the level to return to | |
static uint8_t level_before_off = 0; | |
#endif | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ static uint8_t middle_delay_time = 0; | |
+ #endif | |
if (ramp_style) { | |
mode_min = ramp_discrete_floor; | |
mode_max = ramp_discrete_ceil; | |
@@ -715,6 +723,14 @@ | |
if (ramp_style && (arg % HOLD_TIMEOUT != 0)) { | |
return MISCHIEF_MANAGED; | |
} | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ if (arg && !ramp_style && arg < middle_delay_time) { | |
+ return MISCHIEF_MANAGED; | |
+ } | |
+ else { | |
+ middle_delay_time = 0; | |
+ } | |
+ #endif | |
#ifdef USE_REVERSING | |
// fix ramp direction on first frame if necessary | |
if (!arg) { | |
@@ -750,6 +766,9 @@ | |
#endif | |
)) { | |
blip(); | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ middle_delay_time = arg + HOLD_TIMEOUT; | |
+ #endif | |
} | |
#endif | |
#if defined(BLINK_AT_STEPS) | |
@@ -790,6 +809,14 @@ | |
if (ramp_style && (arg % HOLD_TIMEOUT != 0)) { | |
return MISCHIEF_MANAGED; | |
} | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ if (arg && !ramp_style && arg < middle_delay_time) { | |
+ return MISCHIEF_MANAGED; | |
+ } | |
+ else { | |
+ middle_delay_time = 0; | |
+ } | |
+ #endif | |
// TODO? make it ramp up instead, if already at min? | |
memorized_level = nearest_level((int16_t)actual_level - ramp_step_size); | |
#ifdef USE_THERMAL_REGULATION | |
@@ -810,6 +837,9 @@ | |
#endif | |
)) { | |
blip(); | |
+ #ifdef BLINK_AT_RAMP_MIDDLE_DELAY | |
+ middle_delay_time = arg + HOLD_TIMEOUT; | |
+ #endif | |
} | |
#endif | |
#if defined(BLINK_AT_STEPS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Second version saves 18 bytes of flash by not comparing the current time with the target time but simply exploits the fact that we receive one button event per tick (do we?).