Files
bobbycar-boardcomputer-firm…/main/screens.cpp
T

97 lines
2.3 KiB
C++
Raw Normal View History

2021-11-02 01:43:58 +01:00
#include "screens.h"
// 3rdparty lib includes
#include <tftinstance.h>
#include <screenmanager.h>
2021-11-02 01:43:58 +01:00
// local includes
2022-02-13 20:32:40 +01:00
#include "esptexthelpers.h"
2021-11-02 01:43:58 +01:00
#include "globals.h"
#include "icons/logo.h"
using namespace espgui;
Label bootLabel{32, 250};
2022-10-06 13:41:12 +02:00
namespace {
bool disable_screen_flip{false};
}
2021-11-02 01:43:58 +01:00
void initScreen()
{
2022-10-01 15:21:55 +02:00
// vertical screen
2021-11-02 01:43:58 +01:00
tft.init();
tft.fillScreen(TFT_WHITE);
tft.setTextColor(TFT_BLACK, TFT_WHITE);
tft.setTextFont(4);
2022-10-01 15:21:55 +02:00
tft.setRotation(configs.boardcomputerHardware.flipScreen.value() ? 2 : 0);
espgui::tft.setSwapBytes(true);
2021-11-02 01:43:58 +01:00
tft.pushImage(0, 40, bobbyicons::logo.WIDTH, bobbyicons::logo.HEIGHT, bobbyicons::logo.buffer);
espgui::tft.setSwapBytes(false);
2021-11-02 01:43:58 +01:00
tft.drawString("Bobbycar-OS", 32, 200);
tft.drawString("booting...", 32, 225);
2022-02-13 20:32:40 +01:00
tft.setTextFont(2);
tft.drawString("last reboot reason:", 32, 275);
tft.drawString(espcpputils::toString(esp_reset_reason()), 32, 295);
tft.setTextFont(4);
2021-11-02 01:43:58 +01:00
bootLabel.start();
}
2022-10-02 22:54:19 +02:00
void updateRotation()
{
if (tft.getRotation() != (configs.boardcomputerHardware.flipScreen.value() ? 2 : 0))
{
tft.setRotation(configs.boardcomputerHardware.flipScreen.value() ? 2 : 0);
if (currentDisplay)
currentDisplay->initScreen();
}
}
2021-11-02 01:43:58 +01:00
void updateDisplay()
{
if (currentDisplay)
currentDisplay->update();
if (changeScreenCallback)
{
changeScreenCallback();
changeScreenCallback = {};
}
2022-06-23 21:50:58 +02:00
2022-10-06 13:41:12 +02:00
if (!disable_screen_flip)
updateRotation();
2022-10-01 15:21:55 +02:00
2022-06-23 21:50:58 +02:00
if (const int8_t rawButton = rawButtonRequest.load(); rawButton != -1 && currentDisplay)
{
currentDisplay->rawButtonPressed(rawButton);
currentDisplay->rawButtonReleased(rawButton);
rawButtonRequest = -1;
}
if (const int8_t button = buttonRequest.load(); button != -1 && currentDisplay)
{
const auto btn = espgui::Button(button);
currentDisplay->buttonPressed(btn);
currentDisplay->buttonReleased(btn);
buttonRequest = -1;
}
2022-06-25 21:58:28 +02:00
if (initScreenRequest && currentDisplay)
{
currentDisplay->initScreen();
initScreenRequest = false;
}
2021-11-02 01:43:58 +01:00
}
void redrawDisplay()
{
if (currentDisplay)
{
currentDisplay->redraw();
}
}
2022-10-06 13:41:12 +02:00
void disableScreenFlip(bool enable)
{
disable_screen_flip = enable;
}