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:
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
},
|
||||
{
|
||||
"path": "../components"
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
}
|
||||
@@ -111,10 +111,30 @@ dependencies:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 1.3.0
|
||||
espressif/led_strip:
|
||||
component_hash: 28621486f77229aaf81c71f5e15d6fbf36c2949cf11094e07090593e659e7639
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.0'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 3.0.3
|
||||
idf:
|
||||
source:
|
||||
type: idf
|
||||
version: 5.5.3
|
||||
led:
|
||||
dependencies:
|
||||
- name: idf
|
||||
version: '>=4.1.0'
|
||||
- name: espressif/led_strip
|
||||
version: ^3.0.3
|
||||
source:
|
||||
path: C:\Dev\Classified\Calendink\components\led
|
||||
type: local
|
||||
version: 1.0.0
|
||||
network:
|
||||
dependencies:
|
||||
- name: idf
|
||||
@@ -127,7 +147,8 @@ dependencies:
|
||||
version: 1.0.0
|
||||
direct_dependencies:
|
||||
- idf
|
||||
- led
|
||||
- network
|
||||
manifest_hash: 12f55da0a0684644c57ee6a400e8e98810d36140fad54f35a96e434eb9774b8c
|
||||
target: esp32
|
||||
manifest_hash: 82be8e1c72b7c09d777d347050aba296d424314ce0b7f7642b5bd08a5e276e54
|
||||
target: esp32c6
|
||||
version: 2.0.0
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
idf_component_register(SRCS "main.cpp"
|
||||
PRIV_REQUIRES esp_eth esp_wifi esp_netif driver network nvs_flash
|
||||
PRIV_REQUIRES driver nvs_flash driver
|
||||
esp_event esp_timer led network
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
@@ -4,3 +4,5 @@ dependencies:
|
||||
version: '>=4.1.0'
|
||||
network:
|
||||
path: "../../components/network"
|
||||
led:
|
||||
path: "../../components/led"
|
||||
+44
-20
@@ -1,9 +1,18 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_pm.h"
|
||||
#include "esp_system.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "soc/gpio_num.h"
|
||||
#include "esp_event.h"
|
||||
|
||||
#include "types.hpp"
|
||||
#include "led.hpp"
|
||||
#include "network.hpp"
|
||||
|
||||
static const char *TAG = "ClientMain";
|
||||
@@ -22,30 +31,45 @@ extern "C" void app_main()
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
setup_led();
|
||||
ESP_LOGI(TAG, "LED setup complete");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
ESP_LOGI(TAG, "LED blink 4");
|
||||
led_blink_number(4, 255,255,255);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
ESP_LOGI(TAG, "LED blink 2");
|
||||
led_blink_number(2, 255,255,255);
|
||||
|
||||
turn_off_led();
|
||||
ESP_LOGI(TAG, "LED blink complete");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
// Connect to WiFi
|
||||
ESP_LOGI(TAG, "Initializing WiFi connection");
|
||||
// ESP_LOGI(TAG, "Initializing WiFi connection");
|
||||
|
||||
// Attempting to connect, we don't necessarily need to block forever here
|
||||
// as network.cpp already handles some of the retries
|
||||
esp_err_t err = connect_wifi(CONFIG_CALENDINK_WIFI_SSID, CONFIG_CALENDINK_WIFI_PASSWORD, false);
|
||||
// // Attempting to connect, we don't necessarily need to block forever here
|
||||
// // as network.cpp already handles some of the retries
|
||||
// esp_err_t err = connect_wifi(CONFIG_CALENDINK_WIFI_SSID, CONFIG_CALENDINK_WIFI_PASSWORD, false);
|
||||
|
||||
if (err == ESP_OK) {
|
||||
uint8_t retries = 1;
|
||||
do {
|
||||
err = check_wifi_connection(retries);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "WiFi connection check timeout, retrying... (%d)", retries);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
retries++;
|
||||
} while (err == ESP_ERR_TIMEOUT && retries <= CONFIG_CALENDINK_WIFI_RETRIES);
|
||||
}
|
||||
// if (err == ESP_OK) {
|
||||
// uint8_t retries = 1;
|
||||
// do {
|
||||
// err = check_wifi_connection(retries);
|
||||
// if (err != ESP_OK) {
|
||||
// ESP_LOGW(TAG, "WiFi connection check timeout, retrying... (%d)", retries);
|
||||
// vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
// }
|
||||
// retries++;
|
||||
// } while (err == ESP_ERR_TIMEOUT && retries <= CONFIG_CALENDINK_WIFI_RETRIES);
|
||||
// }
|
||||
|
||||
if (err == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Successfully connected to WiFi!");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to connect to WiFi.");
|
||||
}
|
||||
// if (err == ESP_OK) {
|
||||
// ESP_LOGI(TAG, "Successfully connected to WiFi!");
|
||||
// } else {
|
||||
// ESP_LOGE(TAG, "Failed to connect to WiFi.");
|
||||
// }
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
},
|
||||
{
|
||||
"path": "../components"
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"clangd.arguments": [
|
||||
"--background-index",
|
||||
"--query-driver=**",
|
||||
"--compile-commands-dir=w:\\Classified\\Calendink\\Provider\\build"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -146,11 +146,15 @@ dependencies:
|
||||
type: service
|
||||
version: 1.20.4
|
||||
led:
|
||||
dependencies: []
|
||||
dependencies:
|
||||
- name: idf
|
||||
version: '>=4.1.0'
|
||||
- name: espressif/led_strip
|
||||
version: ^3.0.3
|
||||
source:
|
||||
path: C:\Dev\Classified\Calendink\components\led
|
||||
type: local
|
||||
version: '*'
|
||||
version: 1.0.0
|
||||
lvgl/lvgl:
|
||||
component_hash: 17e68bfd21f0edf4c3ee838e2273da840bf3930e5dbc3bfa6c1190c3aed41f9f
|
||||
dependencies: []
|
||||
@@ -170,13 +174,12 @@ dependencies:
|
||||
version: 1.0.0
|
||||
direct_dependencies:
|
||||
- espressif/ethernet_init
|
||||
- espressif/led_strip
|
||||
- espressif/mdns
|
||||
- idf
|
||||
- joltwallet/littlefs
|
||||
- led
|
||||
- lvgl/lvgl
|
||||
- network
|
||||
manifest_hash: 8a9836e63bff09fce191602012b7b8be5ce92e62a59560b077f9129823441672
|
||||
manifest_hash: d2227bd8a79a4aafd4c3e25c1cc63e12fb3bc2afb66337e9f9412b0e1252145f
|
||||
target: esp32s3
|
||||
version: 2.0.0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
idf_component_register(SRCS "main.cpp"
|
||||
PRIV_REQUIRES esp_http_server
|
||||
nvs_flash vfs esp_timer
|
||||
nvs_flash vfs esp_timer
|
||||
json app_update esp_psram mdns driver network
|
||||
INCLUDE_DIRS "." "../../components/shared")
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ dependencies:
|
||||
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
||||
# # All dependencies of `main` are public by default.
|
||||
# public: true
|
||||
espressif/led_strip: ^3.0.3
|
||||
espressif/mdns: ^1.4.1
|
||||
espressif/ethernet_init: ^1.3.0
|
||||
joltwallet/littlefs: "^1.20" # https://github.com/joltwallet/esp_littlefs
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
idf_component_register(SRCS "led.cpp"
|
||||
INCLUDE_DIRS "." "../shared"
|
||||
PRIV_REQUIRES led_strip)
|
||||
PRIV_REQUIRES led_strip driver)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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,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,5 +1,5 @@
|
||||
version: "1.0.0"
|
||||
description: "CalendarInk Shared Network Component"
|
||||
description: "Calendink Shared Network Component"
|
||||
|
||||
dependencies:
|
||||
idf:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user