#include "led_ring.h" #include "driver/i2c_master.h" #include "driver/i2c_types.h" #include "esp_err.h" #include "esp_log.h" #include "led_strip.h" #include typedef struct { const uint8_t *leds; uint8_t count; } digit_definition_t; static const char *TAG = "[LED_RING]"; static led_strip_handle_t led_ring; #define RING_LEDS 95 #define LED_RING_PIN 7 static QueueHandle_t led_queue; // Led Matrix Maps const uint8_t d0[] = {46, 47, 60, 61, 62, 75, 78, 79, 80, 81, 82, 86, 87, 88, 89, 90}; const uint8_t d1[] = {23, 46, 47, 48, 61, 62, 74, 75, 76, 84, 86, 93, 95}; const uint8_t d2[] = {21, 22, 23, 24, 25, 26, 46, 47, 48, 49, 59, 64, 71, 72, 73, 74, 75, 83, 89, 92, 95}; const uint8_t d3[] = {1, 2, 21, 22, 23, 24, 25, 26, 27, 41, 42, 43, 44, 45, 48, 59, 77, 83, 92, 93, 95}; const uint8_t d4[] = {21, 26, 47, 59, 64, 77, 82, 86, 94, 95}; const uint8_t d5[] = {19, 20, 21, 22, 23, 24, 25, 26, 63, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 90, 91}; const uint8_t d6[] = {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 65, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91}; const uint8_t d7[] = {1, 47, 58, 59, 60, 61, 62, 63, 64, 65, 77, 80, 82, 92, 94}; const uint8_t d8[] = {1, 2, 3, 4, 5, 19, 20, 21, 22, 23, 24, 25, 26, 27, 41, 42, 43, 44, 45, 49, 58, 64, 73, 78, 82, 86, 90, 92, 93, 94, 95}; const uint8_t d9[] = {19, 20, 21, 22, 23, 24, 25, 26, 27, 46, 47, 58, 64, 71, 72, 73, 74, 75, 77, 82, 86, 94, 95}; const uint8_t d10[] = {46, 50, 57, 61, 65, 72, 76, 78, 80, 82, 84, 86, 88, 90, 92, 93, 94, 95}; // Lookup Array for the Digits const digit_definition_t digit_lookup[] = { {d0, sizeof(d0)}, {d1, sizeof(d1)}, {d2, sizeof(d2)}, {d3, sizeof(d3)}, {d4, sizeof(d4)}, {d5, sizeof(d5)}, {d6, sizeof(d6)}, {d7, sizeof(d7)}, {d8, sizeof(d8)}, {d9, sizeof(d9)}, {d10, sizeof(d10)}}; void vTaskLedRing(void *pvParameters) { /* LED Ring config */ led_strip_config_t ring_config = { .strip_gpio_num = LED_RING_PIN, .max_leds = RING_LEDS, }; led_strip_rmt_config_t rmt_ring_config = { .resolution_hz = 10 * 1000 * 1000, // 10 MHz }; esp_err_t err = led_strip_new_rmt_device(&ring_config, &rmt_ring_config, &led_ring); if (err == ESP_OK) { ESP_LOGI(TAG, "GPIO_RING_TASK started"); } led_command_t cmd; while (1) { if (xQueueReceive(led_queue, &cmd, portMAX_DELAY)) { // Clear all LEDS led_strip_clear(led_ring); if (cmd.mode == LED_CMD_SET_DIGIT && cmd.value <= 10) { digit_definition_t digit = digit_lookup[cmd.value]; for (int i = 0; i < digit.count; i++) { // Invert LED Counting for Now led_strip_set_pixel(led_ring, RING_LEDS - digit.leds[i], cmd.r, cmd.g, cmd.b); } } led_strip_refresh(led_ring); } } } void led_ring_init(void) { led_queue = xQueueCreate(10, sizeof(led_command_t)); xTaskCreate(vTaskLedRing, "led_task", 4096, NULL, 5, NULL); } void led_ring_send_command(led_command_t *cmd) { if (led_queue != NULL) { xQueueSend(led_queue, cmd, portMAX_DELAY); } }