mirror of
https://github.com/Lemonochrme/clover.git
synced 2025-06-08 08:40:50 +02:00
Renamed Moisture to Warning. Pictures: Added warning icons. Display: Added setWarningIcon(), some constexpr for icons. Warning: Added warningScreenLoop() and Renamed warningLedLoop().
This commit is contained in:
parent
d58f0ec9b4
commit
d203161a1b
10 changed files with 143 additions and 57 deletions
|
@ -6,9 +6,6 @@
|
|||
|
||||
// XBM Files
|
||||
#include "../Pictures/failed.xbm"
|
||||
#include "../Pictures/humidity.xbm"
|
||||
#include "../Pictures/thermometer.xbm"
|
||||
#include "../Pictures/air_humidity.xbm"
|
||||
|
||||
using namespace Display;
|
||||
|
||||
|
@ -35,9 +32,9 @@ void Screen::Setup(uint8_t *font)
|
|||
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);
|
||||
auto humidityPicture = SpriteBox(ICONS[0].data,ICONS[0].width,ICONS[0].height,StyleWidth::LEFT,StyleHeight::CENTERED);
|
||||
auto thermometerPicture = SpriteBox(ICONS[1].data,ICONS[1].width,ICONS[1].height,StyleWidth::LEFT,StyleHeight::CENTERED);
|
||||
auto airHumidityPicture = SpriteBox(ICONS[2].data,ICONS[2].width,ICONS[2].height,StyleWidth::LEFT,StyleHeight::CENTERED);
|
||||
|
||||
// Config Boxes
|
||||
plantHumidity.SetOffset(OFFSET_TEXT,12);
|
||||
|
@ -148,6 +145,15 @@ void Screen::loop(const float plantHumidity, const float airTemperature, const f
|
|||
_screen->sendBuffer();
|
||||
}
|
||||
|
||||
void Screen::setWarningIcon(Sensors sensorId, bool warning)
|
||||
{
|
||||
const auto realId = static_cast<size_t>(sensorId);
|
||||
if(warning)
|
||||
iconWindow.Update(realId,ICONS_WARNING[realId]);
|
||||
else
|
||||
iconWindow.Update(realId,ICONS[realId]);
|
||||
}
|
||||
|
||||
uint16_t Screen::getHeight() { return _height; }
|
||||
uint16_t Screen::getWidth() { return _width; }
|
||||
U8G2_SSD1306_128X64_NONAME_F_HW_I2C &Screen::getScreen() { return *_screen; }
|
||||
|
|
|
@ -20,6 +20,14 @@
|
|||
#include "../Pictures/clover10.xbm"
|
||||
#include "../Pictures/clover11.xbm"
|
||||
|
||||
// Icons
|
||||
#include "../Pictures/humidity.xbm"
|
||||
#include "../Pictures/thermometer.xbm"
|
||||
#include "../Pictures/air_humidity.xbm"
|
||||
#include "../Pictures/humidity-warning.xbm"
|
||||
#include "../Pictures/thermometer-warning.xbm"
|
||||
#include "../Pictures/air_humidity-warning.xbm"
|
||||
|
||||
namespace Display
|
||||
{
|
||||
constexpr Picture CLOVER_FRAMES[] = {
|
||||
|
@ -35,10 +43,26 @@ namespace Display
|
|||
{clover10_bits, clover10_width, clover10_height},
|
||||
{clover11_bits, clover11_width, clover11_height},
|
||||
};
|
||||
constexpr Picture ICONS[] = {
|
||||
{humidity_bits,humidity_width,humidity_height},
|
||||
{thermometer_bits,thermometer_width,thermometer_height},
|
||||
{air_humidity_bits,air_humidity_width,air_humidity_height},
|
||||
};
|
||||
constexpr Picture ICONS_WARNING[] = {
|
||||
{humidity_warning_bits,humidity_warning_width,humidity_warning_height},
|
||||
{thermometer_warning_bits,thermometer_warning_width,thermometer_warning_height},
|
||||
{air_humidity_warning_bits,air_humidity_warning_width,air_humidity_warning_height},
|
||||
};
|
||||
constexpr uint8_t MAX_BOOT_FRAMES = 25;
|
||||
constexpr uint8_t OFFSET_ICONS = 55;
|
||||
constexpr uint8_t OFFSET_TEXT = 75;
|
||||
|
||||
enum class Sensors {
|
||||
SOIL_MOISTURE = 0,
|
||||
THERMOMETER,
|
||||
AIR_HUMIDITY
|
||||
};
|
||||
|
||||
class Screen
|
||||
{
|
||||
public:
|
||||
|
@ -55,6 +79,7 @@ namespace Display
|
|||
void connected(const char *ipaddress, uint8_t timing);
|
||||
void boot();
|
||||
void loop(const float plantHumidity, const float airTemperature, const float airHumidity);
|
||||
void setWarningIcon(Sensors sensorId, bool warning=true);
|
||||
// Getters
|
||||
uint16_t getHeight();
|
||||
uint16_t getWidth();
|
||||
|
|
6
embedded/lib/Pictures/air_humidity-warning.xbm
Normal file
6
embedded/lib/Pictures/air_humidity-warning.xbm
Normal file
|
@ -0,0 +1,6 @@
|
|||
#define air_humidity_warning_width 16
|
||||
#define air_humidity_warning_height 16
|
||||
static unsigned char air_humidity_warning_bits[] = {
|
||||
0x60, 0x00, 0x90, 0x00, 0x18, 0x01, 0x24, 0x02, 0x42, 0x0a, 0x42, 0x0a,
|
||||
0x04, 0x19, 0x90, 0x3c, 0x38, 0x3e, 0x28, 0x7f, 0x6c, 0x7f, 0x6c, 0x7e,
|
||||
0xfe, 0x3e, 0xee, 0x1e, 0xfe, 0x0e, 0x00, 0x00 };
|
6
embedded/lib/Pictures/humidity-warning.xbm
Normal file
6
embedded/lib/Pictures/humidity-warning.xbm
Normal file
|
@ -0,0 +1,6 @@
|
|||
#define humidity_warning_width 16
|
||||
#define humidity_warning_height 16
|
||||
static unsigned char humidity_warning_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0x40, 0x03, 0x40, 0x03,
|
||||
0x80, 0x07, 0x90, 0x0f, 0xb8, 0x0f, 0x28, 0x1f, 0x6c, 0x1f, 0x6c, 0x1e,
|
||||
0xfe, 0x0e, 0xee, 0x06, 0xfe, 0x02, 0x00, 0x00 };
|
6
embedded/lib/Pictures/thermometer-warning.xbm
Normal file
6
embedded/lib/Pictures/thermometer-warning.xbm
Normal file
|
@ -0,0 +1,6 @@
|
|||
#define thermometer_warning_width 16
|
||||
#define thermometer_warning_height 16
|
||||
static unsigned char thermometer_warning_bits[] = {
|
||||
0x00, 0x00, 0x80, 0x01, 0x40, 0x02, 0xc0, 0x02, 0x40, 0x02, 0xc0, 0x02,
|
||||
0x40, 0x02, 0x90, 0x02, 0x38, 0x02, 0x28, 0x04, 0x6c, 0x08, 0x6c, 0x0e,
|
||||
0xfe, 0x0e, 0xee, 0x06, 0xfe, 0x02, 0x00, 0x00 };
|
|
@ -5,7 +5,7 @@
|
|||
#include "ServerHandler.hpp"
|
||||
#include "MainComponent.hpp"
|
||||
#include "Screen.hpp"
|
||||
#include "moisture.hpp"
|
||||
#include "warning.hpp"
|
||||
|
||||
#ifdef SSID_CLOVER
|
||||
const char *ssid = SSID_CLOVER;
|
||||
|
@ -72,7 +72,8 @@ void loop()
|
|||
|
||||
// Showing screen
|
||||
screen.loop((soilHumidityData / 950.0f) * 100.0f, airTemperatureData, airHumidityData);
|
||||
plantLedLoop(soilHumidityData);
|
||||
Warning::warningLedLoop(soilHumidityData);
|
||||
Warning::warningScreenLoop(soilHumidityData,airTemperatureData,airHumidityData);
|
||||
|
||||
serverHandler.loop();
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#include "moisture.hpp"
|
||||
|
||||
LedMoistureStatus moisture_status(LedMoistureStatus::IDLE);
|
||||
|
||||
void plantLedLoop(float soilHumidity)
|
||||
{
|
||||
auto& led = MainComponent::GetInstance().getLed();
|
||||
|
||||
if ((soilHumidity < MoistureLevel::DRY) && (moisture_status != LedMoistureStatus::DRY))
|
||||
{
|
||||
moisture_status = LedMoistureStatus::DRY;
|
||||
led.setColor(LedNumber::LED_PLANT,LedColors::TOO_DRY,200);
|
||||
}
|
||||
else if (soilHumidity >= MoistureLevel::DRY && soilHumidity < MoistureLevel::HUMID)
|
||||
{
|
||||
led.setColor(LedNumber::LED_PLANT,LedColors::LED_OFF);
|
||||
moisture_status = LedMoistureStatus::IDLE;
|
||||
}
|
||||
else if ((soilHumidity >= MoistureLevel::HUMID) && (moisture_status != LedMoistureStatus::WET))
|
||||
{
|
||||
moisture_status = LedMoistureStatus::WET;
|
||||
led.setColor(LedNumber::LED_PLANT,LedColors::TOO_WET,200);
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef _HEADER_MOISTURE
|
||||
#define _HEADER_MOISTURE
|
||||
|
||||
#include "MainComponent.hpp"
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief See the documentation on 'https://www.mouser.com/datasheet/2/744/Seeed_101020008-1217463.pdf'
|
||||
*/
|
||||
namespace MoistureLevel {
|
||||
constexpr uint16_t AIR = 0;
|
||||
constexpr uint16_t DRY = 300;
|
||||
constexpr uint16_t HUMID = 700;
|
||||
constexpr uint16_t WATER = 950;
|
||||
}
|
||||
|
||||
enum class LedMoistureStatus {
|
||||
IDLE,
|
||||
DRY,
|
||||
WET
|
||||
};
|
||||
|
||||
void plantLedLoop(float soilHumidity);
|
||||
|
||||
#endif // _HEADER_MOISTURE
|
52
embedded/src/warning.cpp
Normal file
52
embedded/src/warning.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "warning.hpp"
|
||||
|
||||
#include "Screen.hpp"
|
||||
#include "MainComponent.hpp"
|
||||
|
||||
using namespace Warning;
|
||||
|
||||
LedMoistureStatus moisture_status(LedMoistureStatus::IDLE);
|
||||
|
||||
void Warning::warningLedLoop(const float soilHumidity)
|
||||
{
|
||||
auto& led = MainComponent::GetInstance().getLed();
|
||||
|
||||
if ((soilHumidity < MoistureLevel::DRY) && (moisture_status != LedMoistureStatus::DRY))
|
||||
{
|
||||
moisture_status = LedMoistureStatus::DRY;
|
||||
led.setColor(LedNumber::LED_PLANT,LedColors::TOO_DRY,200);
|
||||
}
|
||||
else if (soilHumidity >= MoistureLevel::DRY && soilHumidity < MoistureLevel::HUMID)
|
||||
{
|
||||
led.setColor(LedNumber::LED_PLANT,LedColors::LED_OFF);
|
||||
moisture_status = LedMoistureStatus::IDLE;
|
||||
}
|
||||
else if ((soilHumidity >= MoistureLevel::HUMID) && (moisture_status != LedMoistureStatus::WET))
|
||||
{
|
||||
moisture_status = LedMoistureStatus::WET;
|
||||
led.setColor(LedNumber::LED_PLANT,LedColors::TOO_WET,200);
|
||||
}
|
||||
}
|
||||
|
||||
void Warning::warningScreenLoop(const float plantMoisture, const float airTemperature, const float airHumidity)
|
||||
{
|
||||
auto& display = Display::Screen::GetInstance();
|
||||
|
||||
// Plant Moisture Warning
|
||||
if(plantMoisture < MoistureLevel::DRY || plantMoisture > MoistureLevel::HUMID)
|
||||
display.setWarningIcon(Display::Sensors::SOIL_MOISTURE);
|
||||
else
|
||||
display.setWarningIcon(Display::Sensors::SOIL_MOISTURE,false);
|
||||
|
||||
// Temperature Warning
|
||||
if(airTemperature >= AIR_TEMPERATURE_TOO_HOT || airTemperature <= AIR_TEMPERATURE_TOO_COLD)
|
||||
display.setWarningIcon(Display::Sensors::THERMOMETER);
|
||||
else
|
||||
display.setWarningIcon(Display::Sensors::THERMOMETER,false);
|
||||
|
||||
// Humidity Warning
|
||||
if(airHumidity >= AIR_HUMIDITY_SATURATED)
|
||||
display.setWarningIcon(Display::Sensors::AIR_HUMIDITY);
|
||||
else
|
||||
display.setWarningIcon(Display::Sensors::AIR_HUMIDITY,false);
|
||||
}
|
33
embedded/src/warning.hpp
Normal file
33
embedded/src/warning.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef _HEADER_WARNING
|
||||
#define _HEADER_WARNING
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Warning {
|
||||
/**
|
||||
* @brief See the documentation on 'https://www.mouser.com/datasheet/2/744/Seeed_101020008-1217463.pdf'
|
||||
*/
|
||||
namespace MoistureLevel {
|
||||
constexpr uint16_t AIR = 0;
|
||||
constexpr uint16_t DRY = 300;
|
||||
constexpr uint16_t HUMID = 700;
|
||||
constexpr uint16_t WATER = 950;
|
||||
}
|
||||
constexpr float AIR_HUMIDITY_SATURATED = 95.0f;
|
||||
/**
|
||||
* @brief Source : 'https://extension.umd.edu/resource/temperature-and-humidity-indoor-plants/'
|
||||
*/
|
||||
constexpr float AIR_TEMPERATURE_TOO_HOT = 29.0f;
|
||||
constexpr float AIR_TEMPERATURE_TOO_COLD = 14.0f;
|
||||
|
||||
enum class LedMoistureStatus {
|
||||
IDLE,
|
||||
DRY,
|
||||
WET
|
||||
};
|
||||
|
||||
void warningLedLoop(const float soilHumidity);
|
||||
void warningScreenLoop(const float plantMoisture, const float airTemperature, const float airHumidity);
|
||||
}
|
||||
|
||||
#endif // _HEADER_WARNING
|
Loading…
Add table
Reference in a new issue