Last active
May 4, 2022 04:47
-
-
Save starryalley/e774419d5521ca28e6c789bf154c2cbd to your computer and use it in GitHub Desktop.
tocirahl's moonlight patches for Anduril2 based on r642
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
From 16304ebd84709ddde5816d47cc45c96fe435e7f1 Mon Sep 17 00:00:00 2001 | |
From: Mark Kuo <starryalley@gmail.com> | |
Date: Wed, 4 May 2022 14:42:33 +1000 | |
Subject: [PATCH] tocirahl's moonlight patch | |
https://budgetlightforum.com/comment/1857742#comment-1857742 | |
--- | |
.../anduril/cfg-emisar-d4sv2-tintramp.h | 4 ++-- | |
ToyKeeper/spaghetti-monster/anduril/off-mode.c | 5 +++++ | |
ToyKeeper/spaghetti-monster/anduril/ramp-mode.c | 8 ++++++++ | |
ToyKeeper/spaghetti-monster/anduril/tint-ramping.c | 4 ++++ | |
ToyKeeper/spaghetti-monster/fsm-main.c | 4 ++++ | |
ToyKeeper/spaghetti-monster/fsm-ramping.c | 10 +++++----- | |
ToyKeeper/spaghetti-monster/fsm-standby.c | 4 +++- | |
ToyKeeper/spaghetti-monster/fsm-standby.h | 1 + | |
8 files changed, 32 insertions(+), 8 deletions(-) | |
diff --git a/ToyKeeper/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h b/ToyKeeper/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h | |
index 3e54dca..174d1d6 100644 | |
--- a/ToyKeeper/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h | |
+++ b/ToyKeeper/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h | |
@@ -33,8 +33,8 @@ | |
// level_calc.py 5.01 1 130 7135 2 0.2 2000 --pwm dyn:64:16383:511 | |
// 131 to 150: 101% to 200% power | |
// level_calc.py 6.44 1 150 7135 1 0.2 2000 --pwm dyn:74:16383:1022 | |
-#define PWM1_LEVELS 2,2,2,3,3,4,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,28,30,33,35,38,41,44,47,50,54,57,60,64,67,71,74,78,81,84,88,91,94,97,99,101,103,105,106,107,107,107,106,105,102,99,95,90,84,77,68,58,47,34,36,38,40,42,44,47,49,52,54,57,60,63,66,69,73,76,80,83,87,91,96,100,104,109,114,119,124,130,135,141,147,153,160,166,173,180,187,195,203,211,219,228,236,245,255,264,274,285,295,306,317,329,340,353,365,378,391,405,419,433,448,463,479,495,511,530,550,570,591,612,634,657,680,705,730,755,782,809,837,865,895,925,957,989,1022 | |
-#define PWM_TOPS 16383,13234,9781,13826,9593,13434,9973,12021,12900,13193,13150,12899,12508,12023,12666,11982,12181,11422,11393,11247,11018,10731,10826,10434,10365,9927,9767,9565,9332,9076,8806,8693,8395,8096,7928,7626,7439,7143,6948,6665,6393,6203,5946,5700,5465,5187,4926,4681,4451,4195,3957,3700,3463,3213,2983,2718,2476,2231,1986,1742,1501,1245,997,756,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 | |
+#define PWM1_LEVELS 0,0,2,2,2,3,3,4,5,5,6,7,8,9,10,12,13,15,16,18,20,22,24,26,29,31,34,37,40,43,46,49,52,56,59,63,67,70,74,78,81,85,89,92,95,99,102,104,107,109,111,112,113,113,113,112,110,108,105,100,95,89,81,72,61,49,36,38,40,42,44,47,49,52,55,57,60,63,67,70,73,77,81,84,88,93,97,101,106,111,116,121,126,132,138,144,150,156,163,170,177,184,192,199,208,216,224,233,242,252,261,271,282,292,303,315,326,338,350,363,376,390,403,417,432,447,462,478,494,511,530,550,570,591,612,634,657,680,705,730,755,782,809,837,865,895,925,957,989,1022 | |
+#define PWM_TOPS 511,511,16383,13184,9669,13637,9310,13172,14665,11685,12563,12848,12793,12526,12119,12952,12274,12551,11775,11777,11644,11416,11122,10781,10815,10387,10278,10106,9889,9639,9365,9076,8777,8634,8315,8134,7936,7613,7404,7188,6883,6670,6457,6177,5910,5715,5468,5182,4962,4708,4471,4210,3967,3708,3470,3220,2963,2728,2489,2225,1986,1748,1495,1248,993,747,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 | |
#define DEFAULT_LEVEL 70 | |
#define MAX_1x7135 150 | |
#define HALFSPEED_LEVEL 10 | |
diff --git a/ToyKeeper/spaghetti-monster/anduril/off-mode.c b/ToyKeeper/spaghetti-monster/anduril/off-mode.c | |
index f7506c2..73416a3 100644 | |
--- a/ToyKeeper/spaghetti-monster/anduril/off-mode.c | |
+++ b/ToyKeeper/spaghetti-monster/anduril/off-mode.c | |
@@ -117,10 +117,14 @@ uint8_t off_state(Event event, uint16_t arg) { | |
if (arg >= (!ramp_style) * HOLD_TIMEOUT) { // more consistent | |
set_state(steady_state, 1); | |
} | |
+ | |
return MISCHIEF_MANAGED; | |
} | |
// hold, release quickly: go to lowest level (floor) | |
else if (event == EV_click1_hold_release) { | |
+ if (actual_level == 1) | |
+ go_to_low_moon = 1; | |
+ | |
set_state(steady_state, 1); | |
return MISCHIEF_MANAGED; | |
} | |
@@ -138,6 +142,7 @@ uint8_t off_state(Event event, uint16_t arg) { | |
} | |
#endif | |
set_level(nearest_level(memorized_level)); | |
+ | |
return MISCHIEF_MANAGED; | |
} | |
#endif // if (B_TIMING_ON != B_TIMEOUT_T) | |
diff --git a/ToyKeeper/spaghetti-monster/anduril/ramp-mode.c b/ToyKeeper/spaghetti-monster/anduril/ramp-mode.c | |
index f5e9e1f..55c6976 100644 | |
--- a/ToyKeeper/spaghetti-monster/anduril/ramp-mode.c | |
+++ b/ToyKeeper/spaghetti-monster/anduril/ramp-mode.c | |
@@ -253,6 +253,10 @@ uint8_t steady_state(Event event, uint16_t arg) { | |
#ifdef START_AT_MEMORIZED_LEVEL | |
save_config_wl(); | |
#endif | |
+ | |
+ if (actual_level == 1) | |
+ go_to_low_moon = 1; | |
+ | |
return MISCHIEF_MANAGED; | |
} | |
@@ -407,6 +411,10 @@ uint8_t steady_state(Event event, uint16_t arg) { | |
} | |
else if (event == EV_click3_hold_release) { | |
set_level_and_therm_target(memorized_level); | |
+ | |
+ if (actual_level == 1) | |
+ go_to_low_moon = 1; | |
+ | |
return MISCHIEF_MANAGED; | |
} | |
#endif // ifndef USE_TINT_RAMPING | |
diff --git a/ToyKeeper/spaghetti-monster/anduril/tint-ramping.c b/ToyKeeper/spaghetti-monster/anduril/tint-ramping.c | |
index a39b954..192d8a9 100644 | |
--- a/ToyKeeper/spaghetti-monster/anduril/tint-ramping.c | |
+++ b/ToyKeeper/spaghetti-monster/anduril/tint-ramping.c | |
@@ -94,6 +94,10 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { | |
// bug?: for some reason, brightness can seemingly change | |
// from 1/150 to 2/150 without this next line... not sure why | |
set_level(actual_level); | |
+ | |
+ if (actual_level == 1) | |
+ go_to_low_moon = 1; | |
+ | |
return EVENT_HANDLED; | |
} | |
diff --git a/ToyKeeper/spaghetti-monster/fsm-main.c b/ToyKeeper/spaghetti-monster/fsm-main.c | |
index aa907c1..420212e 100644 | |
--- a/ToyKeeper/spaghetti-monster/fsm-main.c | |
+++ b/ToyKeeper/spaghetti-monster/fsm-main.c | |
@@ -179,6 +179,10 @@ int main() { | |
standby_mode(); | |
} | |
+ if (go_to_low_moon) { | |
+ standby_mode(); | |
+ } | |
+ | |
// catch up on interrupts | |
handle_deferred_interrupts(); | |
diff --git a/ToyKeeper/spaghetti-monster/fsm-ramping.c b/ToyKeeper/spaghetti-monster/fsm-ramping.c | |
index b3b8578..c15eb3d 100644 | |
--- a/ToyKeeper/spaghetti-monster/fsm-ramping.c | |
+++ b/ToyKeeper/spaghetti-monster/fsm-ramping.c | |
@@ -179,10 +179,10 @@ void set_level(uint8_t level) { | |
#endif | |
} | |
#endif | |
+ #ifdef USE_TINT_RAMPING | |
+ update_tint(); | |
+ #endif | |
} | |
- #ifdef USE_TINT_RAMPING | |
- update_tint(); | |
- #endif | |
#ifdef PWM1_CNT | |
prev_level = api_level; | |
@@ -356,13 +356,13 @@ void update_tint() { | |
// disable the power channel, if relevant | |
#ifdef LED_ENABLE_PIN | |
- if (warm_PWM) | |
+ if (warm_PWM || (brightness == 0 && tint < 170)) | |
LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN); | |
else | |
LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN); | |
#endif | |
#ifdef LED2_ENABLE_PIN | |
- if (cool_PWM) | |
+ if (cool_PWM|| (brightness == 0 && tint >= 85)) | |
LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN); | |
else | |
LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN); | |
diff --git a/ToyKeeper/spaghetti-monster/fsm-standby.c b/ToyKeeper/spaghetti-monster/fsm-standby.c | |
index 8c4478a..d279df5 100644 | |
--- a/ToyKeeper/spaghetti-monster/fsm-standby.c | |
+++ b/ToyKeeper/spaghetti-monster/fsm-standby.c | |
@@ -50,9 +50,10 @@ void sleep_until_eswitch_pressed() | |
irq_adc = 0; | |
irq_wdt = 0; | |
irq_pcint = 0; | |
- while (go_to_standby) { | |
+ while (go_to_standby || go_to_low_moon) { | |
#else | |
go_to_standby = 0; | |
+ go_to_low_moon = 0; | |
#endif | |
// configure sleep mode | |
@@ -71,6 +72,7 @@ void sleep_until_eswitch_pressed() | |
// determine what woke us up... | |
if (irq_pcint) { // button pressed; wake up | |
go_to_standby = 0; | |
+ go_to_low_moon = 0; | |
} | |
if (irq_adc) { // ADC done measuring | |
#ifndef USE_LOWPASS_WHILE_ASLEEP | |
diff --git a/ToyKeeper/spaghetti-monster/fsm-standby.h b/ToyKeeper/spaghetti-monster/fsm-standby.h | |
index 0149695..507a9e4 100644 | |
--- a/ToyKeeper/spaghetti-monster/fsm-standby.h | |
+++ b/ToyKeeper/spaghetti-monster/fsm-standby.h | |
@@ -24,6 +24,7 @@ | |
// (like... during the middle of a strobe pulse) | |
// set this to nonzero to enter standby mode next time the system is idle | |
volatile uint8_t go_to_standby = 0; | |
+volatile uint8_t go_to_low_moon = 0; | |
#ifdef TICK_DURING_STANDBY | |
#ifndef STANDBY_TICK_SPEED | |
-- | |
2.36.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment