Added battery doubleprogressbar
This commit is contained in:
@ -192,6 +192,7 @@ set(headers
|
||||
webserver_ota.h
|
||||
webserver_settings.h
|
||||
webserver_stringsettings.h
|
||||
widgets/doubleprogressbar.h
|
||||
wifi_bobbycar.h
|
||||
wifitexthelpers.h
|
||||
)
|
||||
@ -391,6 +392,7 @@ set(sources
|
||||
webserver_ota.cpp
|
||||
webserver_settings.cpp
|
||||
webserver_stringsettings.cpp
|
||||
widgets/doubleprogressbar.cpp
|
||||
wifi_bobbycar.cpp
|
||||
wifitexthelpers.cpp
|
||||
)
|
||||
|
@ -193,3 +193,7 @@ std::string getBatteryDebugString()
|
||||
avgVoltage = avgVoltage / controllers.size();
|
||||
return fmt::format("{:.1f}V {}A", avgVoltage, sumCurrent);
|
||||
}
|
||||
|
||||
namespace battery {
|
||||
float bootBatPercentage{-1};
|
||||
}
|
||||
|
@ -32,3 +32,7 @@ std::string getBatteryAdvancedPercentageString();
|
||||
|
||||
float getPercentageByWh(float wh);
|
||||
float getTarget_mAh();
|
||||
|
||||
namespace battery {
|
||||
extern float bootBatPercentage;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "displays/calibratevoltagedisplay.h"
|
||||
#include "accessors/settingsaccessors.h"
|
||||
#include "fmt/core.h"
|
||||
#include "battery.h"
|
||||
|
||||
class CurrentBatteryStatusText : public virtual espgui::TextInterface { public: std::string text() const override { return getBatteryPercentageString(); } };
|
||||
|
||||
@ -37,6 +38,27 @@ using BatteryWHperKMChangeScreen = espgui::makeComponent<
|
||||
|
||||
using namespace espgui;
|
||||
|
||||
void BatteryMenu::start()
|
||||
{
|
||||
Base::start();
|
||||
m_doubleProgressBarBatPercentage.start();
|
||||
}
|
||||
|
||||
void BatteryMenu::redraw()
|
||||
{
|
||||
Base::redraw();
|
||||
|
||||
float avgVoltage = 0;
|
||||
for (auto &controller : controllers)
|
||||
{
|
||||
avgVoltage += controller.getCalibratedVoltage();
|
||||
}
|
||||
avgVoltage = avgVoltage / controllers.size();
|
||||
|
||||
const auto batPercent = getBatteryPercentage(avgVoltage, BatteryCellType(settings.battery.cellType));
|
||||
m_doubleProgressBarBatPercentage.redraw(batPercent, battery::bootBatPercentage);
|
||||
}
|
||||
|
||||
BatteryMenu::BatteryMenu()
|
||||
{
|
||||
constructMenuItem<makeComponent<MenuItem, CurrentBatteryStatusText, DisabledColor, DummyAction>>();
|
||||
|
@ -13,13 +13,19 @@
|
||||
#include "texts.h"
|
||||
#include "battery.h"
|
||||
#include "selectbatterytypemenu.h"
|
||||
#include "widgets/doubleprogressbar.h"
|
||||
|
||||
class BatteryMenu :
|
||||
public espgui::MenuDisplay,
|
||||
public espgui::StaticText<TEXT_BATTERY>
|
||||
{
|
||||
using Base = espgui::MenuDisplay;
|
||||
public:
|
||||
BatteryMenu();
|
||||
|
||||
void start() override;
|
||||
void redraw() override;
|
||||
void back() override;
|
||||
private:
|
||||
bobbygui::DoubleProgressBar m_doubleProgressBarBatPercentage{75, 68, 90, 24, 0, 100, TFT_RED, TFT_GREEN};
|
||||
};
|
||||
|
@ -456,5 +456,19 @@ extern "C" void app_main()
|
||||
if (settings.cloudSettings.udpCloudEnabled)
|
||||
sendUdpCloudPacket();
|
||||
#endif
|
||||
if (battery::bootBatPercentage == -1)
|
||||
{
|
||||
if(controllers.front.feedbackValid && controllers.back.feedbackValid)
|
||||
{
|
||||
float avgVoltage = 0;
|
||||
for (auto &controller : controllers)
|
||||
{
|
||||
avgVoltage += controller.getCalibratedVoltage();
|
||||
}
|
||||
avgVoltage = avgVoltage / controllers.size();
|
||||
if (avgVoltage > 30)
|
||||
battery::bootBatPercentage = getBatteryPercentage(avgVoltage, BatteryCellType(settings.battery.cellType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ esp_err_t webserver_status_handler(httpd_req_t *req)
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "%.*s", result.error().size(), result.error().data());
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", result.error());
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ esp_err_t webserver_status_handler(httpd_req_t *req)
|
||||
{
|
||||
if (!menuDisplayChanged())
|
||||
{
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, "text/plain", "Ok.");
|
||||
}
|
||||
else
|
||||
@ -163,7 +163,7 @@ esp_err_t webserver_status_handler(httpd_req_t *req)
|
||||
}
|
||||
else
|
||||
{
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", "");
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req)
|
||||
const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256);
|
||||
if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty()))
|
||||
{
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
body += "{";
|
||||
if (auto currentDisplay = static_cast<const espgui::Display *>(espgui::currentDisplay.get()))
|
||||
{
|
||||
@ -219,7 +219,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req)
|
||||
|
||||
esp_err_t webserver_triggerButton_handler(httpd_req_t *req)
|
||||
{
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
#ifdef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_FUNKTIONIERT
|
||||
espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil<espcpputils::ticks>(5s).count()};
|
||||
if (!helper.locked())
|
||||
@ -338,7 +338,7 @@ esp_err_t webserver_triggerButton_handler(httpd_req_t *req)
|
||||
|
||||
esp_err_t webserver_triggerItem_handler(httpd_req_t *req)
|
||||
{
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
#ifdef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_FUNKTIONIERT
|
||||
espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil<espcpputils::ticks>(5s).count()};
|
||||
if (!helper.locked())
|
||||
@ -427,7 +427,7 @@ esp_err_t webserver_triggerItem_handler(httpd_req_t *req)
|
||||
|
||||
esp_err_t webserver_setValue_handler(httpd_req_t *req)
|
||||
{
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
#ifdef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_FUNKTIONIERT
|
||||
espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil<espcpputils::ticks>(5s).count()};
|
||||
if (!helper.locked())
|
||||
|
@ -113,7 +113,7 @@ showInputForSetting(std::string_view key, T value, JsonObject &body)
|
||||
|
||||
esp_err_t webserver_dump_nvs_handler(httpd_req_t *req)
|
||||
{
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
#ifdef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_FUNKTIONIERT
|
||||
espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil<espcpputils::ticks>(5s).count()};
|
||||
if (!helper.locked())
|
||||
|
@ -35,7 +35,7 @@ esp_err_t webserver_ota_percentage_handler(httpd_req_t *req)
|
||||
}
|
||||
|
||||
char tmpBuf[256];
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256);
|
||||
if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty()))
|
||||
{
|
||||
@ -97,7 +97,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req)
|
||||
const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256);
|
||||
if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty()))
|
||||
{
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
body += "{";
|
||||
|
||||
if (const esp_app_desc_t *app_desc = esp_ota_get_app_description())
|
||||
@ -157,7 +157,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req)
|
||||
}
|
||||
else if (key_result != ESP_ERR_NOT_FOUND && tmpBuf != stringSettings.webserver_password)
|
||||
{
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", "");
|
||||
}
|
||||
else
|
||||
|
42
main/widgets/doubleprogressbar.cpp
Normal file
42
main/widgets/doubleprogressbar.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "doubleprogressbar.h"
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <cpputils.h>
|
||||
|
||||
// local includes
|
||||
#include "tftinstance.h"
|
||||
|
||||
using namespace espgui;
|
||||
|
||||
namespace bobbygui {
|
||||
DoubleProgressBar::DoubleProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color1, uint32_t color2) :
|
||||
m_x{x}, m_y{y}, m_width{width}, m_height{height}, m_min{min}, m_max{max}, m_color1{color1}, m_color2{color2}
|
||||
{
|
||||
}
|
||||
|
||||
void DoubleProgressBar::start()
|
||||
{
|
||||
m_lastValue1 = m_x+1;
|
||||
m_lastValue2 = m_x+1;
|
||||
tft.drawRect(m_x, m_y, m_width, m_height, TFT_WHITE);
|
||||
}
|
||||
|
||||
void DoubleProgressBar::redraw(int value1, int value2)
|
||||
{
|
||||
value1 = cpputils::mapValueClamped(value1, m_min, m_max, m_x+1, m_x+m_width-1);
|
||||
value2 = cpputils::mapValueClamped(value2, m_min, m_max, m_x+1, m_x+m_width-1);
|
||||
|
||||
if (value1 < m_lastValue1)
|
||||
tft.fillRect(value1, m_y+1, m_lastValue1-value1, (m_height-2) / 2, TFT_BLACK);
|
||||
else if (value1 > m_lastValue1)
|
||||
tft.fillRect(m_lastValue1, m_y+1, value1-m_lastValue1, (m_height-2) / 2, m_color1);
|
||||
|
||||
if (value2 < m_lastValue2)
|
||||
tft.fillRect(value2, m_y+1+(m_height-2)/2, m_lastValue2-value2, (m_height-2) / 2, TFT_BLACK);
|
||||
else if (value2 > m_lastValue2)
|
||||
tft.fillRect(m_lastValue2, m_y+1+(m_height-2)/2, value2-m_lastValue2, (m_height-2) / 2, m_color2);
|
||||
|
||||
m_lastValue1 = value1;
|
||||
m_lastValue2 = value2;
|
||||
}
|
||||
} // namespace bobbygui
|
31
main/widgets/doubleprogressbar.h
Normal file
31
main/widgets/doubleprogressbar.h
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <cstdint>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <TFT_eSPI.h>
|
||||
|
||||
namespace bobbygui {
|
||||
class DoubleProgressBar
|
||||
{
|
||||
public:
|
||||
DoubleProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color1=TFT_YELLOW, uint32_t color2=TFT_YELLOW);
|
||||
|
||||
void start();
|
||||
void redraw(int value1, int value2);
|
||||
|
||||
private:
|
||||
const int m_x;
|
||||
const int m_y;
|
||||
const int m_width;
|
||||
const int m_height;
|
||||
const int m_min;
|
||||
const int m_max;
|
||||
const uint32_t m_color1;
|
||||
const uint32_t m_color2;
|
||||
|
||||
int m_lastValue1{};
|
||||
int m_lastValue2{};
|
||||
};
|
||||
} // namespace espgui
|
Reference in New Issue
Block a user