From 7f6fa967c8ecd54de81d741a1307b7142e1f16b0 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Mon, 28 Feb 2022 01:08:13 +0100 Subject: [PATCH] Added some more code --- main/battery.cpp | 42 +++++++++++++++++++++++++++ main/battery.h | 7 +++++ main/displays/batterygraphdisplay.cpp | 13 +++++++-- main/displays/batterygraphdisplay.h | 2 -- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/main/battery.cpp b/main/battery.cpp index e8cdfff..1a26210 100644 --- a/main/battery.cpp +++ b/main/battery.cpp @@ -257,6 +257,48 @@ uint8_t count_curve_points(BatteryCellType cellType) return count; } +std::optional get_point_n_voltages(BatteryCellType cellType, uint8_t num) +{ + #define GET_POINT_N_VOLTAGES(higherVoltage,lowerVoltage,fromAh,toAh) \ + if (count == num) { \ + uint16_t minVoltage = (lowerVoltage) * 100; \ + uint16_t maxVoltage = (higherVoltage) * 100; \ + return CalibrationPointVoltages{ .minVoltage=minVoltage, .maxVoltage=maxVoltage }; \ + } \ + count++; + + uint8_t count = 0; + CalibrationPointVoltages point; + switch (cellType) + { + case BatteryCellType::_22P: + { + BAT_CURVE_22P(GET_POINT_N_VOLTAGES); + } + case BatteryCellType::HG2: + { + BAT_CURVE_HG2(GET_POINT_N_VOLTAGES); + } + case BatteryCellType::MH1: + { + BAT_CURVE_MH1(GET_POINT_N_VOLTAGES); + } + case BatteryCellType::VTC5: + { + BAT_CURVE_VTC5(GET_POINT_N_VOLTAGES); + } + case BatteryCellType::BAK_25R: + { + BAT_CURVE_25R(GET_POINT_N_VOLTAGES); + } + case BatteryCellType::HE4: + { + BAT_CURVE_HE4(GET_POINT_N_VOLTAGES); + } + } + return std::nullopt; +} + namespace battery { std::optional bootBatPercentage; std::optional bootBatWh; diff --git a/main/battery.h b/main/battery.h index cc92dee..ac8c6f6 100644 --- a/main/battery.h +++ b/main/battery.h @@ -6,6 +6,11 @@ // local includes #include +typedef struct { + uint16_t minVoltage; + uint16_t maxVoltage; +} CalibrationPointVoltages; + // battery curves #define PERCENTAGE(higherVoltage,lowerVoltage,fromAh,toAh) \ if (cellVoltage >= lowerVoltage && cellVoltage <= higherVoltage) \ @@ -150,6 +155,8 @@ float getTarget_mAh(); uint8_t count_curve_points(BatteryCellType cellType); +std::optional get_point_n_voltages(BatteryCellType cellType, uint8_t num); + namespace battery { extern std::optional bootBatPercentage; extern std::optional bootBatWh; diff --git a/main/displays/batterygraphdisplay.cpp b/main/displays/batterygraphdisplay.cpp index 9f699ba..ff63cb1 100644 --- a/main/displays/batterygraphdisplay.cpp +++ b/main/displays/batterygraphdisplay.cpp @@ -4,22 +4,29 @@ #include // local includes +#include "globals.h" #include "displays/menus/batterymenu.h" namespace { constexpr char TEXT_BATTERY_GRAPH[] = "Battery Level"; } // namespace -void BatteryGraphDisplay::initScreen() { +void BatteryGraphDisplay::initScreen() +{ Base::initScreen(); } -std::string BatteryGraphDisplay::text() const { +std::string BatteryGraphDisplay::text() const +{ return TEXT_BATTERY_GRAPH; } -void BatteryGraphDisplay::redraw() { +void BatteryGraphDisplay::redraw() +{ + using namespace espgui; Base::redraw(); + + // tft.drawLine() code } void BatteryGraphDisplay::buttonPressed(espgui::Button button) diff --git a/main/displays/batterygraphdisplay.h b/main/displays/batterygraphdisplay.h index 1e08061..d481b8f 100644 --- a/main/displays/batterygraphdisplay.h +++ b/main/displays/batterygraphdisplay.h @@ -1,7 +1,5 @@ #pragma once -// 3rdparty lib includes - // local includes #include "bobbydisplaywithtitle.h"