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() void QrCodeDebugDisplay::initScreen()
{ {
Base::initScreen(); Base::initScreen();
} }
void QrCodeDebugDisplay::confirm() void QrCodeDebugDisplay::buttonPressed(espgui::Button button)
{ {
uint8_t qrcodeBytes[qrcode_getBufferSize(7)]; Base::buttonPressed(button);
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++) { switch (button)
for (uint8_t x = 0; x < m_qrcode.size; x++) { {
if (qrcode_getModule(&m_qrcode, x, y)) using espgui::Button;
{ case Button::Left:
tft.drawPixel(x+2,y+2, TFT_BLACK); switchScreen<DebugMenu>();
} else { break;
tft.drawPixel(x+2,y+2, TFT_WHITE); 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 #pragma once
// 3rdparty lib includes // 3rdparty lib includes
#include <display.h>
#include <qrcode.h> #include <qrcode.h>
// local includes
#include "bobbydisplay.h"
class QrCodeDebugDisplay : class QrCodeDebugDisplay :
public espgui::Display public BobbyDisplay
{ {
using Base = espgui::Display; using Base = BobbyDisplay;
public: public:
QrCodeDebugDisplay(); QrCodeDebugDisplay();
void initScreen() override; void initScreen() override;
void confirm() override;
void back() override; void buttonPressed(espgui::Button button) override;
private: private:
QRCode m_qrcode; QRCode m_qrcode;
}; };

View File

@ -12,11 +12,14 @@
void SpiroDisplay::initScreen() void SpiroDisplay::initScreen()
{ {
Base::initScreen(); Base::initScreen();
espgui::tft.setRotation(3); espgui::tft.setRotation(3);
} }
void SpiroDisplay::redraw() void SpiroDisplay::redraw()
{ {
Base::redraw();
for (int j = 0; j < std::max(1, n); j++) for (int j = 0; j < std::max(1, n); j++)
{ {
if (i == 0) if (i == 0)
@ -72,9 +75,26 @@ void SpiroDisplay::redraw()
void SpiroDisplay::stop() void SpiroDisplay::stop()
{ {
Base::stop();
espgui::tft.setRotation(0); 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) unsigned int SpiroDisplay::rainbow(int value)
{ {
// Value is expected to be in range 0-127 // 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; 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> #include <cstdint>
// local includes // local includes
#include "display.h" #include "bobbydisplay.h"
#include "actions/switchscreenaction.h"
class SpiroDisplay : public espgui::Display class SpiroDisplay : public BobbyDisplay
{ {
using Base = espgui::Display; using Base = BobbyDisplay;
public: public:
void initScreen() override; void initScreen() override;
void redraw() override; void redraw() override;
void stop() override; void stop() override;
void confirm() override;
void back() override;
private: private:
constexpr static auto DEG2RAD = 0.0174532925; 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() void StarfieldDisplay::initScreen()
{ {
Base::initScreen();
espgui::tft.fillScreen(TFT_BLACK); espgui::tft.fillScreen(TFT_BLACK);
espgui::tft.setRotation(1); espgui::tft.setRotation(1);
@ -41,6 +33,8 @@ void StarfieldDisplay::initScreen()
void StarfieldDisplay::redraw() void StarfieldDisplay::redraw()
{ {
Base::redraw();
uint8_t spawnDepthVariation = 255; uint8_t spawnDepthVariation = 255;
for(int i = 0; i < NSTARS; ++i) for(int i = 0; i < NSTARS; ++i)
@ -80,5 +74,22 @@ void StarfieldDisplay::redraw()
void StarfieldDisplay::stop() void StarfieldDisplay::stop()
{ {
Base::stop();
espgui::tft.setRotation(0); 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> #include <cstdint>
// local includes // local includes
#include "display.h" #include "bobbydisplay.h"
class StarfieldDisplay : public espgui::Display class StarfieldDisplay : public BobbyDisplay
{ {
using Base = BobbyDisplay;
public: public:
StarfieldDisplay(); StarfieldDisplay();
void confirm() override;
void back() override;
void initScreen() override; void initScreen() override;
void redraw() override; void redraw() override;
void stop() override; void stop() override;
void buttonPressed(espgui::Button button) override;
private: private:
static constexpr auto NSTARS = 1024; 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) Base::buttonPressed(button);
ESP_LOGE("BOBBY", "triggerOta() failed with %.*s", result.error().size(), result.error().data());
}
void UpdateDisplay::back() switch (button)
{ {
espgui::switchScreen<OtaMenu>(); 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 #endif

View File

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