Port to ESP32
This commit is contained in:
136
main/led.h
Normal file
136
main/led.h
Normal file
@ -0,0 +1,136 @@
|
||||
/**
|
||||
* @file led.h
|
||||
* @brief LED strip control module for WS2812B
|
||||
*/
|
||||
|
||||
#ifndef LED_H
|
||||
#define LED_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#define LED_STRIP_MAX_LEDS 100 // Maximum LEDs per strip
|
||||
|
||||
/**
|
||||
* @brief RGB color structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
} rgb_t;
|
||||
|
||||
/**
|
||||
* @brief HSV color structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t h; // Hue: 0-255
|
||||
uint8_t s; // Saturation: 0-255
|
||||
uint8_t v; // Value/Brightness: 0-255
|
||||
} hsv_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize LED strips
|
||||
* @param pin_a GPIO pin for strip A (-1 to disable)
|
||||
* @param pin_b GPIO pin for strip B (-1 to disable)
|
||||
* @param num_leds_a Number of LEDs in strip A
|
||||
* @param num_leds_b Number of LEDs in strip B
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t led_init(int8_t pin_a, int8_t pin_b, uint16_t num_leds_a, uint16_t num_leds_b);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize LED strips
|
||||
*/
|
||||
void led_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Set pixel color on strip A
|
||||
* @param index LED index
|
||||
* @param color RGB color
|
||||
*/
|
||||
void led_set_pixel_a(uint16_t index, rgb_t color);
|
||||
|
||||
/**
|
||||
* @brief Set pixel color on strip B
|
||||
* @param index LED index
|
||||
* @param color RGB color
|
||||
*/
|
||||
void led_set_pixel_b(uint16_t index, rgb_t color);
|
||||
|
||||
/**
|
||||
* @brief Set all pixels on strip A to same color
|
||||
* @param color RGB color
|
||||
*/
|
||||
void led_fill_a(rgb_t color);
|
||||
|
||||
/**
|
||||
* @brief Set all pixels on strip B to same color
|
||||
* @param color RGB color
|
||||
*/
|
||||
void led_fill_b(rgb_t color);
|
||||
|
||||
/**
|
||||
* @brief Clear all pixels on both strips (set to black)
|
||||
*/
|
||||
void led_clear_all(void);
|
||||
|
||||
/**
|
||||
* @brief Refresh/update LED strips to show changes
|
||||
*/
|
||||
void led_show(void);
|
||||
|
||||
/**
|
||||
* @brief Fade all pixels towards black
|
||||
* @param amount Fade amount (0-255)
|
||||
*/
|
||||
void led_fade_to_black(uint8_t amount);
|
||||
|
||||
/**
|
||||
* @brief Convert HSV to RGB
|
||||
* @param hsv HSV color
|
||||
* @return RGB color
|
||||
*/
|
||||
rgb_t led_hsv_to_rgb(hsv_t hsv);
|
||||
|
||||
/**
|
||||
* @brief Get number of LEDs in strip A
|
||||
* @return Number of LEDs
|
||||
*/
|
||||
uint16_t led_get_num_leds_a(void);
|
||||
|
||||
/**
|
||||
* @brief Get number of LEDs in strip B
|
||||
* @return Number of LEDs
|
||||
*/
|
||||
uint16_t led_get_num_leds_b(void);
|
||||
|
||||
/**
|
||||
* @brief Get current color of pixel on strip A
|
||||
* @param index LED index
|
||||
* @return RGB color
|
||||
*/
|
||||
rgb_t led_get_pixel_a(uint16_t index);
|
||||
|
||||
/**
|
||||
* @brief Get current color of pixel on strip B
|
||||
* @param index LED index
|
||||
* @return RGB color
|
||||
*/
|
||||
rgb_t led_get_pixel_b(uint16_t index);
|
||||
|
||||
/**
|
||||
* @brief Add color to existing pixel (blending)
|
||||
* @param index LED index on strip A
|
||||
* @param color RGB color to add
|
||||
*/
|
||||
void led_add_pixel_a(uint16_t index, rgb_t color);
|
||||
|
||||
/**
|
||||
* @brief Add color to existing pixel (blending)
|
||||
* @param index LED index on strip B
|
||||
* @param color RGB color to add
|
||||
*/
|
||||
void led_add_pixel_b(uint16_t index, rgb_t color);
|
||||
|
||||
#endif // LED_H
|
||||
Reference in New Issue
Block a user