diff --git a/ePaper-ESP-IDF/components/connectivity/connectivity.c b/ePaper-ESP-IDF/components/connectivity/connectivity.c index 2bbd834..8ba4127 100644 --- a/ePaper-ESP-IDF/components/connectivity/connectivity.c +++ b/ePaper-ESP-IDF/components/connectivity/connectivity.c @@ -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; } } diff --git a/ePaper-ESP-IDF/components/connectivity/include/connectivity.h b/ePaper-ESP-IDF/components/connectivity/include/connectivity.h index 49eaf92..77addfc 100644 --- a/ePaper-ESP-IDF/components/connectivity/include/connectivity.h +++ b/ePaper-ESP-IDF/components/connectivity/include/connectivity.h @@ -1,11 +1,11 @@ #pragma once -#include +#include "esp_err.h" #ifdef __cplusplus extern "C" { #endif -uint8_t init_wifi(void); +esp_err_t init_wifi(void); #ifdef __cplusplus } #endif diff --git a/ePaper-ESP-IDF/components/splash_screen/CMakeLists.txt b/ePaper-ESP-IDF/components/splash_screen/CMakeLists.txt new file mode 100644 index 0000000..183d9f2 --- /dev/null +++ b/ePaper-ESP-IDF/components/splash_screen/CMakeLists.txt @@ -0,0 +1,7 @@ +idf_component_register(SRCS "splash_screen.c" + INCLUDE_DIRS "include" + PRIV_REQUIRES + lilygo-epd47 + connectivity + nvs_flash + mapView) diff --git a/ePaper-ESP-IDF/components/splash_screen/include/splash_screen.h b/ePaper-ESP-IDF/components/splash_screen/include/splash_screen.h new file mode 100644 index 0000000..e498911 --- /dev/null +++ b/ePaper-ESP-IDF/components/splash_screen/include/splash_screen.h @@ -0,0 +1,9 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif +void splash_screen(void); +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/ePaper-ESP-IDF/components/splash_screen/splash_screen.c b/ePaper-ESP-IDF/components/splash_screen/splash_screen.c new file mode 100644 index 0000000..7012862 --- /dev/null +++ b/ePaper-ESP-IDF/components/splash_screen/splash_screen.c @@ -0,0 +1,48 @@ +#include "splash_screen.h" +#include +#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(); +} diff --git a/ePaper-ESP-IDF/main/CMakeLists.txt b/ePaper-ESP-IDF/main/CMakeLists.txt index f472a08..957ddb6 100644 --- a/ePaper-ESP-IDF/main/CMakeLists.txt +++ b/ePaper-ESP-IDF/main/CMakeLists.txt @@ -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) diff --git a/ePaper-ESP-IDF/main/main.cpp b/ePaper-ESP-IDF/main/main.cpp index caa8e20..a84bc73 100644 --- a/ePaper-ESP-IDF/main/main.cpp +++ b/ePaper-ESP-IDF/main/main.cpp @@ -1,63 +1,13 @@ #include -#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); }