mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
Merge remote-tracking branch 'origin/feature/storage-with-preferences' into feature/storage-with-preferences
This commit is contained in:
commit
2d1906c5cc
@ -1,8 +1,6 @@
|
||||
#include "project_config.hpp"
|
||||
|
||||
Preferences preferences;
|
||||
|
||||
ProjectConfig::ProjectConfig() : Config(&preferences, "config"), _already_loaded(false) {}
|
||||
ProjectConfig::ProjectConfig() : _already_loaded(false) {}
|
||||
|
||||
ProjectConfig::~ProjectConfig() {}
|
||||
|
||||
@ -12,9 +10,9 @@ ProjectConfig::~ProjectConfig() {}
|
||||
*/
|
||||
void ProjectConfig::initConfig()
|
||||
{
|
||||
begin();
|
||||
begin("projectConf");
|
||||
this->config.device = {
|
||||
"EyeTrackVR",
|
||||
"eyetrackvr",
|
||||
"",
|
||||
3232,
|
||||
false,
|
||||
@ -58,44 +56,25 @@ void ProjectConfig::load()
|
||||
return;
|
||||
}
|
||||
|
||||
bool device_name_success = this->read("device_name", this->config.device.name);
|
||||
bool device_otapassword_success = this->read("ota_pass", this->config.device.OTAPassword);
|
||||
bool device_otaport_success = this->read("ota_port", this->config.device.OTAPort);
|
||||
|
||||
bool device_success = device_name_success && device_otapassword_success && device_otaport_success;
|
||||
|
||||
bool camera_vflip_success = this->read("camera_vflip", this->config.camera.vflip);
|
||||
bool camera_framesize_success = this->read("cameraFrmsz", this->config.camera.framesize);
|
||||
bool camera_href_success = this->read("camera_href", this->config.camera.href);
|
||||
bool camera_quality_success = this->read("camera_quality", this->config.camera.quality);
|
||||
|
||||
bool camera_success = camera_vflip_success && camera_framesize_success && camera_href_success && camera_quality_success;
|
||||
|
||||
bool network_info_success;
|
||||
for (int i = 0; i < this->config.networks.size(); i++)
|
||||
size_t configLen = getBytesLength("config");
|
||||
if (configLen == 0)
|
||||
{
|
||||
char buff[25];
|
||||
snprintf(buff, sizeof(buff), "%d_name", i);
|
||||
bool networks_name_success = this->read(buff, this->config.networks[i].name);
|
||||
snprintf(buff, sizeof(buff), "%d_ssid", i);
|
||||
bool networks_ssid_success = this->read(buff, this->config.networks[i].ssid);
|
||||
snprintf(buff, sizeof(buff), "%d_password", i);
|
||||
bool networks_password_success = this->read(buff, this->config.networks[i].password);
|
||||
snprintf(buff, sizeof(buff), "%d_channel", i);
|
||||
bool networks_channel_success = this->read(buff, this->config.networks[i].channel);
|
||||
bool networks_adhoc_success = this->read(buff, this->config.networks[i].adhoc);
|
||||
|
||||
network_info_success = networks_name_success && networks_ssid_success && networks_password_success && networks_channel_success && networks_adhoc_success;
|
||||
}
|
||||
|
||||
if (!device_success || !camera_success || !network_info_success)
|
||||
{
|
||||
log_e("Failed to load project config - Generating config and restarting");
|
||||
log_e("Project config not found - Generating config and restarting");
|
||||
save();
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_d("Project config found - Config length: %d", configLen);
|
||||
}
|
||||
|
||||
char buff[configLen];
|
||||
getBytes("config", buff, configLen);
|
||||
|
||||
for (int i = 0; i < configLen; i++)
|
||||
Serial.printf("%02X ", buff[i]);
|
||||
|
||||
this->_already_loaded = true;
|
||||
this->notify(ObserverEvent::configLoaded);
|
||||
@ -105,28 +84,8 @@ void ProjectConfig::save()
|
||||
{
|
||||
log_d("Saving project config");
|
||||
|
||||
this->write("device_name", this->config.device.name);
|
||||
this->write("ota_pass", this->config.device.OTAPassword);
|
||||
this->write("ota_port", this->config.device.OTAPort);
|
||||
|
||||
this->write("camera_vflip", this->config.camera.vflip);
|
||||
this->write("cameraFrmsz", this->config.camera.framesize);
|
||||
this->write("camera_href", this->config.camera.href);
|
||||
this->write("camera_quality", this->config.camera.quality);
|
||||
|
||||
for (int i = 0; i < this->config.networks.size(); i++)
|
||||
{
|
||||
char buff[25];
|
||||
snprintf(buff, sizeof(buff), "%d_name", i);
|
||||
this->write(buff, this->config.networks[i].name);
|
||||
snprintf(buff, sizeof(buff), "%d_ssid", i);
|
||||
this->write(buff, this->config.networks[i].ssid);
|
||||
snprintf(buff, sizeof(buff), "%d_password", i);
|
||||
this->write(buff, this->config.networks[i].password);
|
||||
snprintf(buff, sizeof(buff), "%d_channel", i);
|
||||
this->write(buff, this->config.networks[i].channel);
|
||||
this->write(buff, this->config.networks[i].adhoc);
|
||||
}
|
||||
TrackerConfig_t *tracker_config = (TrackerConfig_t *)&this->config;
|
||||
putBytes("config", tracker_config, 3 * sizeof(TrackerConfig_t));
|
||||
|
||||
log_i("Project config saved and system is rebooting");
|
||||
delay(20000);
|
||||
|
||||
@ -2,13 +2,13 @@
|
||||
#ifndef PROJECT_CONFIG_HPP
|
||||
#define PROJECT_CONFIG_HPP
|
||||
#include <Arduino.h>
|
||||
#include <preferencesAPI.hpp>
|
||||
#include <Preferences.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "data/utilities/Observer.hpp"
|
||||
|
||||
class ProjectConfig : public Config, public ISubject
|
||||
class ProjectConfig : public Preferences, public ISubject
|
||||
{
|
||||
public:
|
||||
ProjectConfig();
|
||||
|
||||
@ -13,18 +13,16 @@ bool Network_Utilities::LoopWifiScan()
|
||||
{
|
||||
// WiFi.scanNetworks will return the number of networks found
|
||||
log_i("[INFO]: Beginning WiFi Scanner");
|
||||
int networks = WiFi.scanNetworks();
|
||||
int networks = WiFi.scanNetworks(true, true);
|
||||
log_i("[INFO]: scan done");
|
||||
log_i("%d networks found", networks);
|
||||
for (int i = networks; i--;)
|
||||
{
|
||||
// Print SSID and RSSI for each network found
|
||||
//! Add method here to interface with the API and forward the scanned networks to the API
|
||||
//! TODO: Add method here to interface with the API and forward the scanned networks to the API
|
||||
log_i("%d: %s (%d) %s\n", i - 1, WiFi.SSID(i), WiFi.RSSI(i), (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");
|
||||
my_delay(0.02L); // delay 20ms
|
||||
}
|
||||
// Wait a bit before scanning again
|
||||
delay(5000);
|
||||
return (networks > 0);
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ int CameraHandler::setupCamera()
|
||||
|
||||
config.ledc_channel = LEDC_CHANNEL_0;
|
||||
config.ledc_timer = LEDC_TIMER_0;
|
||||
config.grab_mode = CAMERA_GRAB_LATEST;
|
||||
config.pin_d0 = Y2_GPIO_NUM;
|
||||
config.pin_d1 = Y3_GPIO_NUM;
|
||||
config.pin_d2 = Y4_GPIO_NUM;
|
||||
@ -22,7 +23,7 @@ int CameraHandler::setupCamera()
|
||||
config.pin_sscb_scl = SIOC_GPIO_NUM;
|
||||
config.pin_pwdn = PWDN_GPIO_NUM;
|
||||
config.pin_reset = RESET_GPIO_NUM;
|
||||
config.xclk_freq_hz = 20000000; // 10000000 stable,
|
||||
config.xclk_freq_hz = 16500000; // 10000000 stable,
|
||||
// 16500000 optimal,
|
||||
// 20000000 max fps
|
||||
config.pixel_format = PIXFORMAT_JPEG;
|
||||
|
||||
@ -76,6 +76,7 @@ void WiFiHandler::setupWifi()
|
||||
|
||||
void WiFiHandler::adhoc(const char *ssid, const char *password, uint8_t channel)
|
||||
{
|
||||
stateManager->setState(WiFiState_e::WiFiState_ADHOC);
|
||||
log_i("\n[INFO]: Setting Access Point...\n");
|
||||
log_i("\n[INFO]: Configuring access point...\n");
|
||||
WiFi.mode(WIFI_AP);
|
||||
@ -86,7 +87,6 @@ void WiFiHandler::adhoc(const char *ssid, const char *password, uint8_t channel)
|
||||
// You can remove the password parameter if you want the AP to be open.
|
||||
WiFi.softAP(ssid, password, channel); // AP mode with password
|
||||
WiFi.setTxPower(WIFI_POWER_11dBm);
|
||||
stateManager->setState(WiFiState_e::WiFiState_ADHOC);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -155,7 +155,6 @@ void WiFiHandler::iniSTA()
|
||||
this->setUpADHOC();
|
||||
log_w("Setting up adhoc mode");
|
||||
log_w("Please use adhoc mode and the app to set your WiFi credentials and reboot the device");
|
||||
stateManager->setState(WiFiState_e::WiFiState_ADHOC);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,14 @@
|
||||
#include "baseAPI.hpp"
|
||||
|
||||
BaseAPI::BaseAPI() {}
|
||||
BaseAPI::BaseAPI(int CONTROL_PORT,
|
||||
WiFiHandler *network,
|
||||
CameraHandler *camera,
|
||||
StateManager<WiFiState_e> *stateManager,
|
||||
std::string api_url) : API_Utilities(CONTROL_PORT,
|
||||
network,
|
||||
camera,
|
||||
stateManager,
|
||||
api_url) {}
|
||||
|
||||
BaseAPI::~BaseAPI() {}
|
||||
|
||||
@ -106,7 +114,7 @@ void BaseAPI::triggerWifiConfigWrite()
|
||||
}
|
||||
}
|
||||
|
||||
//! TODO: Add JSON handling to the POST request
|
||||
//! TODO: ADD JSON handlers for the POST requests
|
||||
void BaseAPI::handleJson(AsyncWebServerRequest *request)
|
||||
{
|
||||
std::string type = request->pathArg(0).c_str();
|
||||
|
||||
@ -70,7 +70,11 @@ protected:
|
||||
route_map_t route_map;
|
||||
|
||||
public:
|
||||
BaseAPI();
|
||||
BaseAPI(int CONTROL_PORT,
|
||||
WiFiHandler *network,
|
||||
CameraHandler *camera,
|
||||
StateManager<WiFiState_e> *stateManager,
|
||||
std::string api_url);
|
||||
|
||||
virtual ~BaseAPI();
|
||||
virtual void begin();
|
||||
|
||||
@ -18,7 +18,16 @@ bool API_Utilities::channel_write = false;
|
||||
//! API Utilities
|
||||
//*********************************************************************************************
|
||||
|
||||
API_Utilities::API_Utilities() : server(new AsyncWebServer(_control_port)) {}
|
||||
API_Utilities::API_Utilities(int CONTROL_PORT,
|
||||
WiFiHandler *network,
|
||||
CameraHandler *camera,
|
||||
StateManager<WiFiState_e> *stateManager,
|
||||
std::string api_url) : server(new AsyncWebServer(CONTROL_PORT)),
|
||||
stateManager(stateManager),
|
||||
network(network),
|
||||
camera(camera),
|
||||
api_url(api_url) {}
|
||||
|
||||
API_Utilities::~API_Utilities() {}
|
||||
|
||||
std::string API_Utilities::shaEncoder(std::string data)
|
||||
|
||||
@ -29,7 +29,11 @@
|
||||
class API_Utilities
|
||||
{
|
||||
public:
|
||||
API_Utilities();
|
||||
API_Utilities(int CONTROL_PORT,
|
||||
WiFiHandler *network,
|
||||
CameraHandler *camera,
|
||||
StateManager<WiFiState_e> *stateManager,
|
||||
std::string api_url);
|
||||
virtual ~API_Utilities();
|
||||
|
||||
static void printASCII();
|
||||
@ -76,7 +80,6 @@ protected:
|
||||
|
||||
protected:
|
||||
std::string api_url;
|
||||
byte _control_port;
|
||||
|
||||
static bool ssid_write;
|
||||
static bool pass_write;
|
||||
|
||||
@ -4,18 +4,15 @@
|
||||
//! API Server
|
||||
//*********************************************************************************************
|
||||
|
||||
APIServer::APIServer(byte control_port,
|
||||
APIServer::APIServer(int CONTROL_PORT,
|
||||
WiFiHandler *network,
|
||||
CameraHandler *camera,
|
||||
StateManager<WiFiState_e> *stateManager,
|
||||
std::string api_url)
|
||||
{
|
||||
this->_control_port = control_port;
|
||||
this->network = network;
|
||||
this->camera = camera;
|
||||
this->stateManager = stateManager;
|
||||
this->api_url = api_url;
|
||||
}
|
||||
std::string api_url) : BaseAPI(CONTROL_PORT,
|
||||
network,
|
||||
camera,
|
||||
stateManager,
|
||||
api_url) {}
|
||||
|
||||
APIServer::~APIServer() {}
|
||||
|
||||
@ -44,6 +41,7 @@ void APIServer::setupServer()
|
||||
routes.emplace("deleteRoute", &APIServer::deleteRoute);
|
||||
|
||||
// Camera Routes
|
||||
|
||||
|
||||
//! reserve enough memory for all routes - must be called after adding routes and before adding routes to route_map
|
||||
indexes.reserve(routes.size()); // this is done to avoid reallocation of memory and copying of data
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
class APIServer : public BaseAPI
|
||||
{
|
||||
public:
|
||||
APIServer(byte control_port,
|
||||
APIServer(int CONTROL_PORT,
|
||||
WiFiHandler *network,
|
||||
CameraHandler *camera,
|
||||
StateManager<WiFiState_e> *stateManager,
|
||||
|
||||
@ -15,7 +15,7 @@ esp_err_t StreamHelpers::stream(httpd_req_t *req)
|
||||
size_t _jpg_buf_len = 0;
|
||||
uint8_t *_jpg_buf = NULL;
|
||||
|
||||
char *part_buf[128];
|
||||
char *part_buf[256];
|
||||
|
||||
static int64_t last_frame = 0;
|
||||
if (!last_frame)
|
||||
@ -89,6 +89,7 @@ int StreamServer::startStreamServer()
|
||||
config.max_uri_handlers = 1;
|
||||
config.server_port = this->STREAM_SERVER_PORT;
|
||||
config.ctrl_port = this->STREAM_SERVER_PORT;
|
||||
config.stack_size = 20480;
|
||||
|
||||
httpd_uri_t stream_page = {
|
||||
.uri = "/",
|
||||
|
||||
@ -53,6 +53,12 @@ void setup()
|
||||
break;
|
||||
}
|
||||
case WiFiState_e::WiFiState_ADHOC:
|
||||
{
|
||||
streamServer.startStreamServer();
|
||||
apiServer.begin();
|
||||
log_d("[SETUP]: Starting Stream Server");
|
||||
break;
|
||||
}
|
||||
case WiFiState_e::WiFiState_Connected:
|
||||
{
|
||||
streamServer.startStreamServer();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user