diff --git a/Core/Src/main.c b/Core/Src/main.c index 867d38c..900c3c7 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -114,7 +114,7 @@ int main(void) MX_DMA_Init(); MX_LoRaWAN_Init(); } - + MX_TOF_Process(); /* USER CODE BEGIN 2 */ //MX_USART2_UART_Init(); /* USER CODE END 2 */ diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index fc22fbc..a302a3c 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -50,7 +50,7 @@ extern volatile sts_cfg_nvm_t sts_cfg_nvm; extern volatile uint32_t rfac_timer; extern volatile uint32_t STS_TOFScanPeriod_msec, STS_TxPeriod_sec, STS_HeartBeatTimerPeriod_sec; volatile uint8_t sts_data_buf[LORAWAN_APP_DATA_BUFFER_MAX_SIZE]={0x0}; -volatile LmHandlerAppData_t sts_app_data={ 0, 0, sts_data_buf }; +// volatile LmHandlerAppData_t sts_app_data={ 0, 0, sts_data_buf }; /* USER CODE END EV */ @@ -536,7 +536,7 @@ void LoRaWAN_Init(void) #endif #if defined(STS_P2)||defined(STS_T6)||defined(L8) - UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_ONESHOT, (void*)OnYunhornSTSWakeUpScanTimerEvent, NULL); + UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, STS_YunhornSTSEventP5_Process, NULL); UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); #endif @@ -562,9 +562,11 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) break; #ifndef STS_R4 +#if 0 case BUT2_Pin: UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStopJoinEvent), CFG_SEQ_Prio_0); break; +#endif #endif case BUT3_Pin: @@ -572,9 +574,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) break; #if (defined(VL53L0)||defined(VL53LX)||defined(L8)) case TOF_INT_EXTI_PIN: - printf("\r\n ToF Event Detected=%d \r\n", ToF_EventDetected); ToF_EventDetected = 1; - printf("\r\n ToF Event Detected=%d \r\n", ToF_EventDetected); break; #endif default: @@ -768,6 +768,9 @@ static void SendTxData(void) sts_r_sensor_data_t sts_r4_sensor_data={0}; #elif defined(STS_M1) sts_r_sensor_data_t sts_m1_sensor_data={0}; +#elif defined(STS_L8) + sts_fhmos_sensor_data_t sts_fhmos_data={0}; +#elif defined(STS_XX) #endif if (LmHandlerIsBusy() == false) @@ -799,7 +802,9 @@ static void SendTxData(void) STS_M1_sensor_read(&sts_m1_sensor_data); #endif - +#ifdef STS_L8 + STS_FHMOS_sensor_read(&sts_fhmos_data); +#endif #ifdef VL53LX #ifdef STS_P2 @@ -968,8 +973,12 @@ static void SendTxData(void) #endif //STS_T6 #if defined(L8) - AppData.Buffer[i++] = 1; - AppData.Buffer[i++] = 8; //testing + AppData.Buffer[i++] = 4; + AppData.Buffer[i++] = sts_fhmos_data.fall_state; + AppData.Buffer[i++] = sts_fhmos_data.human_movement_state; + AppData.Buffer[i++] = sts_fhmos_data.occupancy_state; + AppData.Buffer[i++] = sts_fhmos_data.sos_alarm_state; + //(uint8_t)((sts_l8_sensor_data.tof_range_presence_state & 0xFF)); #endif //STS_T6 @@ -1496,6 +1505,8 @@ void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity) static void OnYunhornSTSWakeUpScanTimerEvent(void *context) { #if defined(STS_P2)||defined(STS_T6)||defined(L8) + UTIL_TIMER_Stop(&YunhornSTSWakeUpScanTimer); + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), CFG_SEQ_Prio_0); UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); diff --git a/STM32CubeIDE/.settings/language.settings.xml b/STM32CubeIDE/.settings/language.settings.xml index 4b0e6ff..c3dfc14 100644 --- a/STM32CubeIDE/.settings/language.settings.xml +++ b/STM32CubeIDE/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf b/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf index c8e6583..e25eacc 100644 Binary files a/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf and b/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf differ diff --git a/STS/Core/Inc/yunhorn_sts_sensors.h b/STS/Core/Inc/yunhorn_sts_sensors.h index f735fb6..cb73240 100644 --- a/STS/Core/Inc/yunhorn_sts_sensors.h +++ b/STS/Core/Inc/yunhorn_sts_sensors.h @@ -216,6 +216,19 @@ typedef struct sts_r_sensor_data } sts_r_sensor_data_t; +typedef struct sts_fhmos_sensor_data +{ + uint16_t install_height_mm; /*Default distance sensor measured distance */ + uint16_t battery_mV; /*mV, 1000mv-5000mv, regular 3300mV - 3600mV --4200mV */ + uint8_t fall_state; /* 0/blue: no occupy, 1/green:occupy yet normal, 2/yellow: suspicious state, 3/red: fall confirmed */ + uint8_t human_movement_state; /* 0/blue: no occupy, 1/green:occupy yet normal, 2/yellow: suspicious state, 3/red: fall confirmed */ + uint8_t occupancy_state; /* 0/blue: no occupy, 1/green:occupy yet normal, 3/red: over stay */ + uint8_t sos_alarm_state; /* 1/green, sos on-duty, 2/yellow, sos button pressed 3/red, alarm */ + uint8_t on_off_event; /* 1: liquid sensed, 0: no liquid sensed */ + + +} sts_fhmos_sensor_data_t; + /** * @brief Store/Write/Flash Configuration in RW RAM */ @@ -264,9 +277,10 @@ void STS_SENSOR_Upload_Config_Invalid_Message(void); void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, uint8_t *appDataBuffer); void STS_SENSOR_Upload_AppData_Message(LmHandlerAppData_t stsAppdata); void STS_SENSOR_MEMS_Get_ID(uint16_t *devID); -void STS_RR_Sensor_Read(sts_tof_range_data_t *sts_rr_sensor_data); +void STS_RR_Sensor_read(sts_tof_range_data_t *sts_rr_sensor_data); void STS_R4_sensor_read(sts_r_sensor_data_t *sts_r_sensor_data); void STS_M1_sensor_read(sts_r_sensor_data_t *sts_m_sensor_data); +void STS_FHMOS_sensor_read(sts_fhmos_sensor_data_t *sts_fhmos_data); void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity); void OnYunhornSTSTxPeriodicityChanged(uint32_t periodicity); void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_size); diff --git a/STS/Core/Src/yunhorn_sts_process.c b/STS/Core/Src/yunhorn_sts_process.c index f88872d..8714e57 100644 --- a/STS/Core/Src/yunhorn_sts_process.c +++ b/STS/Core/Src/yunhorn_sts_process.c @@ -121,7 +121,7 @@ volatile uint8_t sensor_data_ready=0; #if defined(STS_R1)||defined(STS_R5)||defined(STS_R4)||defined(STS_R1D) volatile uint32_t STS_TOFScanPeriod_msec=50, STS_TxPeriod_sec=30, STS_HeartBeatTimerPeriod_sec=3600; #elif defined(STS_L8)||defined(STS_P2)||defined(STS_O6T)||defined(STS_T6) -volatile uint32_t STS_TOFScanPeriod_msec=100, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60; +volatile uint32_t STS_TOFScanPeriod_msec=500, STS_TxPeriod_sec=300, STS_HeartBeatTimerPeriod_sec=3600; #endif static uint8_t outbuf[128]={0x0}; @@ -445,6 +445,8 @@ void STS_YunhornSTSEventP5_Process(void) } #elif defined(L8) //STS_TOF_VL53L8X_Process(); + //STS_TOF_L8_Process(); + printf("\r\n P5 process \r\n"); MX_TOF_Process(); //MX_TOF_Ranging_Process(); #endif diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index ca4a8b9..9cff161 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -34,6 +34,9 @@ extern "C" { #elif defined(L8) #include "53l8a1_ranging_sensor.h" #include "app_tof_pin_conf.h" +#include "yunhorn_sts_sensors.h" +volatile uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_sos_alarm=0; +volatile uint32_t fhmos_fall_counter=0; #endif #include "stm32wlxx_nucleo.h" @@ -69,17 +72,38 @@ extern "C" { #ifdef L8 /* for VL53L8A1 */ #define RANGING_FREQUENCY (10U) /* Ranging frequency Hz (shall be consistent with TimingBudget value) */ -#define LOW_THRESHOLD (200U) -#define HIGH_THRESHOLD (600U) +#define LOW_THRESHOLD (600U) +#define HIGH_THRESHOLD (2000U) +// floor, eg. 2200 +#define OCCUPANCY_THRESHOLD (1500) // assume high people 2000-450 = 1550 +/* ceiling -------------------- zero - 00 ref. 3000 mm high + * + * + * people high --------------- 2100 mm western people + * + * + * + * + * people how ------------------- 900 mm child normal + * + * + * + * other things ----------------- 400 mm + * + * + * floor ----------------------00000 + * + * + */ /* Private variables ---------------------------------------------------------*/ static RANGING_SENSOR_Capabilities_t Cap; static RANGING_SENSOR_ProfileConfig_t Profile; static RANGING_SENSOR_Result_t Result; -static VL53L8CX_ResultsData L8CXResult; -static VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ +//static VL53L8CX_ResultsData L8CXResult; +//static VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ -static VL53L8CX_Configuration Dev; +//static VL53L8CX_Configuration Dev; static void MX_53L8A1_ThresholdDetection_Init(void); static void MX_53L8A1_ThresholdDetection_Process(void); @@ -188,6 +212,7 @@ void MX_TOF_Process(void) //sts_tof_vl53lx_peoplecount_subprocess(); #ifdef L8 //MX_53L8A1_ThresholdDetection_Process(); + printf("\r\n Tof Process\r\n"); STS_TOF_L8_Process(); #endif @@ -198,6 +223,8 @@ void MX_TOF_Process(void) #ifdef L8 void STS_TOF_L8_Process(void) { + printf("\r\n Tof L8 Process\r\n"); + MX_53L8A1_ThresholdDetection_Process(); //while (1) { /* interrupt mode */ @@ -241,7 +268,7 @@ static void MX_53L8A1_ThresholdDetection_Init(void) printf("VL53L8A1_RANGING_SENSOR_Init failed\n"); //while (1); } - printf("\r\nVL53L8A1_RANGING_SENSOR_Init Success\r\n"); + } static void MX_53L8A1_ThresholdDetection_Process(void) @@ -283,8 +310,8 @@ static void MX_53L8A1_ThresholdDetection_Process(void) printf("-------------------------------------------\n\r"); printf("please put a target between %d and %d millimeters from the sensor\n\r", LOW_THRESHOLD, HIGH_THRESHOLD); -#if 1 - //while (1) +#if 0 + while (1) { /* interrupt mode */ if (ToF_EventDetected != 0) @@ -349,28 +376,38 @@ static void print_result(RANGING_SENSOR_Result_t *Result) for (k = (zones_per_line - 1); k >= 0; k--) { if (Result->ZoneResult[j + k].NumberOfTargets > 0) - { - - for(i = 0; i < 16; i++) - { -#if 0 - printf("Zone : %3d, Motion power : %3lu\n", i, Results. - Results.motion_indicator.motion[motion_config.map_id[i]]); -#endif -#if 0 - printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ", - (long)Result->ZoneResult[j + k].Distance[l],(j+k), - (long)Result->ZoneResult[j + k].Status[l]); -#endif - } - - printf("\n"); + { uint16_t distance_i = (long)Result->ZoneResult[j + k].Distance[l]; + if ((distance_i >LOW_THRESHOLD)&&(distance_i ZoneResult[j + k].Status[l]); + else printf("| %5s : %5s ", " ", " "); + } + else + printf("| %5s : %5s ", " ", " "); + } + printf("\n"); /* ---- origin printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ", (long)Result->ZoneResult[j + k].Distance[l],(j+k), (long)Result->ZoneResult[j + k].Status[l]); */ int32_t roi_distance =(uint32_t)(Result->ZoneResult[j + k].Distance[l]); + /* state tree */ + if ((roi_distance > LOW_THRESHOLD)&&(roi_distance < OCCUPANCY_THRESHOLD)) + fhmos_occupancy = 1; + if ((roi_distance < HIGH_THRESHOLD)&&(roi_distance > OCCUPANCY_THRESHOLD)) + { + fhmos_fall = 1; + fhmos_human_movement = 1; + fhmos_fall_counter ++; + if (fhmos_fall_counter++>60) + fhmos_fall =2; + if (fhmos_fall_counter > 200) + fhmos_fall =3; + } + + + + int16_t roi_low = (roi_distance - LOW_THRESHOLD)/10; int16_t roi_high = (HIGH_THRESHOLD - roi_distance)/10; @@ -384,11 +421,6 @@ static void print_result(RANGING_SENSOR_Result_t *Result) //printf("| \033[38;5;10m%5s\033[0m :%2d%5ld ", ".",(j+k), (uint32_t)Result->ZoneResult[j + k].Status[l]); printf("| \033[38;5;10m%5s\033[0m : ", "."); } - } - else - printf("| %5s : %5s ", ".", "."); - } - printf("|\n"); if ((Profile.EnableAmbient != 0) || (Profile.EnableSignal != 0)) { @@ -430,7 +462,19 @@ static void print_result(RANGING_SENSOR_Result_t *Result) #endif -#if defined(STS_P2)||defined(STS_T6) +#ifdef L8 +void STS_FHMOS_sensor_read(sts_fhmos_sensor_data_t *sts_fhmos_data) +{ + //uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_sos_alarm=0; + sts_fhmos_data->fall_state = fhmos_fall; + sts_fhmos_data->human_movement_state =fhmos_human_movement; + sts_fhmos_data->occupancy_state =fhmos_occupancy; + sts_fhmos_data->sos_alarm_state =fhmos_sos_alarm; +} +#endif + + +#if defined(STS_P2)||defined(STS_T6)||defined(L8) uint8_t IsInterruptDetected(uint16_t dev) { // To be filled with customer HW. This function should