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