First commit - WIP
This commit is contained in:
89
src/main.cpp
Normal file
89
src/main.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/* 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"
|
||||
|
||||
|
||||
void setup() {
|
||||
// String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
|
||||
delay (1000);
|
||||
String LVGL_Arduino = String("LVGL Library Version: ") + "9.0.0";
|
||||
Serial.begin(115200);
|
||||
Serial.println(LVGL_Arduino);
|
||||
|
||||
initBME280();
|
||||
|
||||
// Start LVGL
|
||||
setup_grafik();
|
||||
Serial.println("LVGL started");
|
||||
|
||||
// Function to draw the GUI
|
||||
lv_create_main_gui();
|
||||
Serial.println("Main GUI created");
|
||||
|
||||
setValuetoArc(arcTemp, 25.3);
|
||||
setValuetoArc(arcHum, 45.0);
|
||||
delay(1000);
|
||||
// Start WiFi
|
||||
connectToWifi();
|
||||
Serial.println("WiFi started");
|
||||
|
||||
// Start MQTT
|
||||
connectToMqtt();
|
||||
Serial.println("MQTT started");
|
||||
/*
|
||||
// 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);
|
||||
|
||||
mqttReconnectTimer = xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToMqtt));
|
||||
wifiReconnectTimer = xTimerCreate("wifiTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToWifi));
|
||||
WiFi.onEvent(WiFiEvent);
|
||||
mqttClient.onConnect(onMqttConnect);
|
||||
mqttClient.onDisconnect(onMqttDisconnect);
|
||||
mqttClient.onSubscribe(onMqttSubscribe);
|
||||
mqttClient.onUnsubscribe(onMqttUnsubscribe);
|
||||
mqttClient.onMessage(onMqttMessage);
|
||||
mqttClient.setServer(MQTT_HOST, MQTT_PORT);
|
||||
mqttClient.setCredentials(BROKER_USER, BROKER_PASS);
|
||||
connectToWifi();
|
||||
*/
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//readBME280();
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user