Converted led code to support non rgb/strip. Some clean up of network comp. Clean up of provider and client. Base test for client

This commit is contained in:
2026-03-26 21:43:01 -04:00
parent f42236532f
commit 197f4a640c
16 changed files with 186 additions and 49 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
idf_component_register(SRCS "led.cpp"
INCLUDE_DIRS "." "../shared"
PRIV_REQUIRES led_strip)
PRIV_REQUIRES led_strip driver)
+13
View File
@@ -1,5 +1,18 @@
menu "Calendink LED Configuration"
choice CALENDINK_LED_TYPE
prompt "LED Type"
default CALENDINK_LED_TYPE_STRIP
help
Select the type of LED used on the board.
config CALENDINK_LED_TYPE_STRIP
bool "Addressable RGB LED Strip (e.g. WS2812)"
config CALENDINK_LED_TYPE_SIMPLE
bool "Simple GPIO LED (On/Off)"
endchoice
config CALENDINK_LED_GPIO
int "LED GPIO"
default 21
+7
View File
@@ -0,0 +1,7 @@
version: "1.0.0"
description: "Calendink LED Component"
dependencies:
idf:
version: '>=4.1.0'
espressif/led_strip: ^3.0.3
+55 -16
View File
@@ -2,14 +2,26 @@
#include "led.hpp"
// SDK Includes
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#if defined(CONFIG_CALENDINK_LED_TYPE_STRIP) || !defined(CONFIG_CALENDINK_LED_TYPE_SIMPLE)
#ifndef CONFIG_CALENDINK_LED_TYPE_STRIP
#define CONFIG_CALENDINK_LED_TYPE_STRIP 1
#endif
#include "led_strip.h"
#endif
#define LED_GPIO CONFIG_CALENDINK_LED_GPIO
#define LED_GPIO (gpio_num_t)CONFIG_CALENDINK_LED_GPIO
#if defined(CONFIG_CALENDINK_LED_TYPE_STRIP)
internal led_strip_handle_t led_strip;
#endif
void setup_led(void)
{
#if defined(CONFIG_CALENDINK_LED_TYPE_STRIP)
/* LED strip initialization with the GPIO and pixels number*/
led_strip_config_t strip_config = {};
strip_config.strip_gpio_num = LED_GPIO;
@@ -22,12 +34,31 @@ void setup_led(void)
led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
led_strip_clear(led_strip);
#elif defined(CONFIG_CALENDINK_LED_TYPE_SIMPLE)
gpio_reset_pin(LED_GPIO);
gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT);
gpio_set_level(LED_GPIO, 0);
#endif
}
void turn_off_led(void) { led_strip_clear(led_strip); }
void turn_off_led(void)
{
#if defined(CONFIG_CALENDINK_LED_TYPE_STRIP)
led_strip_clear(led_strip);
#elif defined(CONFIG_CALENDINK_LED_TYPE_SIMPLE)
gpio_set_level(LED_GPIO, 1);
vTaskDelay(pdMS_TO_TICKS(100));
gpio_set_level(LED_GPIO, 0);
vTaskDelay(pdMS_TO_TICKS(100));
gpio_set_level(LED_GPIO, 1);
vTaskDelay(pdMS_TO_TICKS(100));
gpio_set_level(LED_GPIO, 0);
#endif
}
void set_led_status(led_status status)
{
#if defined(CONFIG_CALENDINK_LED_TYPE_STRIP)
switch (status)
{
case led_status::ConnectingEthernet:
@@ -47,31 +78,39 @@ void set_led_status(led_status status)
break;
}
led_strip_refresh(led_strip);
#elif defined(CONFIG_CALENDINK_LED_TYPE_SIMPLE)
// For a simple LED we just turn it on to show it's reached a status,
// or we could add simple blink patterns, but keeping it ON is simplest for status presence.
switch (status)
{
case led_status::ConnectingEthernet:
case led_status::ConnectingWifi:
case led_status::ReadyEthernet:
case led_status::ReadyWifi:
case led_status::Failed:
gpio_set_level(LED_GPIO, 1);
break;
}
#endif
}
void led_blink_number(int n, uint8_t r, uint8_t g, uint8_t b)
{
if (n <= 0)
{
for (int i = 0; i < 2; i++)
{
led_strip_set_pixel(led_strip, 0, r, g, b);
led_strip_refresh(led_strip);
vTaskDelay(pdMS_TO_TICKS(50));
led_strip_clear(led_strip);
led_strip_refresh(led_strip);
vTaskDelay(pdMS_TO_TICKS(50));
}
vTaskDelay(pdMS_TO_TICKS(1000));
return;
}
for (int i = 0; i < n; i++)
{
#if defined(CONFIG_CALENDINK_LED_TYPE_STRIP)
led_strip_set_pixel(led_strip, 0, r, g, b);
led_strip_refresh(led_strip);
#elif defined(CONFIG_CALENDINK_LED_TYPE_SIMPLE)
gpio_set_level(LED_GPIO, 1);
#endif
vTaskDelay(pdMS_TO_TICKS(300));
#if defined(CONFIG_CALENDINK_LED_TYPE_STRIP)
led_strip_clear(led_strip);
led_strip_refresh(led_strip);
#elif defined(CONFIG_CALENDINK_LED_TYPE_SIMPLE)
gpio_set_level(LED_GPIO, 0);
#endif
vTaskDelay(pdMS_TO_TICKS(300));
}
vTaskDelay(pdMS_TO_TICKS(1000));
+1 -1
View File
@@ -1,3 +1,3 @@
idf_component_register(SRCS "network.cpp"
INCLUDE_DIRS "." "../shared"
PRIV_REQUIRES esp_eth esp_wifi esp_netif driver)
PRIV_REQUIRES esp_eth esp_wifi esp_netif driver led)
+1 -1
View File
@@ -1,5 +1,5 @@
version: "1.0.0"
description: "CalendarInk Shared Network Component"
description: "Calendink Shared Network Component"
dependencies:
idf:
+1 -1
View File
@@ -20,11 +20,11 @@
// Project includes
#include "network.hpp"
#include "led.hpp"
// Forward declarations
#if CONFIG_CALENDINK_BLINK_IP
internal esp_err_t get_ip_info(esp_netif_ip_info_t *ip_info);
internal void led_blink_number(int n, uint8_t r, uint8_t g, uint8_t b);
internal void blink_last_ip_octet();
#endif