nice frame work for remote control humidity

This commit is contained in:
Yunhorn 2025-07-11 15:55:21 +08:00
parent 3ed02d8898
commit 0aed02050c
6 changed files with 106 additions and 28 deletions

View File

@ -110,7 +110,9 @@ typedef enum
#if defined(STS_L8) #if defined(STS_L8)
CFG_SEQ_Task_YunhornSTSEventSelfTestProcess, /* Self Function Test Process */ CFG_SEQ_Task_YunhornSTSEventSelfTestProcess, /* Self Function Test Process */
#endif #endif
#ifdef STS_K1
CFG_SEQ_Task_YunhornSTSEventRemoteControlSendCMD,
#endif
/* USER CODE END CFG_SEQ_Task_Id_t */ /* USER CODE END CFG_SEQ_Task_Id_t */
CFG_SEQ_Task_NBR CFG_SEQ_Task_NBR
} CFG_SEQ_Task_Id_t; } CFG_SEQ_Task_Id_t;

View File

@ -673,9 +673,10 @@ void STS_Sensor_Init(void)
#endif #endif
#if defined(STS_K1) #if defined(STS_K1)
//UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventRemoteControlSendCMD), UTIL_SEQ_RFU, STS_YunhornSTSEventRemoteControlSendCMD);
UTIL_TIMER_Create(&YunhornSTSIAQK1ScanTimer, STS_IAQK1ScanPeriod_sec*1000, UTIL_TIMER_PERIODIC, (void*)STS_YunhornSTSEventP7_Process, NULL); UTIL_TIMER_Create(&YunhornSTSIAQK1ScanTimer, STS_IAQK1ScanPeriod_sec*1000, UTIL_TIMER_PERIODIC, (void*)STS_YunhornSTSEventP7_Process, NULL);
UTIL_TIMER_Start(&YunhornSTSIAQK1ScanTimer); UTIL_TIMER_Start(&YunhornSTSIAQK1ScanTimer);
#endif #endif
@ -1988,6 +1989,8 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context)
appHeartBeatDataPort = YUNHORN_STS_T6_LORA_APP_HTBT_PORT; appHeartBeatDataPort = YUNHORN_STS_T6_LORA_APP_HTBT_PORT;
#elif defined(STS_L8) #elif defined(STS_L8)
appHeartBeatDataPort = YUNHORN_STS_L8_LORA_APP_HTBT_PORT; appHeartBeatDataPort = YUNHORN_STS_L8_LORA_APP_HTBT_PORT;
#elif defined(STS_K1)
appHeartBeatDataPort = YUNHORN_STS_K1_LORA_APP_HTBT_PORT;
#endif #endif
#if defined(STS_L8)||defined(O6)||defined(O2)||defined(O6T)||defined(O1L)||defined(T6) // for keeping sync with webApp for state/lampbar color, in case failure of uplink message #if defined(STS_L8)||defined(O6)||defined(O2)||defined(O6T)||defined(O1L)||defined(T6) // for keeping sync with webApp for state/lampbar color, in case failure of uplink message

View File

@ -98,13 +98,15 @@ typedef struct
uint8_t SleepStatus; uint8_t SleepStatus;
} STS_PRESENCE_SENSOR_Event_Status_t; } STS_PRESENCE_SENSOR_Event_Status_t;
enum sts_iaq_alert { //#define STS_ALERT_NORMAL 0x00 // (1) WELCOME MESSAGE, NORMAL
STS_ALERT_HUMIDITY_NORMAL=0, #define STS_ALERT_HUMIDITY_NORMAL 0x01 // (1) WELCOME MESSAGE, NORMAL
STS_ALERT_HUMIDITY_HIGH, #define STS_ALERT_HUMIDITY_HIGH 0x02 // (2) CAUTION WET FLOOR
STS_ALERT_HUMIDITY_LOW, #define STS_ALERT_TEMP_HIGH 0x04
STS_ALERT_TEMP_HIGH, #define STS_ALERT_FULL_OCCUPY 0x08 // (3) FULL OCCUPIED,
STS_ALERT_TEMP_LOW, #define STS_ALERT_CLEAN_IN_PROGRESS 0x10 // (4) CLEAN IN PROGRESS,
}; #define STS_ALERT_OTHER1 0x20
#define STS_ALERT_OTHER2 0x40
typedef struct typedef struct
{ {
float temperature; /*!< in degC */ float temperature; /*!< in degC */
@ -482,7 +484,18 @@ typedef struct STS_OO_SensorStatusDataTypeDef
} STS_OO_SensorStatusDataTypeDef; } STS_OO_SensorStatusDataTypeDef;
#ifdef STS_K1
typedef struct service_period_per_day {
uint8_t enable_mask; // enable this time slot or not day of week,
// 0x1f= 0b0001 1111 ---> day1 to day5 of week
// 0x60= 0b0110 0000 ---> day6 5o day 7 of week
uint8_t start_hour; // start hour 00--23 in 24hour
uint8_t start_minute; // start minute 00--59
uint8_t end_hour; // end hour 00-23 in 24 hour
uint8_t end_minute; // end minute 00--60
} t_service_period_per_day;
#endif
/** /**
* @brief Store/Write/Flash Configuration in RW RAM * @brief Store/Write/Flash Configuration in RW RAM
*/ */

View File

@ -57,9 +57,21 @@ volatile uint8_t sts_hall1_read=0,sts_hall2_read=0;
volatile uint8_t last_sts_hall1_read, last_sts_hall2_read; volatile uint8_t last_sts_hall1_read, last_sts_hall2_read;
iaq_sensor_t iaq_sensor_data; iaq_sensor_t iaq_sensor_data;
iaq_sensor_alert_t iaq_sensor_alert={28.0, 5.0, 65.0, 20.0}; iaq_sensor_alert_t iaq_sensor_alert={28.0, 5.0, 65.0, 20.0};
uint8_t sts_alert_id=0, prev_alert_id=0; volatile bool sts_rc_in_service_period=false;
uint8_t sts_alert_id=STS_ALERT_HUMIDITY_NORMAL, prev_alert_id=0;
t_service_period_per_day rc_service_period[4]={
{1,6,30,12,00},
{1,13,00, 18,00},
{0,0,0,0,0},
{0,0,0,0,0}
};
static int STS_IAQ_Generate_Alert(void); static int STS_IAQ_Generate_Alert(void);
static bool STS_Check_Service_Period(void);
#endif #endif
#if defined(STS_L8) #if defined(STS_L8)
#include "app_tof.h" #include "app_tof.h"
#include "sts_lamp_bar.h" #include "sts_lamp_bar.h"
@ -664,7 +676,31 @@ void STS_YunhornSTSEventP6_Process(void)
PME_OFF; PME_OFF;
} }
void STS_YunhornRCRFSendCMD(uint8_t rf_cmd)
{
switch (rf_cmd) {
case 0:
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ======================\n\n RF CMD_BUTTON #0 \n\n======================\r\n");
break;
case 1:
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ======================\n\n RF CMD_BUTTON #1 \n\n======================\r\n");
break;
case 2:
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ======================\n\n RF CMD_BUTTON #2 \n\n======================\r\n");
break;
case 3:
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ======================\n\n RF CMD_BUTTON #3 \n\n======================\r\n");
break;
case 4:
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ======================\n\n RF CMD_BUTTON #5 \n\n======================\r\n");
break;
case 5:
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ======================\n\n RF CMD_BUTTON #6 \n\n======================\r\n");
break;
default:
break;
}
}
/* /*
* STS P7 Process, Detection IAQ Sensors * STS P7 Process, Detection IAQ Sensors
* air quality and odor level sensors * air quality and odor level sensors
@ -680,14 +716,28 @@ void STS_YunhornSTSEventP7_Process(void)
//STS_RF_Show_pic(cause_wet_floor); //STS_RF_Show_pic(cause_wet_floor);
if (prev_alert_id != sts_alert_id) if (prev_alert_id != sts_alert_id)
{ {
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Projector Show Caution Wet floor \r\n");
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Projector Show \n\t Caution\n\t Wet floor> \r\n");
prev_alert_id = sts_alert_id; prev_alert_id = sts_alert_id;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
STS_YunhornRCRFSendCMD(1);
} }
} else { } else {
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Projector Show Caution Wet floor \r\n"); if ((prev_alert_id != sts_alert_id))
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Projector Show \n\t<Welcome>\n\t Prince Walls Hospital> \r\n");
prev_alert_id = sts_alert_id;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
STS_YunhornRCRFSendCMD(0);
}
} }
#endif #endif
} }
@ -722,22 +772,29 @@ static int STS_IAQ_Generate_Alert(void)
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Get Temp and Humidity Error, code=%02x \r\n", eterr); APP_LOG(TS_OFF, VLEVEL_M, "\r\n Get Temp and Humidity Error, code=%02x \r\n", eterr);
} }
if (iaq_sensor_data.humidity >= iaq_sensor_alert.humidity_high) if ((int)iaq_sensor_data.humidity >= (int)iaq_sensor_alert.humidity_high)
{ {
return 1; APP_LOG(TS_OFF, VLEVEL_M, "\r\n*** Measured Humidity=%2d (%), threshold %2d (%) \r\n",
(int)iaq_sensor_data.humidity, (int)iaq_sensor_alert.humidity_high);
sts_alert_id = STS_ALERT_HUMIDITY_HIGH; sts_alert_id = STS_ALERT_HUMIDITY_HIGH;
} else if (iaq_sensor_data.humidity < iaq_sensor_alert.humidity_high) return 1;
{
} else if ((int)iaq_sensor_data.humidity < (int)iaq_sensor_alert.humidity_high)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n*** Measured Humidity=%2d (%), threshold %2d (%) \r\n",
(int)iaq_sensor_data.humidity, (int)iaq_sensor_alert.humidity_high);
sts_alert_id = STS_ALERT_HUMIDITY_NORMAL; sts_alert_id = STS_ALERT_HUMIDITY_NORMAL;
return 0; return 0;
} }
#endif #endif
return 0; return 0;
} }
/*
static void OnSelfMeasureEnvironmentEvent(void *context) static void OnSelfMeasureEnvironmentEvent(void *context)
{ {
@ -745,9 +802,12 @@ static void OnSelfMeasureEnvironmentEvent(void *context)
if (sts_rc_in_service_period == true) if (sts_rc_in_service_period == true)
{ {
if ((sensor_data.humidity >= sts_wet_humidity_threshold) ) // wet floor condition APP_LOG(TS_OFF, VLEVEL_M, "\r\n*** Humidity=%2d (%), threshold %2d (%) \r\n", iaq_sensor_data.humidity, iaq_sensor_alert.humidity_high);
if ((iaq_sensor_data.humidity >= iaq_sensor_alert.humidity_high) ) // wet floor condition
{ {
APP_LOG(TS_OFF, VLEVEL_M, "\r\n*** Humidity=%2d (%), over threshold %2d (%), start WET FLOOR PICTURE \r\n", sensor_data.humidity, sts_wet_humidity_threshold);
APP_LOG(TS_OFF, VLEVEL_M, "\r\n*** Show <Cauion Wef Floor> *** \r\n");
sts_rf_cmd_pic |= STS_RF_SHOW_PIC_WET_FLOOR; sts_rf_cmd_pic |= STS_RF_SHOW_PIC_WET_FLOOR;
@ -755,7 +815,7 @@ static void OnSelfMeasureEnvironmentEvent(void *context)
} else { // non wet floor situation, so just display welcome message or other messages, instead of wet floor } else { // non wet floor situation, so just display welcome message or other messages, instead of wet floor
APP_LOG(TS_OFF, VLEVEL_M, "\r\n*** Humidity=%2d (%), less than threshold %2d (%), Power Off projector\r\n", sensor_data.humidity, sts_wet_humidity_threshold); APP_LOG(TS_OFF, VLEVEL_M, "\r\n*** Shut-off <Cauion Wef Floor> *** \r\n");
sts_rf_cmd_pic &= ~STS_RF_SHOW_PIC_WET_FLOOR; sts_rf_cmd_pic &= ~STS_RF_SHOW_PIC_WET_FLOOR;
@ -763,14 +823,14 @@ static void OnSelfMeasureEnvironmentEvent(void *context)
} }
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_STS_RemoteControlButtonEvent), CFG_SEQ_Prio_0); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRemoteControlSendCMD), CFG_SEQ_Prio_0);
} else { // not in service period, just power off projector in case it's still on } else { // not in service period, just power off projector in case it's still on
if (sts_rf_cmd_status != STS_RF_PROJECTOR_POWER_OFF) { if (sts_rf_cmd_status != STS_RF_PROJECTOR_POWER_OFF) {
sts_rf_cmd_status = STS_RF_PROJECTOR_POWER_OFF; sts_rf_cmd_status = STS_RF_PROJECTOR_POWER_OFF;
sts_rf_cmd_pic = STS_RF_SHOW_PIC_DARK; sts_rf_cmd_pic = STS_RF_SHOW_PIC_DARK;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_STS_RemoteControlButtonEvent), CFG_SEQ_Prio_0); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRemoteControlSendCMD), CFG_SEQ_Prio_0);
} else { } else {
// already power off, do nothing just return // already power off, do nothing just return
return; return;
@ -778,7 +838,7 @@ static void OnSelfMeasureEnvironmentEvent(void *context)
} }
} }
*/
static bool STS_Check_Service_Period(void) static bool STS_Check_Service_Period(void)
{ {
@ -793,7 +853,7 @@ static bool STS_Check_Service_Period(void)
{ {
if (rc_service_period[i].enable_mask) if (rc_service_period[i].enable_mask)
{ {
if ((time_now.tm_hour >= rc_service_period[i].start_hour) && (time_now.tm_minute < rc_service_period[i].end_hour)) if ((time_now.tm_hour >= rc_service_period[i].start_hour) && (time_now.tm_min < rc_service_period[i].end_hour))
{ {
if ((time_now.tm_min >= rc_service_period[i].start_minute) && (time_now.tm_min < rc_service_period[i].end_minute)) if ((time_now.tm_min >= rc_service_period[i].start_minute) && (time_now.tm_min < rc_service_period[i].end_minute))
sts_rc_in_service_period_try = true; sts_rc_in_service_period_try = true;
@ -802,7 +862,7 @@ static bool STS_Check_Service_Period(void)
} }
sts_rc_in_service_period = sts_rc_in_service_period_try; sts_rc_in_service_period = sts_rc_in_service_period_try;
return return sts_rc_in_service_period_try;
} }
/* /*
* STS P8 Process, Detection ETR Sensors, Water flow sensors, pulse counting * STS P8 Process, Detection ETR Sensors, Water flow sensors, pulse counting