aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2018-06-30 19:50:18 -0600
committerSelene ToyKeeper2018-06-30 19:50:18 -0600
commit4a80f1caf108492c65fa787c504a20ba3e4618a8 (patch)
tree4ed8aaf267963534c3d3be002d4a2a1f2be9520c
parentRamp down even faster on high modes. Actually save to eeprom after config mo... (diff)
parentFixed bug: moon mode flickered a bit in momentary mode (diff)
downloadanduril-4a80f1caf108492c65fa787c504a20ba3e4618a8.tar.gz
anduril-4a80f1caf108492c65fa787c504a20ba3e4618a8.tar.bz2
anduril-4a80f1caf108492c65fa787c504a20ba3e4618a8.zip
merged updates from fsm branch, applied fixes to rampingiosv3 too
-rw-r--r--spaghetti-monster/anduril/anduril.c70
-rw-r--r--spaghetti-monster/anduril/cfg-emisar-d4.h4
-rw-r--r--spaghetti-monster/anduril/cfg-fw3a.h6
-rw-r--r--spaghetti-monster/anduril/rampingiosv3.c26
-rw-r--r--spaghetti-monster/fsm-ramping.h16
5 files changed, 81 insertions, 41 deletions
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c
index e3c2f2b..5ad7e6e 100644
--- a/spaghetti-monster/anduril/anduril.c
+++ b/spaghetti-monster/anduril/anduril.c
@@ -29,7 +29,7 @@
#define USE_LVP // FIXME: won't build when this option is turned off
#define USE_THERMAL_REGULATION
-#define DEFAULT_THERM_CEIL 50
+#define DEFAULT_THERM_CEIL 45
#define MIN_THERM_STEPDOWN MAX_1x7135 // lowest value it'll step down to
#ifdef MAX_Nx7135
#define THERM_DOUBLE_SPEED_LEVEL MAX_Nx7135 // throttle back faster when high
@@ -70,7 +70,7 @@
#if defined(FSM_BLF_GT_DRIVER)
#include "cfg-blf-gt.h"
-#elif FSM_BLF_Q8_DRIVER
+#elif defined(FSM_BLF_Q8_DRIVER)
#include "cfg-blf-q8.h"
#elif defined(FSM_EMISAR_D4_DRIVER)
@@ -595,7 +595,16 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
#endif
#ifdef USE_SET_LEVEL_GRADUALLY
// make thermal adjustment speed scale with magnitude
- if (arg & 1) return MISCHIEF_MANAGED; // adjust slower
+ if ((arg & 1) && (actual_level < THERM_DOUBLE_SPEED_LEVEL)) {
+ return MISCHIEF_MANAGED; // adjust slower when not a high mode
+ }
+ #ifdef THERM_HARD_TURBO_DROP
+ else if ((! (actual_level < THERM_DOUBLE_SPEED_LEVEL))
+ && (actual_level > gradual_target)) {
+ gradual_tick();
+ }
+ else {
+ #endif
// [int(62*4 / (x**0.8)) for x in (1,2,4,8,16,32,64,128)]
//uint8_t intervals[] = {248, 142, 81, 46, 26, 15, 8, 5};
// [int(62*4 / (x**0.9)) for x in (1,2,4,8,16,32,64,128)]
@@ -605,15 +614,15 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
uint8_t diff;
static uint8_t ticks_since_adjust = 0;
ticks_since_adjust ++;
- if (target_level > actual_level) diff = target_level - actual_level;
+ if (gradual_target > actual_level) diff = gradual_target - actual_level;
else {
- diff = actual_level - target_level;
- // if we're on a really high mode, drop faster
- if (actual_level >= THERM_DOUBLE_SPEED_LEVEL) {
- diff <<= 1;
- }
+ diff = actual_level - gradual_target;
}
uint8_t magnitude = 0;
+ #ifndef THERM_HARD_TURBO_DROP
+ // if we're on a really high mode, drop faster
+ if (actual_level >= THERM_DOUBLE_SPEED_LEVEL) { magnitude ++; }
+ #endif
while (diff) {
magnitude ++;
diff >>= 1;
@@ -625,6 +634,9 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
ticks_since_adjust = 0;
}
//if (!(arg % ticks_per_adjust)) gradual_tick();
+ #ifdef THERM_HARD_TURBO_DROP
+ }
+ #endif
#endif
return MISCHIEF_MANAGED;
}
@@ -638,6 +650,15 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
delay_4ms(2);
set_level(foo);
#endif
+ #ifdef THERM_HARD_TURBO_DROP
+ if (actual_level > THERM_DOUBLE_SPEED_LEVEL) {
+ #ifdef USE_SET_LEVEL_GRADUALLY
+ set_level_gradually(THERM_DOUBLE_SPEED_LEVEL);
+ #else
+ set_level(THERM_DOUBLE_SPEED_LEVEL);
+ #endif
+ } else
+ #endif
if (actual_level > MIN_THERM_STEPDOWN) {
int16_t stepdown = actual_level - arg;
if (stepdown < MIN_THERM_STEPDOWN) stepdown = MIN_THERM_STEPDOWN;
@@ -1227,6 +1248,18 @@ uint8_t muggle_state(EventPtr event, uint16_t arg) {
}
return MISCHIEF_MANAGED;
}
+ #ifdef USE_THERMAL_REGULATION
+ // overheating is handled specially in muggle mode
+ else if(event == EV_temperature_high) {
+ // don't even try...
+ // go immediately to the bottom, in case someone put the light on
+ // maximum while wrapped in dark-colored flammable insulation
+ // or something, because muggles are cool like that
+ // memorized_level = MUGGLE_FLOOR; // override memory? maybe not
+ set_level(MUGGLE_FLOOR);
+ return MISCHIEF_MANAGED;
+ }
+ #endif
// low voltage is handled specially in muggle mode
else if(event == EV_voltage_low) {
uint8_t lvl = (actual_level >> 1) + (actual_level >> 2);
@@ -1261,6 +1294,7 @@ uint8_t config_state_base(EventPtr event, uint16_t arg,
else {
// TODO: blink out some sort of success pattern
savefunc();
+ save_config();
//set_state(retstate, retval);
pop_state();
}
@@ -1644,16 +1678,6 @@ void loop() {
#endif
if (0) {}
- #ifdef USE_IDLE_MODE
- else if ( (state == steady_state)
- || (state == off_state)
- || (state == lockout_state)
- || (state == goodnight_state) ) {
- // doze until next clock tick
- idle_mode();
- }
- #endif
-
if (state == strobe_state) {
uint8_t st = strobe_type;
// bike flasher
@@ -1751,4 +1775,12 @@ void loop() {
set_level(0);
nice_delay_ms(((beacon_seconds) * 1000) - 500);
}
+
+ #ifdef USE_IDLE_MODE
+ else {
+ // doze until next clock tick
+ idle_mode();
+ }
+ #endif
+
}
diff --git a/spaghetti-monster/anduril/cfg-emisar-d4.h b/spaghetti-monster/anduril/cfg-emisar-d4.h
index d17e2b0..a90d318 100644
--- a/spaghetti-monster/anduril/cfg-emisar-d4.h
+++ b/spaghetti-monster/anduril/cfg-emisar-d4.h
@@ -12,3 +12,7 @@
#define MAX_1x7135 65
#define HALFSPEED_LEVEL 14
#define QUARTERSPEED_LEVEL 5
+
+// optional, makes initial turbo step-down faster so first peak isn't as hot
+//#define THERM_HARD_TURBO_DROP
+
diff --git a/spaghetti-monster/anduril/cfg-fw3a.h b/spaghetti-monster/anduril/cfg-fw3a.h
index 3df426d..2790086 100644
--- a/spaghetti-monster/anduril/cfg-fw3a.h
+++ b/spaghetti-monster/anduril/cfg-fw3a.h
@@ -16,3 +16,9 @@
#define HALFSPEED_LEVEL 14
#define QUARTERSPEED_LEVEL 5
+#ifdef THERM_DOUBLE_SPEED_LEVEL
+#undef THERM_DOUBLE_SPEED_LEVEL
+#endif
+#define THERM_DOUBLE_SPEED_LEVEL MAX_Nx7135
+// optional, makes initial turbo step-down faster so first peak isn't as hot
+//#define THERM_HARD_TURBO_DROP
diff --git a/spaghetti-monster/anduril/rampingiosv3.c b/spaghetti-monster/anduril/rampingiosv3.c
index 1afcbb0..13be1b6 100644
--- a/spaghetti-monster/anduril/rampingiosv3.c
+++ b/spaghetti-monster/anduril/rampingiosv3.c
@@ -28,7 +28,7 @@
#define USE_LVP // FIXME: won't build when this option is turned off
#define USE_THERMAL_REGULATION
-#define DEFAULT_THERM_CEIL 50
+#define DEFAULT_THERM_CEIL 45
#define MIN_THERM_STEPDOWN MAX_1x7135 // lowest value it'll step down to
#ifdef MAX_Nx7135
#define THERM_DOUBLE_SPEED_LEVEL MAX_Nx7135 // throttle back faster when high
@@ -58,7 +58,7 @@
#if defined(FSM_BLF_GT_DRIVER)
#include "cfg-blf-gt.h"
-#elif FSM_BLF_Q8_DRIVER
+#elif defined(FSM_BLF_Q8_DRIVER)
#include "cfg-blf-q8.h"
#elif defined(FSM_EMISAR_D4_DRIVER)
@@ -536,9 +536,9 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
uint8_t diff;
static uint8_t ticks_since_adjust = 0;
ticks_since_adjust ++;
- if (target_level > actual_level) diff = target_level - actual_level;
+ if (gradual_target > actual_level) diff = gradual_target - actual_level;
else {
- diff = actual_level - target_level;
+ diff = actual_level - gradual_target;
}
uint8_t magnitude = 0;
// if we're on a really high mode, drop faster
@@ -1129,16 +1129,6 @@ void loop() {
#endif
if (0) {}
- #ifdef USE_IDLE_MODE
- else if ( (state == steady_state)
- || (state == off_state)
- || (state == lockout_state)
- ) {
- // doze until next clock tick
- idle_mode();
- }
- #endif
-
#ifdef USE_BATTCHECK
else if (state == battcheck_state) {
battcheck();
@@ -1158,4 +1148,12 @@ void loop() {
set_level(0);
nice_delay_ms(((beacon_seconds) * 1000) - 500);
}
+
+ #ifdef USE_IDLE_MODE
+ else {
+ // doze until next clock tick
+ idle_mode();
+ }
+ #endif
+
}
diff --git a/spaghetti-monster/fsm-ramping.h b/spaghetti-monster/fsm-ramping.h
index b942ec0..14c8dae 100644
--- a/spaghetti-monster/fsm-ramping.h
+++ b/spaghetti-monster/fsm-ramping.h
@@ -72,14 +72,14 @@ PROGMEM const uint8_t pwm4_levels[] = { PWM4_LEVELS };
PROGMEM const uint8_t pwm2_levels[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,5,7,10,13,16,19,23,26,30,34,38,42,47,51,56,61,66,72,77,83,89,95,101,108,115,122,129,136,144,152,160,168,177,186,195,204,214,224,234,244,255 };
#define MAX_1x7135 33
#elif RAMP_LENGTH == 150
- // ../../bin/level_calc.py 1 65 7135 1 0.8 150
- // ... mixed with this:
- // ../../bin/level_calc.py 2 150 7135 4 0.33 150 FET 1 10 1500
- PROGMEM const uint8_t pwm1_levels[] = { 1,1,2,2,3,3,4,4,5,6,7,8,9,10,12,13,14,15,17,19,20,22,24,26,29,31,34,36,39,42,45,48,51,55,59,62,66,70,75,79,84,89,93,99,104,110,115,121,127,134,140,147,154,161,168,176,184,192,200,209,217,226,236,245,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0 };
- PROGMEM const uint8_t pwm2_levels[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,4,5,7,8,9,11,12,14,15,17,19,20,22,24,25,27,29,31,33,35,37,39,41,43,45,48,50,52,55,57,59,62,64,67,70,72,75,78,81,84,87,90,93,96,99,102,105,109,112,115,119,122,126,129,133,137,141,144,148,152,156,160,165,169,173,177,182,186,191,195,200,205,209,214,219,224,229,234,239,244,250,255 };
- #define MAX_1x7135 65
- #define HALFSPEED_LEVEL 14
- #define QUARTERSPEED_LEVEL 5
+ // ../../bin/level_calc.py 1 65 7135 1 0.8 150
+ // ... mixed with this:
+ // ../../bin/level_calc.py 2 150 7135 4 0.33 150 FET 1 10 1500
+ PROGMEM const uint8_t pwm1_levels[] = { 1,1,2,2,3,3,4,4,5,6,7,8,9,10,12,13,14,15,17,19,20,22,24,26,29,31,34,36,39,42,45,48,51,55,59,62,66,70,75,79,84,89,93,99,104,110,115,121,127,134,140,147,154,161,168,176,184,192,200,209,217,226,236,245,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0 };
+ PROGMEM const uint8_t pwm2_levels[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,4,5,7,8,9,11,12,14,15,17,19,20,22,24,25,27,29,31,33,35,37,39,41,43,45,48,50,52,55,57,59,62,64,67,70,72,75,78,81,84,87,90,93,96,99,102,105,109,112,115,119,122,126,129,133,137,141,144,148,152,156,160,165,169,173,177,182,186,191,195,200,205,209,214,219,224,229,234,239,244,250,255 };
+ #define MAX_1x7135 65
+ #define HALFSPEED_LEVEL 14
+ #define QUARTERSPEED_LEVEL 5
#endif
#elif PWM_CHANNELS == 3
#if RAMP_LENGTH == 50
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.