diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index a07c1845..fe6145e8 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -71,6 +71,7 @@ void dispatch_backlight(const char*, const char* payload, uint8_t source); void dispatch_web_update(const char*, const char* espOtaUrl, uint8_t source); void dispatch_statusupdate(const char*, const char*, uint8_t source); void dispatch_send_discovery(const char*, const char*, uint8_t source); +void dispatch_send_sensordata(const char*, const char*, uint8_t source); void dispatch_idle(const char*, const char*, uint8_t source); void dispatch_calibrate(const char*, const char*, uint8_t source); void dispatch_antiburn(const char*, const char* payload, uint8_t source); diff --git a/src/hasp/hasp_task.cpp b/src/hasp/hasp_task.cpp new file mode 100644 index 00000000..281b69f2 --- /dev/null +++ b/src/hasp/hasp_task.cpp @@ -0,0 +1,101 @@ +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie +For full license information read the LICENSE file in the project folder */ + +#include "hasplib.h" +#include "hasp_task.h" +#include "sys/net/hasp_network.h" +#include "dev/device.h" + +#if HASP_USE_CONFIG > 0 +#include "hasp_debug.h" +#include "hasp_macro.h" +#endif + +#if HASP_USE_CONFIG > 0 +#include "hasp_config.h" +#include "hasp_gui.h" +#endif + +#if defined(HASP_USE_CUSTOM) +#include "custom/my_custom.h" +#endif + +#ifdef HASP_USE_STAT_COUNTER +extern uint16_t statLoopCounter; // measures the average looptime +#endif + +/* Runs Every Second */ +void task_every_second_cb(lv_task_t* task) +{ + haspEverySecond(); // sleep timer & statusupdate + +#if HASP_USE_TELNET > 0 + telnetEverySecond(); +#endif + +#if defined(HASP_USE_CUSTOM) + custom_every_second(); +#endif + // debugEverySecond(); + + switch(task->repeat_count) { + case 1: + haspDevice.loop_5s(); + + // task is about to get deleted + if(task->repeat_count == 1) task->repeat_count = 6; + + break; + + case 2: +#if HASP_USE_GPIO > 0 + // gpioEvery5Seconds(); +#endif + break; + + case 3: +#if defined(HASP_USE_CUSTOM) + custom_every_5seconds(); +#endif + break; + + case 4: { +#ifdef ARDUINO + bool isConnected = networkEvery5Seconds(); // Check connection + +#if HASP_USE_MQTT > 0 + mqttEvery5Seconds(isConnected); +#endif +#endif // ARDUINO + break; + } + + case 5: +#ifdef HASP_USE_STAT_COUNTER + if(statLoopCounter) + LOG_VERBOSE(TAG_MAIN, F("%d millis per loop, %d counted"), 5000 / statLoopCounter, statLoopCounter); + statLoopCounter = 0; +#endif + break; + } +} + +void task_teleperiod_cb(lv_task_t* task) +{ + if(!mqttIsConnected()) return; + + switch(task->repeat_count) { + case 1: + dispatch_send_sensordata(NULL, NULL, TAG_MSGR); + break; + case 2: + dispatch_send_discovery(NULL, NULL, TAG_MSGR); + break; + case 3: + dispatch_statusupdate(NULL, NULL, TAG_MSGR); + break; + } + + // task is about to get deleted + if(task->repeat_count == 1) task->repeat_count = 4; +} \ No newline at end of file diff --git a/src/hasp/hasp_task.h b/src/hasp/hasp_task.h new file mode 100644 index 00000000..9d6d86c8 --- /dev/null +++ b/src/hasp/hasp_task.h @@ -0,0 +1,10 @@ +/* MIT License - Copyright (c) 2019-2021 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_TASK_H +#define HASP_TASK_H + +#include "hasplib.h" + + +#endif \ No newline at end of file