Add hasp_task

This commit is contained in:
fvanroie 2021-10-21 23:35:32 +02:00
parent e9f6cf87e3
commit 942a92fdf3
3 changed files with 112 additions and 0 deletions

View File

@ -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);

101
src/hasp/hasp_task.cpp Normal file
View File

@ -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;
}

10
src/hasp/hasp_task.h Normal file
View File

@ -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