From b3a49f52717747e06e16b2a4960ca1cc81c38fa3 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Tue, 9 Apr 2024 17:10:37 +0800 Subject: [PATCH] minor change...bad --- Core/Src/sts_lamp_bar.c | 2 +- Core/Src/yunhorn_sts_presence_sensor.c | 4 +- LoRaWAN/App/lora_app.c | 68 +++++++++++++++++--------- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/Core/Src/sts_lamp_bar.c b/Core/Src/sts_lamp_bar.c index 8978106..f7aa3df 100644 --- a/Core/Src/sts_lamp_bar.c +++ b/Core/Src/sts_lamp_bar.c @@ -562,7 +562,7 @@ void STS_Lamp_Bar_Self_Test_Simple(void) luminance_level = 10; do { STS_Lamp_Bar_Set_STS_RGB_Color(color, luminance_level); - HAL_Delay(50); + HAL_Delay(10); luminance_level += 20; } while (luminance_level < 99); //STS_Lamp_Bar_Set_Dark(); diff --git a/Core/Src/yunhorn_sts_presence_sensor.c b/Core/Src/yunhorn_sts_presence_sensor.c index 35610c7..6052b85 100644 --- a/Core/Src/yunhorn_sts_presence_sensor.c +++ b/Core/Src/yunhorn_sts_presence_sensor.c @@ -468,11 +468,11 @@ uint8_t STS_SENSOR_MEMS_Get_ID(uint8_t *devID) { devID[0] = scanned_id[0]; devID[1] = scanned_id[1]; - return true; + return 1; } else { - return false; + return 0; } #endif diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 1d2a569..4402bc5 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -577,12 +577,12 @@ void LoRaWAN_Init(void) YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSOORSSWakeUpTimerEvent, NULL); UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer); - +#if 0 UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, YUNHORN_STS_HEART_BEAT_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL); UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); - +#endif #else UTIL_TIMER_Create(&YunhornSTSSamplingCheckTimer, @@ -2152,7 +2152,7 @@ void STS_REBOOT_CONFIG_Init(void) { APP_LOG(TS_OFF, VLEVEL_M, "Initial Boot with Empty Config, Flash with default config....\r\n"); OnStoreSTSCFGContextRequest(); - UTIL_MEM_set_8((void *)sts_ac_code, 0x00, YUNHORN_STS_AC_CODE_SIZE); + //UTIL_MEM_set_8((void *)sts_ac_code, 0x00, YUNHORN_STS_AC_CODE_SIZE); HAL_Delay(1000); } else { @@ -2203,48 +2203,66 @@ void OnRestoreSTSCFGContextProcess(void) } periodicity = (periodicity > 10)? periodicity : 10; // in seconds unit TxPeriodicity= periodicity*1000; // to ms - OnTxPeriodicityChanged(TxPeriodicity); // in msec unit - uint32_t samplingperiodicity = (sts_cfg_nvm.sampling); + uint32_t samplingperiodicity = (sts_cfg_nvm.sampling); //Heart-beat or Sampling interval if ((char)sts_cfg_nvm.s_unit =='M') { - samplingperiodicity *= 60; + samplingperiodicity *= 60; } else if ((char) sts_cfg_nvm.s_unit =='H') { - samplingperiodicity *= 3600; + samplingperiodicity *= 3600; } else if ((char) sts_cfg_nvm.s_unit =='S') { - samplingperiodicity *= 1; + samplingperiodicity *= 1; } - samplingperiodicity = (samplingperiodicity > 0)? samplingperiodicity : 1; // in seconds unit - OnYunhornSTSSamplingPeriodicityChanged(samplingperiodicity*1000); // in m-sec unit + if ((sts_cfg_nvm.ac[0] ==0x0 )&& (sts_cfg_nvm.ac[19]==0x0)) + { // ensure it's not in production yet + OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit + OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); + } else + { + OnTxPeriodicityChanged(TxPeriodicity); // in msec unit + //Heart-beat or Sampling interval + samplingperiodicity = (samplingperiodicity > 0)? samplingperiodicity : 1; // in seconds unit + HeartBeatPeriodicity = samplingperiodicity*1000; + #if defined(YUNHORN_STS_O7_ENABLED) ||defined(YUNHORN_STS_O5_ENABLED) + OnYunhornSTSSamplingPeriodicityChanged(HeartBeatPeriodicity); // in m-sec unit + #endif + + #if defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)||defined(YUNHORN_STS_R4_ENABLED) + OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); + #endif + } sts_work_mode = sts_cfg_nvm.work_mode; - sts_lamp_bar_color = STS_GREEN; sts_service_mask = sts_cfg_nvm.sts_service_mask; - sts_fall_detection_acc_threshold = (uint8_t)sts_cfg_nvm.fall_detection_acc_threshold*10; - sts_fall_detection_depth_threshold = (uint8_t)sts_cfg_nvm.fall_detection_depth_threshold*10; //in cm - // **** = sts_cfg_nvm.fall_detection_reserve; - sts_occupancy_overtime_threshold = (uint8_t)sts_cfg_nvm.occupancy_overtime_threshold*10; // minutes +#ifdef YUNHORN_STS_O7_ENABLED + sts_lamp_bar_color = STS_GREEN; + sts_fall_detection_acc_threshold = (uint8_t)sts_cfg_nvm.fall_detection_acc_threshold*10; + sts_fall_detection_depth_threshold = (uint8_t)sts_cfg_nvm.fall_detection_depth_threshold*10; //in cm + // **** = sts_cfg_nvm.fall_detection_reserve; + sts_occupancy_overtime_threshold = (uint8_t)sts_cfg_nvm.occupancy_overtime_threshold*10; // minutes +#endif for (uint8_t j=0; j< YUNHORN_STS_AC_CODE_SIZE; j++) { - sts_ac_code[j] = sts_cfg_nvm.ac[j]; + sts_ac_code[j] = sts_cfg_nvm.ac[j]; } - #ifdef YUNHORN_STS_O7_ENABLED if ((sts_version == sts_cfg_nvm.version)&& (NVM_CFG_PARAMETER_SIZE == sts_cfg_nvm.length)) { - STS_PRESENCE_SENSOR_Init(); - STS_PRESENCE_SENSOR_RSS_Init(); + STS_PRESENCE_SENSOR_Init(); + STS_PRESENCE_SENSOR_RSS_Init(); } #endif + } void STS_SENSOR_Distance_Test_Process(void) { +#if defined(YUNHORN_STS_O6_ENABLED)||defined(YUNHORN_STS_O7_ENABLED) sts_distance_rss_distance =0; do { STS_PRESENCE_SENSOR_Distance_Measure_Process(); @@ -2252,13 +2270,17 @@ void STS_SENSOR_Distance_Test_Process(void) } while(sts_distance_rss_distance == 0); APP_LOG(TS_OFF, VLEVEL_H, "\r\nSensor Function Test: Distance Measured =%u mm\r\n", (int)sts_distance_rss_distance); +#endif +#if defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED) + MX_TOF_Process(); +#endif } void STS_SENSOR_Function_Test_Process(void) { char tstbuf[128] =""; uint8_t i=0, count = 1; - uint8_t mems_Dev_ID[2] = ""; + uint8_t mems_Dev_ID[2] = {0x0,0x0}; tstbuf[i++] = (uint8_t) 'S'; tstbuf[i++] = (uint8_t) sts_mtmcode1; @@ -2268,8 +2290,10 @@ void STS_SENSOR_Function_Test_Process(void) tstbuf[i++] = (uint8_t) (99*((GetBatteryLevel()/254)&0xff)); - STS_SENSOR_MEMS_Get_ID(mems_Dev_ID); - if ((mems_Dev_ID[0]==0X0) && (mems_Dev_ID[1]==0x0)) { + count = STS_SENSOR_MEMS_Get_ID(mems_Dev_ID); + //if ((mems_Dev_ID[0]==0X0) && (mems_Dev_ID[1]==0x0)) { + if (count==0) + { tstbuf[i++] = (uint8_t) 'X'; // Slave MEMS Not Avaliable } else