feat: Add initial Ethernet connectivity and LED status indication.
This commit is contained in:
@@ -13,20 +13,57 @@
|
||||
#include "connect.cpp"
|
||||
#include "led_status.cpp"
|
||||
|
||||
extern "C" void app_main() {
|
||||
setup_led();
|
||||
printf("Hello, Worldi!\n");
|
||||
set_led_status(led_status::Connecting);
|
||||
// TODO : Make it configurable
|
||||
internal constexpr bool blockUntilEthernetEstablished = false;
|
||||
internal constexpr uint8_t maxEthernetRetries = 5;
|
||||
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
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));
|
||||
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
// TODO Main loop
|
||||
|
||||
set_led_status(led_status::Failed);
|
||||
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
shutdown:
|
||||
disconnect_ethernet();
|
||||
|
||||
destroy_led();
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_delete_default());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user