new LED matrix pattern
Signed-off-by: Peter Siegmund <mars3142@users.noreply.github.com>
This commit is contained in:
@@ -13,13 +13,16 @@ static const char *TAG = "beacon";
|
||||
|
||||
typedef struct
|
||||
{
|
||||
led_strip_handle_t ledStrip;
|
||||
led_strip_handle_t led_strip;
|
||||
uint32_t size;
|
||||
} LedMatrix;
|
||||
} LedMatrix_t;
|
||||
|
||||
static LedMatrix ledMatrix = {.size = 64};
|
||||
static LedMatrix_t led_matrix = {.size = 64};
|
||||
static SemaphoreHandle_t timer_semaphore;
|
||||
gptimer_handle_t gpTimer = NULL;
|
||||
gptimer_handle_t gptimer = NULL;
|
||||
|
||||
const uint32_t value = 10;
|
||||
const uint32_t mod = 3;
|
||||
|
||||
bool IRAM_ATTR timer_callback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *userCtx)
|
||||
{
|
||||
@@ -40,13 +43,16 @@ void timer_event_task(void *arg)
|
||||
{
|
||||
static bool level = false;
|
||||
level = !level;
|
||||
if (ledMatrix.ledStrip)
|
||||
if (led_matrix.led_strip)
|
||||
{
|
||||
for (uint32_t i = 0; i < (ledMatrix.size / 2); i++)
|
||||
for (uint32_t i = 0; i < led_matrix.size; i++)
|
||||
{
|
||||
led_strip_set_pixel(ledMatrix.ledStrip, i, 0, (level) ? 100 : 0, 0);
|
||||
if (i % mod == 0)
|
||||
{
|
||||
led_strip_set_pixel(led_matrix.led_strip, i, 0, (level) ? value : 0, 0);
|
||||
}
|
||||
}
|
||||
led_strip_refresh(ledMatrix.ledStrip);
|
||||
led_strip_refresh(led_matrix.led_strip);
|
||||
}
|
||||
ESP_LOGD(TAG, "Timer Event, LED now %s", level ? "ON" : "OFF");
|
||||
}
|
||||
@@ -55,40 +61,43 @@ void timer_event_task(void *arg)
|
||||
|
||||
esp_err_t wled_init(void)
|
||||
{
|
||||
led_strip_config_t stripConfig = {.strip_gpio_num = CONFIG_WLED_DIN_PIN,
|
||||
.max_leds = ledMatrix.size,
|
||||
.led_model = LED_MODEL_WS2812,
|
||||
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_RGB,
|
||||
.flags = {
|
||||
.invert_out = false,
|
||||
}};
|
||||
led_strip_config_t strip_config = {.strip_gpio_num = CONFIG_WLED_DIN_PIN,
|
||||
.max_leds = led_matrix.size,
|
||||
.led_model = LED_MODEL_WS2812,
|
||||
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_RGB,
|
||||
.flags = {
|
||||
.invert_out = false,
|
||||
}};
|
||||
|
||||
led_strip_rmt_config_t rmtConfig = {.clk_src = RMT_CLK_SRC_DEFAULT,
|
||||
.resolution_hz = 0,
|
||||
.mem_block_symbols = 0,
|
||||
.flags = {
|
||||
.with_dma = true,
|
||||
}};
|
||||
ESP_ERROR_CHECK(led_strip_new_rmt_device(&stripConfig, &rmtConfig, &ledMatrix.ledStrip));
|
||||
led_strip_rmt_config_t rmt_config = {.clk_src = RMT_CLK_SRC_DEFAULT,
|
||||
.resolution_hz = 0,
|
||||
.mem_block_symbols = 0,
|
||||
.flags = {
|
||||
.with_dma = true,
|
||||
}};
|
||||
|
||||
const uint32_t value = 25;
|
||||
for (uint32_t i = (ledMatrix.size / 2); i < ledMatrix.size; i++)
|
||||
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_matrix.led_strip));
|
||||
|
||||
for (uint32_t i = 0; i < led_matrix.size; i++)
|
||||
{
|
||||
led_strip_set_pixel(ledMatrix.ledStrip, i, value, value, value);
|
||||
if (i % mod != 0)
|
||||
{
|
||||
led_strip_set_pixel(led_matrix.led_strip, i, value, value, value);
|
||||
}
|
||||
}
|
||||
led_strip_refresh(ledMatrix.ledStrip);
|
||||
led_strip_refresh(led_matrix.led_strip);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t beacon_start(void)
|
||||
{
|
||||
if (gpTimer == NULL)
|
||||
if (gptimer == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "GPTimer not initialized");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
esp_err_t ret = gptimer_start(gpTimer);
|
||||
esp_err_t ret = gptimer_start(gptimer);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to start gptimer: %s", esp_err_to_name(ret));
|
||||
@@ -102,12 +111,12 @@ esp_err_t beacon_start(void)
|
||||
|
||||
esp_err_t beacon_stop(void)
|
||||
{
|
||||
if (gpTimer == NULL)
|
||||
if (gptimer == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "GPTimer not initialized");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
esp_err_t ret = gptimer_stop(gpTimer);
|
||||
esp_err_t ret = gptimer_stop(gptimer);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to stop gptimer: %s", esp_err_to_name(ret));
|
||||
@@ -125,9 +134,9 @@ esp_err_t beacon_init(void)
|
||||
|
||||
timer_semaphore = xSemaphoreCreateBinary();
|
||||
|
||||
gptimer_config_t timerConfig = {
|
||||
gptimer_config_t timer_config = {
|
||||
.clk_src = GPTIMER_CLK_SRC_DEFAULT, .direction = GPTIMER_COUNT_UP, .resolution_hz = 1000000};
|
||||
ret = gptimer_new_timer(&timerConfig, &gpTimer);
|
||||
ret = gptimer_new_timer(&timer_config, &gptimer);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to create new gptimer: %s", esp_err_to_name(ret));
|
||||
@@ -135,31 +144,31 @@ esp_err_t beacon_init(void)
|
||||
}
|
||||
|
||||
gptimer_event_callbacks_t callbacks = {.on_alarm = timer_callback};
|
||||
ret = gptimer_register_event_callbacks(gpTimer, &callbacks, NULL);
|
||||
ret = gptimer_register_event_callbacks(gptimer, &callbacks, NULL);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to register timer callbacks: %s", esp_err_to_name(ret));
|
||||
goto cleanupTimer;
|
||||
}
|
||||
|
||||
ret = gptimer_enable(gpTimer);
|
||||
ret = gptimer_enable(gptimer);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to enable gptimer: %s", esp_err_to_name(ret));
|
||||
goto cleanupTimer;
|
||||
}
|
||||
|
||||
gptimer_alarm_config_t alarmConfig = {
|
||||
gptimer_alarm_config_t alarm_config = {
|
||||
.alarm_count = 2000000, .reload_count = 0, .flags.auto_reload_on_alarm = true};
|
||||
ret = gptimer_set_alarm_action(gpTimer, &alarmConfig);
|
||||
ret = gptimer_set_alarm_action(gptimer, &alarm_config);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to set gptimer alarm action: %s", esp_err_to_name(ret));
|
||||
goto cleanupEnabledTimer;
|
||||
}
|
||||
|
||||
BaseType_t taskCreated = xTaskCreate(timer_event_task, "timer_event_task", 4096, NULL, 10, NULL);
|
||||
if (taskCreated != pdPASS)
|
||||
BaseType_t task_created = xTaskCreate(timer_event_task, "timer_event_task", 4096, NULL, 10, NULL);
|
||||
if (task_created != pdPASS)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to create timer event task");
|
||||
ret = ESP_ERR_NO_MEM;
|
||||
@@ -170,15 +179,15 @@ esp_err_t beacon_init(void)
|
||||
goto exit;
|
||||
|
||||
cleanupEnabledTimer:
|
||||
if (gpTimer)
|
||||
if (gptimer)
|
||||
{
|
||||
gptimer_disable(gpTimer);
|
||||
gptimer_disable(gptimer);
|
||||
}
|
||||
cleanupTimer:
|
||||
if (gpTimer)
|
||||
if (gptimer)
|
||||
{
|
||||
gptimer_del_timer(gpTimer);
|
||||
gpTimer = NULL;
|
||||
gptimer_del_timer(gptimer);
|
||||
gptimer = NULL;
|
||||
}
|
||||
exit:
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user