More and more refactorings

This commit is contained in:
2021-12-28 02:19:27 +01:00
parent 9ac12cec05
commit 39a6a7df71
8 changed files with 105 additions and 66 deletions

View File

@ -13,29 +13,38 @@ QrCodeDebugDisplay::QrCodeDebugDisplay()
{
}
void QrCodeDebugDisplay::back()
{
switchScreen<DebugMenu>();
}
void QrCodeDebugDisplay::initScreen()
{
Base::initScreen();
}
void QrCodeDebugDisplay::confirm()
void QrCodeDebugDisplay::buttonPressed(espgui::Button button)
{
uint8_t qrcodeBytes[qrcode_getBufferSize(7)];
qrcode_initText(&m_qrcode, qrcodeBytes, 7, ECC_MEDIUM, fmt::format("WIFI:T:WPA;S:{};P:{};", deviceName, stringSettings.ap_password).c_str());
Base::buttonPressed(button);
for (uint8_t y = 0; y < m_qrcode.size; y++) {
for (uint8_t x = 0; x < m_qrcode.size; x++) {
if (qrcode_getModule(&m_qrcode, x, y))
{
tft.drawPixel(x+2,y+2, TFT_BLACK);
} else {
tft.drawPixel(x+2,y+2, TFT_WHITE);
switch (button)
{
using espgui::Button;
case Button::Left:
switchScreen<DebugMenu>();
break;
case Button::Right:
{
uint8_t qrcodeBytes[qrcode_getBufferSize(7)];
qrcode_initText(&m_qrcode, qrcodeBytes, 7, ECC_MEDIUM, fmt::format("WIFI:T:WPA;S:{};P:{};", deviceName, stringSettings.ap_password).c_str());
for (uint8_t y = 0; y < m_qrcode.size; y++) {
for (uint8_t x = 0; x < m_qrcode.size; x++) {
if (qrcode_getModule(&m_qrcode, x, y))
{
tft.drawPixel(x+2,y+2, TFT_BLACK);
} else {
tft.drawPixel(x+2,y+2, TFT_WHITE);
}
}
}
break;
}
default:;
}
}

View File

@ -1,18 +1,23 @@
#pragma once
// 3rdparty lib includes
#include <display.h>
#include <qrcode.h>
// local includes
#include "bobbydisplay.h"
class QrCodeDebugDisplay :
public espgui::Display
public BobbyDisplay
{
using Base = espgui::Display;
using Base = BobbyDisplay;
public:
QrCodeDebugDisplay();
void initScreen() override;
void confirm() override;
void back() override;
void buttonPressed(espgui::Button button) override;
private:
QRCode m_qrcode;
};

View File

@ -12,11 +12,14 @@
void SpiroDisplay::initScreen()
{
Base::initScreen();
espgui::tft.setRotation(3);
}
void SpiroDisplay::redraw()
{
Base::redraw();
for (int j = 0; j < std::max(1, n); j++)
{
if (i == 0)
@ -72,9 +75,26 @@ void SpiroDisplay::redraw()
void SpiroDisplay::stop()
{
Base::stop();
espgui::tft.setRotation(0);
}
void SpiroDisplay::buttonPressed(espgui::Button button)
{
Base::buttonPressed(button);
switch (button)
{
using espgui::Button;
case Button::Left:
case Button::Right:
espgui::switchScreen<DemosMenu>();
break;
default:;
}
}
unsigned int SpiroDisplay::rainbow(int value)
{
// Value is expected to be in range 0-127
@ -108,13 +128,3 @@ unsigned int SpiroDisplay::rainbow(int value)
}
return (red << 11) + (green << 5) + blue;
}
void SpiroDisplay::confirm()
{
espgui::switchScreen<DemosMenu>();
}
void SpiroDisplay::back()
{
espgui::switchScreen<DemosMenu>();
}

View File

@ -4,21 +4,17 @@
#include <cstdint>
// local includes
#include "display.h"
#include "actions/switchscreenaction.h"
#include "bobbydisplay.h"
class SpiroDisplay : public espgui::Display
class SpiroDisplay : public BobbyDisplay
{
using Base = espgui::Display;
using Base = BobbyDisplay;
public:
void initScreen() override;
void redraw() override;
void stop() override;
void confirm() override;
void back() override;
private:
constexpr static auto DEG2RAD = 0.0174532925;

View File

@ -18,18 +18,10 @@ StarfieldDisplay::StarfieldDisplay() :
{
}
void StarfieldDisplay::confirm()
{
espgui::switchScreen<DemosMenu>();
}
void StarfieldDisplay::back()
{
espgui::switchScreen<DemosMenu>();
}
void StarfieldDisplay::initScreen()
{
Base::initScreen();
espgui::tft.fillScreen(TFT_BLACK);
espgui::tft.setRotation(1);
@ -41,6 +33,8 @@ void StarfieldDisplay::initScreen()
void StarfieldDisplay::redraw()
{
Base::redraw();
uint8_t spawnDepthVariation = 255;
for(int i = 0; i < NSTARS; ++i)
@ -80,5 +74,22 @@ void StarfieldDisplay::redraw()
void StarfieldDisplay::stop()
{
Base::stop();
espgui::tft.setRotation(0);
}
void StarfieldDisplay::buttonPressed(espgui::Button button)
{
Base::buttonPressed(button);
switch (button)
{
using espgui::Button;
case Button::Left:
case Button::Right:
espgui::switchScreen<DemosMenu>();
break;
default:;
}
}

View File

@ -4,20 +4,21 @@
#include <cstdint>
// local includes
#include "display.h"
#include "bobbydisplay.h"
class StarfieldDisplay : public espgui::Display
class StarfieldDisplay : public BobbyDisplay
{
using Base = BobbyDisplay;
public:
StarfieldDisplay();
void confirm() override;
void back() override;
void initScreen() override;
void redraw() override;
void stop() override;
void buttonPressed(espgui::Button button) override;
private:
static constexpr auto NSTARS = 1024;

View File

@ -101,14 +101,20 @@ void UpdateDisplay::redraw()
}
}
void UpdateDisplay::confirm()
void UpdateDisplay::buttonPressed(espgui::Button button)
{
if (const auto result = triggerOta(stringSettings.otaUrl); !result)
ESP_LOGE("BOBBY", "triggerOta() failed with %.*s", result.error().size(), result.error().data());
}
Base::buttonPressed(button);
void UpdateDisplay::back()
{
espgui::switchScreen<OtaMenu>();
switch (button)
{
using espgui::Button;
case Button::Left:
espgui::switchScreen<OtaMenu>();
break;
case Button::Right:
if (const auto result = triggerOta(stringSettings.otaUrl); !result)
ESP_LOGE("BOBBY", "triggerOta() failed with %.*s", result.error().size(), result.error().data());
break;
}
}
#endif

View File

@ -1,21 +1,22 @@
#pragma once
// 3rdparty lib includes
#include <widgets/label.h>
#include <widgets/progressbar.h>
// local includes
#include "display.h"
#include "widgets/label.h"
#include "widgets/progressbar.h"
#include "bobbydisplay.h"
#ifdef FEATURE_OTA
class UpdateDisplay : public espgui::Display
class UpdateDisplay : public BobbyDisplay
{
using Base = espgui::Display;
using Base = BobbyDisplay;
public:
void initScreen() override;
void redraw() override;
void confirm() override;
void back() override;
void buttonPressed(espgui::Button button) override;
private:
espgui::Label m_statusLabel{120, 75};