Création du composant LCD, rajout des écrans de logs et du dashboard

This commit is contained in:
2024-01-19 16:40:28 +01:00
parent b7fe429508
commit 4f3a5bda03
7 changed files with 310 additions and 46 deletions

View File

@ -1,29 +1,52 @@
#include "Program.h"
#include "Arduino.h"
#include "M5LCD.h"
#include "DolibarrClient.h"
int initialize_wifi(WifiConfig wifi) {
lcdScreen->add_log("Connecting to the WiFi network...");
WiFiClass::mode(WIFI_STA); //Optional
WiFi.setSleep(false);
WiFi.begin(wifi.ssid, wifi.password);
Serial.print("Connecting ");
while(WiFiClass::status() != WL_CONNECTED){
delay(WAITING_WIFI_DELAY);
Serial.print(".");
}
Serial.println("Connected to the WiFi network");
return 0;
}
Program::Program() {
/*lcd = new M5LCD();*/
lcdScreen = new M5LCD();
lcdScreen->add_log("Initialize M5LCD component....");
Serial.begin(MONITOR_SPEED);
struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD};
struct DolibarrConfig dolibarr = {DOLIBARR_URL, DOLIBARR_API_TOKEN};
initialize_wifi(wifi_c);
this->client = new DolibarrClient(dolibarr);
}
void Program::loop() {
lcdScreen->update();
if (WiFiClass::status() == WL_CONNECTED && lcdScreen->get_components().wifi != COMPONENT_OK) {
lcdScreen->add_log("Connected to the WiFi network");
lcdScreen->set_wifi_status(COMPONENT_OK);
struct DolibarrConfig dolibarr = {DOLIBARR_URL, DOLIBARR_API_TOKEN};
this->client = new DolibarrClient(dolibarr);
auto *warehouses = this->client->list_warehouse();
if (warehouses != nullptr) {
lcdScreen->add_log("Warehouses found !");
lcdScreen->set_dolibarr_status(COMPONENT_OK);
for (auto &a : *warehouses) {
char buffer[50];
sprintf(buffer, "+ Warehouse '%s' (%s)", a.label.c_str(), a.id.c_str());
lcdScreen->add_log(buffer);
}
} else {
lcdScreen->add_log("Warehouse not found");
lcdScreen->set_dolibarr_status(COMPONENT_KO);
}
} else if (WiFiClass::status() != WL_CONNECTED && lcdScreen->get_components().wifi == COMPONENT_OK) {
lcdScreen->add_log("Wifi signal lost, reconnecting...");
lcdScreen->set_wifi_status(COMPONENT_KO);
struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD};
initialize_wifi(wifi_c);
}
}