mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-24 16:16:55 +01:00
impr asmota device groups
This commit is contained in:
@@ -9,6 +9,7 @@ void BL0937_RunFrame();
|
||||
|
||||
void DRV_DGR_Init();
|
||||
void DRV_DGR_RunFrame();
|
||||
void DRV_DGR_Shutdown();
|
||||
|
||||
void BL_ProcessUpdate(float voltage, float current, float power);
|
||||
void BL09XX_AppendInformationToHTTPIndexPage(http_request_t *request);
|
||||
|
||||
@@ -17,18 +17,20 @@ typedef struct driver_s {
|
||||
void (*initFunc)();
|
||||
void (*onEverySecond)();
|
||||
void (*appendInformationToHTTPIndexPage)(http_request_t *request);
|
||||
void (*runQuickTick)();
|
||||
void (*stopFunc)();
|
||||
bool bLoaded;
|
||||
} driver_t;
|
||||
|
||||
// startDriver BL0937
|
||||
static driver_t g_drivers[] = {
|
||||
{ "TuyaMCU", TuyaMCU_Init, TuyaMCU_RunFrame, NULL, false },
|
||||
{ "NTP", NTP_Init, NTP_OnEverySecond, NULL, false },
|
||||
{ "I2C", DRV_I2C_Init, DRV_I2C_EverySecond, NULL, false },
|
||||
{ "BL0942", BL0942_Init, BL0942_RunFrame, BL09XX_AppendInformationToHTTPIndexPage, false },
|
||||
{ "BL0937", BL0937_Init, BL0937_RunFrame, BL09XX_AppendInformationToHTTPIndexPage, false },
|
||||
{ "TuyaMCU", TuyaMCU_Init, TuyaMCU_RunFrame, NULL, NULL, NULL,false },
|
||||
{ "NTP", NTP_Init, NTP_OnEverySecond, NULL, NULL, NULL, false },
|
||||
{ "I2C", DRV_I2C_Init, DRV_I2C_EverySecond, NULL, NULL, NULL, false },
|
||||
{ "BL0942", BL0942_Init, BL0942_RunFrame, BL09XX_AppendInformationToHTTPIndexPage, NULL, NULL, false },
|
||||
{ "BL0937", BL0937_Init, BL0937_RunFrame, BL09XX_AppendInformationToHTTPIndexPage, NULL, NULL, false },
|
||||
#if PLATFORM_BEKEN
|
||||
{ "DGR", DRV_DGR_Init, DRV_DGR_RunFrame, NULL, false },
|
||||
{ "DGR", DRV_DGR_Init, NULL, NULL, DRV_DGR_RunFrame, DRV_DGR_Shutdown, false },
|
||||
#endif
|
||||
};
|
||||
static int g_numDrivers = sizeof(g_drivers)/sizeof(g_drivers[0]);
|
||||
@@ -57,6 +59,36 @@ void DRV_OnEverySecond() {
|
||||
}
|
||||
}
|
||||
}
|
||||
void DRV_RunQuickTick() {
|
||||
int i;
|
||||
|
||||
for(i = 0; i < g_numDrivers; i++) {
|
||||
if(g_drivers[i].bLoaded) {
|
||||
if(g_drivers[i].runQuickTick != 0) {
|
||||
g_drivers[i].runQuickTick();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void DRV_StopDriver(const char *name) {
|
||||
int i;
|
||||
|
||||
for(i = 0; i < g_numDrivers; i++) {
|
||||
if(!stricmp(g_drivers[i].name,name)) {
|
||||
if(g_drivers[i].bLoaded){
|
||||
if(g_drivers[i].stopFunc != 0) {
|
||||
g_drivers[i].stopFunc();
|
||||
}
|
||||
g_drivers[i].bLoaded = 0;
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_NTP,"Drv %s has been stopped.\n",name);
|
||||
return ;
|
||||
} else {
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_NTP,"Drv %s is not running.\n",name);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void DRV_StartDriver(const char *name) {
|
||||
int i;
|
||||
|
||||
|
||||
@@ -5,5 +5,7 @@ void DRV_Generic_Init();
|
||||
#include "../httpserver/new_http.h"
|
||||
void DRV_AppendInformationToHTTPIndexPage(http_request_t *request);
|
||||
void DRV_OnEverySecond();
|
||||
void DRV_RunQuickTick();
|
||||
void DRV_StartDriver(const char *name);
|
||||
void DRV_StopDriver(const char *name);
|
||||
|
||||
|
||||
@@ -185,6 +185,7 @@ void DRV_DGR_processLightBrightness(byte brightness) {
|
||||
void DRV_DGR_RunFrame() {
|
||||
struct sockaddr_in addr;
|
||||
dgrDevice_t def;
|
||||
char msgbuf[64];
|
||||
|
||||
if(g_dgr_socket==0) {
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_DGR,"no sock\n");
|
||||
@@ -192,7 +193,6 @@ void DRV_DGR_RunFrame() {
|
||||
}
|
||||
// now just enter a read-print loop
|
||||
//
|
||||
char msgbuf[64];
|
||||
int addrlen = sizeof(addr);
|
||||
int nbytes = recvfrom(
|
||||
g_dgr_socket,
|
||||
@@ -245,6 +245,15 @@ void DRV_DGR_RunFrame() {
|
||||
// (beken_thread_arg_t)0 );
|
||||
//
|
||||
//}
|
||||
void DRV_DGR_Shutdown()
|
||||
{
|
||||
if(g_dgr_socket!=0) {
|
||||
close(g_dgr_socket);
|
||||
g_dgr_socket = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DRV_DGR_Init()
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "cmnds/cmd_public.h"
|
||||
#include "i2c/drv_i2c_public.h"
|
||||
#include "driver/drv_tuyaMCU.h"
|
||||
#include "driver/drv_public.h"
|
||||
#include "hal/hal_flashVars.h"
|
||||
#include "hal/hal_pins.h"
|
||||
|
||||
@@ -792,6 +793,8 @@ void PIN_ticks(void *param)
|
||||
int i;
|
||||
int value;
|
||||
|
||||
DRV_RunQuickTick();
|
||||
|
||||
// WiFi LED
|
||||
// In Open Access point mode, fast blink (250ms)
|
||||
if(Main_IsOpenAccessPointMode()) {
|
||||
|
||||
@@ -137,6 +137,7 @@ void Main_OnWiFiStatusChange(int code){
|
||||
ADDLOGF_INFO("Main_OnWiFiStatusChange - WIFI_STA_CONNECTED\r\n");
|
||||
|
||||
if(bSafeMode == 0 && strlen(CFG_DeviceGroups_GetName())>0){
|
||||
DRV_StopDriver("DGR");
|
||||
DRV_StartDriver("DGR");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user