mirror of
https://github.com/Lemonochrme/clover.git
synced 2025-06-08 16:50:50 +02:00
Screen: Added failed logo. Updated Box to have a FORCED_CENTERED. When Wifi is not connected, show failed screen.
This commit is contained in:
parent
ad71d0997b
commit
7e1d7f1526
11 changed files with 69 additions and 21 deletions
|
@ -26,11 +26,12 @@ namespace Display
|
||||||
UNDEFINED,
|
UNDEFINED,
|
||||||
TOP,
|
TOP,
|
||||||
CENTERED,
|
CENTERED,
|
||||||
BOTTOM
|
BOTTOM,
|
||||||
|
FORCE_CENTERED
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Box is a virtual class which can be derived into many box elements
|
* @brief Box is an abstract class which can be derived into many box elements
|
||||||
* and will be used in the 'Components' object.
|
* and will be used in the 'Components' object.
|
||||||
* It is composed of 4 functions which may or not be used.
|
* It is composed of 4 functions which may or not be used.
|
||||||
* Each box should use the Screen Interface in the Display function,
|
* Each box should use the Screen Interface in the Display function,
|
||||||
|
|
|
@ -32,8 +32,10 @@ void Components::Display()
|
||||||
{
|
{
|
||||||
const auto size_boxes = GetSize((*it)->getStyleHeight());
|
const auto size_boxes = GetSize((*it)->getStyleHeight());
|
||||||
(*it)->Display(size_boxes, totalSize);
|
(*it)->Display(size_boxes, totalSize);
|
||||||
// Index and verticalPadding only incrementing for the same style. (eg : it and it+1 as the same style.)
|
|
||||||
if (it + 1 != _boxes.end() && ((*(it+1))->getStyleHeight() == (*it)->getStyleHeight()))
|
/* Index and verticalPadding only incrementing for the same style. (eg : it and it+1 as the same style.)
|
||||||
|
Plus, it has to not be FORCED to be incremented.*/
|
||||||
|
if (it + 1 != _boxes.end() && ((*(it+1))->getStyleHeight() == (*it)->getStyleHeight()) && ((*it)->getStyleHeight() != StyleHeight::FORCE_CENTERED))
|
||||||
totalSize += (*it)->getHeight() + (2*(*it)->getPadding());
|
totalSize += (*it)->getHeight() + (2*(*it)->getPadding());
|
||||||
else
|
else
|
||||||
totalSize = 0;
|
totalSize = 0;
|
||||||
|
|
|
@ -45,6 +45,7 @@ void SpriteBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos)
|
||||||
switch(this->_styleHeight)
|
switch(this->_styleHeight)
|
||||||
{
|
{
|
||||||
case StyleHeight::CENTERED:
|
case StyleHeight::CENTERED:
|
||||||
|
case StyleHeight::FORCE_CENTERED:
|
||||||
// idk must be the size of all the above
|
// idk must be the size of all the above
|
||||||
Screen::GetInstance().getScreen().drawXBM(_x, static_cast<uint16_t>((centeredOffset / 2)) + size_pos,_width,_height,_sprite);
|
Screen::GetInstance().getScreen().drawXBM(_x, static_cast<uint16_t>((centeredOffset / 2)) + size_pos,_width,_height,_sprite);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -46,6 +46,7 @@ void TextBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos)
|
||||||
switch (this->_styleHeight)
|
switch (this->_styleHeight)
|
||||||
{
|
{
|
||||||
case StyleHeight::CENTERED:
|
case StyleHeight::CENTERED:
|
||||||
|
case StyleHeight::FORCE_CENTERED:
|
||||||
Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, static_cast<uint16_t>((centeredOffset / 2)) + size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str());
|
Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, static_cast<uint16_t>((centeredOffset / 2)) + size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str());
|
||||||
break;
|
break;
|
||||||
case StyleHeight::BOTTOM:
|
case StyleHeight::BOTTOM:
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
// XBM Files
|
// XBM Files
|
||||||
#include "Components/SpriteBox.hpp"
|
#include "Components/SpriteBox.hpp"
|
||||||
#include "../Pictures/clover.xbm"
|
#include "../Pictures/clover.xbm"
|
||||||
|
#include "../Pictures/failed.xbm"
|
||||||
|
|
||||||
using namespace Display;
|
using namespace Display;
|
||||||
|
|
||||||
|
@ -30,6 +31,9 @@ void Screen::Setup(uint8_t *font)
|
||||||
// Static Components
|
// Static Components
|
||||||
connectingWindow.Add({std::make_shared<TextBox>(headerSetup),
|
connectingWindow.Add({std::make_shared<TextBox>(headerSetup),
|
||||||
std::make_shared<TextBox>(TextBox("connect", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0))});
|
std::make_shared<TextBox>(TextBox("connect", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0))});
|
||||||
|
connectionfailedWindow.Add({std::make_shared<TextBox>(headerSetup),
|
||||||
|
std::make_shared<TextBox>(TextBox("Failed to connect.", StyleWidth::RIGHT, StyleHeight::CENTERED, U8G2_BTN_BW0,3)),
|
||||||
|
std::make_shared<SpriteBox>(SpriteBox(failed_bits,failed_height,failed_width,StyleWidth::LEFT,StyleHeight::FORCE_CENTERED))});
|
||||||
connectedWindow.Add({std::make_shared<TextBox>(headerSetup),
|
connectedWindow.Add({std::make_shared<TextBox>(headerSetup),
|
||||||
std::make_shared<TextBox>(TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
|
std::make_shared<TextBox>(TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
|
||||||
std::make_shared<TextBox>(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
|
std::make_shared<TextBox>(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
|
||||||
|
@ -63,6 +67,15 @@ void Screen::connecting(uint8_t state)
|
||||||
_screen->sendBuffer();
|
_screen->sendBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Screen::notConnected()
|
||||||
|
{
|
||||||
|
_screen->clearBuffer();
|
||||||
|
// Component
|
||||||
|
connectionfailedWindow.Display();
|
||||||
|
// Displaying
|
||||||
|
_screen->sendBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
void Screen::connected(const char *ipaddress, uint8_t timing)
|
void Screen::connected(const char *ipaddress, uint8_t timing)
|
||||||
{
|
{
|
||||||
_screen->clearBuffer();
|
_screen->clearBuffer();
|
||||||
|
|
|
@ -20,6 +20,7 @@ namespace Display
|
||||||
// Public functions
|
// Public functions
|
||||||
void Setup(uint8_t *font);
|
void Setup(uint8_t *font);
|
||||||
void connecting(uint8_t state=0);
|
void connecting(uint8_t state=0);
|
||||||
|
void notConnected();
|
||||||
void connected(const char *ipaddress, uint8_t timing);
|
void connected(const char *ipaddress, uint8_t timing);
|
||||||
void loop();
|
void loop();
|
||||||
// Getters
|
// Getters
|
||||||
|
@ -44,6 +45,7 @@ namespace Display
|
||||||
// Static Components
|
// Static Components
|
||||||
TextBox headerSetup;
|
TextBox headerSetup;
|
||||||
Components connectingWindow;
|
Components connectingWindow;
|
||||||
|
Components connectionfailedWindow;
|
||||||
Components connectedWindow;
|
Components connectedWindow;
|
||||||
Components loopWindow;
|
Components loopWindow;
|
||||||
};
|
};
|
||||||
|
|
6
embedded/lib/Pictures/failed.xbm
Normal file
6
embedded/lib/Pictures/failed.xbm
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#define failed_width 16
|
||||||
|
#define failed_height 16
|
||||||
|
static unsigned char failed_bits[] = {
|
||||||
|
0x00, 0x00, 0x06, 0x60, 0x0e, 0x70, 0x1c, 0x38, 0x38, 0x1c, 0x70, 0x0e,
|
||||||
|
0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07, 0x70, 0x0e, 0x38, 0x1c,
|
||||||
|
0x1c, 0x38, 0x0e, 0x70, 0x06, 0x60, 0x00, 0x00 };
|
|
@ -1,27 +1,39 @@
|
||||||
#include "ServerHandler.hpp"
|
#include "ServerHandler.hpp"
|
||||||
#include "../Display/Screen.hpp"
|
#include "../Display/Screen.hpp"
|
||||||
|
|
||||||
ServerHandler::ServerHandler() : server(80), display_time(0) {
|
ServerHandler::ServerHandler() : server(80), display_time(0), _connected(false)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerHandler::~ServerHandler() {}
|
ServerHandler::~ServerHandler() {}
|
||||||
|
|
||||||
void ServerHandler::setup(const char* ssid, const char* password) { // On utilise les scope resolution operator pour définir les méthodes la classe ServerHandle qui elle est dans hpp
|
void ServerHandler::setup(const char *ssid, const char *password)
|
||||||
|
{ // On utilise les scope resolution operator pour définir les méthodes la classe ServerHandle qui elle est dans hpp
|
||||||
uint8_t state(0);
|
uint8_t state(0);
|
||||||
|
uint16_t tryConnection(0);
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
// Testing connection
|
||||||
|
while ((WiFi.status() != WL_CONNECTED) && (tryConnection < MAX_CONNECT_TRIES))
|
||||||
|
{
|
||||||
delay(500);
|
delay(500);
|
||||||
Display::Screen::GetInstance().connecting(state);
|
Display::Screen::GetInstance().connecting(state);
|
||||||
state >= 3 ? state = 0 : state++;
|
state >= 3 ? state = 0 : state++;
|
||||||
|
tryConnection++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tryConnection < MAX_CONNECT_TRIES)
|
||||||
|
{
|
||||||
|
_connected = true;
|
||||||
server.begin();
|
server.begin();
|
||||||
server.on("/", [this]() { this->handleRoot(); }); // fonction lamda pour gérer les requettes get
|
server.on("/", [this]()
|
||||||
|
{ this->handleRoot(); }); // fonction lamda pour gérer les requettes get
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerHandler::loop() {
|
void ServerHandler::loop()
|
||||||
|
{
|
||||||
if (display_time < MAX_TIME)
|
if (display_time < MAX_TIME)
|
||||||
{
|
{
|
||||||
Display::Screen::GetInstance().connected(WiFi.localIP().toString().c_str(), display_time);
|
Display::Screen::GetInstance().connected(WiFi.localIP().toString().c_str(), display_time);
|
||||||
|
@ -30,12 +42,11 @@ void ServerHandler::loop() {
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerHandler::showNext()
|
bool ServerHandler::showNext() { return (display_time >= MAX_TIME); }
|
||||||
{
|
bool ServerHandler::isConnected() { return _connected; }
|
||||||
return (display_time >= MAX_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServerHandler::handleRoot() {
|
void ServerHandler::handleRoot()
|
||||||
|
{
|
||||||
auto &dataHandler = DataHandler::GetInstance();
|
auto &dataHandler = DataHandler::GetInstance();
|
||||||
String jsonFormattedData = dataHandler.getJsonData();
|
String jsonFormattedData = dataHandler.getJsonData();
|
||||||
server.send(200, "application/json", jsonFormattedData);
|
server.send(200, "application/json", jsonFormattedData);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "DataHandler.hpp"
|
#include "DataHandler.hpp"
|
||||||
|
|
||||||
constexpr uint8_t MAX_TIME = 28;
|
constexpr uint8_t MAX_TIME = 28;
|
||||||
|
constexpr uint16_t MAX_CONNECT_TRIES = 20;
|
||||||
|
|
||||||
class ServerHandler {
|
class ServerHandler {
|
||||||
public:
|
public:
|
||||||
|
@ -21,6 +22,7 @@ public:
|
||||||
void loop();
|
void loop();
|
||||||
// Return if the screen needs to be changed.
|
// Return if the screen needs to be changed.
|
||||||
bool showNext();
|
bool showNext();
|
||||||
|
bool isConnected();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Singleton
|
// Singleton
|
||||||
|
@ -32,6 +34,7 @@ private:
|
||||||
void handleRoot();
|
void handleRoot();
|
||||||
ESP8266WebServer server;
|
ESP8266WebServer server;
|
||||||
uint8_t display_time;
|
uint8_t display_time;
|
||||||
|
bool _connected;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
[env:nodemcuv2]
|
[env:nodemcuv2]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
|
build_flags = -fexceptions
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
tzapu/WiFiManager@^0.16.0
|
tzapu/WiFiManager@^0.16.0
|
||||||
|
|
|
@ -28,6 +28,13 @@ void loop()
|
||||||
auto& dataHandler = DataHandler::GetInstance();
|
auto& dataHandler = DataHandler::GetInstance();
|
||||||
auto& screen = Display::Screen::GetInstance();
|
auto& screen = Display::Screen::GetInstance();
|
||||||
|
|
||||||
|
// If could not connect, show screen failure
|
||||||
|
if(!serverHandler.isConnected())
|
||||||
|
{
|
||||||
|
screen.notConnected();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If serverHandler finished showing ip.
|
// If serverHandler finished showing ip.
|
||||||
if (serverHandler.showNext())
|
if (serverHandler.showNext())
|
||||||
screen.loop();
|
screen.loop();
|
||||||
|
|
Loading…
Add table
Reference in a new issue