From d96c5a670e1ca6880a5a14bcf54cfde5d6a6aa39 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Thu, 14 Dec 2023 10:14:56 +0100 Subject: [PATCH] Screen: Added icons for sensors. Added offset control for all Boxes. Created window for icons. Stylized main loop. --- embedded/lib/Display/Components/Box.hpp | 10 ++++- embedded/lib/Display/Components/SpriteBox.cpp | 8 ++-- embedded/lib/Display/Components/TextBox.cpp | 8 ++-- embedded/lib/Display/Screen.cpp | 40 ++++++++++++++----- embedded/lib/Display/Screen.hpp | 4 +- embedded/lib/Pictures/air_humidity.xbm | 6 +++ embedded/lib/Pictures/humidity.xbm | 6 +++ embedded/lib/Pictures/luminosity.xbm | 6 +++ embedded/lib/Pictures/thermometer.xbm | 6 +++ 9 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 embedded/lib/Pictures/air_humidity.xbm create mode 100644 embedded/lib/Pictures/humidity.xbm create mode 100644 embedded/lib/Pictures/luminosity.xbm create mode 100644 embedded/lib/Pictures/thermometer.xbm diff --git a/embedded/lib/Display/Components/Box.hpp b/embedded/lib/Display/Components/Box.hpp index 5b7b426..ffc029d 100644 --- a/embedded/lib/Display/Components/Box.hpp +++ b/embedded/lib/Display/Components/Box.hpp @@ -44,7 +44,7 @@ namespace Display * @brief Construct a new Box object, can be ignored. */ Box(StyleHeight sh, u8g2_uint_t h_padding, uint16_t height) - : _styleHeight(sh), _paddingHeight(h_padding), _height(height) {}; + : _styleHeight(sh), _paddingHeight(h_padding), _height(height), _xOffset(0), _yOffset(0){}; /** * @brief Used to display the element on the screen. @@ -81,10 +81,18 @@ namespace Display virtual uint16_t getHeight() { return _height; } + virtual void SetOffset(uint16_t xOffset, uint16_t yOffset=0) + { + _xOffset = xOffset; + _yOffset = yOffset; + } + protected: StyleHeight _styleHeight; u8g2_uint_t _paddingHeight; uint16_t _height; + uint16_t _xOffset; + uint16_t _yOffset; }; } diff --git a/embedded/lib/Display/Components/SpriteBox.cpp b/embedded/lib/Display/Components/SpriteBox.cpp index ad77b37..94c2400 100644 --- a/embedded/lib/Display/Components/SpriteBox.cpp +++ b/embedded/lib/Display/Components/SpriteBox.cpp @@ -45,17 +45,19 @@ void SpriteBox::Calculate() void SpriteBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos) { const auto centeredOffset = (Screen::GetInstance().getHeight() - size); + auto x = _x + this->_xOffset; + auto y = size_pos + this->_yOffset; switch(this->_styleHeight) { case StyleHeight::CENTERED: case StyleHeight::FORCE_CENTERED: // idk must be the size of all the above - Screen::GetInstance().getScreen().drawXBM(_x, static_cast((centeredOffset / 2)) + size_pos,_width,_height,_sprite); + Screen::GetInstance().getScreen().drawXBM(x, static_cast((centeredOffset / 2)) + y,_width,_height,_sprite); break; case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawXBM(_x, centeredOffset + size_pos,_width,_height,_sprite); + Screen::GetInstance().getScreen().drawXBM(x, centeredOffset + y,_width,_height,_sprite); break; default: - Screen::GetInstance().getScreen().drawXBM(_x, size_pos,_width,_height,_sprite); + Screen::GetInstance().getScreen().drawXBM(x, y,_width,_height,_sprite); } } \ No newline at end of file diff --git a/embedded/lib/Display/Components/TextBox.cpp b/embedded/lib/Display/Components/TextBox.cpp index 9494fd1..b0eddfe 100644 --- a/embedded/lib/Display/Components/TextBox.cpp +++ b/embedded/lib/Display/Components/TextBox.cpp @@ -43,16 +43,18 @@ void TextBox::Calculate() void TextBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos) { const auto centeredOffset = (Screen::GetInstance().getHeight() - size); + const auto x = _paddingWidth + _x + this->_xOffset; + const auto y = size_pos + _height + this->_yOffset; switch (this->_styleHeight) { case StyleHeight::CENTERED: case StyleHeight::FORCE_CENTERED: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, static_cast((centeredOffset / 2)) + size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(x, static_cast((centeredOffset / 2)) + y, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; case StyleHeight::BOTTOM: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, centeredOffset + size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(x, centeredOffset + y, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); break; default: - Screen::GetInstance().getScreen().drawButtonUTF8(_paddingWidth + _x, size_pos + _height, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); + Screen::GetInstance().getScreen().drawButtonUTF8(x, y, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str()); } } \ No newline at end of file diff --git a/embedded/lib/Display/Screen.cpp b/embedded/lib/Display/Screen.cpp index 94c39e4..22af48d 100644 --- a/embedded/lib/Display/Screen.cpp +++ b/embedded/lib/Display/Screen.cpp @@ -4,6 +4,9 @@ // XBM Files #include "../Pictures/failed.xbm" +#include "../Pictures/humidity.xbm" +#include "../Pictures/thermometer.xbm" +#include "../Pictures/air_humidity.xbm" using namespace Display; @@ -25,7 +28,23 @@ void Screen::Setup(uint8_t *font) _font = font; _screen->setFont(_font); - headerSetup = TextBox("Clover Setup", StyleWidth::LEFT, StyleHeight::TOP, U8G2_BTN_INV, 2, 5, true); + // Creating Boxes + auto headerSetup = TextBox("Clover Setup", StyleWidth::LEFT, StyleHeight::TOP, U8G2_BTN_INV, 2, 5, true); + auto plantHumidity = TextBox("plantHumidity", StyleWidth::LEFT, StyleHeight::TOP, U8G2_BTN_BW0, 0, 0); + auto airTemperature = TextBox("airTemperature", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 0); + auto airHumidity = TextBox("airHumidity", StyleWidth::LEFT, StyleHeight::BOTTOM, U8G2_BTN_BW0, 0, 6); + auto humidityPicture = SpriteBox(humidity_bits,humidity_width,humidity_height,StyleWidth::LEFT,StyleHeight::CENTERED); + auto thermometerPicture = SpriteBox(thermometer_bits,thermometer_width,thermometer_height,StyleWidth::LEFT,StyleHeight::CENTERED); + auto airHumidityPicture = SpriteBox(air_humidity_bits,air_humidity_width,air_humidity_height,StyleWidth::LEFT,StyleHeight::CENTERED); + + // Config Boxes + plantHumidity.SetOffset(OFFSET_TEXT,12); + airTemperature.SetOffset(OFFSET_TEXT); + airHumidity.SetOffset(OFFSET_TEXT); + humidityPicture.SetOffset(OFFSET_ICONS); + thermometerPicture.SetOffset(OFFSET_ICONS); + airHumidityPicture.SetOffset(OFFSET_ICONS); + // Static Components connectingWindow.Add({std::make_shared(headerSetup), std::make_shared(TextBox("connect", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0))}); @@ -37,10 +56,12 @@ void Screen::Setup(uint8_t *font) std::make_shared(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), std::make_shared(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); bootWindow.Add(std::make_shared(SpriteBox(CLOVER_FRAMES[0].data, CLOVER_FRAMES[0].height, CLOVER_FRAMES[0].width, StyleWidth::CENTERED, StyleHeight::CENTERED))); - loopWindow.Add({std::make_shared(TextBox("plantHumidity", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), - std::make_shared(TextBox("airTemperature", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), - std::make_shared(TextBox("airHumidity", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)), - std::make_shared(TextBox("light", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))}); + loopWindow.Add({std::make_shared(plantHumidity), + std::make_shared(airTemperature), + std::make_shared(airHumidity)}); + iconWindow.Add({std::make_shared(humidityPicture), + std::make_shared(thermometerPicture), + std::make_shared(airHumidityPicture)}); } void Screen::connecting(uint8_t state) @@ -111,12 +132,13 @@ void Screen::loop(const float plantHumidity, const float airTemperature, const f { _screen->clearBuffer(); // Updating with values - loopWindow.Update(0,String("Humidity: ")+String(plantHumidity,2)+String("%")); - loopWindow.Update(1,String("Air Temperature: ")+String(airTemperature,2)+String("°C")); - loopWindow.Update(2,String("Air Humidity: ")+String(airHumidity,2)+String("%")); - loopWindow.Update(3,String("Light: ")+String(light,2)+String("%")); + loopWindow.Update(0,String("Hum: ")+String(plantHumidity,1)+String("%")); + loopWindow.Update(1,String("Tem: ")+String(airTemperature,1)+String("°C")); + loopWindow.Update(2,String("Hum: ")+String(airHumidity,1)+String("%")); + //loopWindow.Update(3,String("Light: ")+String(light,1)+String("%")); // Component loopWindow.Display(); + iconWindow.Display(); // Displaying _screen->sendBuffer(); } diff --git a/embedded/lib/Display/Screen.hpp b/embedded/lib/Display/Screen.hpp index ad45663..c92c9c5 100644 --- a/embedded/lib/Display/Screen.hpp +++ b/embedded/lib/Display/Screen.hpp @@ -36,6 +36,8 @@ namespace Display {clover11_bits, clover11_width, clover11_height}, }; constexpr uint8_t MAX_BOOT_FRAMES = 25; + constexpr uint8_t OFFSET_ICONS = 55; + constexpr uint8_t OFFSET_TEXT = 75; class Screen { @@ -77,12 +79,12 @@ namespace Display bool _booted; // Static Components - TextBox headerSetup; Components connectingWindow; Components connectionfailedWindow; Components connectedWindow; Components bootWindow; Components loopWindow; + Components iconWindow; }; } diff --git a/embedded/lib/Pictures/air_humidity.xbm b/embedded/lib/Pictures/air_humidity.xbm new file mode 100644 index 0000000..1e05f61 --- /dev/null +++ b/embedded/lib/Pictures/air_humidity.xbm @@ -0,0 +1,6 @@ +#define air_humidity_width 16 +#define air_humidity_height 16 +static unsigned char air_humidity_bits[] = { + 0x60, 0x00, 0x90, 0x00, 0x18, 0x01, 0x24, 0x02, 0x42, 0x0a, 0x42, 0x0a, + 0x04, 0x19, 0xf8, 0x3c, 0x00, 0x3e, 0x00, 0x7f, 0xe0, 0x7f, 0xe0, 0x7f, + 0xc0, 0x3f, 0x80, 0x1f, 0x00, 0x0f, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/humidity.xbm b/embedded/lib/Pictures/humidity.xbm new file mode 100644 index 0000000..1b8eed4 --- /dev/null +++ b/embedded/lib/Pictures/humidity.xbm @@ -0,0 +1,6 @@ +#define humidity_width 16 +#define humidity_height 16 +static unsigned char humidity_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0x40, 0x03, 0x40, 0x03, + 0xa0, 0x07, 0xd0, 0x0f, 0xf0, 0x0f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, + 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/luminosity.xbm b/embedded/lib/Pictures/luminosity.xbm new file mode 100644 index 0000000..8894479 --- /dev/null +++ b/embedded/lib/Pictures/luminosity.xbm @@ -0,0 +1,6 @@ +#define luminosity_width 16 +#define luminosity_height 16 +static unsigned char luminosity_bits[] = { + 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0x18, 0x18, 0xc8, 0x13, 0xe0, 0x07, + 0xf4, 0x2f, 0xf6, 0x6f, 0xf6, 0x6f, 0xf4, 0x2f, 0xe0, 0x07, 0xc8, 0x13, + 0x18, 0x18, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00 }; diff --git a/embedded/lib/Pictures/thermometer.xbm b/embedded/lib/Pictures/thermometer.xbm new file mode 100644 index 0000000..2576f17 --- /dev/null +++ b/embedded/lib/Pictures/thermometer.xbm @@ -0,0 +1,6 @@ +#define thermometer_width 16 +#define thermometer_height 16 +static unsigned char thermometer_bits[] = { + 0x00, 0x00, 0x80, 0x01, 0x40, 0x02, 0xc0, 0x02, 0x40, 0x02, 0xc0, 0x02, + 0x40, 0x02, 0xc0, 0x02, 0x40, 0x02, 0x20, 0x04, 0x10, 0x08, 0xf0, 0x0f, + 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x00, 0x00 };