/// // // leds.h defines structs and functions for addressing an HD107s ledstrip over serial using the GPIO pins. // /// #ifndef _potion_leds_h #define _potion_leds_h #include #include #include #include "esp_system.h" enum LedsSendStatus { LEDS_SEND_WAITING, LEDS_SEND_REQUESTED, LEDS_SENDING, }; // pack the struct to match exactly 8 * 4 = 32bits struct __attribute__((__packed__)) LedComponents { // RGB component values uint8_t red; uint8_t green; uint8_t blue; uint8_t global; // global baseline brightness, highest 3 bits should always be ones }; // union of components and their representation as a u32 // allows for easier sending of data over serial union Led { struct LedComponents components; uint32_t bits; }; // point on a gradient struct GradientPoint { union Led 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 { struct GradientPoint 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 }; struct LedThreadData { TaskHandle_t task; TaskFunction_t func; }; // buffer that will be written out to the led strip over serial extern uint32_t g_serial_out_buffer[122]; // 120-long slice of the out buffer that represents the first few leds extern union Led* g_leds; extern struct Gradient g_default_gradient; extern struct Gradient g_current_gradient; extern int g_leds_are_default; extern enum LedsSendStatus g_leds_send_state; extern SemaphoreHandle_t g_led_mutex; extern struct LedThreadData g_led_thread_data; #define CLOCK 4 #define DATA 5 extern void send_leds(); extern void set_led_range(int start, int end, union Led value); extern void leds_set_default_gradient(const struct Gradient* gradient); extern void leds_set_current_gradient(const struct Gradient* gradient, int defer_send); extern void leds_reset_gradient(int defer_send); extern void leds_thread(); extern void leds_init(); #endif // !_leds_h