92 lines
1.9 KiB
C++
92 lines
1.9 KiB
C++
#include <cassert>
|
|
#include <cstdio>
|
|
|
|
#include "esp_event.h"
|
|
#include "esp_log.h"
|
|
#include "esp_system.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "nvs.h"
|
|
#include "nvs_flash.h"
|
|
#include "sdkconfig.h"
|
|
|
|
#include "epd.hpp"
|
|
#include "led.hpp"
|
|
#include "network.hpp"
|
|
#include "provider.hpp"
|
|
|
|
#include "test_image.h"
|
|
|
|
static const char *TAG = "ClientMain";
|
|
|
|
extern "C" void app_main()
|
|
{
|
|
ESP_LOGI(TAG, "Hello, Calendink Client!");
|
|
|
|
// Initialize NVS
|
|
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);
|
|
|
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
|
|
|
setup_led();
|
|
|
|
// Connect to WiFi
|
|
if (false)
|
|
{
|
|
ESP_LOGI(TAG, "Initializing WiFi connection");
|
|
initialize_network();
|
|
|
|
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);
|
|
led_blink_number(3, 255, 0, 0);
|
|
}
|
|
retries++;
|
|
} while (err == ESP_ERR_TIMEOUT &&
|
|
retries <= CONFIG_CALENDINK_WIFI_RETRIES);
|
|
}
|
|
|
|
if (err == ESP_OK)
|
|
{
|
|
ESP_LOGI(TAG, "Successfully connected to WiFi!");
|
|
test_provider_communication();
|
|
}
|
|
else
|
|
{
|
|
ESP_LOGE(TAG, "Failed to connect to WiFi.");
|
|
}
|
|
}
|
|
|
|
turn_off_led();
|
|
|
|
ESP_LOGI(TAG, "Initializing EPD");
|
|
epd_init();
|
|
epd_init_display();
|
|
// epd_clear(epd_color::WHITE);
|
|
epd_draw_bitmap(epd_color::WHITE, test_image);
|
|
epd_refresh();
|
|
epd_shutdown_display();
|
|
|
|
if (false)
|
|
{
|
|
disconnect_wifi();
|
|
shutdown_network();
|
|
}
|
|
}
|