1
0
mirror of https://github.com/whowechina/popn_pico.git synced 2025-01-31 12:13:46 +01:00

Theme color with fixed hue code

This commit is contained in:
whowechina 2024-12-10 21:16:09 +08:00
parent 66923f10f4
commit 34a902b997
3 changed files with 63 additions and 16 deletions

View File

@ -47,6 +47,12 @@ uint32_t rgb32(uint32_t r, uint32_t g, uint32_t b, bool gamma_fix)
#endif
}
#if RGB_ORDER == GRB
#define MIX_RGB(r, g, b) ((r << 8) | (g << 16) | b)
#else
#define MIX_RGB(r, g, b) ((r << 16) | (g << 8) | b)
#endif
uint32_t rgb32_from_hsv(uint8_t h, uint8_t s, uint8_t v)
{
uint32_t region, remainder, p, q, t;
@ -64,17 +70,17 @@ uint32_t rgb32_from_hsv(uint8_t h, uint8_t s, uint8_t v)
switch (region) {
case 0:
return v << 16 | t << 8 | p;
return MIX_RGB(v, t, p);
case 1:
return q << 16 | v << 8 | p;
return MIX_RGB(q, v, p);
case 2:
return p << 16 | v << 8 | t;
return MIX_RGB(p, v, t);
case 3:
return p << 16 | q << 8 | v;
return MIX_RGB(p, q, v);
case 4:
return t << 16 | p << 8 | v;
return MIX_RGB(t, p, v);
default:
return v << 16 | p << 8 | q;
return MIX_RGB(v, p, q);
}
}

View File

@ -28,13 +28,12 @@ void light_set_cab_all(uint32_t color, bool hid);
#define RGB(r, g, b) ((r << 16) | (g << 8) | b)
#endif
#define RED RGB(255, 0, 0)
#define GREEN RGB(0, 255, 0)
#define BLUE RGB(0, 0, 255)
#define YELLOW RGB(255, 255, 0)
#define CYAN RGB(0, 255, 255)
#define MAGENTA RGB(255, 0, 255)
#define WHITE RGB(255, 255, 255)
#define BLACK RGB(0, 0, 0)
#define HUE_RED 0
#define HUE_GREEN 85
#define HUE_BLUE 170
#define HUE_YELLOW 42
#define HUE_CYAN 127
#define HUE_MAGENTA 212
#endif

View File

@ -32,19 +32,61 @@
#include "light.h"
#include "button.h"
typedef struct {
uint8_t h;
uint8_t s;
uint8_t v;
} hsv_t;
static struct {
hsv_t on[9];
hsv_t off[9];
} main_theme = {
.on = {
{ 0, 0, 255 },
{ HUE_YELLOW, 240, 255 },
{ HUE_GREEN, 240, 255 },
{ HUE_BLUE, 240, 255 },
{ HUE_RED, 240, 255 },
{ HUE_BLUE, 240, 255 },
{ HUE_GREEN, 240, 255 },
{ HUE_YELLOW, 240, 255 },
{ 0, 0, 255 },
},
.off = {
{ 0, 0, 128 },
{ HUE_YELLOW, 255, 80 },
{ HUE_GREEN, 255, 80 },
{ HUE_BLUE, 255, 80 },
{ HUE_RED, 255, 80 },
{ HUE_BLUE, 255, 80 },
{ HUE_GREEN, 255, 80 },
{ HUE_YELLOW, 255, 80 },
{ 0, 0, 128 },
}
};
static uint32_t hsv2rgb(hsv_t hsv)
{
return rgb32_from_hsv(hsv.h, hsv.s, hsv.v);
}
static void light_render()
{
uint32_t phase = time_us_32() >> 16;
for (int i = 0; i < 9; i ++) {
uint32_t color = rgb32_from_hsv(phase + i * 27, 255, 128);
// uint32_t color = rgb32_from_hsv(phase + i * 27, 255, 128);
uint32_t color = hsv2rgb(main_theme.off[i]);
light_set_button(i, color, false);
}
uint16_t button = button_read();
for (int i = 0; i < 9; i++) {
if (button & (1 << i)) {
light_set_button(i, WHITE, false);
// light_set_button(i, WHITE, false);
light_set_button(i, hsv2rgb(main_theme.on[i]), false);
}
}