Merge pull request #229 from bobbycar-graz/cleanup

This commit is contained in:
CommanderRedYT
2022-01-04 22:25:33 +01:00
committed by GitHub
12 changed files with 92 additions and 14 deletions

View File

@@ -15,7 +15,6 @@ jobs:
SONAR_SERVER_URL: "https://sonarcloud.io" SONAR_SERVER_URL: "https://sonarcloud.io"
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
SONAR_CACHE_DIR: sonar_cache SONAR_CACHE_DIR: sonar_cache
environment: Analysis
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:

View File

@@ -8,7 +8,6 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: Userconfigs
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:

View File

@@ -197,4 +197,5 @@ std::string getBatteryDebugString()
namespace battery { namespace battery {
std::optional<float> bootBatPercentage; std::optional<float> bootBatPercentage;
std::optional<float> bootBatWh;
} }

View File

@@ -35,4 +35,5 @@ float getTarget_mAh();
namespace battery { namespace battery {
extern std::optional<float> bootBatPercentage; extern std::optional<float> bootBatPercentage;
extern std::optional<float> bootBatWh;
} }

View File

@@ -9,6 +9,8 @@
#include <textwithvaluehelper.h> #include <textwithvaluehelper.h>
#include <fmt/core.h> #include <fmt/core.h>
#include <tftinstance.h>
// Local includes // Local includes
#include "utils.h" #include "utils.h"
#include "icons/settings.h" #include "icons/settings.h"
@@ -38,6 +40,15 @@ constexpr char TEXT_VOLTAGECALIBRATION_RESET[] = "Reset calibration";
constexpr char TEXT_BACK[] = "Back"; constexpr char TEXT_BACK[] = "Back";
class CurrentBatteryStatusText : public virtual espgui::TextInterface { public: std::string text() const override { return getBatteryPercentageString(); } }; 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< using BatteryCellSeriesChangeScreen = espgui::makeComponent<
BobbyChangeValueDisplay<uint8_t>, BobbyChangeValueDisplay<uint8_t>,
@@ -64,10 +75,10 @@ using BatteryWHperKMChangeScreen = espgui::makeComponent<
>; >;
} // namespace } // namespace
BatteryMenu::BatteryMenu()
{
using namespace espgui; using namespace espgui;
BatteryMenu::BatteryMenu()
{
constructMenuItem<makeComponent<MenuItem, CurrentBatteryStatusText, DisabledColor, DummyAction>>(); constructMenuItem<makeComponent<MenuItem, CurrentBatteryStatusText, DisabledColor, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>(); constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CELL_SERIES, BatterySeriesCellsAccessor>, SwitchScreenAction<BatteryCellSeriesChangeScreen>>>(); constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CELL_SERIES, BatterySeriesCellsAccessor>, SwitchScreenAction<BatteryCellSeriesChangeScreen>>>();
@@ -75,6 +86,7 @@ BatteryMenu::BatteryMenu()
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_BATTERY_WHKM, BatteryWHperKMAccessor>, SwitchScreenAction<BatteryWHperKMChangeScreen>>>(); constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_BATTERY_WHKM, BatteryWHperKMAccessor>, SwitchScreenAction<BatteryWHperKMChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECT_CELL_TYPE>, SwitchScreenAction<BatteryTypeMenu>>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECT_CELL_TYPE>, SwitchScreenAction<BatteryTypeMenu>>>();
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>(); constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, WhStatisticsText, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_CALIBRATE>, SwitchScreenAction<CalibrateVoltageDisplay>, StaticMenuItemIcon<&bobbyicons::settings>>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERY_CALIBRATE>, SwitchScreenAction<CalibrateVoltageDisplay>, StaticMenuItemIcon<&bobbyicons::settings>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
} }
@@ -84,6 +96,13 @@ std::string BatteryMenu::text() const
return TEXT_BATTERY; return TEXT_BATTERY;
} }
void BatteryMenu::initScreen()
{
Base::initScreen();
m_batPercentBootLabel.start();
m_batPercentNowLabel.start();
}
void BatteryMenu::start() void BatteryMenu::start()
{ {
Base::start(); Base::start();
@@ -103,7 +122,16 @@ void BatteryMenu::redraw()
const auto batPercent = getBatteryPercentage(avgVoltage, BatteryCellType(configs.battery.cellType.value)); const auto batPercent = getBatteryPercentage(avgVoltage, BatteryCellType(configs.battery.cellType.value));
if (battery::bootBatPercentage) if (battery::bootBatPercentage)
{
m_doubleProgressBarBatPercentage.redraw(batPercent, *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() void BatteryMenu::back()

View File

@@ -3,6 +3,7 @@
// local includes // local includes
#include "displays/bobbymenudisplay.h" #include "displays/bobbymenudisplay.h"
#include "widgets/doubleprogressbar.h" #include "widgets/doubleprogressbar.h"
#include "widgets/label.h"
class BatteryMenu : public BobbyMenuDisplay class BatteryMenu : public BobbyMenuDisplay
{ {
@@ -13,10 +14,13 @@ public:
std::string text() const override; std::string text() const override;
void initScreen() override;
void start() override; void start() override;
void redraw() override; void redraw() override;
void back() override; void back() override;
private: private:
bobbygui::DoubleProgressBar m_doubleProgressBarBatPercentage{75, 68, 90, 24, 0, 100, TFT_RED, TFT_GREEN}; 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};
}; };

View File

@@ -31,6 +31,7 @@ NetworkSettingsMenu::NetworkSettingsMenu()
constructMenuItem<makeComponentArgs<MenuItem, DnsText, DummyAction>>(uint8_t{0}); constructMenuItem<makeComponentArgs<MenuItem, DnsText, DummyAction>>(uint8_t{0});
constructMenuItem<makeComponentArgs<MenuItem, DnsText, DummyAction>>(uint8_t{1}); constructMenuItem<makeComponentArgs<MenuItem, DnsText, DummyAction>>(uint8_t{1});
constructMenuItem<makeComponentArgs<MenuItem, DnsText, DummyAction>>(uint8_t{2}); constructMenuItem<makeComponentArgs<MenuItem, DnsText, DummyAction>>(uint8_t{2});
constructMenuItem<makeComponent<MenuItem, WifiTxPowerText, DummyAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<SettingsMenu>, StaticMenuItemIcon<&icons::back>>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<SettingsMenu>, StaticMenuItemIcon<&icons::back>>>();
} }

View File

@@ -12,10 +12,6 @@
#include "newsettings.h" #include "newsettings.h"
namespace espnow { namespace espnow {
namespace {
constexpr const char * const TAG = "BOBBY_ESP_NOW";
} // namespace
uint16_t lastYear; // Used for esp-now timesync uint16_t lastYear; // Used for esp-now timesync
std::deque<esp_now_message_t> message_queue{}; std::deque<esp_now_message_t> message_queue{};
@@ -25,6 +21,33 @@ uint8_t initialized{0};
bool receiveTimeStamp{true}; bool receiveTimeStamp{true};
bool receiveTsFromOtherBobbycars{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 { namespace {
extern "C" void onReceive(const uint8_t *mac_addr, const uint8_t *data, int data_len) 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 (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."); ESP_LOGW(TAG, "cannot execute esp_now_init(): tcp stack is down.");
return; return;
@@ -119,12 +142,12 @@ void initESPNow()
void handle() 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(); initESPNow();
return; 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) if (initialized > 0)
{ {
@@ -189,7 +212,7 @@ void handle()
if (msg.type == "T") if (msg.type == "T")
{ {
if (!receiveTimeStamp || !configs.espnow.syncTime.value) if (!receiveTimeStamp || !configs.espnow.syncTime.value)
return; goto clear;
if (const auto result = cpputils::fromString<uint64_t>(msg.content); result) if (const auto result = cpputils::fromString<uint64_t>(msg.content); result)
{ {
@@ -203,7 +226,7 @@ void handle()
else if (msg.type == "BOBBYT") else if (msg.type == "BOBBYT")
{ {
if (!receiveTsFromOtherBobbycars || !configs.espnow.syncTimeWithOthers.value) if (!receiveTsFromOtherBobbycars || !configs.espnow.syncTimeWithOthers.value)
return; goto clear;
if (const auto result = cpputils::fromString<uint64_t>(msg.content); result) if (const auto result = cpputils::fromString<uint64_t>(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()); 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));
} }
} }

View File

@@ -94,6 +94,9 @@ extern "C" void app_main()
{ {
const auto now = espchrono::millis_clock::now(); const auto now = espchrono::millis_clock::now();
// if (!heap_caps_check_integrity_all(true))
// ESP_LOGW(TAG, "OIS IM OARSCH!!!!!");
for (auto &schedulerTask : schedulerTasks) for (auto &schedulerTask : schedulerTasks)
{ {
schedulerTask.loop(); schedulerTask.loop();
@@ -124,7 +127,10 @@ extern "C" void app_main()
} }
avgVoltage = avgVoltage / controllers.size(); avgVoltage = avgVoltage / controllers.size();
if (avgVoltage > 30) if (avgVoltage > 30)
{
battery::bootBatPercentage = getBatteryPercentage(avgVoltage, BatteryCellType(configs.battery.cellType.value)); battery::bootBatPercentage = getBatteryPercentage(avgVoltage, BatteryCellType(configs.battery.cellType.value));
battery::bootBatWh = getRemainingWattHours();
}
} }
} }
} }

View File

@@ -557,6 +557,7 @@ public:
#define HELPER(x) callback(x); #define HELPER(x) callback(x);
NEW_SETTINGS(HELPER) NEW_SETTINGS(HELPER)
#undef HELPER #undef HELPER
callback(bleSettings.bleEnabled);
} }
auto getAllConfigParams() auto getAllConfigParams()

View File

@@ -40,3 +40,11 @@ std::string DnsText::text() const
text += wifi_stack::toString(*dns_ip); text += wifi_stack::toString(*dns_ip);
return text; 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 "";
}

View File

@@ -25,3 +25,9 @@ public:
private: private:
const uint8_t m_index; const uint8_t m_index;
}; };
class WifiTxPowerText : public virtual espgui::TextInterface
{
public:
std::string text() const override;
};