Merge pull request #283 from bobbycar-graz/error-handling
This commit is contained in:
@ -271,7 +271,6 @@ std::optional<CalibrationPointVoltages> get_point_n_voltages(BatteryCellType cel
|
|||||||
count++;
|
count++;
|
||||||
|
|
||||||
uint8_t count = 0;
|
uint8_t count = 0;
|
||||||
CalibrationPointVoltages point;
|
|
||||||
switch (cellType)
|
switch (cellType)
|
||||||
{
|
{
|
||||||
case BatteryCellType::_22P:
|
case BatteryCellType::_22P:
|
||||||
|
@ -11,6 +11,7 @@ constexpr const char * const TAG = "BatteryGraphDisplay";
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "newsettings.h"
|
#include "newsettings.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "actions/bluetoothbeginmasteraction.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr char TEXT_BATTERY_GRAPH[] = "Battery Level";
|
constexpr char TEXT_BATTERY_GRAPH[] = "Battery Level";
|
||||||
@ -20,29 +21,15 @@ namespace {
|
|||||||
void BatteryGraphDisplay::initScreen()
|
void BatteryGraphDisplay::initScreen()
|
||||||
{
|
{
|
||||||
Base::initScreen();
|
Base::initScreen();
|
||||||
const auto points = count_curve_points(configs.battery.cellType.value);
|
drawBatteryCurve();
|
||||||
const auto max_height = espgui::tft.height() - 1;
|
|
||||||
const auto max_width = espgui::tft.width() - 4;
|
|
||||||
const uint16_t part = max_width / points;
|
|
||||||
const auto min_voltage = getMinBatCellVoltage(configs.battery.cellType.value);
|
|
||||||
const auto max_voltage = getMaxBatCellVoltage(configs.battery.cellType.value);
|
|
||||||
ESP_LOGI(TAG, "min_voltage: %f, max_voltage: %f", min_voltage, max_voltage);
|
|
||||||
for (uint8_t i = 0; points >= i; i++) {
|
|
||||||
// draw lines between point->minVoltage and point->maxVoltage from left to right
|
|
||||||
if (const auto point = get_point_n_voltages(configs.battery.cellType.value, points - i); point)
|
|
||||||
{
|
|
||||||
const int x1 = 2 + part * (points - i + 1);
|
|
||||||
const int y1 = float_map(point->minVoltage / 100.f, min_voltage, max_voltage, max_height, TOP_OFFSET);
|
|
||||||
const int x2 = 2 + part * (points - i);
|
|
||||||
const int y2 = float_map(point->maxVoltage / 100.f, min_voltage, max_voltage, max_height, TOP_OFFSET);
|
|
||||||
espgui::tft.drawLine(x1, y1, x2, y2, TFT_WHITE);
|
|
||||||
ESP_LOGI(TAG, "espgui::tft.drawLine(%d, %d, %d, %d, TFT_WHITE);", x1, y1, x2, y2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BatteryGraphDisplay::text() const
|
std::string BatteryGraphDisplay::text() const
|
||||||
{
|
{
|
||||||
|
if (const auto avgVoltage = controllers.getAvgVoltage(); avgVoltage)
|
||||||
|
{
|
||||||
|
return fmt::format("{} ({:.1f}%)", TEXT_BATTERY_GRAPH, getBatteryPercentage(*avgVoltage, configs.battery.cellType.value));
|
||||||
|
}
|
||||||
return TEXT_BATTERY_GRAPH;
|
return TEXT_BATTERY_GRAPH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,16 +44,17 @@ void BatteryGraphDisplay::redraw()
|
|||||||
return;
|
return;
|
||||||
const auto cellType = configs.battery.cellType.value;
|
const auto cellType = configs.battery.cellType.value;
|
||||||
|
|
||||||
const uint16_t onePercent = tft.width() / 100;
|
const float onePercent = (tft.width() - 4) / 100.f;
|
||||||
const uint16_t xOffset = onePercent * getBatteryPercentage(*avgVoltage, cellType);
|
const auto percentage = getBatteryPercentage(*avgVoltage, cellType);
|
||||||
const uint16_t lastXOffset = onePercent * getBatteryPercentage(m_lastBatVoltage, cellType);
|
const uint16_t xOffset = onePercent * (100 - percentage);
|
||||||
|
const uint16_t lastXOffset = onePercent * (100 - getBatteryPercentage(m_lastBatVoltage, cellType));
|
||||||
|
|
||||||
// clear the old one and draw the new one
|
// clear the old one and draw the new one
|
||||||
tft.fillRect(lastXOffset, TOP_OFFSET, onePercent, tft.height() - TOP_OFFSET, TFT_BLACK);
|
tft.fillRect(lastXOffset + 2, TOP_OFFSET, onePercent, tft.height() - TOP_OFFSET, TFT_BLACK);
|
||||||
tft.fillRect(xOffset, TOP_OFFSET, onePercent, tft.height() - TOP_OFFSET, TFT_WHITE);
|
tft.fillRect(xOffset + 2, TOP_OFFSET, onePercent, tft.height() - TOP_OFFSET, TFT_WHITE);
|
||||||
m_lastBatVoltage = *avgVoltage;
|
m_lastBatVoltage = *avgVoltage;
|
||||||
|
drawBatteryCurve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// tft.drawLine() code
|
// tft.drawLine() code
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,3 +72,24 @@ void BatteryGraphDisplay::buttonPressed(espgui::Button button)
|
|||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BatteryGraphDisplay::drawBatteryCurve()
|
||||||
|
{
|
||||||
|
const auto points = count_curve_points(configs.battery.cellType.value);
|
||||||
|
const auto max_height = espgui::tft.height() - 1;
|
||||||
|
const auto max_width = espgui::tft.width() - 4;
|
||||||
|
const uint16_t part = max_width / points;
|
||||||
|
const auto min_voltage = getMinBatCellVoltage(configs.battery.cellType.value);
|
||||||
|
const auto max_voltage = getMaxBatCellVoltage(configs.battery.cellType.value);
|
||||||
|
for (uint8_t i = 0; points >= i; i++) {
|
||||||
|
// draw lines between point->minVoltage and point->maxVoltage from left to right
|
||||||
|
if (const auto point = get_point_n_voltages(configs.battery.cellType.value, points - i); point)
|
||||||
|
{
|
||||||
|
const int x1 = 2 + part * (points - i + 1);
|
||||||
|
const int y1 = float_map(point->minVoltage / 100.f, min_voltage, max_voltage, max_height, TOP_OFFSET);
|
||||||
|
const int x2 = 2 + part * (points - i);
|
||||||
|
const int y2 = float_map(point->maxVoltage / 100.f, min_voltage, max_voltage, max_height, TOP_OFFSET);
|
||||||
|
espgui::tft.drawLine(x1, y1, x2, y2, TFT_WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -13,6 +13,8 @@ public:
|
|||||||
|
|
||||||
void buttonPressed(espgui::Button button) override;
|
void buttonPressed(espgui::Button button) override;
|
||||||
|
|
||||||
|
static void drawBatteryCurve();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float m_lastBatVoltage{0};
|
float m_lastBatVoltage{0};
|
||||||
};
|
};
|
||||||
|
@ -6,12 +6,11 @@
|
|||||||
// local includes
|
// local includes
|
||||||
#include "actions/dummyaction.h"
|
#include "actions/dummyaction.h"
|
||||||
#include "actions/switchscreenaction.h"
|
#include "actions/switchscreenaction.h"
|
||||||
|
#include "bobbyerrorhandler.h"
|
||||||
#include "buildserver.h"
|
#include "buildserver.h"
|
||||||
#include "displays/menus/otamenu.h"
|
#include "displays/menus/otamenu.h"
|
||||||
#include "globals.h"
|
|
||||||
#include "icons/back.h"
|
#include "icons/back.h"
|
||||||
#include "icons/reboot.h"
|
#include "icons/reboot.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "newsettings.h"
|
#include "newsettings.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -124,7 +123,7 @@ void SelectBuildserverBranchMenu::update()
|
|||||||
check_descriptor_request();
|
check_descriptor_request();
|
||||||
if (!request_failed.empty())
|
if (!request_failed.empty())
|
||||||
{
|
{
|
||||||
this->buildMenuRequestError(request_failed);
|
BobbyErrorHandler{}.errorOccured(fmt::format("Error: {}", request_failed));
|
||||||
request_failed = {};
|
request_failed = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,12 +153,3 @@ void SelectBuildserverBranchMenu::back()
|
|||||||
{
|
{
|
||||||
espgui::switchScreen<OtaMenu>();
|
espgui::switchScreen<OtaMenu>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectBuildserverBranchMenu::buildMenuRequestError(std::string error)
|
|
||||||
{
|
|
||||||
using namespace espgui;
|
|
||||||
|
|
||||||
auto &item = constructMenuItem<makeComponent<MenuItem, ChangeableText, DefaultFont, StaticColor<TFT_RED>, DummyAction>>();
|
|
||||||
item.setTitle(error);
|
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<OtaMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
|
||||||
}
|
|
||||||
|
@ -11,7 +11,6 @@ public:
|
|||||||
|
|
||||||
std::string text() const override;
|
std::string text() const override;
|
||||||
|
|
||||||
void buildMenuRequestError(std::string error);
|
|
||||||
void update() override;
|
void update() override;
|
||||||
void back() override;
|
void back() override;
|
||||||
};
|
};
|
||||||
|
@ -6,13 +6,12 @@
|
|||||||
#include "fmt/core.h"
|
#include "fmt/core.h"
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "buildserver.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "actions/dummyaction.h"
|
#include "actions/dummyaction.h"
|
||||||
#include "actions/switchscreenaction.h"
|
#include "actions/switchscreenaction.h"
|
||||||
#include "icons/back.h"
|
#include "bobbyerrorhandler.h"
|
||||||
|
#include "buildserver.h"
|
||||||
#include "displays/menus/otamenu.h"
|
#include "displays/menus/otamenu.h"
|
||||||
#include "globals.h"
|
#include "icons/back.h"
|
||||||
#include "newsettings.h"
|
#include "newsettings.h"
|
||||||
|
|
||||||
#define MESSAGE(text) constructMenuItem<makeComponent<MenuItem, StaticText<text>, DefaultFont, StaticColor<TFT_RED>, DummyAction>>()
|
#define MESSAGE(text) constructMenuItem<makeComponent<MenuItem, StaticText<text>, DefaultFont, StaticColor<TFT_RED>, DummyAction>>()
|
||||||
@ -108,7 +107,7 @@ void SelectBuildMenu::update()
|
|||||||
check_descriptor_request();
|
check_descriptor_request();
|
||||||
if (!request_failed.empty())
|
if (!request_failed.empty())
|
||||||
{
|
{
|
||||||
this->buildMenuRequestError(request_failed);
|
BobbyErrorHandler{}.errorOccured(fmt::format("Error: {}", request_failed));
|
||||||
request_failed = {};
|
request_failed = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,13 +138,6 @@ void SelectBuildMenu::buildMenuFromJson()
|
|||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<OtaMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<OtaMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectBuildMenu::buildMenuRequestError(std::string error)
|
|
||||||
{
|
|
||||||
auto &item = constructMenuItem<makeComponent<MenuItem, ChangeableText, DefaultFont, StaticColor<TFT_RED>, DummyAction>>();
|
|
||||||
item.setTitle(error);
|
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<OtaMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SelectBuildMenu::back()
|
void SelectBuildMenu::back()
|
||||||
{
|
{
|
||||||
switchScreen<OtaMenu>();
|
switchScreen<OtaMenu>();
|
||||||
|
@ -17,5 +17,4 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void buildMenuFromJson();
|
void buildMenuFromJson();
|
||||||
void buildMenuRequestError(std::string error);
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user