Implemented a tesla like performance bar
This commit is contained in:
@ -20,7 +20,6 @@ using BremsGraphDisplay = makeComponent<GraphDisplay<1>, StaticText<TEXT_BREMS>,
|
||||
using AvgSpeedGraphDisplay = makeComponent<GraphDisplay<1>, StaticText<TEXT_AVGSPEED>, MultiStatisticsSingleImpl, AvgSpeedStatistics>;
|
||||
using AvgSpeedKmhGraphDisplay = makeComponent<GraphDisplay<1>, StaticText<TEXT_AVGSPEEDKMH>, MultiStatisticsSingleImpl, AvgSpeedKmhStatistics>;
|
||||
using SumCurrentGraphDisplay = makeComponent<GraphDisplay<1>, StaticText<TEXT_SUMCURRENT>, MultiStatisticsSingleImpl, SumCurrentStatistics>;
|
||||
using SumAbsoluteCurrentGraphDisplay = makeComponent<GraphDisplay<1>, StaticText<TEXT_SUMABSOLUTECURRENT>, MultiStatisticsSingleImpl, SumAbsoluteCurrentStatistics>;
|
||||
using FrontVoltageGraphDisplay = makeComponent<GraphDisplay<1>, StaticText<TEXT_FRONTVOLTAGE>, MultiStatisticsSingleImpl, FrontVoltageStatistics>;
|
||||
using BackVoltageGraphDisplay = makeComponent<GraphDisplay<1>, StaticText<TEXT_BACKVOLTAGE>, MultiStatisticsSingleImpl, BackVoltageStatistics>;
|
||||
#ifdef FEATURE_BMS
|
||||
@ -57,7 +56,6 @@ class GraphsMenu :
|
||||
makeComponent<MenuItem, StaticText<TEXT_AVGSPEED>, SwitchScreenAction<AvgSpeedGraphDisplay>>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_AVGSPEEDKMH>, SwitchScreenAction<AvgSpeedKmhGraphDisplay>>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_SUMCURRENT>, SwitchScreenAction<SumCurrentGraphDisplay>>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_SUMABSOLUTECURRENT>, SwitchScreenAction<SumAbsoluteCurrentGraphDisplay>>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_FRONTVOLTAGE>, SwitchScreenAction<FrontVoltageGraphDisplay>>,
|
||||
makeComponent<MenuItem, StaticText<TEXT_BACKVOLTAGE>, SwitchScreenAction<BackVoltageGraphDisplay>>,
|
||||
#ifdef FEATURE_BMS
|
||||
|
@ -8,6 +8,9 @@
|
||||
#include "actions/switchscreenaction.h"
|
||||
#include "globals.h"
|
||||
#include "utils.h"
|
||||
#include "widgets/label.h"
|
||||
#include "widgets/reverseprogressbar.h"
|
||||
#include "widgets/progressbar.h"
|
||||
#include "widgets/verticalmeter.h"
|
||||
#include "widgets/vumeter.h"
|
||||
|
||||
@ -29,14 +32,19 @@ public:
|
||||
private:
|
||||
VuMeter m_vuMeter;
|
||||
|
||||
ReverseProgressBar m_dischargingBar{10, 135, 90, 15, 0, 40, TFT_GREEN};
|
||||
ProgressBar m_chargingBar{100, 135, 90, 15, 0, 40, TFT_RED};
|
||||
|
||||
Label m_sumCurrentLabel{195,135};
|
||||
|
||||
static constexpr auto x = 40;
|
||||
std::array<VerticalMeter, 6> meters{{
|
||||
VerticalMeter{"U f", 0*x, 160},
|
||||
VerticalMeter{"U b", 1*x, 160},
|
||||
VerticalMeter{"Ivl", 2*x, 160},
|
||||
VerticalMeter{"Ivr", 3*x, 160},
|
||||
VerticalMeter{"Ihl", 4*x, 160},
|
||||
VerticalMeter{"Ihr", 5*x, 160}
|
||||
VerticalMeter{"U f", "%.1fV", 0*x, 160},
|
||||
VerticalMeter{"U b", "%.1fV", 1*x, 160},
|
||||
VerticalMeter{"Ivl", "%.1fA", 2*x, 160},
|
||||
VerticalMeter{"Ivr", "%.1fA", 3*x, 160},
|
||||
VerticalMeter{"Ihl", "%.1fA", 4*x, 160},
|
||||
VerticalMeter{"Ihr", "%.1fA", 5*x, 160}
|
||||
}};
|
||||
};
|
||||
|
||||
@ -46,6 +54,11 @@ void MetersDisplay::initScreen()
|
||||
|
||||
m_vuMeter.start();
|
||||
|
||||
m_dischargingBar.start();
|
||||
m_chargingBar.start();
|
||||
|
||||
m_sumCurrentLabel.start();
|
||||
|
||||
for (auto &meter : meters)
|
||||
meter.start();
|
||||
}
|
||||
@ -54,6 +67,13 @@ void MetersDisplay::redraw()
|
||||
{
|
||||
m_vuMeter.redraw(avgSpeedKmh);
|
||||
|
||||
m_dischargingBar.redraw(sumCurrent<0.f?(-sumCurrent):0.f);
|
||||
m_chargingBar.redraw(sumCurrent>0.f?sumCurrent:0.f);
|
||||
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
tft.setTextFont(2);
|
||||
m_sumCurrentLabel.redraw(toString(sumCurrent) + 'A');
|
||||
|
||||
meters[0].redraw(fixBatVoltage(controllers.front.feedback.batVoltage), 35, 50);
|
||||
meters[1].redraw(fixBatVoltage(controllers.back.feedback.batVoltage), 35, 50);
|
||||
meters[2].redraw(fixCurrent(controllers.front.feedback.left.current), -10, 10);
|
||||
|
@ -21,7 +21,7 @@ float gas, brems;
|
||||
int16_t raw_gametrakX, raw_gametrakY, raw_gametrakDist;
|
||||
float gametrakX, gametrakY, gametrakDist;
|
||||
#endif
|
||||
float avgSpeed, avgSpeedKmh, sumCurrent, sumAbsoluteCurrent;
|
||||
float avgSpeed, avgSpeedKmh, sumCurrent;
|
||||
|
||||
char deviceName[32];
|
||||
|
||||
|
@ -195,7 +195,6 @@ union X {
|
||||
AvgSpeedGraphDisplay avgSpeedGraphDisplay;
|
||||
AvgSpeedKmhGraphDisplay avgSpeedKmhGraphDisplay;
|
||||
SumCurrentGraphDisplay sumCurrentGraphDisplay;
|
||||
SumAbsoluteCurrentGraphDisplay sumAbsoluteCurrentGraphDisplay;
|
||||
FrontVoltageGraphDisplay frontVoltageGraphDisplay;
|
||||
BackVoltageGraphDisplay backVoltageGraphDisplay;
|
||||
#ifdef FEATURE_BMS
|
||||
@ -348,7 +347,6 @@ template<> decltype(displays.bremsGraphDisplay) &
|
||||
template<> decltype(displays.avgSpeedGraphDisplay) &getRefByType<decltype(displays.avgSpeedGraphDisplay)>() { return displays.avgSpeedGraphDisplay; }
|
||||
template<> decltype(displays.avgSpeedKmhGraphDisplay) &getRefByType<decltype(displays.avgSpeedKmhGraphDisplay)>() { return displays.avgSpeedKmhGraphDisplay; }
|
||||
template<> decltype(displays.sumCurrentGraphDisplay) &getRefByType<decltype(displays.sumCurrentGraphDisplay)>() { return displays.sumCurrentGraphDisplay; }
|
||||
template<> decltype(displays.sumAbsoluteCurrentGraphDisplay) &getRefByType<decltype(displays.sumAbsoluteCurrentGraphDisplay)>() { return displays.sumAbsoluteCurrentGraphDisplay; }
|
||||
template<> decltype(displays.frontVoltageGraphDisplay) &getRefByType<decltype(displays.frontVoltageGraphDisplay)>() { return displays.frontVoltageGraphDisplay; }
|
||||
template<> decltype(displays.backVoltageGraphDisplay) &getRefByType<decltype(displays.backVoltageGraphDisplay)>() { return displays.backVoltageGraphDisplay; }
|
||||
#ifdef FEATURE_BMS
|
||||
|
@ -9,7 +9,7 @@
|
||||
namespace {
|
||||
namespace statistics {
|
||||
using ContainerType = ring_buffer<float, 200>;
|
||||
ContainerType gas, brems, avgSpeed, avgSpeedKmh, sumCurrent, sumAbsoluteCurrent, frontVoltage, backVoltage, frontLeftCurrent, frontRightCurrent, backLeftCurrent, backRightCurrent
|
||||
ContainerType gas, brems, avgSpeed, avgSpeedKmh, sumCurrent, frontVoltage, backVoltage, frontLeftCurrent, frontRightCurrent, backLeftCurrent, backRightCurrent
|
||||
#ifdef FEATURE_BMS
|
||||
, bmsVoltage, bmsCurrent, bmsPower
|
||||
#endif
|
||||
@ -23,7 +23,6 @@ void pushStats()
|
||||
statistics::avgSpeed.push_back(avgSpeed);
|
||||
statistics::avgSpeedKmh.push_back(avgSpeedKmh);
|
||||
statistics::sumCurrent.push_back(sumCurrent);
|
||||
statistics::sumAbsoluteCurrent.push_back(sumAbsoluteCurrent);
|
||||
if (controllers.front.feedbackValid)
|
||||
{
|
||||
statistics::frontVoltage.push_back(fixBatVoltage(controllers.front.feedback.batVoltage));
|
||||
@ -61,7 +60,6 @@ using BremsStatistics = BufferAccessorImpl<statistics::brems>;
|
||||
using AvgSpeedStatistics = BufferAccessorImpl<statistics::avgSpeed>;
|
||||
using AvgSpeedKmhStatistics = BufferAccessorImpl<statistics::avgSpeedKmh>;
|
||||
using SumCurrentStatistics = BufferAccessorImpl<statistics::sumCurrent>;
|
||||
using SumAbsoluteCurrentStatistics = BufferAccessorImpl<statistics::sumAbsoluteCurrent>;
|
||||
using FrontVoltageStatistics = BufferAccessorImpl<statistics::frontVoltage>;
|
||||
using BackVoltageStatistics = BufferAccessorImpl<statistics::backVoltage>;
|
||||
#ifdef FEATURE_BMS
|
||||
|
@ -181,7 +181,6 @@ constexpr char TEXT_BREMS[] = "Brems";
|
||||
constexpr char TEXT_AVGSPEED[] = "Avg. speed";
|
||||
constexpr char TEXT_AVGSPEEDKMH[] = "Avg. speed KMH";
|
||||
constexpr char TEXT_SUMCURRENT[] = "Sum current";
|
||||
constexpr char TEXT_SUMABSOLUTECURRENT[] = "Sum absolute current";
|
||||
constexpr char TEXT_FRONTVOLTAGE[] = "Front voltage";
|
||||
constexpr char TEXT_BACKVOLTAGE[] = "Back voltage";
|
||||
constexpr char TEXT_BMSVOLTAGE[] = "BMS voltage";
|
||||
|
@ -266,7 +266,6 @@ void updateAccumulators()
|
||||
{
|
||||
avgSpeed = 0.f;
|
||||
sumCurrent = 0.f;
|
||||
sumAbsoluteCurrent = 0.f;
|
||||
uint8_t count{0};
|
||||
|
||||
for (const Controller &controller : controllers)
|
||||
@ -282,10 +281,6 @@ void updateAccumulators()
|
||||
controller.feedback.left.current +
|
||||
controller.feedback.right.current;
|
||||
|
||||
sumAbsoluteCurrent +=
|
||||
std::abs(controller.feedback.left.current) +
|
||||
std::abs(controller.feedback.right.current);
|
||||
|
||||
count +=2;
|
||||
}
|
||||
|
||||
@ -293,7 +288,6 @@ void updateAccumulators()
|
||||
avgSpeed /= count;
|
||||
|
||||
sumCurrent = fixCurrent(sumCurrent);
|
||||
sumAbsoluteCurrent = fixCurrent(sumAbsoluteCurrent);
|
||||
|
||||
avgSpeedKmh = convertToKmh(avgSpeed);
|
||||
}
|
||||
|
@ -7,9 +7,7 @@ namespace {
|
||||
class ProgressBar
|
||||
{
|
||||
public:
|
||||
ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color=TFT_YELLOW) :
|
||||
m_x{x}, m_y{y}, m_width{width}, m_height{height}, m_min{min}, m_max{max}, m_color{color}
|
||||
{}
|
||||
ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color=TFT_YELLOW);
|
||||
|
||||
void start();
|
||||
void redraw(int value);
|
||||
@ -23,11 +21,17 @@ private:
|
||||
const int m_max;
|
||||
const uint32_t m_color;
|
||||
|
||||
int m_lastValue{m_x+1};
|
||||
int m_lastValue;
|
||||
};
|
||||
|
||||
ProgressBar::ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color) :
|
||||
m_x{x}, m_y{y}, m_width{width}, m_height{height}, m_min{min}, m_max{max}, m_color{color}
|
||||
{
|
||||
}
|
||||
|
||||
void ProgressBar::start()
|
||||
{
|
||||
m_lastValue = m_x+1;
|
||||
tft.drawRect(m_x, m_y, m_width, m_height, TFT_WHITE);
|
||||
}
|
||||
|
||||
|
50
src/widgets/reverseprogressbar.h
Normal file
50
src/widgets/reverseprogressbar.h
Normal file
@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include "globals.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace {
|
||||
class ReverseProgressBar
|
||||
{
|
||||
public:
|
||||
ReverseProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color=TFT_YELLOW);
|
||||
|
||||
void start();
|
||||
void redraw(int value);
|
||||
|
||||
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_color;
|
||||
|
||||
int m_lastValue;
|
||||
};
|
||||
|
||||
ReverseProgressBar::ReverseProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color) :
|
||||
m_x{x}, m_y{y}, m_width{width}, m_height{height}, m_min{min}, m_max{max}, m_color{color}
|
||||
{
|
||||
}
|
||||
|
||||
void ReverseProgressBar::start()
|
||||
{
|
||||
m_lastValue = m_x+m_width-1;
|
||||
tft.drawRect(m_x, m_y, m_width, m_height, TFT_WHITE);
|
||||
}
|
||||
|
||||
void ReverseProgressBar::redraw(int value)
|
||||
{
|
||||
value = scaleBetween(value, m_min, m_max, m_x+m_width-1, m_x+1);
|
||||
|
||||
if (value < m_lastValue)
|
||||
tft.fillRect(value, m_y+1, m_lastValue-value, m_height-2, m_color);
|
||||
else if (value > m_lastValue)
|
||||
tft.fillRect(m_lastValue, m_y+1, value-m_lastValue, m_height-2, TFT_BLACK);
|
||||
|
||||
m_lastValue = value;
|
||||
}
|
||||
|
||||
}
|
@ -7,21 +7,22 @@ namespace {
|
||||
class VerticalMeter
|
||||
{
|
||||
public:
|
||||
VerticalMeter(const char *text, int x, int y);
|
||||
VerticalMeter(const char *text, const char *format, int x, int y);
|
||||
|
||||
void start();
|
||||
void redraw(float value, float min, float max);
|
||||
|
||||
private:
|
||||
const char * const m_text;
|
||||
const char * const m_format;
|
||||
const int m_x;
|
||||
const int m_y;
|
||||
|
||||
float m_oldValue{};
|
||||
};
|
||||
|
||||
VerticalMeter::VerticalMeter(const char *text, int x, int y) :
|
||||
m_text{text}, m_x{x}, m_y{y}
|
||||
VerticalMeter::VerticalMeter(const char *text, const char *format, int x, int y) :
|
||||
m_text{text}, m_format{format}, m_x{x}, m_y{y}
|
||||
{
|
||||
}
|
||||
|
||||
@ -49,8 +50,8 @@ void VerticalMeter::redraw(float value, float min, float max)
|
||||
{
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK);
|
||||
|
||||
char buf[8];
|
||||
dtostrf(value, 4, 0, buf);
|
||||
char buf[16];
|
||||
snprintf(&buf[0], 16, m_format, value);
|
||||
tft.drawRightString(buf, m_x + 36 - 5, 187 - 27 + 155 - 18, 2);
|
||||
|
||||
const int dx = 3 + m_x;
|
||||
|
Reference in New Issue
Block a user