From d53ba0d8cb2f491f95adabf7b37cf195ae1fe5e6 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 25 Aug 2023 16:21:04 -0600 Subject: 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) --- spaghetti-monster/fsm-channels.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'spaghetti-monster/fsm-channels.c') 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; -- cgit v1.2.3