70 lines
1.6 KiB
C++
70 lines
1.6 KiB
C++
// STD Lib
|
|
#include <stdio.h>
|
|
|
|
// SDK
|
|
#include "driver/gpio.h"
|
|
#include "esp_log.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "sdkconfig.h"
|
|
#include "soc/gpio_num.h"
|
|
|
|
// Project cpp
|
|
#include "connect.cpp"
|
|
#include "led_status.cpp"
|
|
|
|
// TODO : Make it configurable
|
|
internal constexpr bool blockUntilEthernetEstablished = false;
|
|
internal constexpr uint8_t maxEthernetRetries = 5;
|
|
|
|
extern "C" void app_main() {
|
|
printf("Hello, Worldi!\n");
|
|
|
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
|
|
|
setup_led();
|
|
|
|
set_led_status(led_status::Connecting);
|
|
esp_err_t result = connect_ethernet(blockUntilEthernetEstablished);
|
|
if (result != ESP_OK) {
|
|
set_led_status(led_status::Failed);
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
goto shutdown;
|
|
}
|
|
|
|
// Check for ethernet connection until its made
|
|
if (!blockUntilEthernetEstablished) {
|
|
uint8 retries = 1;
|
|
do {
|
|
set_led_status(led_status::Connecting);
|
|
result = check_ethernet_connection(retries);
|
|
|
|
if (result != ESP_OK) {
|
|
set_led_status(led_status::Failed);
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
}
|
|
|
|
retries++;
|
|
} while (result == ESP_ERR_TIMEOUT && retries <= maxEthernetRetries);
|
|
}
|
|
|
|
if (result != ESP_OK) {
|
|
// TODO : Wifi connection
|
|
// Needs to disconnect ethernet at that point if we go wifi
|
|
// If wifi failes -> total shutdown
|
|
goto shutdown;
|
|
}
|
|
|
|
set_led_status(led_status::Ready);
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
|
|
// TODO Main loop
|
|
|
|
shutdown:
|
|
disconnect_ethernet();
|
|
|
|
destroy_led();
|
|
|
|
ESP_ERROR_CHECK(esp_event_loop_delete_default());
|
|
}
|