split into more components

Signed-off-by: Peter Siegmund <peter@rdkr.com>
This commit is contained in:
Peter Siegmund
2024-06-07 23:00:21 +02:00
parent 3cb1b31a37
commit 53d4bf2c5b
7 changed files with 78 additions and 68 deletions

View File

@@ -50,7 +50,7 @@ static void event_handler(void* arg,
}
}
uint8_t init_wifi(void) {
esp_err_t init_wifi(void) {
s_wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_netif_init());
@@ -92,12 +92,12 @@ uint8_t init_wifi(void) {
* can test which event actually happened. */
if (bits & WIFI_CONNECTED_BIT) {
ESP_LOGI(TAG, "connected to ap SSID:%s", WIFI_SSID);
return 0;
return ESP_OK;
} else if (bits & WIFI_FAIL_BIT) {
ESP_LOGI(TAG, "Failed to connect to SSID:%s", WIFI_SSID);
return 1;
return ESP_ERR_TIMEOUT;
} else {
ESP_LOGE(TAG, "UNEXPECTED EVENT");
return -1;
return ESP_FAIL;
}
}

View File

@@ -1,11 +1,11 @@
#pragma once
#include <stdint.h>
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
uint8_t init_wifi(void);
esp_err_t init_wifi(void);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,7 @@
idf_component_register(SRCS "splash_screen.c"
INCLUDE_DIRS "include"
PRIV_REQUIRES
lilygo-epd47
connectivity
nvs_flash
mapView)

View File

@@ -0,0 +1,9 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void splash_screen(void);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,48 @@
#include "splash_screen.h"
#include <stdio.h>
#include "connectivity.h"
#include "epd_driver.h"
#include "fonts/opensans16.h"
#include "nvs_flash.h"
#include "sdkconfig.h"
void nvs_init(void) {
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
}
void wifi_init(void) {
epd_poweron();
epd_clear();
int32_t x = 100;
int32_t y = 100;
const int16_t bufferSize = 200;
char buffer[bufferSize];
snprintf(buffer, bufferSize, "Connecting to SSDI: %s", CONFIG_WIFI_SSID);
writeln(&OpenSans16, buffer, &x, &y, NULL);
esp_err_t ret = init_wifi();
if (ret != ESP_OK) {
epd_clear();
x = 100;
y = 100;
snprintf(buffer, bufferSize, "Failed to connect to WiFi: %s",
esp_err_to_name(ret));
writeln(&OpenSans16, buffer, &x, &y, NULL);
epd_poweroff();
while (1) {
///
};
}
epd_poweroff();
}
void splash_screen(void) {
epd_init();
nvs_init();
wifi_init();
}

View File

@@ -1,11 +1,7 @@
idf_component_register(SRCS "main.cpp"
INCLUDE_DIRS "."
PRIV_REQUIRES
lilygo-epd47
smartconfig
connectivity
mapView
nvs_flash
json)
splash_screen
mapView)
spiffs_create_partition_image(spiffs ../data FLASH_IN_PROJECT)

View File

@@ -1,63 +1,13 @@
#include <stdio.h>
#include "connectivity.h"
#include "epd_driver.h"
#include "esp_task.h"
#include "esp_task_wdt.h"
#include "fonts/opensans16.h"
#include "freertos/task.h"
#include "mapView.h"
#include "nvs_flash.h"
#include "sdkconfig.h"
#include "smartconfig.h"
#include "utilities.h"
void nvs_init(void) {
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
}
void splash_screen(void) {
epd_init();
nvs_init();
epd_poweron();
epd_clear();
int32_t x = 100;
int32_t y = 100;
char buffer[100];
sprintf(buffer, "Connecting to SSDI: %s", CONFIG_WIFI_SSID);
writeln(&OpenSans16, buffer, &x, &y, NULL);
auto ret = init_wifi();
if (ret != 0) {
epd_clear();
writeln(&OpenSans16, "Failed to connect to WiFi.", &x, &y, NULL);
epd_poweroff();
while (1) {
///
};
}
epd_poweroff();
}
void setup(void) {
splash_screen();
// init_smartconfig();
xTaskCreatePinnedToCore(mapView, "mapView", 4096, NULL, 5, NULL, 1);
}
void loop(void) {
vTaskDelay(pdMS_TO_TICKS(100));
}
#include "splash_screen.h"
extern "C" void app_main(void) {
setup();
while (1) {
loop();
}
splash_screen();
xTaskCreatePinnedToCore(mapView, "mapView", 4096, NULL, 5, NULL, 1);
vTaskDelete(NULL);
}