diff --git a/main/leds.h b/main/leds.h index 16b2a7d..be324d2 100644 --- a/main/leds.h +++ b/main/leds.h @@ -10,10 +10,10 @@ #include #include #include +#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(); } }