mirror of
https://github.com/Lemonochrme/clover.git
synced 2025-06-08 08:40:50 +02:00
DataHandler: Rearanged data acquisition to handle more sensors. Screen: Showing example screen.
This commit is contained in:
parent
0fe4c2ecee
commit
36fc6b40fb
5 changed files with 40 additions and 21 deletions
|
@ -4,13 +4,10 @@ DataHandler::DataHandler() {}
|
|||
|
||||
DataHandler::~DataHandler() {}
|
||||
|
||||
void DataHandler::updateTemperatureData(float temp) {
|
||||
temperature = temp;
|
||||
}
|
||||
|
||||
void DataHandler::updateHumidityData(float hum) {
|
||||
humidity = hum;
|
||||
}
|
||||
void DataHandler::updatePlantHumidityData(float humidity) { plantHumidity = humidity; }
|
||||
void DataHandler::updateAirTemperatureData(float temperature) { airTemperature = temperature; }
|
||||
void DataHandler::updateAirHumidityData(float humidity) { airHumidity = humidity; }
|
||||
void DataHandler::updateLightData(float light) { this->light = light; }
|
||||
|
||||
String DataHandler::getJsonData() {
|
||||
return buildJson();
|
||||
|
@ -18,8 +15,10 @@ String DataHandler::getJsonData() {
|
|||
|
||||
String DataHandler::buildJson() {
|
||||
StaticJsonDocument<200> document; // Taille = 200
|
||||
document["temperature"] = temperature;
|
||||
document["humidity"] = humidity;
|
||||
document["plantHumidity"] = plantHumidity;
|
||||
document["airTemperature"] = airTemperature;
|
||||
document["airHumidity"] = airHumidity;
|
||||
document["light"] = light;
|
||||
|
||||
String jsonFormattedData;
|
||||
serializeJson(document, jsonFormattedData);
|
||||
|
|
|
@ -13,8 +13,10 @@ public:
|
|||
}
|
||||
// Public functions
|
||||
String getJsonData();
|
||||
void updateTemperatureData(float temperature);
|
||||
void updateHumidityData(float humidity);
|
||||
void updatePlantHumidityData(float humidity);
|
||||
void updateAirTemperatureData(float temperature);
|
||||
void updateAirHumidityData(float humidity);
|
||||
void updateLightData(float light);
|
||||
|
||||
private:
|
||||
// Singleton
|
||||
|
@ -22,8 +24,14 @@ private:
|
|||
~DataHandler();
|
||||
DataHandler(const DataHandler&) = delete;
|
||||
DataHandler& operator=(const DataHandler&) = delete;
|
||||
float temperature;
|
||||
float humidity;
|
||||
|
||||
// Variables
|
||||
float plantHumidity;
|
||||
float airTemperature;
|
||||
float airHumidity;
|
||||
float light;
|
||||
|
||||
// Fonctions
|
||||
String buildJson();
|
||||
};
|
||||
|
||||
|
|
|
@ -37,7 +37,10 @@ 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("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)));
|
||||
loopWindow.Add(std::make_shared<TextBox>(TextBox("Welcome to Clover!", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)));
|
||||
loopWindow.Add({std::make_shared<TextBox>(TextBox("plantHumidity", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
|
||||
std::make_shared<TextBox>(TextBox("airTemperature", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
|
||||
std::make_shared<TextBox>(TextBox("airHumidity", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
|
||||
std::make_shared<TextBox>(TextBox("light", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))});
|
||||
}
|
||||
|
||||
void Screen::connecting(uint8_t state)
|
||||
|
@ -104,9 +107,14 @@ void Screen::boot()
|
|||
_screen->sendBuffer();
|
||||
}
|
||||
|
||||
void Screen::loop()
|
||||
void Screen::loop(const float plantHumidity, const float airTemperature, const float airHumidity, const float light)
|
||||
{
|
||||
_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("%"));
|
||||
// Component
|
||||
loopWindow.Display();
|
||||
// Displaying
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace Display
|
|||
void notConnected();
|
||||
void connected(const char *ipaddress, uint8_t timing);
|
||||
void boot();
|
||||
void loop();
|
||||
void loop(const float plantHumidity, const float airTemperature, const float airHumidity, const float light);
|
||||
// Getters
|
||||
uint16_t getHeight();
|
||||
uint16_t getWidth();
|
||||
|
|
|
@ -54,16 +54,20 @@ void loop()
|
|||
|
||||
// Data gathered from various sensors
|
||||
// 0 -> air(0), 0-300 -> dry(20), 300-700 -> humid (580), 700-950 -> water(940)
|
||||
auto humidityData = static_cast<float>(std::any_cast<int>(humidity.getValue()));
|
||||
auto temperatureData = random(300, 150) / 10.0;
|
||||
auto plantHumidityData = static_cast<float>(std::any_cast<int>(humidity.getValue()));
|
||||
auto airTemperatureData = random(150, 300) / 10.0;
|
||||
auto airHumidityData = random(0, 1000) / 10.0;
|
||||
auto lightData = random(0, 1000) / 10.0;
|
||||
|
||||
// Updating the data handler
|
||||
dataHandler.updateTemperatureData(temperatureData);
|
||||
dataHandler.updateHumidityData(humidityData);
|
||||
dataHandler.updatePlantHumidityData(plantHumidityData);
|
||||
dataHandler.updateAirTemperatureData(airTemperatureData);
|
||||
dataHandler.updateAirHumidityData(airHumidityData);
|
||||
dataHandler.updateLightData(lightData);
|
||||
// (debug) Printing to serial the data
|
||||
Serial.println(dataHandler.getJsonData());
|
||||
// Screen showing
|
||||
screen.loop();
|
||||
screen.loop(plantHumidityData,airTemperatureData,airHumidityData,lightData);
|
||||
// Server sending data
|
||||
serverHandler.loop();
|
||||
}
|
Loading…
Add table
Reference in a new issue