split into more components
Signed-off-by: Peter Siegmund <peter@rdkr.com>
This commit is contained in:
@@ -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();
|
s_wifi_event_group = xEventGroupCreate();
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_netif_init());
|
ESP_ERROR_CHECK(esp_netif_init());
|
||||||
@@ -92,12 +92,12 @@ uint8_t init_wifi(void) {
|
|||||||
* can test which event actually happened. */
|
* can test which event actually happened. */
|
||||||
if (bits & WIFI_CONNECTED_BIT) {
|
if (bits & WIFI_CONNECTED_BIT) {
|
||||||
ESP_LOGI(TAG, "connected to ap SSID:%s", WIFI_SSID);
|
ESP_LOGI(TAG, "connected to ap SSID:%s", WIFI_SSID);
|
||||||
return 0;
|
return ESP_OK;
|
||||||
} else if (bits & WIFI_FAIL_BIT) {
|
} else if (bits & WIFI_FAIL_BIT) {
|
||||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s", WIFI_SSID);
|
ESP_LOGI(TAG, "Failed to connect to SSID:%s", WIFI_SSID);
|
||||||
return 1;
|
return ESP_ERR_TIMEOUT;
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||||
return -1;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "esp_err.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
uint8_t init_wifi(void);
|
esp_err_t init_wifi(void);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
7
ePaper-ESP-IDF/components/splash_screen/CMakeLists.txt
Normal file
7
ePaper-ESP-IDF/components/splash_screen/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
idf_component_register(SRCS "splash_screen.c"
|
||||||
|
INCLUDE_DIRS "include"
|
||||||
|
PRIV_REQUIRES
|
||||||
|
lilygo-epd47
|
||||||
|
connectivity
|
||||||
|
nvs_flash
|
||||||
|
mapView)
|
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
void splash_screen(void);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
48
ePaper-ESP-IDF/components/splash_screen/splash_screen.c
Normal file
48
ePaper-ESP-IDF/components/splash_screen/splash_screen.c
Normal 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();
|
||||||
|
}
|
@@ -1,11 +1,7 @@
|
|||||||
idf_component_register(SRCS "main.cpp"
|
idf_component_register(SRCS "main.cpp"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
PRIV_REQUIRES
|
PRIV_REQUIRES
|
||||||
lilygo-epd47
|
splash_screen
|
||||||
smartconfig
|
mapView)
|
||||||
connectivity
|
|
||||||
mapView
|
|
||||||
nvs_flash
|
|
||||||
json)
|
|
||||||
|
|
||||||
spiffs_create_partition_image(spiffs ../data FLASH_IN_PROJECT)
|
spiffs_create_partition_image(spiffs ../data FLASH_IN_PROJECT)
|
||||||
|
@@ -1,63 +1,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "connectivity.h"
|
|
||||||
#include "epd_driver.h"
|
|
||||||
#include "esp_task.h"
|
#include "esp_task.h"
|
||||||
#include "esp_task_wdt.h"
|
#include "freertos/task.h"
|
||||||
#include "fonts/opensans16.h"
|
|
||||||
#include "mapView.h"
|
#include "mapView.h"
|
||||||
#include "nvs_flash.h"
|
#include "splash_screen.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));
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void app_main(void) {
|
extern "C" void app_main(void) {
|
||||||
setup();
|
splash_screen();
|
||||||
while (1) {
|
|
||||||
loop();
|
xTaskCreatePinnedToCore(mapView, "mapView", 4096, NULL, 5, NULL, 1);
|
||||||
}
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user