aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-channels.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-08-25 16:21:04 -0600
committerSelene ToyKeeper2023-08-25 16:21:04 -0600
commitd53ba0d8cb2f491f95adabf7b37cf195ae1fe5e6 (patch)
tree818702217e01029d67f759a2b43ee912e370ef77 /spaghetti-monster/fsm-channels.c
parentadded emisar-d4k-3ch build (diff)
downloadanduril-d53ba0d8cb2f491f95adabf7b37cf195ae1fe5e6.tar.gz
anduril-d53ba0d8cb2f491f95adabf7b37cf195ae1fe5e6.tar.bz2
anduril-d53ba0d8cb2f491f95adabf7b37cf195ae1fe5e6.zip
made custom 3H handler system work, added circular HSV ramping,
fixed some minor issues with LEDs not getting turned off in corner cases (strobe on channel 1 -> strobe on channel 2, 1 might not get turned off)
Diffstat (limited to 'spaghetti-monster/fsm-channels.c')
-rw-r--r--spaghetti-monster/fsm-channels.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/spaghetti-monster/fsm-channels.c b/spaghetti-monster/fsm-channels.c
index 944bdcb..69add93 100644
--- a/spaghetti-monster/fsm-channels.c
+++ b/spaghetti-monster/fsm-channels.c
@@ -86,21 +86,26 @@ void calc_2ch_blend(
RGB_t hsv2rgb(uint8_t h, uint8_t s, uint8_t v) {
RGB_t color;
- uint16_t region, fpart, high, low, rising, falling;
-
if (s == 0) { // grey
color.r = color.g = color.b = v;
return color;
}
- // make hue 0-5
+ uint8_t region;
+ uint16_t fpart;
+ uint16_t high, low, rising, falling;
+
+ // hue has 6 segments, 0-5
region = ((uint16_t)h * 6) >> 8;
// find remainder part, make it from 0-255
fpart = ((uint16_t)h * 6) - (region << 8);
// calculate graph segments, doing integer multiplication
+ // TODO: calculate 16-bit results, not 8-bit
high = v;
low = (v * (255 - s)) >> 8;
+ // TODO: use a cosine crossfade instead of linear
+ // (because it looks better and feels more natural)
falling = (v * (255 - ((s * fpart) >> 8))) >> 8;
rising = (v * (255 - ((s * (255 - fpart)) >> 8))) >> 8;