mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
Initial changes, cleanup and improvements
This commit is contained in:
parent
d3c402525c
commit
4705e41476
@ -1,10 +1,8 @@
|
|||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
|
|
||||||
char *Helpers::itoa(int value, char *result, int base)
|
char* Helpers::itoa(int value, char* result, int base) {
|
||||||
{
|
|
||||||
// check that the base if valid
|
// check that the base if valid
|
||||||
if (base < 2 || base > 36)
|
if (base < 2 || base > 36) {
|
||||||
{
|
|
||||||
*result = '\0';
|
*result = '\0';
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -12,19 +10,19 @@ char *Helpers::itoa(int value, char *result, int base)
|
|||||||
char *ptr = result, *ptr1 = result, tmp_char;
|
char *ptr = result, *ptr1 = result, tmp_char;
|
||||||
int tmp_value;
|
int tmp_value;
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
tmp_value = value;
|
tmp_value = value;
|
||||||
value /= base;
|
value /= base;
|
||||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)];
|
*ptr++ =
|
||||||
|
"zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxy"
|
||||||
|
"z"[35 + (tmp_value - value * base)];
|
||||||
} while (value);
|
} while (value);
|
||||||
|
|
||||||
// Apply negative sign
|
// Apply negative sign
|
||||||
if (tmp_value < 0)
|
if (tmp_value < 0)
|
||||||
*ptr++ = '-';
|
*ptr++ = '-';
|
||||||
*ptr-- = '\0';
|
*ptr-- = '\0';
|
||||||
while (ptr1 < ptr)
|
while (ptr1 < ptr) {
|
||||||
{
|
|
||||||
tmp_char = *ptr;
|
tmp_char = *ptr;
|
||||||
*ptr-- = *ptr1;
|
*ptr-- = *ptr1;
|
||||||
*ptr1++ = tmp_char;
|
*ptr1++ = tmp_char;
|
||||||
@ -32,8 +30,9 @@ char *Helpers::itoa(int value, char *result, int base)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void split(const std::string &str, const std::string &splitBy, std::vector<std::string> &tokens)
|
void split(const std::string& str,
|
||||||
{
|
const std::string& splitBy,
|
||||||
|
std::vector<std::string>& tokens) {
|
||||||
/* Store the original string in the array, so we can loop the rest
|
/* Store the original string in the array, so we can loop the rest
|
||||||
* of the algorithm. */
|
* of the algorithm. */
|
||||||
tokens.emplace_back(str);
|
tokens.emplace_back(str);
|
||||||
@ -45,16 +44,14 @@ void split(const std::string &str, const std::string &splitBy, std::vector<std::
|
|||||||
// Create a string for temporarily storing the fragment we're processing.
|
// Create a string for temporarily storing the fragment we're processing.
|
||||||
std::string frag;
|
std::string frag;
|
||||||
// Loop infinitely - break is internal.
|
// Loop infinitely - break is internal.
|
||||||
while (true)
|
while (true) {
|
||||||
{
|
|
||||||
/* Store the last string in the vector, which is the only logical
|
/* Store the last string in the vector, which is the only logical
|
||||||
* candidate for processing. */
|
* candidate for processing. */
|
||||||
frag = tokens.back();
|
frag = tokens.back();
|
||||||
/* The index where the split is. */
|
/* The index where the split is. */
|
||||||
splitAt = frag.find(splitBy);
|
splitAt = frag.find(splitBy);
|
||||||
// If we didn't find a new split point...
|
// If we didn't find a new split point...
|
||||||
if (splitAt == std::string::npos)
|
if (splitAt == std::string::npos) {
|
||||||
{
|
|
||||||
// Break the loop and (implicitly) return.
|
// Break the loop and (implicitly) return.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -63,30 +60,27 @@ void split(const std::string &str, const std::string &splitBy, std::vector<std::
|
|||||||
tokens.back() = frag.substr(0, splitAt);
|
tokens.back() = frag.substr(0, splitAt);
|
||||||
/* Push everything from the right side of the split to the next empty
|
/* Push everything from the right side of the split to the next empty
|
||||||
* index in the vector. */
|
* index in the vector. */
|
||||||
tokens.emplace_back(frag.substr(splitAt + splitLen, frag.size() - (splitAt + splitLen)));
|
tokens.emplace_back(
|
||||||
|
frag.substr(splitAt + splitLen, frag.size() - (splitAt + splitLen)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> Helpers::split(const std::string &s, char delimiter)
|
std::vector<std::string> Helpers::split(const std::string& s, char delimiter) {
|
||||||
{
|
|
||||||
std::vector<std::string> parts;
|
std::vector<std::string> parts;
|
||||||
std::string part;
|
std::string part;
|
||||||
std::istringstream tokenStream(s);
|
std::istringstream tokenStream(s);
|
||||||
while (std::getline(tokenStream, part, delimiter))
|
while (std::getline(tokenStream, part, delimiter)) {
|
||||||
{
|
|
||||||
parts.push_back(part);
|
parts.push_back(part);
|
||||||
}
|
}
|
||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Helpers::update_progress_bar(int progress, int total)
|
void Helpers::update_progress_bar(int progress, int total) {
|
||||||
{
|
|
||||||
int barWidth = 70;
|
int barWidth = 70;
|
||||||
|
|
||||||
std::cout << "\r[";
|
std::cout << "\r[";
|
||||||
int pos = barWidth * progress / total;
|
int pos = barWidth * progress / total;
|
||||||
for (int i = 0; i < barWidth; ++i)
|
for (int i = 0; i < barWidth; ++i) {
|
||||||
{
|
|
||||||
if (i < pos)
|
if (i < pos)
|
||||||
std::cout << "=";
|
std::cout << "=";
|
||||||
else if (i == pos)
|
else if (i == pos)
|
||||||
|
|||||||
@ -1,15 +1,19 @@
|
|||||||
#ifndef HELPERS_HPP
|
#ifndef HELPERS_HPP
|
||||||
#define HELPERS_HPP
|
#define HELPERS_HPP
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Helpers
|
const unsigned char ETVR_HEADER[] = {0xFF, 0xA0, 0xFF, 0xA1, 0x01};
|
||||||
{
|
const char* const ETVR_HEADER_BYTES = "\xff\xa0\xff\xa1";
|
||||||
|
|
||||||
|
namespace Helpers {
|
||||||
char* itoa(int value, char* result, int base);
|
char* itoa(int value, char* result, int base);
|
||||||
void split(std::string str, std::string splitBy, std::vector<std::string> &tokens);
|
void split(std::string str,
|
||||||
|
std::string splitBy,
|
||||||
|
std::vector<std::string>& tokens);
|
||||||
std::vector<std::string> split(const std::string& s, char delimiter);
|
std::vector<std::string> split(const std::string& s, char delimiter);
|
||||||
void update_progress_bar(int progress, int total);
|
void update_progress_bar(int progress, int total);
|
||||||
|
|
||||||
@ -19,19 +23,19 @@ namespace Helpers
|
|||||||
/// @param ...args
|
/// @param ...args
|
||||||
/// @return
|
/// @return
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
std::string format_string(const std::string &format, Args... args)
|
std::string format_string(const std::string& format, Args... args) {
|
||||||
{
|
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) +
|
||||||
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
|
1; // Extra space for '\0'
|
||||||
if (size_s <= 0)
|
if (size_s <= 0) {
|
||||||
{
|
|
||||||
std::cout << "Error during formatting.";
|
std::cout << "Error during formatting.";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
auto size = static_cast<size_t>(size_s);
|
auto size = static_cast<size_t>(size_s);
|
||||||
std::unique_ptr<char[]> buf(new char[size]);
|
std::unique_ptr<char[]> buf(new char[size]);
|
||||||
std::snprintf(buf.get(), size, format.c_str(), args...);
|
std::snprintf(buf.get(), size, format.c_str(), args...);
|
||||||
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
return std::string(buf.get(),
|
||||||
}
|
buf.get() + size - 1); // We don't want the '\0' inside
|
||||||
}
|
}
|
||||||
|
} // namespace Helpers
|
||||||
|
|
||||||
#endif // HELPERS_HPP
|
#endif // HELPERS_HPP
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
*between blinks.
|
*between blinks.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO rethink this
|
||||||
LEDManager::ledStateMap_t LEDManager::ledStateMap = {
|
LEDManager::ledStateMap_t LEDManager::ledStateMap = {
|
||||||
{LEDStates_e::_LedStateNone, {{0, 500}}},
|
{LEDStates_e::_LedStateNone, {{0, 500}}},
|
||||||
{LEDStates_e::_Improv_Error,
|
{LEDStates_e::_Improv_Error,
|
||||||
@ -58,7 +59,7 @@ LEDManager::~LEDManager() {}
|
|||||||
|
|
||||||
void LEDManager::begin() {
|
void LEDManager::begin() {
|
||||||
pinMode(_ledPin, OUTPUT);
|
pinMode(_ledPin, OUTPUT);
|
||||||
// the defualt state is _LedStateNone so we're fine
|
// the default state is _LedStateNone so we're fine
|
||||||
this->currentState = ledStateManager.getCurrentState();
|
this->currentState = ledStateManager.getCurrentState();
|
||||||
this->currentPatternIndex = 0;
|
this->currentPatternIndex = 0;
|
||||||
BlinkPatterns_t pattern =
|
BlinkPatterns_t pattern =
|
||||||
@ -66,7 +67,12 @@ void LEDManager::begin() {
|
|||||||
this->toggleLED(pattern.state);
|
this->toggleLED(pattern.state);
|
||||||
this->nextStateChangeMillis = pattern.delayTime;
|
this->nextStateChangeMillis = pattern.delayTime;
|
||||||
|
|
||||||
log_d("begin %d", this->currentPatternIndex);
|
log_d("Led manager began with: %d", this->currentPatternIndex);
|
||||||
|
|
||||||
|
#ifdef CONFIG_CAMERA_MODULE_SWROOM_BABBLE_S3
|
||||||
|
log_d("Setting up LED for the Babble board");
|
||||||
|
this->setupBabbeLed();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,6 +126,19 @@ void LEDManager::handleLED() {
|
|||||||
log_d("updated stage %d", this->currentPatternIndex);
|
log_d("updated stage %d", this->currentPatternIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_CAMERA_MODULE_SWROOM_BABBLE_S3
|
||||||
|
void LEDManager::setupBabbeLed() {
|
||||||
|
// Set IR emitter strength to 100%.
|
||||||
|
const int ledPin = 1; // Replace this with a command endpoint eventually.
|
||||||
|
const int freq = 5000;
|
||||||
|
const int ledChannel = 0;
|
||||||
|
const int resolution = 8;
|
||||||
|
const int dutyCycle = 255;
|
||||||
|
ledcSetup(ledChannel, freq, resolution);
|
||||||
|
ledcAttachPin(ledPin, ledChannel);
|
||||||
|
ledcWrite(ledChannel, dutyCycle);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* @brief Turn the LED on or off
|
* @brief Turn the LED on or off
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
#ifndef LEDMANAGER_HPP
|
#ifndef LEDMANAGER_HPP
|
||||||
#define LEDMANAGER_HPP
|
#define LEDMANAGER_HPP
|
||||||
#include <vector>
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <data/StateManager/StateManager.hpp>
|
#include <data/StateManager/StateManager.hpp>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class LEDManager
|
class LEDManager {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
LEDManager(byte pin);
|
LEDManager(byte pin);
|
||||||
virtual ~LEDManager();
|
virtual ~LEDManager();
|
||||||
@ -14,19 +13,22 @@ public:
|
|||||||
void begin();
|
void begin();
|
||||||
void handleLED();
|
void handleLED();
|
||||||
void toggleLED(bool state) const;
|
void toggleLED(bool state) const;
|
||||||
|
#ifdef CONFIG_CAMERA_MODULE_SWROOM_BABBLE_S3
|
||||||
|
void setupBabbeLed();
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
byte _ledPin;
|
byte _ledPin;
|
||||||
unsigned long nextStateChangeMillis = 0;
|
unsigned long nextStateChangeMillis = 0;
|
||||||
bool _ledState;
|
bool _ledState;
|
||||||
|
|
||||||
struct BlinkPatterns_t
|
struct BlinkPatterns_t {
|
||||||
{
|
|
||||||
int state;
|
int state;
|
||||||
int delayTime;
|
int delayTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::unordered_map<LEDStates_e, std::vector<BlinkPatterns_t>> ledStateMap_t;
|
typedef std::unordered_map<LEDStates_e, std::vector<BlinkPatterns_t>>
|
||||||
|
ledStateMap_t;
|
||||||
static ledStateMap_t ledStateMap;
|
static ledStateMap_t ledStateMap;
|
||||||
static std::vector<LEDStates_e> keepAliveStates;
|
static std::vector<LEDStates_e> keepAliveStates;
|
||||||
LEDStates_e currentState;
|
LEDStates_e currentState;
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
#ifndef HASH_H_
|
|
||||||
#define HASH_H_
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
// #define DEBUG_SHA1
|
|
||||||
|
|
||||||
void sha1(const uint8_t* data, uint32_t size, uint8_t hash[20]);
|
|
||||||
void sha1(const char* data, uint32_t size, uint8_t hash[20]);
|
|
||||||
void sha1(const std::string& data, uint8_t hash[20]);
|
|
||||||
|
|
||||||
std::string sha1(const uint8_t* data, uint32_t size);
|
|
||||||
std::string sha1(const char* data, uint32_t size);
|
|
||||||
std::string sha1(const std::string& data);
|
|
||||||
|
|
||||||
#endif /* HASH_H_ */
|
|
||||||
@ -102,17 +102,6 @@ void BaseAPI::setWiFi(AsyncWebServerRequest* request) {
|
|||||||
projectConfig.setWifiConfig(networkName, ssid, password, channel, power,
|
projectConfig.setWifiConfig(networkName, ssid, password, channel, power,
|
||||||
adhoc, true);
|
adhoc, true);
|
||||||
|
|
||||||
/* if (WiFiStateManager->getCurrentState() ==
|
|
||||||
WiFiState_e::WiFiState_ADHOC)
|
|
||||||
{
|
|
||||||
projectConfig.setAPWifiConfig(ssid, password, &channel, adhoc,
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
} */
|
|
||||||
|
|
||||||
request->send(200, MIMETYPE_JSON,
|
request->send(200, MIMETYPE_JSON,
|
||||||
"{\"msg\":\"Done. Wifi Creds have been set.\"}");
|
"{\"msg\":\"Done. Wifi Creds have been set.\"}");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
//! Warning do not format this file with clang-format or it will break the code
|
//! Warning do not format this file with clang-format or it will break the code
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
@ -31,7 +30,6 @@ constexpr int HTTP_ANY = 0b01111111;
|
|||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include "Hash.h"
|
|
||||||
|
|
||||||
#include "data/utilities/network_utilities.hpp"
|
#include "data/utilities/network_utilities.hpp"
|
||||||
#include "tasks/tasks.hpp"
|
#include "tasks/tasks.hpp"
|
||||||
@ -101,7 +99,8 @@ class BaseAPI {
|
|||||||
networkMethodsMap_t;
|
networkMethodsMap_t;
|
||||||
|
|
||||||
ProjectConfig& projectConfig;
|
ProjectConfig& projectConfig;
|
||||||
/// @brief Local instance of the AsyncWebServer - so that we dont need to use new and delete
|
/// @brief Local instance of the AsyncWebServer - so that we dont need to use
|
||||||
|
/// new and delete
|
||||||
AsyncWebServer server;
|
AsyncWebServer server;
|
||||||
#ifndef SIM_ENABLED
|
#ifndef SIM_ENABLED
|
||||||
CameraHandler& camera;
|
CameraHandler& camera;
|
||||||
|
|||||||
@ -6,7 +6,8 @@ MDNSHandler::MDNSHandler(ProjectConfig& configManager)
|
|||||||
bool MDNSHandler::startMDNS() {
|
bool MDNSHandler::startMDNS() {
|
||||||
const std::string service = "_openiristracker";
|
const std::string service = "_openiristracker";
|
||||||
auto mdnsConfig = configManager.getMDNSConfig();
|
auto mdnsConfig = configManager.getMDNSConfig();
|
||||||
if (!MDNS.begin(mdnsConfig.hostname.c_str())) // lowercase only - as this will be the url
|
if (!MDNS.begin(mdnsConfig.hostname
|
||||||
|
.c_str())) // lowercase only - as this will be the url
|
||||||
{
|
{
|
||||||
mdnsStateManager.setState(MDNSState_e::MDNSState_Error);
|
mdnsStateManager.setState(MDNSState_e::MDNSState_Error);
|
||||||
log_e("Error initializing MDNS");
|
log_e("Error initializing MDNS");
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
#include "wifihandler.hpp"
|
#include "wifihandler.hpp"
|
||||||
#include <WiFi.h>
|
|
||||||
#include "data/StateManager/StateManager.hpp"
|
|
||||||
#include "data/utilities/helpers.hpp"
|
|
||||||
|
|
||||||
WiFiHandler::WiFiHandler(ProjectConfig& configManager,
|
WiFiHandler::WiFiHandler(ProjectConfig& configManager,
|
||||||
const std::string& ssid,
|
const std::string& ssid,
|
||||||
@ -18,10 +15,11 @@ WiFiHandler::WiFiHandler(ProjectConfig& configManager,
|
|||||||
WiFiHandler::~WiFiHandler() {}
|
WiFiHandler::~WiFiHandler() {}
|
||||||
|
|
||||||
void WiFiHandler::begin() {
|
void WiFiHandler::begin() {
|
||||||
|
// just to be sure, we reeset everything before we do anything, some boards
|
||||||
// just to be sure, we reeset everything before we do anything, some boards were having problems otherwise
|
// were having problems otherwise
|
||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
// we purposefully set the lowest min required security level, some boards have problems connecting otherwise
|
// we purposefully set the lowest min required security level, some boards
|
||||||
|
// have problems connecting otherwise
|
||||||
// https://github.com/espressif/arduino-esp32/issues/8770
|
// https://github.com/espressif/arduino-esp32/issues/8770
|
||||||
WiFi.setMinSecurity(WIFI_AUTH_WEP);
|
WiFi.setMinSecurity(WIFI_AUTH_WEP);
|
||||||
|
|
||||||
@ -33,7 +31,9 @@ void WiFiHandler::begin() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_d("ADHOC is disabled, setting up STA network and checking transmission power \n\r");
|
log_d(
|
||||||
|
"ADHOC is disabled, setting up STA network and checking transmission "
|
||||||
|
"power \n\r");
|
||||||
auto txpower = configManager.getWiFiTxPowerConfig();
|
auto txpower = configManager.getWiFiTxPowerConfig();
|
||||||
log_d("Setting Wifi Power to: %d", txpower.power);
|
log_d("Setting Wifi Power to: %d", txpower.power);
|
||||||
log_d("Setting WiFi sleep mode to NONE \n\r");
|
log_d("Setting WiFi sleep mode to NONE \n\r");
|
||||||
@ -47,13 +47,8 @@ void WiFiHandler::begin() {
|
|||||||
if (networks.empty()) {
|
if (networks.empty()) {
|
||||||
log_i("No networks found in config, trying the default one \n\r");
|
log_i("No networks found in config, trying the default one \n\r");
|
||||||
|
|
||||||
if (this->iniSTA(
|
if (this->iniSTA(this->ssid, this->password, this->channel,
|
||||||
this->ssid,
|
(wifi_power_t)txpower.power)) {
|
||||||
this->password,
|
|
||||||
this->channel,
|
|
||||||
(wifi_power_t)txpower.power
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,9 +134,8 @@ bool WiFiHandler::iniSTA(const std::string& ssid,
|
|||||||
const std::string& password,
|
const std::string& password,
|
||||||
uint8_t channel,
|
uint8_t channel,
|
||||||
wifi_power_t power) {
|
wifi_power_t power) {
|
||||||
|
// since networks may not have a password, we only need to check if we have an
|
||||||
// since networks may not have a password, we only need to check if we have an ssid
|
// ssid bail if we don't
|
||||||
// bail if we don't
|
|
||||||
if (ssid == "") {
|
if (ssid == "") {
|
||||||
log_d("ssid missing, bailing");
|
log_d("ssid missing, bailing");
|
||||||
return false;
|
return false;
|
||||||
@ -160,7 +154,8 @@ bool WiFiHandler::iniSTA(const std::string& ssid,
|
|||||||
log_d("Setting hostname %s \n\r");
|
log_d("Setting hostname %s \n\r");
|
||||||
WiFi.setHostname(mdnsConfig.hostname.c_str());
|
WiFi.setHostname(mdnsConfig.hostname.c_str());
|
||||||
log_i("Setting TX power to: %d \n\r", (uint8_t)power);
|
log_i("Setting TX power to: %d \n\r", (uint8_t)power);
|
||||||
WiFi.setTxPower(power); // https://github.com/espressif/arduino-esp32/issues/5698
|
WiFi.setTxPower(
|
||||||
|
power); // https://github.com/espressif/arduino-esp32/issues/5698
|
||||||
WiFi.begin(ssid.c_str(), password.c_str(), channel);
|
WiFi.begin(ssid.c_str(), password.c_str(), channel);
|
||||||
|
|
||||||
log_d("Waiting for WiFi to connect... \n\r");
|
log_d("Waiting for WiFi to connect... \n\r");
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef WIFIHANDLER_HPP
|
#ifndef WIFIHANDLER_HPP
|
||||||
#define WIFIHANDLER_HPP
|
#define WIFIHANDLER_HPP
|
||||||
|
#include <WiFi.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "data/StateManager/StateManager.hpp"
|
||||||
#include "data/config/project_config.hpp"
|
#include "data/config/project_config.hpp"
|
||||||
|
#include "data/utilities/helpers.hpp"
|
||||||
|
|
||||||
#include "data/utilities/Observer.hpp"
|
#include "data/utilities/Observer.hpp"
|
||||||
|
|
||||||
class WiFiHandler : public IObserver<ConfigState_e> {
|
class WiFiHandler : public IObserver<ConfigState_e> {
|
||||||
@ -29,7 +33,6 @@ class WiFiHandler : public IObserver<ConfigState_e> {
|
|||||||
|
|
||||||
ProjectConfig& configManager;
|
ProjectConfig& configManager;
|
||||||
|
|
||||||
|
|
||||||
bool _enable_adhoc;
|
bool _enable_adhoc;
|
||||||
std::string ssid;
|
std::string ssid;
|
||||||
std::string password;
|
std::string password;
|
||||||
|
|||||||
@ -6,18 +6,16 @@
|
|||||||
* @param mdnsName The mDNS hostname to use
|
* @param mdnsName The mDNS hostname to use
|
||||||
*/
|
*/
|
||||||
ProjectConfig deviceConfig("openiris", MDNS_HOSTNAME);
|
ProjectConfig deviceConfig("openiris", MDNS_HOSTNAME);
|
||||||
CommandManager commandManager(&deviceConfig);
|
CommandManager commandManager(deviceConfig);
|
||||||
SerialManager serialManager(&commandManager);
|
SerialManager serialManager(&commandManager);
|
||||||
|
|
||||||
#ifdef CONFIG_CAMERA_MODULE_ESP32S3_XIAO_SENSE
|
#ifdef CONFIG_CAMERA_MODULE_ESP32S3_XIAO_SENSE
|
||||||
LEDManager ledManager(LED_BUILTIN);
|
LEDManager ledManager(LED_BUILTIN);
|
||||||
|
|
||||||
#elif CONFIG_CAMERA_MODULE_SWROOM_BABBLE_S3
|
#elif CONFIG_CAMERA_MODULE_SWROOM_BABBLE_S3
|
||||||
LEDManager ledManager(38);
|
LEDManager ledManager(38);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
LEDManager ledManager(33);
|
LEDManager ledManager(33);
|
||||||
#endif // ESP32S3_XIAO_SENSE
|
#endif
|
||||||
|
|
||||||
#ifndef SIM_ENABLED
|
#ifndef SIM_ENABLED
|
||||||
CameraHandler cameraHandler(deviceConfig);
|
CameraHandler cameraHandler(deviceConfig);
|
||||||
@ -30,10 +28,10 @@ WiFiHandler wifiHandler(deviceConfig,
|
|||||||
WIFI_CHANNEL,
|
WIFI_CHANNEL,
|
||||||
ENABLE_ADHOC);
|
ENABLE_ADHOC);
|
||||||
MDNSHandler mdnsHandler(deviceConfig);
|
MDNSHandler mdnsHandler(deviceConfig);
|
||||||
#ifdef SIM_ENABLED
|
|
||||||
APIServer apiServer(deviceConfig, wifiStateManager, "/control");
|
|
||||||
#else
|
|
||||||
APIServer apiServer(deviceConfig, cameraHandler, "/control");
|
APIServer apiServer(deviceConfig, cameraHandler, "/control");
|
||||||
|
|
||||||
|
#ifndef SIM_ENABLED
|
||||||
StreamServer streamServer;
|
StreamServer streamServer;
|
||||||
#endif // SIM_ENABLED
|
#endif // SIM_ENABLED
|
||||||
|
|
||||||
@ -45,37 +43,22 @@ void etvr_eye_tracker_web_init() {
|
|||||||
log_d("[SETUP]: Starting MDNS Handler");
|
log_d("[SETUP]: Starting MDNS Handler");
|
||||||
mdnsHandler.startMDNS();
|
mdnsHandler.startMDNS();
|
||||||
|
|
||||||
switch (wifiStateManager.getCurrentState()) {
|
auto wifiState = wifiStateManager.getCurrentState();
|
||||||
case WiFiState_e::WiFiState_Disconnected: {
|
|
||||||
//! TODO: Implement
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case WiFiState_e::WiFiState_ADHOC: {
|
|
||||||
#ifndef SIM_ENABLED
|
#ifndef SIM_ENABLED
|
||||||
|
if (wifiState == WiFiState_e::WiFiState_Connected ||
|
||||||
|
wifiState == WiFiState_e::WiFiState_ADHOC) {
|
||||||
|
{
|
||||||
log_d("[SETUP]: Starting Stream Server");
|
log_d("[SETUP]: Starting Stream Server");
|
||||||
streamServer.startStreamServer();
|
auto result = streamServer.startTCPStreamServer();
|
||||||
#endif // SIM_ENABLED
|
// streamServer.startStreamServer();
|
||||||
|
// auto result = streamServer.startUDPStreamServer();
|
||||||
|
|
||||||
|
log_d("[SETUP]: Stream Server state: %s",
|
||||||
|
result ? "Connected" : "Failed to connect");
|
||||||
log_d("[SETUP]: Starting API Server");
|
log_d("[SETUP]: Starting API Server");
|
||||||
apiServer.setup();
|
apiServer.setup();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case WiFiState_e::WiFiState_Connected: {
|
|
||||||
#ifndef SIM_ENABLED
|
|
||||||
log_d("[SETUP]: Starting Stream Server");
|
|
||||||
streamServer.startStreamServer();
|
|
||||||
#endif // SIM_ENABLED
|
#endif // SIM_ENABLED
|
||||||
log_d("[SETUP]: Starting API Server");
|
|
||||||
apiServer.setup();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case WiFiState_e::WiFiState_Connecting: {
|
|
||||||
//! TODO: Implement
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case WiFiState_e::WiFiState_Error: {
|
|
||||||
//! TODO: Implement
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // ETVR_EYE_TRACKER_WEB_API
|
#endif // ETVR_EYE_TRACKER_WEB_API
|
||||||
@ -86,22 +69,10 @@ void setup() {
|
|||||||
Logo::printASCII();
|
Logo::printASCII();
|
||||||
ledManager.begin();
|
ledManager.begin();
|
||||||
|
|
||||||
#ifdef CONFIG_CAMERA_MODULE_SWROOM_BABBLE_S3 // Set IR emitter strength to 100%.
|
|
||||||
const int ledPin = 1; // Replace this with a command endpoint eventually.
|
|
||||||
const int freq = 5000;
|
|
||||||
const int ledChannel = 0;
|
|
||||||
const int resolution = 8;
|
|
||||||
const int dutyCycle = 255;
|
|
||||||
ledcSetup(ledChannel, freq, resolution);
|
|
||||||
ledcAttachPin(1, ledChannel);
|
|
||||||
ledcWrite(ledChannel, dutyCycle);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef SIM_ENABLED
|
#ifndef SIM_ENABLED
|
||||||
deviceConfig.attach(cameraHandler);
|
deviceConfig.attach(cameraHandler);
|
||||||
#endif // SIM_ENABLED
|
#endif // SIM_ENABLED
|
||||||
deviceConfig.load();
|
deviceConfig.load();
|
||||||
|
|
||||||
serialManager.init();
|
serialManager.init();
|
||||||
|
|
||||||
#ifndef ETVR_EYE_TRACKER_USB_API
|
#ifndef ETVR_EYE_TRACKER_USB_API
|
||||||
@ -112,6 +83,10 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
#ifndef ETVR_EYE_TRACKER_USB_API
|
||||||
|
streamServer.sendTCPFrame();
|
||||||
|
#endif
|
||||||
|
// streamServer.sendUDPFrame();
|
||||||
ledManager.handleLED();
|
ledManager.handleLED();
|
||||||
serialManager.run();
|
serialManager.run();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user