diff --git a/main/battery.cpp b/main/battery.cpp index 1a26210..f12d773 100644 --- a/main/battery.cpp +++ b/main/battery.cpp @@ -232,26 +232,32 @@ uint8_t count_curve_points(BatteryCellType cellType) case BatteryCellType::_22P: { BAT_CURVE_22P(COUNT_CURVE_POINTS); + break; } case BatteryCellType::HG2: { BAT_CURVE_HG2(COUNT_CURVE_POINTS); + break; } case BatteryCellType::MH1: { BAT_CURVE_MH1(COUNT_CURVE_POINTS); + break; } case BatteryCellType::VTC5: { BAT_CURVE_VTC5(COUNT_CURVE_POINTS); + break; } case BatteryCellType::BAK_25R: { BAT_CURVE_25R(COUNT_CURVE_POINTS); + break; } case BatteryCellType::HE4: { BAT_CURVE_HE4(COUNT_CURVE_POINTS); + break; } } return count; @@ -274,26 +280,32 @@ std::optional get_point_n_voltages(BatteryCellType cel case BatteryCellType::_22P: { BAT_CURVE_22P(GET_POINT_N_VOLTAGES); + break; } case BatteryCellType::HG2: { BAT_CURVE_HG2(GET_POINT_N_VOLTAGES); + break; } case BatteryCellType::MH1: { BAT_CURVE_MH1(GET_POINT_N_VOLTAGES); + break; } case BatteryCellType::VTC5: { BAT_CURVE_VTC5(GET_POINT_N_VOLTAGES); + break; } case BatteryCellType::BAK_25R: { BAT_CURVE_25R(GET_POINT_N_VOLTAGES); + break; } case BatteryCellType::HE4: { BAT_CURVE_HE4(GET_POINT_N_VOLTAGES); + break; } } return std::nullopt; diff --git a/main/battery.h b/main/battery.h index ac8c6f6..02846c1 100644 --- a/main/battery.h +++ b/main/battery.h @@ -32,6 +32,10 @@ if (cellVoltage >= lowerVoltage && cellVoltage <= higherVoltage) \ if (fromAh == 0) \ return higherVoltage * configs.battery.cellsSeries.value; + +// All curves here have to follow the same order (highest-voltage first) +// as some functions require this to display data in correct order + // 22P #define BAT_MIN_AH_22P 2.2 #define BAT_CURVE_22P(func) \ diff --git a/main/displays/batterygraphdisplay.cpp b/main/displays/batterygraphdisplay.cpp index 25261c7..8a5ea18 100644 --- a/main/displays/batterygraphdisplay.cpp +++ b/main/displays/batterygraphdisplay.cpp @@ -1,4 +1,5 @@ #include "batterygraphdisplay.h" +constexpr const char * const TAG = "BatteryGraphDisplay"; // 3rdparty lib includes #include @@ -8,14 +9,27 @@ #include "battery.h" #include "globals.h" #include "displays/menus/batterymenu.h" +#include "newsettings.h" namespace { constexpr char TEXT_BATTERY_GRAPH[] = "Battery Level"; + constexpr const uint8_t TOP_OFFSET = 40; } // namespace void BatteryGraphDisplay::initScreen() { Base::initScreen(); + const auto points = count_curve_points(configs.battery.cellType.value); + ESP_LOGI(TAG, "Battery graph points: %d, cell type: %s", points, toString(configs.battery.cellType.value).c_str()); + const auto available_space = espgui::tft.height() - TOP_OFFSET; + const uint16_t onePercent = espgui::tft.width() / 100; + 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) + { + // draw line between minVoltage and maxVoltage of point. When implemented, please contact @CommanderRedYT so that he can move and optimize the code + } + } } std::string BatteryGraphDisplay::text() const @@ -34,13 +48,13 @@ void BatteryGraphDisplay::redraw() return; const auto cellType = configs.battery.cellType.value; - uint16_t onePercent = tft.width() / 100; - uint16_t xOffset = onePercent * getBatteryPercentage(*avgVoltage, cellType); - uint16_t lastXOffset = onePercent * getBatteryPercentage(m_lastBatVoltage, cellType); + const uint16_t onePercent = tft.width() / 100; + const uint16_t xOffset = onePercent * getBatteryPercentage(*avgVoltage, cellType); + const uint16_t lastXOffset = onePercent * getBatteryPercentage(m_lastBatVoltage, cellType); // clear the old one and draw the new one - tft.fillRect(lastXOffset, 40, onePercent, tft.height() - 40, TFT_BLACK); - tft.fillRect(xOffset, 40, onePercent, tft.height() - 40, TFT_WHITE); + tft.fillRect(lastXOffset, TOP_OFFSET, onePercent, tft.height() - TOP_OFFSET, TFT_BLACK); + tft.fillRect(xOffset, TOP_OFFSET, onePercent, tft.height() - TOP_OFFSET, TFT_WHITE); m_lastBatVoltage = *avgVoltage; }