mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Merge setup() and loop() of PC and Arduino
This commit is contained in:
parent
cb1d860635
commit
d0e383e398
@ -123,7 +123,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef HASP_USE_CONSOLE
|
||||
#define HASP_USE_CONSOLE 1
|
||||
#define HASP_USE_CONSOLE HASP_TARGET_ARDUINO
|
||||
#endif
|
||||
|
||||
/* Filesystem */
|
||||
|
@ -1,8 +1,6 @@
|
||||
/* MIT License - Copyright (c) 2019-2024 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#if HASP_TARGET_ARDUINO
|
||||
|
||||
/*
|
||||
#ifdef CORE_DEBUG_LEVEL
|
||||
#undef CORE_DEBUG_LEVEL
|
||||
@ -28,9 +26,9 @@
|
||||
#include "hasp_gui.h"
|
||||
#endif
|
||||
|
||||
bool isConnected;
|
||||
uint8_t mainLoopCounter = 0;
|
||||
unsigned long mainLastLoopTime = 0;
|
||||
static bool isConnected;
|
||||
static uint8_t mainLoopCounter = 0;
|
||||
static unsigned long mainLastLoopTime = 0;
|
||||
|
||||
#ifdef HASP_USE_STAT_COUNTER
|
||||
uint16_t statLoopCounter = 0; // measures the average looptime
|
||||
@ -40,11 +38,18 @@ void setup()
|
||||
{
|
||||
// hal_setup();
|
||||
|
||||
#if HASP_TARGET_ARDUINO
|
||||
esp_log_level_set("*", ESP_LOG_NONE); // set all components to ERROR level
|
||||
// esp_log_level_set("wifi", ESP_LOG_NONE); // enable WARN logs from WiFi stack
|
||||
// esp_log_level_set("dhcpc", ESP_LOG_INFO); // enable INFO logs from DHCP client
|
||||
// esp_log_level_set("esp_crt_bundle", ESP_LOG_VERBOSE); // enable WARN logs from WiFi stack
|
||||
// esp_log_level_set("esp_tls", ESP_LOG_VERBOSE); // enable WARN logs from WiFi stack
|
||||
#elif HASP_TARGET_PC
|
||||
// Initialize lvgl environment
|
||||
lv_init();
|
||||
lv_log_register_print_cb(debugLvglLogEvent);
|
||||
#endif
|
||||
|
||||
haspDevice.init();
|
||||
|
||||
/****************************
|
||||
@ -149,7 +154,7 @@ void setup()
|
||||
gui_setup_lvgl_task();
|
||||
#endif // HASP_USE_LVGL_TASK
|
||||
|
||||
mainLastLoopTime = -1000; // reset loop counter
|
||||
mainLastLoopTime = 0; // reset loop counter
|
||||
}
|
||||
|
||||
IRAM_ATTR void loop()
|
||||
@ -195,7 +200,7 @@ IRAM_ATTR void loop()
|
||||
|
||||
/* Timer Loop */
|
||||
if(millis() - mainLastLoopTime >= 1000) {
|
||||
mainLastLoopTime += 1000;
|
||||
mainLastLoopTime = millis();
|
||||
|
||||
/* Runs Every Second */
|
||||
haspEverySecond(); // sleep timer & statusupdate
|
||||
@ -237,10 +242,9 @@ IRAM_ATTR void loop()
|
||||
case 4:
|
||||
#if HASP_USE_WIFI > 0 || HASP_USE_ETHERNET > 0
|
||||
isConnected = networkEvery5Seconds(); // Check connection
|
||||
|
||||
#endif
|
||||
#if HASP_USE_MQTT > 0
|
||||
mqttEvery5Seconds(isConnected);
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
|
||||
@ -270,5 +274,3 @@ IRAM_ATTR void loop()
|
||||
delay(2); // ms
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
118
src/main_pc.cpp
118
src/main_pc.cpp
@ -26,28 +26,20 @@
|
||||
|
||||
#include "hasplib.h"
|
||||
|
||||
// #include "app_hal.h"
|
||||
#if USE_MONITOR
|
||||
#include "display/monitor.h"
|
||||
#endif
|
||||
|
||||
#include "hasp_debug.h"
|
||||
#include "hasp_gui.h"
|
||||
|
||||
#include "dev/device.h"
|
||||
|
||||
bool isConnected;
|
||||
|
||||
uint8_t mainLoopCounter = 0;
|
||||
unsigned long mainLastLoopTime = 0;
|
||||
|
||||
#ifdef HASP_USE_STAT_COUNTER
|
||||
uint16_t statLoopCounter = 0; // measures the average looptime
|
||||
#endif
|
||||
|
||||
// hasp_gui.cpp
|
||||
extern uint16_t tft_width;
|
||||
extern uint16_t tft_height;
|
||||
|
||||
// main.cpp
|
||||
extern void setup();
|
||||
extern void loop();
|
||||
|
||||
#if defined(WINDOWS)
|
||||
// https://gist.github.com/kingseva/a918ec66079a9475f19642ec31276a21
|
||||
void BindStdHandlesToConsole()
|
||||
@ -110,106 +102,6 @@ void InitializeConsoleOutput()
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Initialize lvgl environment
|
||||
lv_init();
|
||||
lv_log_register_print_cb(debugLvglLogEvent);
|
||||
|
||||
// Read & Apply User Configuration
|
||||
#if HASP_USE_CONFIG > 0
|
||||
configSetup();
|
||||
#endif
|
||||
|
||||
haspDevice.init(); // hardware setup
|
||||
// hal_setup();
|
||||
guiSetup();
|
||||
|
||||
dispatchSetup(); // for hasp and oobe
|
||||
haspSetup();
|
||||
|
||||
#if HASP_USE_MQTT > 0
|
||||
mqttSetup(); // Hasp must be running
|
||||
mqttStart();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_GPIO > 0
|
||||
gpioSetup();
|
||||
#endif
|
||||
|
||||
#if defined(HASP_USE_CUSTOM)
|
||||
custom_setup();
|
||||
#endif
|
||||
|
||||
mainLastLoopTime = millis(); // - 1000; // reset loop counter
|
||||
// delay(250);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
haspLoop();
|
||||
#if HASP_USE_MQTT
|
||||
mqttLoop();
|
||||
#endif
|
||||
|
||||
// debugLoop(); // Console
|
||||
haspDevice.loop();
|
||||
guiLoop();
|
||||
|
||||
#if HASP_USE_GPIO > 0
|
||||
gpioLoop();
|
||||
#endif
|
||||
|
||||
#if defined(HASP_USE_CUSTOM)
|
||||
custom_loop();
|
||||
#endif
|
||||
|
||||
#ifdef HASP_USE_STAT_COUNTER
|
||||
statLoopCounter++; // measures the average looptime
|
||||
#endif
|
||||
|
||||
/* Timer Loop */
|
||||
if(millis() - mainLastLoopTime >= 1000) {
|
||||
/* Runs Every Second */
|
||||
haspEverySecond(); // sleep timer
|
||||
dispatchEverySecond(); // sleep timer
|
||||
|
||||
#if HASP_USE_ARDUINOOTA > 0
|
||||
otaEverySecond(); // progressbar
|
||||
#endif
|
||||
|
||||
#if defined(HASP_USE_CUSTOM)
|
||||
custom_every_second();
|
||||
#endif
|
||||
|
||||
/* Runs Every 5 Seconds */
|
||||
if(mainLoopCounter == 0 || mainLoopCounter == 5) {
|
||||
|
||||
haspDevice.loop_5s();
|
||||
#if HASP_USE_GPIO > 0
|
||||
gpioEvery5Seconds();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MQTT
|
||||
mqttEvery5Seconds(true);
|
||||
#endif
|
||||
|
||||
#if defined(HASP_USE_CUSTOM)
|
||||
custom_every_5seconds();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Reset loop counter every 10 seconds */
|
||||
if(mainLoopCounter >= 9) {
|
||||
mainLoopCounter = 0;
|
||||
} else {
|
||||
mainLoopCounter++;
|
||||
}
|
||||
mainLastLoopTime += 1000;
|
||||
}
|
||||
// delay(6);
|
||||
}
|
||||
|
||||
void usage(const char* progName, const char* version)
|
||||
{
|
||||
std::cout
|
||||
|
@ -26,8 +26,8 @@ build_flags =
|
||||
-D HASP_USE_SPIFFS=0
|
||||
-D HASP_USE_LITTLEFS=0
|
||||
-D HASP_USE_EEPROM=0
|
||||
-D HASP_USE_GPIO=1
|
||||
-D HASP_USE_CONFIG=0 ; Standalone application, as library
|
||||
-D HASP_USE_GPIO=0
|
||||
-D HASP_USE_CONFIG=1
|
||||
-D HASP_USE_DEBUG=1
|
||||
-D HASP_USE_PNGDECODE=1
|
||||
-D HASP_USE_BMPDECODE=1
|
||||
|
@ -26,8 +26,8 @@ build_flags =
|
||||
-D HASP_USE_LITTLEFS=0
|
||||
-D LV_USE_FS_IF=1
|
||||
-D HASP_USE_EEPROM=0
|
||||
-D HASP_USE_GPIO=1
|
||||
-D HASP_USE_CONFIG=0 ; Standalone application, as library
|
||||
-D HASP_USE_GPIO=0
|
||||
-D HASP_USE_CONFIG=1
|
||||
-D HASP_USE_DEBUG=1
|
||||
-D HASP_USE_PNGDECODE=1
|
||||
-D HASP_USE_BMPDECODE=1
|
||||
|
@ -20,8 +20,8 @@ build_flags =
|
||||
-D HASP_USE_SPIFFS=0
|
||||
-D HASP_USE_LITTLEFS=0
|
||||
-D HASP_USE_EEPROM=0
|
||||
-D HASP_USE_GPIO=1
|
||||
-D HASP_USE_CONFIG=1 ; Standalone application, as library
|
||||
-D HASP_USE_GPIO=0
|
||||
-D HASP_USE_CONFIG=1
|
||||
-D HASP_USE_DEBUG=1
|
||||
-D HASP_USE_PNGDECODE=1
|
||||
-D HASP_USE_BMPDECODE=1
|
||||
|
@ -25,8 +25,8 @@ build_flags =
|
||||
-D HASP_USE_SPIFFS=0
|
||||
-D HASP_USE_LITTLEFS=0
|
||||
-D HASP_USE_EEPROM=0
|
||||
-D HASP_USE_GPIO=1
|
||||
-D HASP_USE_CONFIG=1 ; Standalone application, as library
|
||||
-D HASP_USE_GPIO=0
|
||||
-D HASP_USE_CONFIG=1
|
||||
-D HASP_USE_DEBUG=1
|
||||
-D HASP_USE_PNGDECODE=1
|
||||
-D HASP_USE_BMPDECODE=1
|
||||
|
Loading…
x
Reference in New Issue
Block a user