mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
big update
- renamed observers folder to utilities - created a make_unique function in the utilities namespace - migrated the main.cpp object creations to unique pointers
This commit is contained in:
parent
6ad444c866
commit
1bfb67ca40
@ -3,7 +3,7 @@
|
||||
#include <preferencesAPI.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "data/Observer/Observer.h"
|
||||
#include "data/utilities/Observer.hpp"
|
||||
|
||||
class ProjectConfig : public Config, public ISubject
|
||||
{
|
||||
|
||||
10
ESP/lib/src/data/utilities/makeunique.hpp
Normal file
10
ESP/lib/src/data/utilities/makeunique.hpp
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
namespace Utilities
|
||||
{
|
||||
template <typename T, typename... Args>
|
||||
std::unique_ptr<T> make_unique(Args &&...args)
|
||||
{
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <esp_camera.h>
|
||||
#include "data/Observer/Observer.h"
|
||||
#include "data/utilities/Observer.hpp"
|
||||
#include "data/config/project_config.hpp"
|
||||
|
||||
class CameraHandler : IObserver
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <ESPmDNS.h>
|
||||
#include "data/StateManager/StateManager.hpp"
|
||||
#include "data/Observer/Observer.h"
|
||||
#include "data/utilities/Observer.hpp"
|
||||
#include "data/config/project_config.hpp"
|
||||
|
||||
class MDNSHandler : public IObserver
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
#include <data/utilities/makeunique.hpp>
|
||||
#include <network/WifiHandler/WifiHandler.hpp>
|
||||
#include <network/mDNS/MDNSManager.hpp>
|
||||
#include <io/camera/cameraHandler.hpp>
|
||||
@ -11,40 +12,43 @@
|
||||
|
||||
#include <network/OTA/OTA.hpp>
|
||||
|
||||
int STREAM_SERVER_PORT = 80;
|
||||
int CONTROL_SERVER_PORT = 81;
|
||||
uint8_t STREAM_SERVER_PORT = 80;
|
||||
uint8_t CONTROL_SERVER_PORT = 81;
|
||||
|
||||
OTA ota;
|
||||
LEDManager ledManager(33);
|
||||
CameraHandler cameraHandler(&projectConfig);
|
||||
APIServer apiServer(CONTROL_SERVER_PORT, &cameraHandler);
|
||||
MDNSHandler mdnsHandler(&mdnsStateManager, &projectConfig);
|
||||
StreamServer streamServer(STREAM_SERVER_PORT);
|
||||
// Create smart pointers to the various classes that will be used in the program to make sure that they are deleted when the program ends
|
||||
// This is done to make sure that the memory is freed when the program ends and we are not left with dangling pointers to memory that is no longer in use
|
||||
// Make unique is a templated function that takes a class and returns a unique pointer to that class - it is used to create a unique pointer to a class and ensure exception safety
|
||||
std::unique_ptr<OTA> ota = Utilities::make_unique<OTA>();
|
||||
std::unique_ptr<LEDManager> ledManager = Utilities::make_unique<LEDManager>(33);
|
||||
std::unique_ptr<CameraHandler> cameraHandler = Utilities::make_unique<CameraHandler>(&projectConfig);
|
||||
std::unique_ptr<APIServer> apiServer = Utilities::make_unique<APIServer>(CONTROL_SERVER_PORT, &*cameraHandler);
|
||||
std::unique_ptr<MDNSHandler> mdnsHandler = Utilities::make_unique<MDNSHandler>(&mdnsStateManager, &projectConfig);
|
||||
std::unique_ptr<StreamServer> streamServer = Utilities::make_unique<StreamServer>(STREAM_SERVER_PORT);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
ledManager.begin();
|
||||
ledManager->begin();
|
||||
projectConfig.initStructures();
|
||||
projectConfig.load();
|
||||
cameraHandler.setupCamera();
|
||||
cameraHandler->setupCamera();
|
||||
|
||||
WiFiHandler::setupWifi(&wifiStateManager, &projectConfig);
|
||||
mdnsHandler.startMDNS();
|
||||
mdnsHandler->startMDNS();
|
||||
|
||||
if (wifiStateManager.getCurrentState() == ProgramStates::DeviceStates::WiFiState_e::WiFiState_Connected)
|
||||
{
|
||||
apiServer.startAPIServer();
|
||||
streamServer.startStreamServer();
|
||||
apiServer->startAPIServer();
|
||||
streamServer->startStreamServer();
|
||||
}
|
||||
ota.SetupOTA(&projectConfig);
|
||||
ota->SetupOTA(&projectConfig);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
ota.HandleOTAUpdate();
|
||||
ledManager.displayStatus();
|
||||
ota->HandleOTAUpdate();
|
||||
ledManager->displayStatus();
|
||||
serialManager.handleSerial();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user