aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-adc.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2021-12-16 11:23:58 -0700
committerSelene ToyKeeper2021-12-16 11:23:58 -0700
commitc1e1313bd4fc33563ac42ec565a55a90f1c9f35a (patch)
tree3b5ab88695dc45fa39a5d532012cd188ebd4eecc /spaghetti-monster/fsm-adc.c
parentfixed SP10 ramp flickering properly, using double-buffered registers (diff)
parentfixed bug where tint-ramping could end up 1 brightness ramp step different th... (diff)
downloadanduril-c1e1313bd4fc33563ac42ec565a55a90f1c9f35a.tar.gz
anduril-c1e1313bd4fc33563ac42ec565a55a90f1c9f35a.tar.bz2
anduril-c1e1313bd4fc33563ac42ec565a55a90f1c9f35a.zip
merged anduril2 branch for upstream changes
Diffstat (limited to 'spaghetti-monster/fsm-adc.c')
-rw-r--r--spaghetti-monster/fsm-adc.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c
index 975d12e..c5401ea 100644
--- a/spaghetti-monster/fsm-adc.c
+++ b/spaghetti-monster/fsm-adc.c
@@ -306,10 +306,28 @@ static inline void ADC_voltage_handler() {
uint16_t measurement;
// latest ADC value
- if (adc_reset) { // while asleep, or just after waking, don't lowpass
+ if (adc_reset) { // just after waking, don't lowpass
measurement = adc_raw[0];
- adc_smooth[0] = measurement; // no lowpass while asleep
+ adc_smooth[0] = measurement; // no lowpass, just use the latest value
}
+ #ifdef USE_LOWPASS_WHILE_ASLEEP
+ else if (go_to_standby) { // weaker lowpass while asleep
+ // occasionally the aux LED color can oscillate during standby,
+ // while using "voltage" mode ... so try to reduce the oscillation
+ uint16_t m = adc_raw[0];
+ uint16_t v = adc_smooth[0];
+ #if 0
+ // fixed-rate lowpass, slow, more stable but takes longer to settle
+ if (m < v) { v -= 64; }
+ if (m > v) { v += 64; }
+ #else
+ // weighted lowpass, faster but less stable
+ v = (m>>1) + (v>>1);
+ #endif
+ adc_smooth[0] = v;
+ measurement = v;
+ }
+ #endif
else measurement = adc_smooth[0];
// values stair-step between intervals of 64, with random variations