更新到最新进度

This commit is contained in:
2025-10-28 16:44:44 +08:00
parent f615f8cfa8
commit 616aebbb4f
4 changed files with 31 additions and 17 deletions

View File

@ -3,6 +3,7 @@
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#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);

View File

@ -2,6 +2,9 @@
#include <math.h>
#include <string.h>
#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;
}
}

View File

@ -1,3 +1,5 @@
#include <math.h>
#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);
}
}
}

View File

@ -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;
}
}