mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Add hasp_task
This commit is contained in:
parent
e9f6cf87e3
commit
942a92fdf3
@ -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
101
src/hasp/hasp_task.cpp
Normal 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
10
src/hasp/hasp_task.h
Normal 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
|
Loading…
x
Reference in New Issue
Block a user