Created gradient_t struct and added movement param to gradient_point_t

animation
Sara 2023-09-22 12:32:14 +02:00
parent ec1068f461
commit 4c73126dd3
2 changed files with 26 additions and 10 deletions

View File

@ -10,10 +10,10 @@
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>
#include "shared.h"
#include "esp8266/gpio_register.h"
#include "esp_system.h"
#include "rom/ets_sys.h"
#include "shared.h"
#include "driver/gpio.h"
// pack the struct to match exactly 8 * 4 = 32bits
@ -36,6 +36,14 @@ union led_t {
struct gradient_point_t {
union led_t led; // value of the led at this point
size_t offset; // offset (measured in leds) from the beginning
short movement; // direction of movement over time
};
struct gradient_t {
struct gradient_point_t points[16]; // array of gradient points, support at most 16 points in a gradient
size_t points_len; // number of used gradient points
float duration; // amount of time to allow this gradient to last
// positive means an amount in second 0 or negative means indefinitely until further notice
};
// buffer that will be written out to the led strip over serial
@ -43,6 +51,9 @@ uint32_t g_serial_out_buffer[62];
// 60-long slice of the out buffer that represents the first few leds
union led_t* g_leds = ((union led_t*)g_serial_out_buffer + 1);
struct gradient_t g_default_gradient;
struct gradient_t g_current_gradient;
int g_leds_are_default = 1;
#define CLOCK 4
#define DATA 5
@ -139,20 +150,27 @@ void set_led_range(int start, int end, union led_t value) {
}
static
void leds_set_gradient(struct gradient_point_t* points, size_t points_len, int send) {
struct gradient_point_t from = points[0];
void leds_set_default_gradient(const struct gradient_t* gradient) {
g_default_gradient = *gradient;
}
static
void leds_set_current_gradient(const struct gradient_t* gradient, int defer_send) {
struct gradient_point_t from = gradient->points[0];
struct gradient_point_t to;
// set_led_range(0, points[0].offset, points[0].led);
// set_led_range(points[points_len-1].offset, 60, points[points_len-1].led);
set_led_range(0, gradient->points[0].offset, gradient->points[0].led);
set_led_range(gradient->points[gradient->points_len-1].offset, 60, gradient->points[gradient->points_len-1].led);
for(int i = 1; i < points_len; ++i) {
to = points[i];
g_current_gradient = *gradient;
for(int i = 1; i < gradient->points_len; ++i) {
to = gradient->points[i];
lerp_points_between(from, to);
from = to;
}
if(send) {
if(!defer_send) {
send_leds();
}
}

View File

@ -26,7 +26,6 @@
#include "esp_netif.h"
#include "sys_arch.h"
static
httpd_handle_t g_http_server = NULL;
@ -79,7 +78,6 @@ struct parse_error_t parse_leds_query(char* query_string, size_t query_size) {
gradient.points[point].led.components.green = atoi(query_value);
} else {
return (struct parse_error_t) {
.is_error = 1,
.error = "ERROR: Point missing green component &g."
};
}