diff options
| author | Selene ToyKeeper | 2023-10-13 14:29:57 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2023-10-13 14:29:57 -0600 |
| commit | 1fdec464891262b06d19f53d1f152a560effa576 (patch) | |
| tree | 35475c9519a09191076581680cbf4b336c322b63 /spaghetti-monster/fsm-channels.c | |
| parent | misc comments, spacing, documentation (diff) | |
| download | anduril-1fdec464891262b06d19f53d1f152a560effa576.tar.gz anduril-1fdec464891262b06d19f53d1f152a560effa576.tar.bz2 anduril-1fdec464891262b06d19f53d1f152a560effa576.zip | |
rewrote emisar-d4k-3ch to use delta-sigma modulation (PWM + DSM),
which gives much better resolution, especially for the 8-bit channel.
Also...
- set_channel_mode() aborts when going from/to the same channel,
to avoid unnecessary flicker
- hsv2rgb() uses 16-bit R/G/B and V now
- changed default channel to All
- reduced default channel modes to just A, B, C, and All
- smooth ramp floor defaults to 1/150
- raised level when aux LEDs turn on high during use
(for better compatibility with red main LEDs)
Diffstat (limited to 'spaghetti-monster/fsm-channels.c')
| -rw-r--r-- | spaghetti-monster/fsm-channels.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/spaghetti-monster/fsm-channels.c b/spaghetti-monster/fsm-channels.c index 62b608c..cc78536 100644 --- a/spaghetti-monster/fsm-channels.c +++ b/spaghetti-monster/fsm-channels.c @@ -9,7 +9,10 @@ #if NUM_CHANNEL_MODES > 1 void set_channel_mode(uint8_t mode) { + if (mode == channel_mode) return; // abort if nothing to do + uint8_t cur_level = actual_level; + // turn off old LEDs before changing channel set_level(0); @@ -85,7 +88,7 @@ void calc_2ch_blend( #ifdef USE_HSV2RGB -RGB_t hsv2rgb(uint8_t h, uint8_t s, uint8_t v) { +RGB_t hsv2rgb(uint8_t h, uint8_t s, uint16_t v) { RGB_t color; if (s == 0) { // grey @@ -105,11 +108,11 @@ RGB_t hsv2rgb(uint8_t h, uint8_t s, uint8_t v) { // calculate graph segments, doing integer multiplication // TODO: calculate 16-bit results, not 8-bit high = v; - low = (v * (255 - s)) >> 8; + low = ((uint32_t)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; + falling = ((uint32_t)v * (255 - ((s * fpart) >> 8))) >> 8; + rising = ((uint32_t)v * (255 - ((s * (255 - fpart)) >> 8))) >> 8; // default floor color.r = low; |
