mirror of
https://github.com/Lemonochrme/clover.git
synced 2025-06-08 16:50:50 +02:00
Screen: Added icons for sensors. Added offset control for all Boxes. Created window for icons. Stylized main loop.
This commit is contained in:
parent
36fc6b40fb
commit
d96c5a670e
9 changed files with 77 additions and 17 deletions
|
@ -44,7 +44,7 @@ namespace Display
|
||||||
* @brief Construct a new Box object, can be ignored.
|
* @brief Construct a new Box object, can be ignored.
|
||||||
*/
|
*/
|
||||||
Box(StyleHeight sh, u8g2_uint_t h_padding, uint16_t height)
|
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.
|
* @brief Used to display the element on the screen.
|
||||||
|
@ -81,10 +81,18 @@ namespace Display
|
||||||
|
|
||||||
virtual uint16_t getHeight() { return _height; }
|
virtual uint16_t getHeight() { return _height; }
|
||||||
|
|
||||||
|
virtual void SetOffset(uint16_t xOffset, uint16_t yOffset=0)
|
||||||
|
{
|
||||||
|
_xOffset = xOffset;
|
||||||
|
_yOffset = yOffset;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
StyleHeight _styleHeight;
|
StyleHeight _styleHeight;
|
||||||
u8g2_uint_t _paddingHeight;
|
u8g2_uint_t _paddingHeight;
|
||||||
uint16_t _height;
|
uint16_t _height;
|
||||||
|
uint16_t _xOffset;
|
||||||
|
uint16_t _yOffset;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,17 +45,19 @@ void SpriteBox::Calculate()
|
||||||
void SpriteBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos)
|
void SpriteBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos)
|
||||||
{
|
{
|
||||||
const auto centeredOffset = (Screen::GetInstance().getHeight() - size);
|
const auto centeredOffset = (Screen::GetInstance().getHeight() - size);
|
||||||
|
auto x = _x + this->_xOffset;
|
||||||
|
auto y = size_pos + this->_yOffset;
|
||||||
switch(this->_styleHeight)
|
switch(this->_styleHeight)
|
||||||
{
|
{
|
||||||
case StyleHeight::CENTERED:
|
case StyleHeight::CENTERED:
|
||||||
case StyleHeight::FORCE_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)) + y,_width,_height,_sprite);
|
||||||
break;
|
break;
|
||||||
case StyleHeight::BOTTOM:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
Screen::GetInstance().getScreen().drawXBM(_x, size_pos,_width,_height,_sprite);
|
Screen::GetInstance().getScreen().drawXBM(x, y,_width,_height,_sprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -43,16 +43,18 @@ void TextBox::Calculate()
|
||||||
void TextBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos)
|
void TextBox::Display(u8g2_uint_t size, u8g2_uint_t size_pos)
|
||||||
{
|
{
|
||||||
const auto centeredOffset = (Screen::GetInstance().getHeight() - size);
|
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)
|
switch (this->_styleHeight)
|
||||||
{
|
{
|
||||||
case StyleHeight::CENTERED:
|
case StyleHeight::CENTERED:
|
||||||
case StyleHeight::FORCE_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(x, static_cast<uint16_t>((centeredOffset / 2)) + y, _style, _textWidth, this->_paddingHeight, _paddingWidth, _text.c_str());
|
||||||
break;
|
break;
|
||||||
case StyleHeight::BOTTOM:
|
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;
|
break;
|
||||||
default:
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
// XBM Files
|
// XBM Files
|
||||||
#include "../Pictures/failed.xbm"
|
#include "../Pictures/failed.xbm"
|
||||||
|
#include "../Pictures/humidity.xbm"
|
||||||
|
#include "../Pictures/thermometer.xbm"
|
||||||
|
#include "../Pictures/air_humidity.xbm"
|
||||||
|
|
||||||
using namespace Display;
|
using namespace Display;
|
||||||
|
|
||||||
|
@ -25,7 +28,23 @@ void Screen::Setup(uint8_t *font)
|
||||||
_font = font;
|
_font = font;
|
||||||
_screen->setFont(_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
|
// 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))});
|
||||||
|
@ -37,10 +56,12 @@ void Screen::Setup(uint8_t *font)
|
||||||
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)),
|
||||||
std::make_shared<TextBox>(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))});
|
std::make_shared<TextBox>(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))});
|
||||||
bootWindow.Add(std::make_shared<SpriteBox>(SpriteBox(CLOVER_FRAMES[0].data, CLOVER_FRAMES[0].height, CLOVER_FRAMES[0].width, StyleWidth::CENTERED, StyleHeight::CENTERED)));
|
bootWindow.Add(std::make_shared<SpriteBox>(SpriteBox(CLOVER_FRAMES[0].data, CLOVER_FRAMES[0].height, CLOVER_FRAMES[0].width, StyleWidth::CENTERED, StyleHeight::CENTERED)));
|
||||||
loopWindow.Add({std::make_shared<TextBox>(TextBox("plantHumidity", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
|
loopWindow.Add({std::make_shared<TextBox>(plantHumidity),
|
||||||
std::make_shared<TextBox>(TextBox("airTemperature", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
|
std::make_shared<TextBox>(airTemperature),
|
||||||
std::make_shared<TextBox>(TextBox("airHumidity", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
|
std::make_shared<TextBox>(airHumidity)});
|
||||||
std::make_shared<TextBox>(TextBox("light", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))});
|
iconWindow.Add({std::make_shared<SpriteBox>(humidityPicture),
|
||||||
|
std::make_shared<SpriteBox>(thermometerPicture),
|
||||||
|
std::make_shared<SpriteBox>(airHumidityPicture)});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::connecting(uint8_t state)
|
void Screen::connecting(uint8_t state)
|
||||||
|
@ -111,12 +132,13 @@ void Screen::loop(const float plantHumidity, const float airTemperature, const f
|
||||||
{
|
{
|
||||||
_screen->clearBuffer();
|
_screen->clearBuffer();
|
||||||
// Updating with values
|
// Updating with values
|
||||||
loopWindow.Update(0,String("Humidity: ")+String(plantHumidity,2)+String("%"));
|
loopWindow.Update(0,String("Hum: ")+String(plantHumidity,1)+String("%"));
|
||||||
loopWindow.Update(1,String("Air Temperature: ")+String(airTemperature,2)+String("°C"));
|
loopWindow.Update(1,String("Tem: ")+String(airTemperature,1)+String("°C"));
|
||||||
loopWindow.Update(2,String("Air Humidity: ")+String(airHumidity,2)+String("%"));
|
loopWindow.Update(2,String("Hum: ")+String(airHumidity,1)+String("%"));
|
||||||
loopWindow.Update(3,String("Light: ")+String(light,2)+String("%"));
|
//loopWindow.Update(3,String("Light: ")+String(light,1)+String("%"));
|
||||||
// Component
|
// Component
|
||||||
loopWindow.Display();
|
loopWindow.Display();
|
||||||
|
iconWindow.Display();
|
||||||
// Displaying
|
// Displaying
|
||||||
_screen->sendBuffer();
|
_screen->sendBuffer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ namespace Display
|
||||||
{clover11_bits, clover11_width, clover11_height},
|
{clover11_bits, clover11_width, clover11_height},
|
||||||
};
|
};
|
||||||
constexpr uint8_t MAX_BOOT_FRAMES = 25;
|
constexpr uint8_t MAX_BOOT_FRAMES = 25;
|
||||||
|
constexpr uint8_t OFFSET_ICONS = 55;
|
||||||
|
constexpr uint8_t OFFSET_TEXT = 75;
|
||||||
|
|
||||||
class Screen
|
class Screen
|
||||||
{
|
{
|
||||||
|
@ -77,12 +79,12 @@ namespace Display
|
||||||
bool _booted;
|
bool _booted;
|
||||||
|
|
||||||
// Static Components
|
// Static Components
|
||||||
TextBox headerSetup;
|
|
||||||
Components connectingWindow;
|
Components connectingWindow;
|
||||||
Components connectionfailedWindow;
|
Components connectionfailedWindow;
|
||||||
Components connectedWindow;
|
Components connectedWindow;
|
||||||
Components bootWindow;
|
Components bootWindow;
|
||||||
Components loopWindow;
|
Components loopWindow;
|
||||||
|
Components iconWindow;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
embedded/lib/Pictures/air_humidity.xbm
Normal file
6
embedded/lib/Pictures/air_humidity.xbm
Normal file
|
@ -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 };
|
6
embedded/lib/Pictures/humidity.xbm
Normal file
6
embedded/lib/Pictures/humidity.xbm
Normal file
|
@ -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 };
|
6
embedded/lib/Pictures/luminosity.xbm
Normal file
6
embedded/lib/Pictures/luminosity.xbm
Normal file
|
@ -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 };
|
6
embedded/lib/Pictures/thermometer.xbm
Normal file
6
embedded/lib/Pictures/thermometer.xbm
Normal file
|
@ -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 };
|
Loading…
Add table
Reference in a new issue