mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 05:06:44 +00:00
Optimize performance of the main loop
This commit is contained in:
parent
71193fef4d
commit
2d9e73d0ff
@ -3,9 +3,12 @@
|
|||||||
|
|
||||||
#if !(defined(WINDOWS) || defined(POSIX))
|
#if !(defined(WINDOWS) || defined(POSIX))
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include "hasplib.h"
|
||||||
#include "lvgl.h"
|
#include "hasp_oobe.h"
|
||||||
#include "hasp_conf.h" // load first
|
#include "sys/net/hasp_network.h"
|
||||||
|
#include "dev/device.h"
|
||||||
|
#include "drv/hasp_drv_touch.h"
|
||||||
|
#include "ArduinoLog.h"
|
||||||
|
|
||||||
#if HASP_USE_CONFIG > 0
|
#if HASP_USE_CONFIG > 0
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
@ -16,18 +19,10 @@
|
|||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "hasp_oobe.h"
|
|
||||||
|
|
||||||
#include "hasp/hasp_dispatch.h"
|
|
||||||
#include "hasp/hasp.h"
|
|
||||||
|
|
||||||
#include "sys/net/hasp_network.h"
|
|
||||||
|
|
||||||
#include "dev/device.h"
|
|
||||||
|
|
||||||
bool isConnected;
|
bool isConnected;
|
||||||
uint8_t mainLoopCounter = 0;
|
uint8_t mainLoopCounter = 0;
|
||||||
unsigned long mainLastLoopTime = 0;
|
unsigned long mainLastLoopTime = 0;
|
||||||
|
uint8_t statLoopCounter = 0;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@ -116,6 +111,7 @@ IRAM_ATTR void loop()
|
|||||||
{
|
{
|
||||||
guiLoop();
|
guiLoop();
|
||||||
// haspLoop();
|
// haspLoop();
|
||||||
|
|
||||||
networkLoop();
|
networkLoop();
|
||||||
|
|
||||||
#if HASP_USE_GPIO > 0
|
#if HASP_USE_GPIO > 0
|
||||||
@ -126,53 +122,65 @@ IRAM_ATTR void loop()
|
|||||||
mqttLoop();
|
mqttLoop();
|
||||||
#endif // MQTT
|
#endif // MQTT
|
||||||
|
|
||||||
haspDevice.loop();
|
// haspDevice.loop();
|
||||||
|
|
||||||
#if HASP_USE_CONSOLE > 0
|
#if HASP_USE_CONSOLE > 0
|
||||||
// debugLoop();
|
// debugLoop();
|
||||||
consoleLoop();
|
consoleLoop();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
statLoopCounter++;
|
||||||
/* Timer Loop */
|
/* Timer Loop */
|
||||||
if(millis() - mainLastLoopTime >= 1000) {
|
if(millis() - mainLastLoopTime >= 1000) {
|
||||||
|
mainLastLoopTime += 1000;
|
||||||
|
|
||||||
/* Runs Every Second */
|
/* Runs Every Second */
|
||||||
haspEverySecond(); // sleep timer & statusupdate
|
haspEverySecond(); // sleep timer & statusupdate
|
||||||
|
|
||||||
|
#if HASP_USE_TELNET > 0
|
||||||
|
telnetEverySecond();
|
||||||
|
#endif
|
||||||
|
|
||||||
// debugEverySecond();
|
// debugEverySecond();
|
||||||
|
|
||||||
/* Runs Every 5 Seconds */
|
switch(++mainLoopCounter) {
|
||||||
if(mainLoopCounter == 0 || mainLoopCounter == 5) {
|
case 1:
|
||||||
isConnected = networkEvery5Seconds(); // Check connection
|
haspDevice.loop_5s();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
#if HASP_USE_HTTP > 0
|
#if HASP_USE_HTTP > 0
|
||||||
// httpEvery5Seconds();
|
// httpEvery5Seconds();
|
||||||
#endif
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
#if HASP_USE_GPIO > 0
|
||||||
|
// gpioEvery5Seconds();
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
isConnected = networkEvery5Seconds(); // Check connection
|
||||||
|
|
||||||
#if HASP_USE_MQTT > 0
|
#if HASP_USE_MQTT > 0
|
||||||
mqttEvery5Seconds(isConnected);
|
mqttEvery5Seconds(isConnected);
|
||||||
#endif
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
#if HASP_USE_GPIO > 0
|
case 5:
|
||||||
// gpioEvery5Seconds();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
haspDevice.loop_5s();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reset loop counter every 10 seconds */
|
|
||||||
if(mainLoopCounter >= 9) {
|
|
||||||
mainLoopCounter = 0;
|
mainLoopCounter = 0;
|
||||||
} else {
|
if(statLoopCounter)
|
||||||
mainLoopCounter++;
|
LOG_VERBOSE(TAG_MAIN, F("%d millis per loop, %d counted"), 5000 / statLoopCounter, statLoopCounter);
|
||||||
|
statLoopCounter = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mainLastLoopTime += 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
delay(2); // ms
|
delay(2); // ms
|
||||||
#else
|
#else
|
||||||
delay(5); // ms
|
delay(2); // ms
|
||||||
// delay((lv_task_get_idle() >> 5) + 3); // 2..5 ms
|
// delay((lv_task_get_idle() >> 5) + 3); // 2..5 ms
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user