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:
+55
-16
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user