Added battery status display
This commit is contained in:
@ -62,6 +62,7 @@ set(headers
|
|||||||
debuginputhandler.h
|
debuginputhandler.h
|
||||||
debugtexthelpers.h
|
debugtexthelpers.h
|
||||||
displays/batterygraphdisplay.h
|
displays/batterygraphdisplay.h
|
||||||
|
displays/batteryinfodisplay.h
|
||||||
displays/bmsdisplay.h
|
displays/bmsdisplay.h
|
||||||
displays/bobbychangevaluedisplay.h
|
displays/bobbychangevaluedisplay.h
|
||||||
displays/bobbydisplay.h
|
displays/bobbydisplay.h
|
||||||
@ -156,10 +157,12 @@ set(headers
|
|||||||
displays/qrcodedebug.h
|
displays/qrcodedebug.h
|
||||||
displays/qrdisplay.h
|
displays/qrdisplay.h
|
||||||
displays/qrimportdisplay.h
|
displays/qrimportdisplay.h
|
||||||
|
displays/speedinfodisplay.h
|
||||||
displays/spirodisplay.h
|
displays/spirodisplay.h
|
||||||
displays/starfielddisplay.h
|
displays/starfielddisplay.h
|
||||||
displays/statusdisplay.h
|
displays/statusdisplay.h
|
||||||
displays/updatedisplay.h
|
displays/updatedisplay.h
|
||||||
|
displays/xydebugdisplay.h
|
||||||
dnsannounce.h
|
dnsannounce.h
|
||||||
dpad.h
|
dpad.h
|
||||||
dpad3wire.h
|
dpad3wire.h
|
||||||
@ -308,6 +311,7 @@ set(sources
|
|||||||
debuginputhandler.cpp
|
debuginputhandler.cpp
|
||||||
debugtexthelpers.cpp
|
debugtexthelpers.cpp
|
||||||
displays/batterygraphdisplay.cpp
|
displays/batterygraphdisplay.cpp
|
||||||
|
displays/batteryinfodisplay.cpp
|
||||||
displays/bmsdisplay.cpp
|
displays/bmsdisplay.cpp
|
||||||
displays/bobbychangevaluedisplay.cpp
|
displays/bobbychangevaluedisplay.cpp
|
||||||
displays/bobbydisplay.cpp
|
displays/bobbydisplay.cpp
|
||||||
@ -400,10 +404,12 @@ set(sources
|
|||||||
displays/qrcodedebug.cpp
|
displays/qrcodedebug.cpp
|
||||||
displays/qrdisplay.cpp
|
displays/qrdisplay.cpp
|
||||||
displays/qrimportdisplay.cpp
|
displays/qrimportdisplay.cpp
|
||||||
|
displays/speedinfodisplay.cpp
|
||||||
displays/spirodisplay.cpp
|
displays/spirodisplay.cpp
|
||||||
displays/starfielddisplay.cpp
|
displays/starfielddisplay.cpp
|
||||||
displays/statusdisplay.cpp
|
displays/statusdisplay.cpp
|
||||||
displays/updatedisplay.cpp
|
displays/updatedisplay.cpp
|
||||||
|
displays/xydebugdisplay.cpp
|
||||||
dnsannounce.cpp
|
dnsannounce.cpp
|
||||||
dpad.cpp
|
dpad.cpp
|
||||||
dpad3wire.cpp
|
dpad3wire.cpp
|
||||||
|
78
main/displays/batteryinfodisplay.cpp
Normal file
78
main/displays/batteryinfodisplay.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include "batteryinfodisplay.h"
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <screenmanager.h>
|
||||||
|
#include <tftinstance.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "battery.h"
|
||||||
|
#include "displays/menus/mainmenu.h"
|
||||||
|
#include "displays/speedinfodisplay.h"
|
||||||
|
#include "displays/statusdisplay.h"
|
||||||
|
|
||||||
|
// display with big battery and ten bars (0-100%)
|
||||||
|
|
||||||
|
void BatteryInfoDisplay::initScreen()
|
||||||
|
{
|
||||||
|
using namespace espgui;
|
||||||
|
Base::initScreen();
|
||||||
|
|
||||||
|
tft.drawRoundRect(m_offset, m_offset, tft.width() - (m_offset * 2), tft.height() - (m_offset * 2), 10, TFT_WHITE);
|
||||||
|
tft.drawRoundRect((tft.width() / 2) - (m_offset / 2), m_offset / 2, m_offset, m_offset / 2, 3, TFT_WHITE);
|
||||||
|
m_lastBarCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatteryInfoDisplay::redraw()
|
||||||
|
{
|
||||||
|
using namespace espgui;
|
||||||
|
Base::redraw();
|
||||||
|
|
||||||
|
// calculate height of space available for all bars
|
||||||
|
const auto min_x = m_offset + 3; // leave 2 pixels + 1 pixel for border
|
||||||
|
const auto max_x = tft.width() - m_offset - 3;
|
||||||
|
const auto topY = m_offset + 3;
|
||||||
|
const auto bottomY = tft.height() - m_offset - 3;
|
||||||
|
const auto height = bottomY - topY;
|
||||||
|
const auto width = max_x - min_x;
|
||||||
|
const uint16_t segment_height = (height / 10);
|
||||||
|
|
||||||
|
if (const auto avgVoltage = controllers.getAvgVoltage(); avgVoltage)
|
||||||
|
{
|
||||||
|
const auto cellType = configs.battery.cellType.value();
|
||||||
|
const uint16_t percentage = getBatteryPercentage(*avgVoltage, cellType);
|
||||||
|
const auto segment_count = std::max(percentage / 10, 1);
|
||||||
|
|
||||||
|
if (segment_count != m_lastBarCount)
|
||||||
|
{
|
||||||
|
m_lastBarCount = segment_count;
|
||||||
|
// draw battery
|
||||||
|
for (auto i = 0; i < 10; ++i)
|
||||||
|
{
|
||||||
|
const auto y = bottomY - (i * segment_height) - segment_height;
|
||||||
|
tft.fillRoundRect(min_x, y, width, segment_height - 2, 10, segment_count > i ? TFT_GREEN : TFT_DARKGREY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// tft.fillRect(0, 0, tft.width(), topY, TFT_CYAN);
|
||||||
|
// tft.fillRect(0, bottomY, tft.width(), tft.height()-bottomY, TFT_YELLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatteryInfoDisplay::buttonPressed(espgui::Button button)
|
||||||
|
{
|
||||||
|
Base::buttonPressed(button);
|
||||||
|
|
||||||
|
switch (button) {
|
||||||
|
using espgui::Button;
|
||||||
|
case Button::Right:
|
||||||
|
espgui::pushScreen<MainMenu>();
|
||||||
|
break;
|
||||||
|
case Button::Up:
|
||||||
|
espgui::switchScreen<StatusDisplay>();
|
||||||
|
break;
|
||||||
|
case Button::Down:
|
||||||
|
espgui::switchScreen<SpeedInfoDisplay>();
|
||||||
|
break;
|
||||||
|
default:;
|
||||||
|
}
|
||||||
|
}
|
18
main/displays/batteryinfodisplay.h
Normal file
18
main/displays/batteryinfodisplay.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "bobbydisplay.h"
|
||||||
|
|
||||||
|
class BatteryInfoDisplay : public BobbyDisplay
|
||||||
|
{
|
||||||
|
using Base = BobbyDisplay;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void initScreen() override;
|
||||||
|
void redraw() override;
|
||||||
|
|
||||||
|
void buttonPressed(espgui::Button button) override;
|
||||||
|
private:
|
||||||
|
static constexpr const auto m_offset = 40;
|
||||||
|
uint16_t m_lastBarCount{0};
|
||||||
|
};
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS)
|
#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS)
|
||||||
#include "displays/menus/mainmenu.h"
|
#include "displays/menus/mainmenu.h"
|
||||||
#include "displays/metersdisplay.h"
|
#include "displays/speedinfodisplay.h"
|
||||||
#include "displays/statusdisplay.h"
|
#include "displays/statusdisplay.h"
|
||||||
#include "screenmanager.h"
|
#include "screenmanager.h"
|
||||||
#include "tftinstance.h"
|
#include "tftinstance.h"
|
||||||
@ -102,7 +102,7 @@ void BmsDisplay::buttonPressed(espgui::Button button)
|
|||||||
{
|
{
|
||||||
using espgui::Button;
|
using espgui::Button;
|
||||||
case Button::Right: pushScreen<MainMenu>(); break;
|
case Button::Right: pushScreen<MainMenu>(); break;
|
||||||
case Button::Up: switchScreen<MetersDisplay>(); break;
|
case Button::Up: switchScreen<SpeedInfoDisplay>(); break;
|
||||||
case Button::Down: switchScreen<StatusDisplay>(); break;
|
case Button::Down: switchScreen<StatusDisplay>(); break;
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "displays/menus/mainmenu.h"
|
#include "displays/menus/mainmenu.h"
|
||||||
#include "displays/statusdisplay.h"
|
#include "displays/statusdisplay.h"
|
||||||
#include "displays/bmsdisplay.h"
|
|
||||||
|
|
||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
|
|
||||||
@ -58,14 +57,12 @@ void MetersDisplay::buttonPressed(espgui::Button button)
|
|||||||
switch (button)
|
switch (button)
|
||||||
{
|
{
|
||||||
using espgui::Button;
|
using espgui::Button;
|
||||||
case Button::Right: pushScreen<MainMenu>(); break;
|
case Button::Right:
|
||||||
case Button::Up: switchScreen<StatusDisplay>(); break;
|
pushScreen<MainMenu>();
|
||||||
|
break;
|
||||||
|
case Button::Up:
|
||||||
case Button::Down:
|
case Button::Down:
|
||||||
#ifdef FEATURE_BMS
|
|
||||||
switchScreen<BmsDisplay>();
|
|
||||||
#else
|
|
||||||
switchScreen<StatusDisplay>();
|
switchScreen<StatusDisplay>();
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
|
42
main/displays/speedinfodisplay.cpp
Normal file
42
main/displays/speedinfodisplay.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include "speedinfodisplay.h"
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <screenmanager.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "displays/batteryinfodisplay.h"
|
||||||
|
#include "displays/menus/mainmenu.h"
|
||||||
|
#include "displays/statusdisplay.h"
|
||||||
|
|
||||||
|
void SpeedInfoDisplay::initScreen()
|
||||||
|
{
|
||||||
|
Base::initScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpeedInfoDisplay::redraw()
|
||||||
|
{
|
||||||
|
Base::redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpeedInfoDisplay::buttonPressed(espgui::Button button)
|
||||||
|
{
|
||||||
|
Base::buttonPressed(button);
|
||||||
|
|
||||||
|
switch (button) {
|
||||||
|
using espgui::Button;
|
||||||
|
case Button::Right:
|
||||||
|
espgui::pushScreen<MainMenu>();
|
||||||
|
break;
|
||||||
|
case Button::Up:
|
||||||
|
espgui::switchScreen<BatteryInfoDisplay>();
|
||||||
|
break;
|
||||||
|
case Button::Down:
|
||||||
|
#ifdef FEATURE_BMS
|
||||||
|
espgui::switchScreen<BmsDisplay>();
|
||||||
|
#else
|
||||||
|
espgui::switchScreen<StatusDisplay>();
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
default:;
|
||||||
|
}
|
||||||
|
}
|
15
main/displays/speedinfodisplay.h
Normal file
15
main/displays/speedinfodisplay.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "bobbydisplay.h"
|
||||||
|
|
||||||
|
class SpeedInfoDisplay : public BobbyDisplay
|
||||||
|
{
|
||||||
|
using Base = BobbyDisplay;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void initScreen() override;
|
||||||
|
void redraw() override;
|
||||||
|
|
||||||
|
void buttonPressed(espgui::Button button) override;
|
||||||
|
};
|
@ -4,23 +4,23 @@
|
|||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <fmt/core.h>
|
|
||||||
#include <espwifistack.h>
|
#include <espwifistack.h>
|
||||||
|
#include <fmt/core.h>
|
||||||
#include <tftinstance.h>
|
#include <tftinstance.h>
|
||||||
#include <schedulertask.h>
|
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "displays/menus/mainmenu.h"
|
#include "displays/batteryinfodisplay.h"
|
||||||
|
#include "displays/speedinfodisplay.h"
|
||||||
#ifdef FEATURE_BMS
|
#ifdef FEATURE_BMS
|
||||||
#include "displays/bmsdisplay.h"
|
#include "displays/bmsdisplay.h"
|
||||||
#else
|
|
||||||
#include "displays/metersdisplay.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
#include "displays/menus/mainmenu.h"
|
||||||
|
#include "displays/metersdisplay.h"
|
||||||
#include "drivingstatistics.h"
|
#include "drivingstatistics.h"
|
||||||
#include "udpcloud.h"
|
|
||||||
#include "modes/defaultmode.h"
|
#include "modes/defaultmode.h"
|
||||||
#include "taskmanager.h"
|
|
||||||
#include "newsettings.h"
|
#include "newsettings.h"
|
||||||
|
#include "taskmanager.h"
|
||||||
|
#include "udpcloud.h"
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
@ -230,23 +230,24 @@ void StatusDisplay::buttonPressed(espgui::Button button)
|
|||||||
switch (button)
|
switch (button)
|
||||||
{
|
{
|
||||||
using espgui::Button;
|
using espgui::Button;
|
||||||
case Button::Right: pushScreen<MainMenu>(); break;
|
case Button::Right:
|
||||||
|
pushScreen<MainMenu>();
|
||||||
|
break;
|
||||||
case Button::Up:
|
case Button::Up:
|
||||||
if (simplified)
|
if (simplified)
|
||||||
return;
|
return;
|
||||||
#ifdef FEATURE_BMS
|
#ifdef FEATURE_BMS
|
||||||
switchScreen<BmsDisplay>();
|
switchScreen<BmsDisplay>();
|
||||||
#else
|
#else
|
||||||
switchScreen<MetersDisplay>();
|
switchScreen<SpeedInfoDisplay>();
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case Button::Down:
|
case Button::Down:
|
||||||
if (simplified)
|
if (simplified)
|
||||||
return;
|
return;
|
||||||
switchScreen<MetersDisplay>();
|
switchScreen<BatteryInfoDisplay>();
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
|
default:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,17 +4,17 @@
|
|||||||
#include <esp_heap_caps.h>
|
#include <esp_heap_caps.h>
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
|
#include <espchrono.h>
|
||||||
#include <widgets/label.h>
|
#include <widgets/label.h>
|
||||||
#include <widgets/progressbar.h>
|
#include <widgets/progressbar.h>
|
||||||
#include <espchrono.h>
|
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "bobbydisplay.h"
|
|
||||||
#include "modeinterface.h"
|
|
||||||
#include "globals.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "icons/alert.h"
|
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
|
#include "bobbydisplay.h"
|
||||||
|
#include "globals.h"
|
||||||
|
#include "icons/alert.h"
|
||||||
|
#include "modeinterface.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
class StatusDisplay : public BobbyDisplay
|
class StatusDisplay : public BobbyDisplay
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user