mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
Remove OpenIris namespace - code cleanup
This commit is contained in:
parent
cdb89b8444
commit
62df54295f
@ -9,8 +9,8 @@ extern char *MDSNTrackerName;
|
||||
extern int STREAM_SERVER_PORT;
|
||||
extern int CONTROL_SERVER_PORT;
|
||||
|
||||
extern OpenIris::LEDManager ledManager;
|
||||
extern OpenIris::StateManager stateManager;
|
||||
extern OpenIris::CameraHandler cameraHandler;
|
||||
extern LEDManager ledManager;
|
||||
extern StateManager stateManager;
|
||||
extern CameraHandler cameraHandler;
|
||||
|
||||
#endif
|
||||
@ -1,21 +1,17 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace OpenIris
|
||||
class LEDManager
|
||||
{
|
||||
private:
|
||||
uint8_t ledPin;
|
||||
|
||||
class LEDManager
|
||||
{
|
||||
private:
|
||||
uint8_t ledPin;
|
||||
public:
|
||||
explicit LEDManager(uint8_t pin) : ledPin(pin) {}
|
||||
|
||||
public:
|
||||
explicit LEDManager(uint8_t pin) : ledPin(pin) {}
|
||||
|
||||
void setupLED() const;
|
||||
void on() const;
|
||||
void off() const;
|
||||
void blink(unsigned int time);
|
||||
void displayStatus();
|
||||
};
|
||||
}
|
||||
void setupLED() const;
|
||||
void on() const;
|
||||
void off() const;
|
||||
void blink(unsigned int time);
|
||||
void displayStatus();
|
||||
};
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
#pragma once
|
||||
#include <ESPmDNS.h>
|
||||
|
||||
namespace OpenIris
|
||||
namespace MDNSHandler
|
||||
{
|
||||
namespace MDNSHandler
|
||||
{
|
||||
void setupMDNS();
|
||||
}
|
||||
}
|
||||
void setupMDNS();
|
||||
}
|
||||
|
||||
@ -1,57 +1,54 @@
|
||||
#pragma once
|
||||
#include <ArduinoOTA.h>
|
||||
|
||||
namespace OpenIris
|
||||
class OTA
|
||||
{
|
||||
class OTA
|
||||
private:
|
||||
bool isOTAEnabled = false;
|
||||
|
||||
public:
|
||||
void SetupOTA(const char *OTAPassword, uint16_t OTAServerPort)
|
||||
{
|
||||
private:
|
||||
bool isOTAEnabled = false;
|
||||
log_i("Setting up OTA updates");
|
||||
|
||||
public:
|
||||
void SetupOTA(const char *OTAPassword, uint16_t OTAServerPort)
|
||||
if (OTAPassword == nullptr)
|
||||
{
|
||||
log_i("Setting up OTA updates");
|
||||
log_e("THE PASSWORD IS REQUIRED, [[ABORTING]]");
|
||||
return;
|
||||
}
|
||||
ArduinoOTA.setPort(OTAServerPort);
|
||||
isOTAEnabled = true;
|
||||
|
||||
if (OTAPassword == nullptr)
|
||||
{
|
||||
log_e("THE PASSWORD IS REQUIRED, [[ABORTING]]");
|
||||
return;
|
||||
}
|
||||
ArduinoOTA.setPort(OTAServerPort);
|
||||
isOTAEnabled = true;
|
||||
|
||||
ArduinoOTA
|
||||
.onStart([]()
|
||||
{
|
||||
ArduinoOTA
|
||||
.onStart([]()
|
||||
{
|
||||
String type;
|
||||
if (ArduinoOTA.getCommand() == U_FLASH)
|
||||
type = "sketch";
|
||||
else // U_SPIFFS
|
||||
type = "filesystem"; })
|
||||
.onEnd([]()
|
||||
{ log_i("OTA updated finished successfully!"); })
|
||||
.onProgress([](unsigned int progress, unsigned int total)
|
||||
{ log_i("Progress: %u%%\r", (progress / (total / 100))); })
|
||||
.onError([](ota_error_t error)
|
||||
{
|
||||
.onEnd([]()
|
||||
{ log_i("OTA updated finished successfully!"); })
|
||||
.onProgress([](unsigned int progress, unsigned int total)
|
||||
{ log_i("Progress: %u%%\r", (progress / (total / 100))); })
|
||||
.onError([](ota_error_t error)
|
||||
{
|
||||
log_e("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) log_e("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) log_e("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) log_e("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) log_e("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) log_e("End Failed"); });
|
||||
log_i("Starting up basic OTA server");
|
||||
log_i("OTA will be live for 30s, after which it will be disabled until restart");
|
||||
ArduinoOTA.begin();
|
||||
}
|
||||
log_i("Starting up basic OTA server");
|
||||
log_i("OTA will be live for 30s, after which it will be disabled until restart");
|
||||
ArduinoOTA.begin();
|
||||
}
|
||||
|
||||
void HandleOTAUpdate()
|
||||
void HandleOTAUpdate()
|
||||
{
|
||||
if (isOTAEnabled)
|
||||
{
|
||||
if (isOTAEnabled)
|
||||
{
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,28 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
namespace OpenIris
|
||||
enum State
|
||||
{
|
||||
enum State
|
||||
{
|
||||
Starting = 1,
|
||||
ConnectingToWifi = 2,
|
||||
ConnectingToWifiError = 3,
|
||||
ConnectingToWifiSuccess = 4,
|
||||
ServerError = 5,
|
||||
CameraError = 6,
|
||||
MDNSSuccess = 7,
|
||||
MDNSError = 8,
|
||||
};
|
||||
Starting = 1,
|
||||
ConnectingToWifi = 2,
|
||||
ConnectingToWifiError = 3,
|
||||
ConnectingToWifiSuccess = 4,
|
||||
ServerError = 5,
|
||||
CameraError = 6,
|
||||
MDNSSuccess = 7,
|
||||
MDNSError = 8,
|
||||
};
|
||||
|
||||
class StateManager
|
||||
{
|
||||
public:
|
||||
StateManager() : current_state(Starting) {}
|
||||
void setState(State state);
|
||||
State getCurrentState();
|
||||
class StateManager
|
||||
{
|
||||
public:
|
||||
StateManager() : current_state(Starting) {}
|
||||
void setState(State state);
|
||||
State getCurrentState();
|
||||
|
||||
private:
|
||||
State current_state;
|
||||
};
|
||||
|
||||
}
|
||||
private:
|
||||
State current_state;
|
||||
};
|
||||
|
||||
@ -2,10 +2,7 @@
|
||||
#include <WiFi.h>
|
||||
#include "pinout.h"
|
||||
|
||||
namespace OpenIris
|
||||
namespace WiFiHandler
|
||||
{
|
||||
namespace WiFiHandler
|
||||
{
|
||||
void setupWifi(const char *ssid, const char *password);
|
||||
}
|
||||
}
|
||||
void setupWifi(const char *ssid, const char *password);
|
||||
}
|
||||
|
||||
@ -3,19 +3,16 @@
|
||||
#include "esp_camera.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace OpenIris
|
||||
class CameraHandler
|
||||
{
|
||||
class CameraHandler
|
||||
{
|
||||
private:
|
||||
sensor_t *camera_sensor;
|
||||
camera_config_t config;
|
||||
private:
|
||||
sensor_t *camera_sensor;
|
||||
camera_config_t config;
|
||||
|
||||
public:
|
||||
int setupCamera();
|
||||
int setCameraResolution(framesize_t frameSize);
|
||||
int setVFlip(int direction);
|
||||
int setHFlip(int direction);
|
||||
int setVieWindow(int offsetX, int offsetY, int outputX, int outputY);
|
||||
};
|
||||
}
|
||||
public:
|
||||
int setupCamera();
|
||||
int setCameraResolution(framesize_t frameSize);
|
||||
int setVFlip(int direction);
|
||||
int setHFlip(int direction);
|
||||
int setVieWindow(int offsetX, int offsetY, int outputX, int outputY);
|
||||
};
|
||||
|
||||
@ -4,19 +4,16 @@
|
||||
#include "esp_camera.h"
|
||||
#include "esp_http_server.h"
|
||||
|
||||
namespace OpenIris
|
||||
namespace StreamHelpers
|
||||
{
|
||||
esp_err_t stream(httpd_req_t *req);
|
||||
}
|
||||
class StreamServer
|
||||
{
|
||||
namespace StreamHelpers
|
||||
{
|
||||
esp_err_t stream(httpd_req_t *req);
|
||||
}
|
||||
class StreamServer
|
||||
{
|
||||
|
||||
private:
|
||||
httpd_handle_t camera_stream = nullptr;
|
||||
private:
|
||||
httpd_handle_t camera_stream = nullptr;
|
||||
|
||||
public:
|
||||
int startStreamServer();
|
||||
};
|
||||
}
|
||||
public:
|
||||
int startStreamServer();
|
||||
};
|
||||
|
||||
@ -6,16 +6,13 @@
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
namespace OpenIris
|
||||
class APIServer
|
||||
{
|
||||
class APIServer
|
||||
{
|
||||
private:
|
||||
void command_handler(AsyncWebServerRequest *request);
|
||||
AsyncWebServer *server;
|
||||
private:
|
||||
void command_handler(AsyncWebServerRequest *request);
|
||||
AsyncWebServer *server;
|
||||
|
||||
public:
|
||||
APIServer();
|
||||
void startAPIServer();
|
||||
};
|
||||
}
|
||||
public:
|
||||
APIServer();
|
||||
void startAPIServer();
|
||||
};
|
||||
|
||||
@ -1,27 +1,27 @@
|
||||
#include "LEDManager.h"
|
||||
|
||||
void OpenIris::LEDManager::setupLED() const
|
||||
void LEDManager::setupLED() const
|
||||
{
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
void OpenIris::LEDManager::on() const
|
||||
void LEDManager::on() const
|
||||
{
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
|
||||
void OpenIris::LEDManager::off() const
|
||||
void LEDManager::off() const
|
||||
{
|
||||
digitalWrite(ledPin, HIGH);
|
||||
}
|
||||
|
||||
void OpenIris::LEDManager::blink(unsigned int time)
|
||||
void LEDManager::blink(unsigned int time)
|
||||
{
|
||||
on();
|
||||
delay(time);
|
||||
off();
|
||||
}
|
||||
|
||||
void OpenIris::LEDManager::displayStatus()
|
||||
void LEDManager::displayStatus()
|
||||
{
|
||||
}
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
#include "MDNSManager.h"
|
||||
#include "GlobalVars.h"
|
||||
|
||||
void OpenIris::MDNSHandler::setupMDNS()
|
||||
void MDNSHandler::setupMDNS()
|
||||
{
|
||||
if (MDNS.begin(MDSNTrackerName))
|
||||
{
|
||||
stateManager.setState(OpenIris::State::MDNSSuccess);
|
||||
stateManager.setState(State::MDNSSuccess); // todo make it a separate state from the global one
|
||||
MDNS.addService("openIrisTracker", "tcp", 80);
|
||||
MDNS.addServiceTxt("openIrisTracker", "tcp", "stream_port", String(80));
|
||||
log_d("MDNS initialized!");
|
||||
}
|
||||
else
|
||||
{
|
||||
stateManager.setState(OpenIris::State::MDNSError);
|
||||
stateManager.setState(State::MDNSError);
|
||||
log_e("Error initializing MDNS");
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,11 @@
|
||||
#include "StateManager.h"
|
||||
|
||||
namespace OpenIris
|
||||
void StateManager::setState(State state)
|
||||
{
|
||||
void StateManager::setState(State state)
|
||||
{
|
||||
current_state = state;
|
||||
}
|
||||
current_state = state;
|
||||
}
|
||||
|
||||
State StateManager::getCurrentState()
|
||||
{
|
||||
return current_state;
|
||||
}
|
||||
}
|
||||
State StateManager::getCurrentState()
|
||||
{
|
||||
return current_state;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "cameraHandler.h"
|
||||
|
||||
int OpenIris::CameraHandler::setupCamera()
|
||||
int CameraHandler::setupCamera()
|
||||
{
|
||||
log_d("Setting up camera \r\n");
|
||||
|
||||
@ -31,7 +31,7 @@ int OpenIris::CameraHandler::setupCamera()
|
||||
{
|
||||
log_d("Found psram, setting the 240x240 image quality");
|
||||
config.frame_size = FRAMESIZE_240X240;
|
||||
config.jpeg_quality = 7; // 0-63 lower number = higher quality, more latency and less fps 7 for most fps, 5 for best quality
|
||||
config.jpeg_quality = 7; // 0-63 lower number = higher quality, more latency and less fps 7 for most fps, 5 for best quality
|
||||
config.fb_count = 3;
|
||||
}
|
||||
else
|
||||
@ -47,9 +47,9 @@ int OpenIris::CameraHandler::setupCamera()
|
||||
camera_sensor = esp_camera_sensor_get();
|
||||
// fixes corrupted jpegs, https://github.com/espressif/esp32-camera/issues/203
|
||||
camera_sensor->set_reg(camera_sensor, 0xff, 0xff, 0x00); // banksel
|
||||
camera_sensor->set_reg(camera_sensor, 0xd3, 0xff, 5); // clock
|
||||
camera_sensor->set_reg(camera_sensor, 0xd3, 0xff, 5); // clock
|
||||
camera_sensor->set_brightness(camera_sensor, 2); // -2 to 2 I see no difference between numbers..
|
||||
camera_sensor->set_contrast(camera_sensor, 2); // -2 to 2
|
||||
camera_sensor->set_contrast(camera_sensor, 2); // -2 to 2
|
||||
camera_sensor->set_saturation(camera_sensor, -2); // -2 to 2
|
||||
camera_sensor->set_whitebal(camera_sensor, 1); // 0 = disable , 1 = enable
|
||||
camera_sensor->set_awb_gain(camera_sensor, 1); // 0 = disable , 1 = enable
|
||||
@ -81,7 +81,7 @@ int OpenIris::CameraHandler::setupCamera()
|
||||
}
|
||||
}
|
||||
|
||||
int OpenIris::CameraHandler::setCameraResolution(framesize_t frameSize)
|
||||
int CameraHandler::setCameraResolution(framesize_t frameSize)
|
||||
{
|
||||
if (camera_sensor->pixformat == PIXFORMAT_JPEG)
|
||||
{
|
||||
@ -98,23 +98,12 @@ int OpenIris::CameraHandler::setCameraResolution(framesize_t frameSize)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int OpenIris::CameraHandler::setVFlip(int direction)
|
||||
int CameraHandler::setVFlip(int direction)
|
||||
{
|
||||
return camera_sensor->set_vflip(camera_sensor, direction);
|
||||
}
|
||||
|
||||
int OpenIris::CameraHandler::setHFlip(int direction)
|
||||
int CameraHandler::setHFlip(int direction)
|
||||
{
|
||||
return camera_sensor->set_hmirror(camera_sensor, direction);
|
||||
}
|
||||
|
||||
int OpenIris::CameraHandler::setVieWindow(int offsetX, int offsetY, int outputX, int outputY)
|
||||
{
|
||||
// we're only providing these parameters as these are the only ones that actually affect the ov2640
|
||||
// TODO: if we're going to support different sensors - this will have to be moved to per-sensor implementation 'cause
|
||||
// TODO: manufacturers handle it differently each time
|
||||
|
||||
// we're doubling the totalX and totalY parameters to make it easier for end user to adjust the eye ROI
|
||||
// it also seems to produce a cleaner image
|
||||
return camera_sensor->set_res_raw(camera_sensor, 0, 0, 0, 0, offsetX, offsetY, outputX * 2, outputY * 2, outputX, outputY, true, true);
|
||||
}
|
||||
}
|
||||
@ -16,12 +16,12 @@ const char *MDSNTrackerName = "OpenIrisTracker";
|
||||
int STREAM_SERVER_PORT = 80;
|
||||
int CONTROL_SERVER_PORT = 81;
|
||||
|
||||
auto ota = OpenIris::OTA();
|
||||
auto ledManager = OpenIris::LEDManager(33);
|
||||
auto cameraHandler = OpenIris::CameraHandler();
|
||||
auto stateManager = OpenIris::StateManager();
|
||||
auto apiServer = OpenIris::APIServer();
|
||||
auto streamServer = OpenIris::StreamServer();
|
||||
auto ota = OTA();
|
||||
auto ledManager = LEDManager(33);
|
||||
auto cameraHandler = CameraHandler();
|
||||
auto stateManager = StateManager();
|
||||
auto apiServer = APIServer();
|
||||
auto streamServer = StreamServer();
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -29,8 +29,8 @@ void setup()
|
||||
Serial.setDebugOutput(true);
|
||||
ledManager.setupLED();
|
||||
cameraHandler.setupCamera();
|
||||
OpenIris::WiFiHandler::setupWifi(ssid, password);
|
||||
OpenIris::MDNSHandler::setupMDNS();
|
||||
WiFiHandler::setupWifi(ssid, password);
|
||||
MDNSHandler::setupMDNS();
|
||||
apiServer.startAPIServer();
|
||||
streamServer.startStreamServer();
|
||||
ledManager.on();
|
||||
|
||||
@ -5,7 +5,7 @@ constexpr static char *STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary
|
||||
constexpr static char *STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n";
|
||||
constexpr static char *STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %u\r\nX-Timestamp: %d.%06d\r\n\r\n";
|
||||
|
||||
esp_err_t OpenIris::StreamHelpers::stream(httpd_req_t *req)
|
||||
esp_err_t StreamHelpers::stream(httpd_req_t *req)
|
||||
{
|
||||
long last_request_time = 0;
|
||||
camera_fb_t *fb = NULL;
|
||||
@ -83,7 +83,7 @@ esp_err_t OpenIris::StreamHelpers::stream(httpd_req_t *req)
|
||||
return res;
|
||||
}
|
||||
|
||||
int OpenIris::StreamServer::startStreamServer()
|
||||
int StreamServer::startStreamServer()
|
||||
{
|
||||
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
|
||||
config.max_uri_handlers = 1;
|
||||
@ -93,7 +93,7 @@ int OpenIris::StreamServer::startStreamServer()
|
||||
httpd_uri_t stream_page = {
|
||||
.uri = "/",
|
||||
.method = HTTP_GET,
|
||||
.handler = &OpenIris::StreamHelpers::stream,
|
||||
.handler = &StreamHelpers::stream,
|
||||
.user_ctx = nullptr};
|
||||
|
||||
int status = httpd_start(&camera_stream, &config);
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
#include "GlobalVars.h"
|
||||
#include "webserverHandler.h"
|
||||
|
||||
OpenIris::APIServer::APIServer()
|
||||
APIServer::APIServer()
|
||||
{
|
||||
this->server = new AsyncWebServer(CONTROL_SERVER_PORT);
|
||||
}
|
||||
|
||||
void OpenIris::APIServer::startAPIServer()
|
||||
void APIServer::startAPIServer()
|
||||
{
|
||||
this->server->on(
|
||||
"/control",
|
||||
HTTP_GET,
|
||||
std::bind(&OpenIris::APIServer::command_handler, this, std::placeholders::_1));
|
||||
std::bind(&APIServer::command_handler, this, std::placeholders::_1));
|
||||
|
||||
log_d("Initializing web server");
|
||||
this->server->begin();
|
||||
}
|
||||
|
||||
void OpenIris::APIServer::command_handler(AsyncWebServerRequest *request)
|
||||
void APIServer::command_handler(AsyncWebServerRequest *request)
|
||||
{
|
||||
if (request->hasParam("framesize"))
|
||||
{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include "WifiHandler.h"
|
||||
#include "GlobalVars.h"
|
||||
|
||||
void OpenIris::WiFiHandler::setupWifi(const char *ssid, const char *password)
|
||||
void WiFiHandler::setupWifi(const char *ssid, const char *password)
|
||||
{
|
||||
log_d("Initializing connection to wifi");
|
||||
|
||||
@ -16,14 +16,14 @@ void OpenIris::WiFiHandler::setupWifi(const char *ssid, const char *password)
|
||||
{
|
||||
wifi_status = WiFi.status();
|
||||
Serial.print(".");
|
||||
stateManager.setState(OpenIris::State::ConnectingToWifi);
|
||||
stateManager.setState(State::ConnectingToWifi);
|
||||
time_spent_connecting += 1600;
|
||||
delay(1600);
|
||||
}
|
||||
|
||||
if (wifi_status == WL_CONNECTED)
|
||||
{
|
||||
stateManager.setState(OpenIris::State::ConnectingToWifiSuccess);
|
||||
stateManager.setState(State::ConnectingToWifiSuccess);
|
||||
delay(1600);
|
||||
log_i("\n\rWiFi connected\n\r");
|
||||
log_i("ESP will be streaming under 'http://%s:80/\r\n", WiFi.localIP().toString().c_str());
|
||||
@ -31,7 +31,7 @@ void OpenIris::WiFiHandler::setupWifi(const char *ssid, const char *password)
|
||||
}
|
||||
else
|
||||
{
|
||||
stateManager.setState(OpenIris::State::ConnectingToWifiError);
|
||||
stateManager.setState(State::ConnectingToWifiError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user