diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index 0fcbb2f..cf11761 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -15,7 +15,6 @@ jobs: SONAR_SERVER_URL: "https://sonarcloud.io" BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed SONAR_CACHE_DIR: sonar_cache - environment: Analysis strategy: fail-fast: false matrix: diff --git a/.github/workflows/userconfigs.yml b/.github/workflows/userconfigs.yml index e3ac07e..523b7ba 100644 --- a/.github/workflows/userconfigs.yml +++ b/.github/workflows/userconfigs.yml @@ -8,7 +8,6 @@ on: jobs: build: runs-on: ubuntu-latest - environment: Userconfigs strategy: fail-fast: false matrix: diff --git a/main/battery.cpp b/main/battery.cpp index 3de7a8b..df1f24f 100644 --- a/main/battery.cpp +++ b/main/battery.cpp @@ -197,4 +197,5 @@ std::string getBatteryDebugString() namespace battery { std::optional bootBatPercentage; +std::optional bootBatWh; } diff --git a/main/battery.h b/main/battery.h index e17ff06..466a97f 100644 --- a/main/battery.h +++ b/main/battery.h @@ -35,4 +35,5 @@ float getTarget_mAh(); namespace battery { extern std::optional bootBatPercentage; +extern std::optional bootBatWh; } diff --git a/main/displays/menus/batterymenu.cpp b/main/displays/menus/batterymenu.cpp index d3b5d96..886b6e4 100644 --- a/main/displays/menus/batterymenu.cpp +++ b/main/displays/menus/batterymenu.cpp @@ -9,6 +9,8 @@ #include #include +#include + // Local includes #include "utils.h" #include "icons/settings.h" @@ -38,6 +40,15 @@ constexpr char TEXT_VOLTAGECALIBRATION_RESET[] = "Reset calibration"; constexpr char TEXT_BACK[] = "Back"; class CurrentBatteryStatusText : public virtual espgui::TextInterface { public: std::string text() const override { return getBatteryPercentageString(); } }; +class WhStatisticsText : public virtual espgui::TextInterface { public: std::string text() const override + { + if (battery::bootBatWh) + { + return fmt::format("&s&2{}Wh => &1{}Wh &6({})", (int)*battery::bootBatWh, (int)getRemainingWattHours(), (int)getRemainingWattHours() - (int)battery::bootBatWh.value()); + } + return ""; + } +}; using BatteryCellSeriesChangeScreen = espgui::makeComponent< BobbyChangeValueDisplay, @@ -64,10 +75,10 @@ using BatteryWHperKMChangeScreen = espgui::makeComponent< >; } // namespace +using namespace espgui; + BatteryMenu::BatteryMenu() { - using namespace espgui; - constructMenuItem>(); constructMenuItem>(); constructMenuItem, SwitchScreenAction>>(); @@ -75,6 +86,7 @@ BatteryMenu::BatteryMenu() constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem>(); + constructMenuItem>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&bobbyicons::settings>>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } @@ -84,6 +96,13 @@ std::string BatteryMenu::text() const return TEXT_BATTERY; } +void BatteryMenu::initScreen() +{ + Base::initScreen(); + m_batPercentBootLabel.start(); + m_batPercentNowLabel.start(); +} + void BatteryMenu::start() { Base::start(); @@ -103,7 +122,16 @@ void BatteryMenu::redraw() const auto batPercent = getBatteryPercentage(avgVoltage, BatteryCellType(configs.battery.cellType.value)); if (battery::bootBatPercentage) + { m_doubleProgressBarBatPercentage.redraw(batPercent, *battery::bootBatPercentage); + + tft.setTextFont(2); + tft.setTextColor(TFT_DARKGREY, TFT_BLACK); + m_batPercentNowLabel.redraw(fmt::format("{:.2f} %", batPercent)); + m_batPercentBootLabel.redraw(fmt::format("{:.2f} %", *battery::bootBatPercentage)); + tft.setTextFont(4); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + } } void BatteryMenu::back() diff --git a/main/displays/menus/batterymenu.h b/main/displays/menus/batterymenu.h index 01740c6..d6912b4 100644 --- a/main/displays/menus/batterymenu.h +++ b/main/displays/menus/batterymenu.h @@ -3,6 +3,7 @@ // local includes #include "displays/bobbymenudisplay.h" #include "widgets/doubleprogressbar.h" +#include "widgets/label.h" class BatteryMenu : public BobbyMenuDisplay { @@ -13,10 +14,13 @@ public: std::string text() const override; + void initScreen() override; void start() override; void redraw() override; void back() override; private: bobbygui::DoubleProgressBar m_doubleProgressBarBatPercentage{75, 68, 90, 24, 0, 100, TFT_RED, TFT_GREEN}; + espgui::Label m_batPercentNowLabel {170, 68}; + espgui::Label m_batPercentBootLabel{170, 82}; }; diff --git a/main/displays/menus/networksettingsmenu.cpp b/main/displays/menus/networksettingsmenu.cpp index b57753c..e306a46 100644 --- a/main/displays/menus/networksettingsmenu.cpp +++ b/main/displays/menus/networksettingsmenu.cpp @@ -31,6 +31,7 @@ NetworkSettingsMenu::NetworkSettingsMenu() constructMenuItem>(uint8_t{0}); constructMenuItem>(uint8_t{1}); constructMenuItem>(uint8_t{2}); + constructMenuItem>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::back>>>(); } diff --git a/main/espnowfunctions.cpp b/main/espnowfunctions.cpp index 96c9cd6..351b5d8 100644 --- a/main/espnowfunctions.cpp +++ b/main/espnowfunctions.cpp @@ -12,10 +12,6 @@ #include "newsettings.h" namespace espnow { -namespace { -constexpr const char * const TAG = "BOBBY_ESP_NOW"; -} // namespace - uint16_t lastYear; // Used for esp-now timesync std::deque message_queue{}; @@ -25,6 +21,33 @@ uint8_t initialized{0}; bool receiveTimeStamp{true}; bool receiveTsFromOtherBobbycars{true}; +namespace { +constexpr const char * const TAG = "BOBBY_ESP_NOW"; + +inline bool espnow_init_allowed() { + const auto wifi_mode = wifi_stack::get_wifi_mode(); + return + ( + (configs.espnow.syncBlink.value || configs.espnow.syncTime.value || configs.espnow.syncTimeWithOthers.value) + && + ( + (configs.wifiApEnabled.value && wifi_stack::get_wifi_mode() == WIFI_MODE_AP) + || + ( + configs.wifiStaEnabled.value + && + wifi_stack::get_sta_status() != wifi_stack::WiFiStaStatus::NO_SHIELD + && + ( + wifi_mode == WIFI_MODE_STA || + wifi_mode == WIFI_MODE_APSTA + ) + ) + ) + ); +} +} // namespace + namespace { extern "C" void onReceive(const uint8_t *mac_addr, const uint8_t *data, int data_len) { @@ -56,7 +79,7 @@ void initESPNow() if (initialized < 1) { - if (!configs.wifiApEnabled.value && (!configs.wifiStaEnabled.value && wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::NO_SHIELD) || (wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_STA && wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_AP && wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_APSTA)) + if (!configs.wifiApEnabled.value && (!configs.wifiStaEnabled.value && wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::NO_SHIELD) || (wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_STA && wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_AP && wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_APSTA) && (configs.espnow.syncBlink.value || configs.espnow.syncBlink.value || configs.espnow.syncBlink.value)) { ESP_LOGW(TAG, "cannot execute esp_now_init(): tcp stack is down."); return; @@ -119,12 +142,12 @@ void initESPNow() void handle() { - if (initialized < 255 && !(!configs.wifiApEnabled.value && (!configs.wifiStaEnabled.value && wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::NO_SHIELD) || (wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_STA && wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_AP && wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_APSTA))) + if (initialized < 255 && espnow_init_allowed()) { initESPNow(); return; } - else if (!configs.wifiApEnabled.value && (!configs.wifiStaEnabled.value && wifi_stack::get_sta_status() == wifi_stack::WiFiStaStatus::NO_SHIELD) || (wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_STA && wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_AP && wifi_stack::get_wifi_mode() != wifi_mode_t::WIFI_MODE_APSTA)) + else if (!espnow_init_allowed() && initialized >= 255) { if (initialized > 0) { @@ -189,7 +212,7 @@ void handle() if (msg.type == "T") { if (!receiveTimeStamp || !configs.espnow.syncTime.value) - return; + goto clear; if (const auto result = cpputils::fromString(msg.content); result) { @@ -203,7 +226,7 @@ void handle() else if (msg.type == "BOBBYT") { if (!receiveTsFromOtherBobbycars || !configs.espnow.syncTimeWithOthers.value) - return; + goto clear; if (const auto result = cpputils::fromString(msg.content); result) { @@ -220,7 +243,8 @@ void handle() ESP_LOGI(TAG, "Unkown Type: %s - Message: %s", msg.type.c_str(), msg.content.c_str()); } } - message_queue.clear(); +clear: + message_queue.erase(std::begin(message_queue), std::end(message_queue)); } } diff --git a/main/main.cpp b/main/main.cpp index 6953535..6dd1e40 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -94,6 +94,9 @@ extern "C" void app_main() { const auto now = espchrono::millis_clock::now(); +// if (!heap_caps_check_integrity_all(true)) +// ESP_LOGW(TAG, "OIS IM OARSCH!!!!!"); + for (auto &schedulerTask : schedulerTasks) { schedulerTask.loop(); @@ -124,7 +127,10 @@ extern "C" void app_main() } avgVoltage = avgVoltage / controllers.size(); if (avgVoltage > 30) + { battery::bootBatPercentage = getBatteryPercentage(avgVoltage, BatteryCellType(configs.battery.cellType.value)); + battery::bootBatWh = getRemainingWattHours(); + } } } } diff --git a/main/newsettings.h b/main/newsettings.h index 9cc02f7..c4fd82d 100644 --- a/main/newsettings.h +++ b/main/newsettings.h @@ -557,6 +557,7 @@ public: #define HELPER(x) callback(x); NEW_SETTINGS(HELPER) #undef HELPER + callback(bleSettings.bleEnabled); } auto getAllConfigParams() diff --git a/main/texthelpers/networktexthelpers.cpp b/main/texthelpers/networktexthelpers.cpp index e5f96ed..e549b1d 100644 --- a/main/texthelpers/networktexthelpers.cpp +++ b/main/texthelpers/networktexthelpers.cpp @@ -40,3 +40,11 @@ std::string DnsText::text() const text += wifi_stack::toString(*dns_ip); return text; } + +std::string WifiTxPowerText::text() const +{ + int8_t power; + if(const auto err = esp_wifi_get_max_tx_power(&power); err == ESP_OK) + return fmt::format("&stx-power: {:.2f} dBm ({})&f", power * 0.25f, power); + return ""; +} diff --git a/main/texthelpers/networktexthelpers.h b/main/texthelpers/networktexthelpers.h index cafbb27..a8007bf 100644 --- a/main/texthelpers/networktexthelpers.h +++ b/main/texthelpers/networktexthelpers.h @@ -25,3 +25,9 @@ public: private: const uint8_t m_index; }; + +class WifiTxPowerText : public virtual espgui::TextInterface +{ +public: + std::string text() const override; +};