From 616aebbb4f3796c61f2cdebbf7fade8ac64dcd1f Mon Sep 17 00:00:00 2001 From: passthem Date: Tue, 28 Oct 2025 16:44:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=B0=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.c | 8 +++----- src/color_utils.c | 28 ++++++++++++++++++++++------ src/shader.c | 9 ++++----- src/spi_utils.c | 3 ++- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/app.c b/src/app.c index e8edab3..4599a2f 100644 --- a/src/app.c +++ b/src/app.c @@ -3,6 +3,7 @@ #include #include #include +#include #define RES_BYTES 40 #define COLOR_BYTES 24 @@ -57,6 +58,7 @@ void submit(AppContext* ctx) { construct_buffer(ctx->buffer, ctx->colors, ctx->num_leds, COLOR_BYTES, RES_BYTES); send_buffer(ctx->light_fd, ctx->buffer, ctx->data_size); + // printf("114\n"); } void event_loop(AppContext* ctx) { @@ -70,11 +72,7 @@ void event_loop(AppContext* ctx) { void exit_app(AppContext* ctx) { for (int i = 0; i < ctx->num_leds; i++) { - if (i == 0) { - ctx->colors[i] = hex_to_color(0xFFFFFF); - } else { - ctx->colors[i] = hex_to_color(0x000000); - } + ctx->colors[i] = hex_to_color(0x000000); } submit(ctx); diff --git a/src/color_utils.c b/src/color_utils.c index af934a8..9c53c92 100644 --- a/src/color_utils.c +++ b/src/color_utils.c @@ -2,6 +2,9 @@ #include #include +#define DATA_HIGH 0b00011111 +#define DATA_LOW 0b00000011 + Color hex_to_color(int hex) { Color color; @@ -60,15 +63,27 @@ Color hsv_to_color(double h, double s, double v) { return color; } +Color fix_color(const Color color) { + Color result; + + result.r = color.r * color.r / 0xff; + result.g = color.g * color.g * 0x88 / 0xff / 0xff; + result.b = color.b * color.b * 0x66 / 0xff / 0xff; + + return result; +} + void set_color(uint8_t* buffer, const Color color) { - for (int i = 7; i >= 0; i--) - *buffer++ = (color.g & (1 << i)) ? 0b11111000 : 0b10000000; + // *buffer++ = 0x00; for (int i = 7; i >= 0; i--) - *buffer++ = (color.r & (1 << i)) ? 0b11111000 : 0b10000000; + *buffer++ = (color.g & (1 << i)) ? DATA_HIGH : DATA_LOW; for (int i = 7; i >= 0; i--) - *buffer++ = (color.b & (1 << i)) ? 0b11111000 : 0b10000000; + *buffer++ = (color.r & (1 << i)) ? DATA_HIGH : DATA_LOW; + + for (int i = 7; i >= 0; i--) + *buffer++ = (color.b & (1 << i)) ? DATA_HIGH : DATA_LOW; } int construct_buffer(uint8_t* buffer, @@ -79,7 +94,8 @@ int construct_buffer(uint8_t* buffer, const int data_size = num_leds * color_bytes + res_bytes; memset(buffer, 0, data_size); for (int i = 0; i < num_leds; i++) { - set_color(buffer + i * color_bytes, colors[i]); + // set_color(buffer + i * color_bytes, colors[i]); + set_color(buffer + i * color_bytes, fix_color(colors[i])); } return data_size; -} \ No newline at end of file +} diff --git a/src/shader.c b/src/shader.c index e2f4166..c4015da 100644 --- a/src/shader.c +++ b/src/shader.c @@ -1,3 +1,5 @@ +#include + #include "shader.h" void init_status(Status* status) { @@ -7,15 +9,12 @@ void init_status(Status* status) { } Color shader(Status* status) { - if (status->index == 0) { - return hex_to_color(0xFFFFFF); - } - switch (status->mode) { case LIGHT_MODE_RAINBOW: return hsv_to_color(status->time * 120 + status->index * 6, 1, 1); + // return hsv_to_color(60, 1, 0.2); default: return hex_to_color(0xFFFFFF); } -} \ No newline at end of file +} diff --git a/src/spi_utils.c b/src/spi_utils.c index 2476911..3900881 100644 --- a/src/spi_utils.c +++ b/src/spi_utils.c @@ -9,6 +9,7 @@ const uint8_t spi_mode = SPI_MODE_0; const uint8_t spi_bits = 8; const uint32_t spi_speed = 6400000; +// const uint32_t spi_speed=6400; int init_device(const char* device) { int fd; @@ -43,4 +44,4 @@ int send_buffer(int fd, uint8_t* buffer, const int data_size) { } return ret; -} \ No newline at end of file +}