Merge pull request #229 from bobbycar-graz/cleanup
This commit is contained in:
1
.github/workflows/analysis.yml
vendored
1
.github/workflows/analysis.yml
vendored
@ -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:
|
||||
|
1
.github/workflows/userconfigs.yml
vendored
1
.github/workflows/userconfigs.yml
vendored
@ -8,7 +8,6 @@ on:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
environment: Userconfigs
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
|
@ -197,4 +197,5 @@ std::string getBatteryDebugString()
|
||||
|
||||
namespace battery {
|
||||
std::optional<float> bootBatPercentage;
|
||||
std::optional<float> bootBatWh;
|
||||
}
|
||||
|
@ -35,4 +35,5 @@ float getTarget_mAh();
|
||||
|
||||
namespace battery {
|
||||
extern std::optional<float> bootBatPercentage;
|
||||
extern std::optional<float> bootBatWh;
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <textwithvaluehelper.h>
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include <tftinstance.h>
|
||||
|
||||
// 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<uint8_t>,
|
||||
@ -64,10 +75,10 @@ using BatteryWHperKMChangeScreen = espgui::makeComponent<
|
||||
>;
|
||||
} // namespace
|
||||
|
||||
using namespace espgui;
|
||||
|
||||
BatteryMenu::BatteryMenu()
|
||||
{
|
||||
using namespace espgui;
|
||||
|
||||
constructMenuItem<makeComponent<MenuItem, CurrentBatteryStatusText, DisabledColor, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
||||
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, StaticText<TEXT_SELECT_CELL_TYPE>, SwitchScreenAction<BatteryTypeMenu>>>();
|
||||
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_BACK>, SwitchScreenAction<MainMenu>, 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()
|
||||
|
@ -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};
|
||||
};
|
||||
|
@ -31,6 +31,7 @@ NetworkSettingsMenu::NetworkSettingsMenu()
|
||||
constructMenuItem<makeComponentArgs<MenuItem, DnsText, DummyAction>>(uint8_t{0});
|
||||
constructMenuItem<makeComponentArgs<MenuItem, DnsText, DummyAction>>(uint8_t{1});
|
||||
constructMenuItem<makeComponentArgs<MenuItem, DnsText, DummyAction>>(uint8_t{2});
|
||||
constructMenuItem<makeComponent<MenuItem, WifiTxPowerText, DummyAction>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<SettingsMenu>, StaticMenuItemIcon<&icons::back>>>();
|
||||
}
|
||||
|
||||
|
@ -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<esp_now_message_t> 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<uint64_t>(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<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());
|
||||
}
|
||||
}
|
||||
message_queue.clear();
|
||||
clear:
|
||||
message_queue.erase(std::begin(message_queue), std::end(message_queue));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -557,6 +557,7 @@ public:
|
||||
#define HELPER(x) callback(x);
|
||||
NEW_SETTINGS(HELPER)
|
||||
#undef HELPER
|
||||
callback(bleSettings.bleEnabled);
|
||||
}
|
||||
|
||||
auto getAllConfigParams()
|
||||
|
@ -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 "";
|
||||
}
|
||||
|
@ -25,3 +25,9 @@ public:
|
||||
private:
|
||||
const uint8_t m_index;
|
||||
};
|
||||
|
||||
class WifiTxPowerText : public virtual espgui::TextInterface
|
||||
{
|
||||
public:
|
||||
std::string text() const override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user