More displays converted to bobby displays

This commit is contained in:
2021-12-28 02:44:10 +01:00
parent 39a6a7df71
commit 3403c65987
10 changed files with 117 additions and 82 deletions

View File

@ -14,6 +14,8 @@
void Lockscreen::start()
{
Base::start();
m_numbers = {0,0,0,0};
m_currentIndex = 0;
m_pressed = false;
@ -33,6 +35,8 @@ void Lockscreen::start()
void Lockscreen::initScreen()
{
Base::initScreen();
espgui::tft.fillScreen(TFT_BLACK);
espgui::tft.setTextFont(4);
espgui::tft.setTextColor(TFT_YELLOW);
@ -66,12 +70,16 @@ void Lockscreen::initScreen()
void Lockscreen::update()
{
Base::update();
// just in case someone changes that settings somehow
profileButtonDisabled = !settings.lockscreen.allowPresetSwitch;
}
void Lockscreen::redraw()
{
Base::redraw();
if (m_pressed || m_back_pressed)
{
drawRect(m_currentIndex, 1, TFT_BLACK);
@ -151,21 +159,28 @@ void Lockscreen::stop()
}
}
void Lockscreen::confirm()
void Lockscreen::buttonPressed(espgui::Button button)
{
m_pressed = true;
}
Base::buttonPressed(button);
void Lockscreen::back()
{
if (m_currentIndex > 0)
m_currentIndex--;
m_back_pressed = true;
}
void Lockscreen::rotate(int offset)
{
m_rotated += offset;
switch (button)
{
using espgui::Button;
case Button::Left:
if (m_currentIndex > 0)
m_currentIndex--;
m_back_pressed = true;
break;
case Button::Right:
m_pressed = true;
break;
case Button::Up:
m_rotated--;
break;
case Button::Down:
m_rotated++;
break;
}
}
void Lockscreen::drawRect(int index, int offset, uint32_t color) const

View File

@ -3,18 +3,20 @@
// system includes
#include <array>
// 3rdparty lib includes
#include <widgets/label.h>
// local includes
#include "display.h"
#include "widgets/label.h"
#include "bobbydisplay.h"
#include "modes/ignoreinputmode.h"
#ifdef LOCKSCREEN_PLUGIN
#include "ledstrip.h"
#endif
class Lockscreen : public espgui::Display
class Lockscreen : public BobbyDisplay
{
using Base = espgui::Display;
using Base = BobbyDisplay;
static constexpr auto boxWidth = 35;
static constexpr auto boxHeight = 50;
@ -27,9 +29,7 @@ public:
void redraw() override;
void stop() override;
void confirm() override;
void back() override;
void rotate(int offset) override;
void buttonPressed(espgui::Button button) override;
private:
void drawRect(int index, int offset, uint32_t color) const;

View File

@ -15,6 +15,8 @@ using namespace espgui;
void MetersDisplay::initScreen()
{
Base::initScreen();
tft.fillScreen(TFT_BLACK);
m_vuMeter.start();
@ -30,6 +32,8 @@ void MetersDisplay::initScreen()
void MetersDisplay::redraw()
{
Base::redraw();
m_vuMeter.redraw(avgSpeedKmh);
m_dischargingBar.redraw(sumCurrent<0.f?(-sumCurrent):0.f);
@ -47,24 +51,26 @@ void MetersDisplay::redraw()
meters[5].redraw(fixCurrent(controllers.back.feedback.right.dcLink), -10, 10);
}
void MetersDisplay::confirm()
void StatusDisplay::buttonPressed(espgui::Button button)
{
switchScreen<MainMenu>();
}
Base::buttonPressed(button);
void MetersDisplay::back()
{
switchScreen<MainMenu>();
}
void MetersDisplay::rotate(int offset)
{
if (offset < 0)
switch (button)
{
using espgui::Button;
case Button::Left:
case Button::Right:
switchScreen<MainMenu>();
break;
case Button::Up:
switchScreen<StatusDisplay>();
else if (offset > 0)
break;
case Button::Down:
#ifdef FEATURE_BMS
switchScreen<BmsDisplay>();
#else
switchScreen<StatusDisplay>();
#endif
break;
}
}

View File

@ -4,7 +4,6 @@
#include <array>
// 3rdparty lib includes
#include <display.h>
#include <actions/switchscreenaction.h>
#include <widgets/label.h>
#include <widgets/reverseprogressbar.h>
@ -12,16 +11,18 @@
#include <widgets/verticalmeter.h>
#include <widgets/vumeter.h>
class MetersDisplay :
public espgui::Display
// local includes
#include "bobbydisplay.h"
class MetersDisplay : public BobbyDisplay
{
using Base = BobbyDisplay;
public:
void initScreen() override;
void redraw() override;
void confirm() override;
void back() override;
void rotate(int offset) override;
void buttonPressed(espgui::Button button) override;
private:
espgui::VuMeter m_vuMeter;

View File

@ -20,6 +20,8 @@ PingPongDisplay::PingPongDisplay() :
void PingPongDisplay::initScreen()
{
Base::initScreen();
espgui::tft.fillScreen(TFT_BLACK);
espgui::tft.setRotation(1);
@ -28,6 +30,8 @@ void PingPongDisplay::initScreen()
void PingPongDisplay::redraw()
{
Base::redraw();
lpaddle();
rpaddle();
@ -38,17 +42,24 @@ void PingPongDisplay::redraw()
void PingPongDisplay::stop()
{
Base::stop();
espgui::tft.setRotation(0);
}
void PingPongDisplay::confirm()
void PingPongDisplay::buttonPressed(espgui::Button button)
{
espgui::switchScreen<DemosMenu>();
}
Base::buttonPressed(button);
void PingPongDisplay::back()
{
espgui::switchScreen<DemosMenu>();
switch (button)
{
using espgui::Button;
case Button::Left:
case Button::Right:
espgui::switchScreen<DemosMenu>();
break;
default:;
}
}
void PingPongDisplay::midline()

View File

@ -3,11 +3,13 @@
// system includes
#include <cstdint>
// 3rdparty lib includes
#include "display.h"
// local includes
#include "bobbydisplay.h"
class PingPongDisplay : public espgui::Display
class PingPongDisplay : public BobbyDisplay
{
using Base = BobbyDisplay;
public:
PingPongDisplay();
@ -15,8 +17,7 @@ public:
void redraw() override;
void stop() override;
void confirm() override;
void back() override;
void buttonPressed(espgui::Button button) override;
private:
void midline();

View File

@ -14,6 +14,8 @@ using namespace std::chrono_literals;
void PoweroffDisplay::start()
{
Base::start();
m_startTime = espchrono::millis_clock::now();
for (Controller &controller : controllers)
@ -22,6 +24,8 @@ void PoweroffDisplay::start()
void PoweroffDisplay::initScreen()
{
Base::initScreen();
espgui::tft.fillScreen(TFT_BLACK);
espgui::tft.setTextColor(TFT_YELLOW);
@ -37,20 +41,16 @@ void PoweroffDisplay::initScreen()
void PoweroffDisplay::update()
{
Base::update();
if (espchrono::millis_clock::now() - m_startTime >= 1000ms)
espgui::switchScreen<MainMenu>();
}
void PoweroffDisplay::stop()
{
Base::stop();
for (Controller &controller : controllers)
controller.command.poweroff = false;
}
void PoweroffDisplay::confirm()
{
}
void PoweroffDisplay::back()
{
}

View File

@ -4,20 +4,18 @@
#include <espchrono.h>
// local includes
#include "display.h"
#include "bobbydisplay.h"
class PoweroffDisplay : public espgui::Display
class PoweroffDisplay : public BobbyDisplay
{
using Base = BobbyDisplay;
public:
void start() override;
void initScreen() override;
void update() override;
void redraw() override {}
void stop() override;
void confirm() override;
void back() override;
private:
espchrono::millis_clock::time_point m_startTime;
};

View File

@ -12,6 +12,8 @@
#if defined(FEATURE_CAN) && defined(FEATURE_POWERSUPPLY)
void PowerSupplyDisplay::initScreen()
{
Base::initScreen();
espgui::tft.fillScreen(TFT_BLACK);
espgui::tft.setTextColor(TFT_WHITE, TFT_BLACK);
@ -25,22 +27,24 @@ void PowerSupplyDisplay::initScreen()
void PowerSupplyDisplay::redraw()
{
Base::redraw();
m_voltageLabel.redraw(std::to_string(50.4) + 'V');
m_currentLabel.redraw(std::to_string(15.1) + 'A');
}
void PowerSupplyDisplay::confirm()
void PowerSupplyDisplay::buttonPressed(espgui::Button button)
{
// TODO
}
Base::buttonPressed(button);
void PowerSupplyDisplay::back()
{
espgui::switchScreen<MainMenu>();
}
void PowerSupplyDisplay::rotate(int offset)
{
// TODO
switch (button)
{
using espgui::Button;
case Button::Left:
case Button::Right:
espgui::switchScreen<MainMenu>();
break;
default:;
}
}
#endif

View File

@ -1,22 +1,21 @@
#pragma once
// 3rdparty lib includes
#include "display.h"
#include "widgets/label.h"
#include <widgets/label.h>
// local includes
#include "bobbydisplay.h"
#if defined(FEATURE_CAN) && defined(FEATURE_POWERSUPPLY)
class PowerSupplyDisplay : public espgui::Display
class PowerSupplyDisplay : public BobbyDisplay
{
using Base = espgui::Display;
using Base = BobbyDisplay;
public:
void initScreen() override;
void redraw() override;
void confirm() override;
void back() override;
void rotate(int offset) override;
void buttonPressed(espgui::Button button) override
espgui::Label m_voltageLabel{120, 50};
espgui::Label m_currentLabel{120, 75};