code cleanup
Some checks failed
ESP-IDF Build / build (esp32c6, release-v5.4) (push) Has been cancelled
ESP-IDF Build / build (esp32c6, release-v5.5) (push) Has been cancelled
ESP-IDF Build / build (esp32s3, release-v5.4) (push) Has been cancelled
ESP-IDF Build / build (esp32s3, release-v5.5) (push) Has been cancelled

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2025-12-20 20:41:55 +01:00
parent 387b9d4c65
commit e16cfbd03c
68 changed files with 927 additions and 74637 deletions

View File

@@ -1,11 +1,11 @@
#include "led_status.h"
#include "esp_log.h"
#include "esp_timer.h" // For high-resolution timestamps
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "led_strip.h"
#include <esp_log.h>
#include <esp_timer.h> // For high-resolution timestamps
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <freertos/task.h>
#include <led_strip.h>
static const char *TAG = "led_status";
@@ -32,7 +32,7 @@ static void led_status_task(void *pvParameters)
uint64_t now_us = esp_timer_get_time();
// Take the mutex to safely access the control data
if (xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE)
if (xSemaphoreTake(mutex, pdMS_TO_TICKS(100)) == pdTRUE)
{
for (int i = 0; i < STATUS_LED_COUNT; i++)
@@ -75,6 +75,10 @@ static void led_status_task(void *pvParameters)
// Release the mutex
xSemaphoreGive(mutex);
}
else
{
ESP_LOGW(TAG, "Failed to acquire mutex within timeout");
}
// Update the physical LED strip with the new values
led_strip_refresh(led_strip);
@@ -119,27 +123,33 @@ esp_err_t led_status_init(int gpio_num)
}
// Start task
xTaskCreate(led_status_task, "led_status_task", 2048, NULL, tskIDLE_PRIORITY + 1, NULL);
xTaskCreatePinnedToCore(led_status_task, "led_status_task", 2048, NULL, tskIDLE_PRIORITY + 2, NULL,
CONFIG_FREERTOS_NUMBER_OF_CORES - 1);
return ESP_OK;
}
// Function to set the behavior
esp_err_t led_status_set_behavior(uint8_t index, led_behavior_t behavior)
esp_err_t led_status_set_behavior(led_behavior_t behavior)
{
if (index >= STATUS_LED_COUNT)
if (behavior.index >= STATUS_LED_COUNT)
{
return ESP_ERR_INVALID_ARG;
}
if (xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE)
if (xSemaphoreTake(mutex, pdMS_TO_TICKS(100)) == pdTRUE)
{
led_controls[index].behavior = behavior;
led_controls[behavior.index].behavior = behavior;
// Reset internal state variables to start the new pattern cleanly
led_controls[index].is_on_in_blink = false;
led_controls[index].last_toggle_time_us = esp_timer_get_time();
led_controls[behavior.index].is_on_in_blink = false;
led_controls[behavior.index].last_toggle_time_us = esp_timer_get_time();
xSemaphoreGive(mutex);
}
else
{
ESP_LOGE(TAG, "Failed to acquire mutex for set_behavior");
return ESP_FAIL;
}
return ESP_OK;
}

View File

@@ -29,9 +29,12 @@ static void set_all_pixels(const rgb_t color)
}
led_strip_refresh(led_strip);
led_behavior_t led2_behavior = {.mode = LED_MODE_SOLID,
.color = {.red = color.red, .green = color.green, .blue = color.blue}};
led_status_set_behavior(2, led2_behavior);
led_behavior_t led_behavior = {
.index = 2,
.mode = LED_MODE_SOLID,
.color = {.red = color.red, .green = color.green, .blue = color.blue},
};
led_status_set_behavior(led_behavior);
}
void led_strip_task(void *pvParameters)
@@ -90,7 +93,8 @@ esp_err_t led_strip_init(void)
set_all_pixels((rgb_t){.red = 0, .green = 0, .blue = 0});
xTaskCreate(led_strip_task, "led_strip_task", 4096, NULL, tskIDLE_PRIORITY + 1, NULL);
xTaskCreatePinnedToCore(led_strip_task, "led_strip_task", 4096, NULL, tskIDLE_PRIORITY + 1, NULL,
CONFIG_FREERTOS_NUMBER_OF_CORES - 1);
ESP_LOGI(TAG, "LED strip initialized");