121 lines
4.0 KiB
C++
121 lines
4.0 KiB
C++
/* Rui Santos & Sara Santos - Random Nerd Tutorials - https://RandomNerdTutorials.com/esp32-lvgl-ebook/
|
||
THIS EXAMPLE WAS TESTED WITH THE FOLLOWING HARDWARE:
|
||
1) ESP32-2432S028R 2.8 inch 240×320 also known as the Cheap Yellow Display (CYD): https://makeradvisor.com/tools/cyd-cheap-yellow-display-esp32-2432s028r/
|
||
SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/cyd-lvgl/
|
||
2) REGULAR ESP32 Dev Board + 2.8 inch 240x320 TFT Display: https://makeradvisor.com/tools/2-8-inch-ili9341-tft-240x320/ and https://makeradvisor.com/tools/esp32-dev-board-wi-fi-bluetooth/
|
||
SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/esp32-tft-lvgl/
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||
*/
|
||
#define MAIN
|
||
|
||
/* Install the "lvgl" library version 9.X by kisvegabor to interface with the TFT Display - https://lvgl.io/
|
||
*** IMPORTANT: lv_conf.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials ***
|
||
*** YOU MUST USE THE lv_conf.h FILE PROVIDED IN THE LINK BELOW IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS ***
|
||
FULL INSTRUCTIONS AVAILABLE ON HOW CONFIGURE THE LIBRARY: https://RandomNerdTutorials.com/cyd-lvgl/ or https://RandomNerdTutorials.com/esp32-tft-lvgl/ */
|
||
#include <lvgl.h>
|
||
|
||
/* Install the "TFT_eSPI" library by Bodmer to interface with the TFT Display - https://github.com/Bodmer/TFT_eSPI
|
||
*** IMPORTANT: User_Setup.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials ***
|
||
*** YOU MUST USE THE User_Setup.h FILE PROVIDED IN THE LINK BELOW IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS ***
|
||
FULL INSTRUCTIONS AVAILABLE ON HOW CONFIGURE THE LIBRARY: https://RandomNerdTutorials.com/cyd-lvgl/ or https://RandomNerdTutorials.com/esp32-tft-lvgl/ */
|
||
#include <TFT_eSPI.h>
|
||
|
||
|
||
#include "Weifi.h"
|
||
#include "mqtt.h"
|
||
#include "handlebme280.h"
|
||
#include "grafik.h"
|
||
#include "main.h"
|
||
|
||
#include <locale.h>
|
||
|
||
#define BMWREADTIME 10000
|
||
#define NTPREADTIME 1000
|
||
|
||
long bmeReadtimer = 0;
|
||
long ntpReadtimer = 0;
|
||
|
||
BME280Data bmedata;
|
||
|
||
int currentSecond = -1;
|
||
|
||
void showDateTime(struct tm tinfo);
|
||
|
||
void setup() {
|
||
setlocale(LC_ALL, "de_DE");
|
||
String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
|
||
Serial.begin(115200);
|
||
delay (1000);
|
||
Serial.println(LVGL_Arduino);
|
||
|
||
initBME280();
|
||
|
||
// Start LVGL
|
||
setup_grafik();
|
||
Serial.println("LVGL started");
|
||
|
||
bmedata = readBME280();
|
||
arcTemp.value = bmedata.temp;
|
||
arcHum.value = bmedata.hum;
|
||
delay(1000);
|
||
|
||
// Function to draw the GUI
|
||
lv_create_main_gui();
|
||
Serial.println("Main GUI created");
|
||
|
||
// Start WiFi
|
||
connectToWifi();
|
||
|
||
// Start MQTT
|
||
setupMQTT();
|
||
connectToMqtt();
|
||
Serial.println("MQTT started");
|
||
|
||
timeinfo = gettheTime(NTPREADTIME);
|
||
showDateTime(timeinfo);
|
||
|
||
bmeReadtimer = millis();
|
||
|
||
drawChart();
|
||
|
||
/*
|
||
// Register print function for debugging
|
||
lv_log_register_print_cb(log_print);
|
||
Serial.println("Print function registered");
|
||
|
||
// Function to draw the GUI
|
||
lv_create_main_gui();
|
||
Serial.println("Main GUI created");
|
||
*/
|
||
delay(1000);
|
||
|
||
|
||
}
|
||
|
||
void loop() {
|
||
timeinfo = gettheTime(NTPREADTIME);
|
||
if (timeinfo.tm_sec == 0) { // minute over
|
||
showDateTime(timeinfo);
|
||
}
|
||
if (millis() - bmeReadtimer > BMWREADTIME) {
|
||
bmeReadtimer = millis();
|
||
bmedata = readBME280();
|
||
setValuetoArc(arcTemp, bmedata.temp);
|
||
setValuetoArc(arcHum, bmedata.hum);
|
||
updatechartData(bmedata.temp, bmedata.hum);
|
||
|
||
}
|
||
lv_task_handler(); // let the GUI do its work
|
||
lv_tick_inc(5); // tell LVGL how much time has passed
|
||
delay(5); // let this time pass
|
||
}
|
||
|
||
void showDateTime(struct tm tinfo) {
|
||
char time[6];
|
||
char date[50];
|
||
strftime(time, 6, "%H:%M", &tinfo);
|
||
strftime(date, 50, "%A, %d %B %Y", &tinfo);
|
||
lv_label_set_text(time_label, time);
|
||
lv_label_set_text(date_label, date);
|
||
} |