mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
refactor: prepare for merging binaries
This commit is contained in:
parent
8229a3a1e5
commit
14cc1dad62
3
.github/workflows/build_release_bins.yml
vendored
3
.github/workflows/build_release_bins.yml
vendored
@ -63,6 +63,9 @@ jobs:
|
||||
pio run --environment ${{ matrix.target_name }}${{ matrix.target_build_type }}
|
||||
echo "::endgroup::"
|
||||
unzip -l './build/${{ matrix.target_name }}${{ matrix.target_build_type }}/*.zip'
|
||||
#echo "::group::pio merge binaries"
|
||||
#esptool --chip esp32 merge_bin -o merged-firmware.bin --flash_mode dio --flash_freq 40m --flash_size 4MB 0x1000 bootloader.bin 0x8000 partitions.bin 0xe000 boot.bin 0x10000 OpenIris-v1.3.0-esp32AIThinker-8229a3a-master.bin
|
||||
#echo "::endgroup::"
|
||||
- name: Archive Firmware name File
|
||||
# create an environment variable with the name of the firmware file by catting the firmware_name.txt file
|
||||
run: |
|
||||
|
||||
@ -15,15 +15,15 @@ indent_style = tab
|
||||
[CMakeLists.txt]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
max_line_length = 80
|
||||
max_line_length = 120
|
||||
|
||||
[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}]
|
||||
indent_size = 2
|
||||
cpp_indent_case_contents_when_block = true
|
||||
cpp_new_line_before_open_brace_namespace = same_line
|
||||
indent_size = 4
|
||||
#cpp_indent_case_contents_when_block = true
|
||||
#cpp_new_line_before_open_brace_namespace = same_line
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[README.md]
|
||||
max_line_length = 80
|
||||
max_line_length = 120
|
||||
|
||||
@ -1,163 +1,153 @@
|
||||
#include "WifiHandler.hpp"
|
||||
|
||||
WiFiHandler::WiFiHandler(ProjectConfig *configManager,
|
||||
StateManager<WiFiState_e> *stateManager,
|
||||
const std::string &ssid,
|
||||
const std::string &password,
|
||||
uint8_t channel) : configManager(configManager),
|
||||
stateManager(stateManager),
|
||||
ssid(ssid),
|
||||
password(password),
|
||||
channel(channel),
|
||||
power(0),
|
||||
_enable_adhoc(false) {}
|
||||
WiFiHandler::WiFiHandler(ProjectConfig* configManager,
|
||||
StateManager<WiFiState_e>* stateManager,
|
||||
const std::string& ssid,
|
||||
const std::string& password,
|
||||
uint8_t channel)
|
||||
: configManager(configManager),
|
||||
stateManager(stateManager),
|
||||
ssid(ssid),
|
||||
password(password),
|
||||
channel(channel),
|
||||
power(0),
|
||||
_enable_adhoc(false) {}
|
||||
|
||||
WiFiHandler::~WiFiHandler() {}
|
||||
|
||||
void WiFiHandler::setupWifi()
|
||||
{
|
||||
if (this->_enable_adhoc ||
|
||||
stateManager->getCurrentState() == WiFiState_e::WiFiState_ADHOC)
|
||||
{
|
||||
this->setUpADHOC();
|
||||
return;
|
||||
}
|
||||
ProjectConfig::WiFiTxPower_t *txpower = configManager->getWiFiTxPowerConfig();
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.setSleep(WIFI_PS_NONE);
|
||||
void WiFiHandler::setupWifi() {
|
||||
if (this->_enable_adhoc ||
|
||||
stateManager->getCurrentState() == WiFiState_e::WiFiState_ADHOC) {
|
||||
this->setUpADHOC();
|
||||
return;
|
||||
}
|
||||
ProjectConfig::WiFiTxPower_t* txpower = configManager->getWiFiTxPowerConfig();
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.setSleep(WIFI_PS_NONE);
|
||||
|
||||
log_i("Initializing connection to wifi \n\r");
|
||||
stateManager->setState(WiFiState_e::WiFiState_Connecting);
|
||||
log_i("Initializing connection to wifi \n\r");
|
||||
stateManager->setState(WiFiState_e::WiFiState_Connecting);
|
||||
|
||||
std::vector<ProjectConfig::WiFiConfig_t> *networks =
|
||||
configManager->getWifiConfigs();
|
||||
std::vector<ProjectConfig::WiFiConfig_t>* networks =
|
||||
configManager->getWifiConfigs();
|
||||
|
||||
if (networks->empty())
|
||||
{
|
||||
log_i("No networks found in config, trying the default one \n\r");
|
||||
if (this->iniSTA(this->ssid, this->password, this->channel,
|
||||
(wifi_power_t)txpower->power))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_i(
|
||||
"Could not connect to the hardcoded network, setting up ADHOC "
|
||||
"network \n\r");
|
||||
this->setUpADHOC();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (networks->empty()) {
|
||||
log_i("No networks found in config, trying the default one \n\r");
|
||||
if (this->iniSTA(this->ssid, this->password, this->channel,
|
||||
(wifi_power_t)txpower->power)) {
|
||||
return;
|
||||
} else {
|
||||
log_i(
|
||||
"Could not connect to the hardcoded network, setting up ADHOC "
|
||||
"network \n\r");
|
||||
this->setUpADHOC();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto networkIterator = networks->begin();
|
||||
networkIterator != networks->end(); ++networkIterator)
|
||||
{
|
||||
if (this->iniSTA(
|
||||
networkIterator->ssid, networkIterator->password,
|
||||
networkIterator->channel, (wifi_power_t)networkIterator->power))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (auto networkIterator = networks->begin();
|
||||
networkIterator != networks->end(); ++networkIterator) {
|
||||
if (this->iniSTA(networkIterator->ssid, networkIterator->password,
|
||||
networkIterator->channel,
|
||||
(wifi_power_t)networkIterator->power)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// at this point, we've tried every network, let's just setup adhoc
|
||||
log_i(
|
||||
"We've gone through every network, each timed out. Trying to connect "
|
||||
"to hardcoded network: %s \n\r",
|
||||
this->ssid.c_str());
|
||||
if (this->iniSTA(this->ssid, this->password, this->channel,
|
||||
(wifi_power_t)txpower->power))
|
||||
{
|
||||
log_i("Successfully connected to the hardcoded network. \n\r");
|
||||
}
|
||||
else
|
||||
{
|
||||
log_i(
|
||||
"Could not connect to the hardcoded network, setting up adhoc. "
|
||||
"\n\r");
|
||||
this->setUpADHOC();
|
||||
}
|
||||
// at this point, we've tried every network, let's just setup adhoc
|
||||
log_i(
|
||||
"We've gone through every network, each timed out. Trying to connect "
|
||||
"to hardcoded network: %s \n\r",
|
||||
this->ssid.c_str());
|
||||
if (this->iniSTA(this->ssid, this->password, this->channel,
|
||||
(wifi_power_t)txpower->power)) {
|
||||
log_i("Successfully connected to the hardcoded network. \n\r");
|
||||
} else {
|
||||
log_i(
|
||||
"Could not connect to the hardcoded network, setting up adhoc. "
|
||||
"\n\r");
|
||||
this->setUpADHOC();
|
||||
}
|
||||
}
|
||||
|
||||
void WiFiHandler::adhoc(const std::string &ssid, uint8_t channel, const std::string &password)
|
||||
{
|
||||
stateManager->setState(WiFiState_e::WiFiState_ADHOC);
|
||||
void WiFiHandler::adhoc(const std::string& ssid,
|
||||
uint8_t channel,
|
||||
const std::string& password) {
|
||||
stateManager->setState(WiFiState_e::WiFiState_ADHOC);
|
||||
|
||||
log_i("\n[INFO]: Configuring access point...\n");
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.setSleep(WIFI_PS_NONE);
|
||||
Serial.printf("\r\nStarting AP. \r\n");
|
||||
IPAddress IP = WiFi.softAPIP();
|
||||
Serial.printf("[INFO]: AP IP address: %s.\r\n", IP.toString().c_str());
|
||||
// You can remove the password parameter if you want the AP to be open.
|
||||
ProjectConfig::WiFiTxPower_t *txpower = configManager->getWiFiTxPowerConfig();
|
||||
WiFi.softAP(ssid.c_str(), password.c_str(), channel); // AP mode with password
|
||||
WiFi.setTxPower((wifi_power_t)txpower->power);
|
||||
log_i("\n[INFO]: Configuring access point...\n");
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.setSleep(WIFI_PS_NONE);
|
||||
Serial.printf("\r\nStarting AP. \r\n");
|
||||
IPAddress IP = WiFi.softAPIP();
|
||||
Serial.printf("[INFO]: AP IP address: %s.\r\n", IP.toString().c_str());
|
||||
// You can remove the password parameter if you want the AP to be open.
|
||||
ProjectConfig::WiFiTxPower_t* txpower = configManager->getWiFiTxPowerConfig();
|
||||
WiFi.softAP(ssid.c_str(), password.c_str(),
|
||||
channel); // AP mode with password
|
||||
WiFi.setTxPower((wifi_power_t)txpower->power);
|
||||
}
|
||||
|
||||
void WiFiHandler::setUpADHOC()
|
||||
{
|
||||
log_i("\n[INFO]: Setting Up Access Point...\n");
|
||||
size_t ssidLen = configManager->getAPWifiConfig()->ssid.length();
|
||||
size_t passwordLen = configManager->getAPWifiConfig()->password.length();
|
||||
if (ssidLen <= 0)
|
||||
{
|
||||
log_i("\n[INFO]: Configuring access point with default values\n");
|
||||
this->adhoc(WIFI_AP_SSID, WIFI_AP_CHANNEL, WIFI_AP_PASSWORD);
|
||||
return;
|
||||
}
|
||||
void WiFiHandler::setUpADHOC() {
|
||||
log_i("\n[INFO]: Setting Up Access Point...\n");
|
||||
size_t ssidLen = configManager->getAPWifiConfig()->ssid.length();
|
||||
size_t passwordLen = configManager->getAPWifiConfig()->password.length();
|
||||
if (ssidLen <= 0) {
|
||||
log_i("\n[INFO]: Configuring access point with default values\n");
|
||||
this->adhoc(WIFI_AP_SSID, WIFI_AP_CHANNEL, WIFI_AP_PASSWORD);
|
||||
return;
|
||||
}
|
||||
|
||||
if (passwordLen <= 0)
|
||||
{
|
||||
log_i("\n[INFO]: Configuring access point without a password\n");
|
||||
this->adhoc(configManager->getAPWifiConfig()->ssid,
|
||||
configManager->getAPWifiConfig()->channel);
|
||||
return;
|
||||
}
|
||||
if (passwordLen <= 0) {
|
||||
log_i("\n[INFO]: Configuring access point without a password\n");
|
||||
this->adhoc(configManager->getAPWifiConfig()->ssid,
|
||||
configManager->getAPWifiConfig()->channel);
|
||||
return;
|
||||
}
|
||||
|
||||
this->adhoc(configManager->getAPWifiConfig()->ssid,
|
||||
configManager->getAPWifiConfig()->channel,
|
||||
configManager->getAPWifiConfig()->password);
|
||||
this->adhoc(configManager->getAPWifiConfig()->ssid,
|
||||
configManager->getAPWifiConfig()->channel,
|
||||
configManager->getAPWifiConfig()->password);
|
||||
|
||||
log_i("\n[INFO]: Configuring access point...\n");
|
||||
log_d("\n[DEBUG]: ssid: %s\n", configManager->getAPWifiConfig()->ssid.c_str());
|
||||
log_d("\n[DEBUG]: password: %s\n", configManager->getAPWifiConfig()->password.c_str());
|
||||
log_d("\n[DEBUG]: channel: %d\n", configManager->getAPWifiConfig()->channel);
|
||||
log_i("\n[INFO]: Configuring access point...\n");
|
||||
log_d("\n[DEBUG]: ssid: %s\n",
|
||||
configManager->getAPWifiConfig()->ssid.c_str());
|
||||
log_d("\n[DEBUG]: password: %s\n",
|
||||
configManager->getAPWifiConfig()->password.c_str());
|
||||
log_d("\n[DEBUG]: channel: %d\n", configManager->getAPWifiConfig()->channel);
|
||||
}
|
||||
|
||||
bool WiFiHandler::iniSTA(const std::string &ssid, const std::string &password,
|
||||
uint8_t channel, wifi_power_t power)
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
unsigned long startingMillis = currentMillis;
|
||||
int connectionTimeout = 30000; // 30 seconds
|
||||
int progress = 0;
|
||||
bool WiFiHandler::iniSTA(const std::string& ssid,
|
||||
const std::string& password,
|
||||
uint8_t channel,
|
||||
wifi_power_t power) {
|
||||
unsigned long currentMillis = millis();
|
||||
unsigned long startingMillis = currentMillis;
|
||||
int connectionTimeout = 30000; // 30 seconds
|
||||
int progress = 0;
|
||||
|
||||
stateManager->setState(WiFiState_e::WiFiState_Connecting);
|
||||
log_i("Trying to connect to: %s \n\r", ssid.c_str());
|
||||
stateManager->setState(WiFiState_e::WiFiState_Connecting);
|
||||
log_i("Trying to connect to: %s \n\r", ssid.c_str());
|
||||
|
||||
auto mdnsConfig = configManager->getMDNSConfig();
|
||||
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE,
|
||||
INADDR_NONE); // need to call before setting hostname
|
||||
WiFi.setHostname(mdnsConfig->hostname.c_str());
|
||||
WiFi.begin(ssid.c_str(), password.c_str(), channel);
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
progress++;
|
||||
currentMillis = millis();
|
||||
Helpers::update_progress_bar(progress, 100);
|
||||
delay(301);
|
||||
if ((currentMillis - startingMillis) >= connectionTimeout)
|
||||
{
|
||||
stateManager->setState(WiFiState_e::WiFiState_Error);
|
||||
log_e("Connection to: %s TIMEOUT \n\r", ssid.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
stateManager->setState(WiFiState_e::WiFiState_Connected);
|
||||
log_i("Successfully connected to %s \n\r", ssid.c_str());
|
||||
log_i("Setting TX power to: %d \n\r", (uint8_t)power);
|
||||
WiFi.setTxPower(power);
|
||||
return true;
|
||||
auto mdnsConfig = configManager->getMDNSConfig();
|
||||
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE,
|
||||
INADDR_NONE); // need to call before setting hostname
|
||||
WiFi.setHostname(mdnsConfig->hostname.c_str());
|
||||
WiFi.begin(ssid.c_str(), password.c_str(), channel);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
progress++;
|
||||
currentMillis = millis();
|
||||
Helpers::update_progress_bar(progress, 100);
|
||||
delay(301);
|
||||
if ((currentMillis - startingMillis) >= connectionTimeout) {
|
||||
stateManager->setState(WiFiState_e::WiFiState_Error);
|
||||
log_e("Connection to: %s TIMEOUT \n\r", ssid.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
stateManager->setState(WiFiState_e::WiFiState_Connected);
|
||||
log_i("Successfully connected to %s \n\r", ssid.c_str());
|
||||
log_i("Setting TX power to: %d \n\r", (uint8_t)power);
|
||||
WiFi.setTxPower(power);
|
||||
return true;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user