#include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/gpio.h" #include "esp_log.h" #include "sdkconfig.h" #include "esp_camera.h" #include "nvs_flash.h" #include "esp_psram.h" #include #include #include #include #include #include #include #include #include #include #include #ifdef CONFIG_WIRED_MODE #include #endif #define BLINK_GPIO (gpio_num_t) CONFIG_BLINK_GPIO static const char *TAG = "[MAIN]"; std::shared_ptr dependencyRegistry = std::make_unique(); std::shared_ptr commandManager = std::make_shared(dependencyRegistry); WebSocketLogger webSocketLogger; Preferences preferences; std::shared_ptr deviceConfig = std::make_shared(&preferences); WiFiManager wifiManager(deviceConfig); MDNSManager mdnsManager(deviceConfig); std::shared_ptr cameraHandler = std::make_shared(deviceConfig); StreamServer streamServer(80); RestAPI restAPI("http://0.0.0.0:81", commandManager); #ifdef CONFIG_WIRED_MODE UVCStreamManager uvcStream; #endif #ifdef CONFIG_USE_ILLUMNATIOR_PIN LEDManager ledManager(BLINK_GPIO, CONFIG_ILLUMINATOR_PIN); #else LEDManager ledManager(BLINK_GPIO); #endif static void initNVSStorage() { 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); } int test_log(const char *format, va_list args) { webSocketLogger.log_message(format, args); return vprintf(format, args); } extern "C" void app_main(void) { dependencyRegistry->registerService(DependencyType::project_config, deviceConfig); dependencyRegistry->registerService(DependencyType::camera_manager, cameraHandler); // uvc plan // cleanup the logs - done // prepare the camera to be initialized with UVC - done? // debug uvc performance - done // porting plan: // port the wifi manager first. - worky!!! // port the logo - done // port preferences lib - DONE; prolly temporary // then port the config - done, needs todos done // State Management - done // then port the led manager as this will be fairly easy - done // then port the mdns stuff - done // then port the camera manager - done // then port the streaming stuff (web and uvc) - done // then add ADHOC and support for more networks in wifi manager - done // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // simplify commands - a simple dependency injection + std::function should do it - DONE // something like // template // void registerService(std::shared_pointer service) // services[std::type_index(typeid(T))] = service; // where services is an std::unordered_map>; // I can then use like std::shared_ptr resolve() { return services[typeid(T)]; } to get it in the command // which can be like a second parameter of the command, like std::function // simplify config - DONE // here I can decouple the loading, initializing and saving logic from the config class and move // that into the separate modules, and have the config class only act as a container // port serial manager // implement OTA stuff, but prepare it for future use // add endpoint to check firmware version // add firmware version somewhere // setup CI and building for other boards // then port the Elegant OTA stuff - I'll roll my own // finish todos, overhaul stuff a bit // maybe swich websocket logging to udp logging Logo::printASCII(); initNVSStorage(); esp_log_set_vprintf(&test_log); ledManager.setup(); deviceConfig->load(); wifiManager.Begin(); mdnsManager.start(); restAPI.begin(); cameraHandler->setupCamera(); // make sure the server runs on a separate core streamServer.startStreamServer(); #ifdef CONFIG_WIRED_MODE uvcStream.setup(); #endif while (1) { ledManager.handleLED(); restAPI.poll(); vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS); } }