refactor: prepare for merging binaries

This commit is contained in:
ZanzyTHEbar 2023-02-04 19:28:13 +00:00
parent 8229a3a1e5
commit 14cc1dad62
3 changed files with 138 additions and 145 deletions

View File

@ -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: |

View File

@ -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

View File

@ -4,7 +4,8 @@ WiFiHandler::WiFiHandler(ProjectConfig *configManager,
StateManager<WiFiState_e>* stateManager,
const std::string& ssid,
const std::string& password,
uint8_t channel) : configManager(configManager),
uint8_t channel)
: configManager(configManager),
stateManager(stateManager),
ssid(ssid),
password(password),
@ -14,11 +15,9 @@ WiFiHandler::WiFiHandler(ProjectConfig *configManager,
WiFiHandler::~WiFiHandler() {}
void WiFiHandler::setupWifi()
{
void WiFiHandler::setupWifi() {
if (this->_enable_adhoc ||
stateManager->getCurrentState() == WiFiState_e::WiFiState_ADHOC)
{
stateManager->getCurrentState() == WiFiState_e::WiFiState_ADHOC) {
this->setUpADHOC();
return;
}
@ -32,16 +31,12 @@ void WiFiHandler::setupWifi()
std::vector<ProjectConfig::WiFiConfig_t>* networks =
configManager->getWifiConfigs();
if (networks->empty())
{
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))
{
(wifi_power_t)txpower->power)) {
return;
}
else
{
} else {
log_i(
"Could not connect to the hardcoded network, setting up ADHOC "
"network \n\r");
@ -51,12 +46,10 @@ void WiFiHandler::setupWifi()
}
for (auto networkIterator = networks->begin();
networkIterator != networks->end(); ++networkIterator)
{
if (this->iniSTA(
networkIterator->ssid, networkIterator->password,
networkIterator->channel, (wifi_power_t)networkIterator->power))
{
networkIterator != networks->end(); ++networkIterator) {
if (this->iniSTA(networkIterator->ssid, networkIterator->password,
networkIterator->channel,
(wifi_power_t)networkIterator->power)) {
return;
}
}
@ -67,12 +60,9 @@ void WiFiHandler::setupWifi()
"to hardcoded network: %s \n\r",
this->ssid.c_str());
if (this->iniSTA(this->ssid, this->password, this->channel,
(wifi_power_t)txpower->power))
{
(wifi_power_t)txpower->power)) {
log_i("Successfully connected to the hardcoded network. \n\r");
}
else
{
} else {
log_i(
"Could not connect to the hardcoded network, setting up adhoc. "
"\n\r");
@ -80,8 +70,9 @@ void WiFiHandler::setupWifi()
}
}
void WiFiHandler::adhoc(const std::string &ssid, uint8_t channel, const std::string &password)
{
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");
@ -92,24 +83,22 @@ void WiFiHandler::adhoc(const std::string &ssid, uint8_t channel, const std::str
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.softAP(ssid.c_str(), password.c_str(),
channel); // AP mode with password
WiFi.setTxPower((wifi_power_t)txpower->power);
}
void WiFiHandler::setUpADHOC()
{
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)
{
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)
{
if (passwordLen <= 0) {
log_i("\n[INFO]: Configuring access point without a password\n");
this->adhoc(configManager->getAPWifiConfig()->ssid,
configManager->getAPWifiConfig()->channel);
@ -121,14 +110,17 @@ void WiFiHandler::setUpADHOC()
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]: 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)
{
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
@ -142,14 +134,12 @@ bool WiFiHandler::iniSTA(const std::string &ssid, const std::string &password,
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)
{
while (WiFi.status() != WL_CONNECTED) {
progress++;
currentMillis = millis();
Helpers::update_progress_bar(progress, 100);
delay(301);
if ((currentMillis - startingMillis) >= connectionTimeout)
{
if ((currentMillis - startingMillis) >= connectionTimeout) {
stateManager->setState(WiFiState_e::WiFiState_Error);
log_e("Connection to: %s TIMEOUT \n\r", ssid.c_str());
return false;