touch buttons set LED programs, added another ribbon LED program

also added PRNG
This commit is contained in:
true
2026-05-09 08:42:57 -07:00
parent b2de3abe08
commit 2c151b1bf4
7 changed files with 343 additions and 6 deletions

View File

@@ -3,7 +3,7 @@
*/
#include "matrix.h"
#include "misc/tinymt.h"
static uint32_t s[8] = {0};
@@ -31,6 +31,17 @@ void lp_ribbon_upward(uint16_t wait, uint16_t rate, uint8_t fade)
1: timeout
2: index
*/
if (fade > 0x80)
fade = 0x80;
// reduce 1-frame bright blip
for (i = 0; i < sizeof(led_set.ribbon); i++) {
if (led_set.ribbon[i] >= 0xd0) {
led_set.ribbon[i] = 0xd0;
}
}
switch (s[0]) {
case 0: { // timeout
if (!s[1]) {
@@ -64,16 +75,62 @@ void lp_ribbon_upward(uint16_t wait, uint16_t rate, uint8_t fade)
// fade in and up
led_set.ribbon[x] = 0x20;
if (x) led_set.ribbon[x - 1] = 0x66;
if (x > 1) led_set.ribbon[x - 2] = 0xd0;
if (x > 1) led_set.ribbon[x - 2] = 0xef;
}
}
// fade out LEDs
for (i = 0; i < sizeof(led_set.ribbon); i++) {
if (led_set.ribbon[i] >= 0x70) {
led_set.ribbon[i] -= fade;
}
if (led_set.ribbon[i] >= fade) {
led_set.ribbon[i] -= fade;
} else {
led_set.ribbon[i] >>= 1;
// led_set.ribbon[i] >>= 1;
if (led_set.ribbon[i])
led_set.ribbon[i]--;
}
}
matrix_flag_update();
}
void lp_ribbon_twinkle(uint8_t idle, uint8_t max, uint8_t thresh_lo, uint8_t thresh_hi)
{
/*
idle: attempted idle target. ideally an odd number not a power of two.
max: maximum brightness. anything higher is clamped to this
thresh_lo: rand must be lower than this to make any adjustment this cycle
thresh_hi: rand must be this or higher to force a bright twinkle
*/
uint32_t i;
uint32_t w, x;
s[1]++;
for (i = 0; i < sizeof(led_set.ribbon); i++) {
x = prng_get8();
if (x < thresh_lo) {
w = (idle > 3) ? 3 : idle;
// swing around idle level
if (led_set.ribbon[i] > idle) {
led_set.ribbon[i] >>= 1;
} else {
led_set.ribbon[i] += (w - 1);
}
}
// only make bright stars every 4 frames
if ((x >= thresh_hi) && ((s[1] & 3) == 0)) {
w = prng_get8();
led_set.ribbon[i] += w;
if (led_set.ribbon[i] > max) {
led_set.ribbon[i] = max;
}
}
}