revised for enter/exit potential state and theshold

This commit is contained in:
Yunhorn 2025-01-02 23:27:44 +08:00
parent aee02adc04
commit 6f806e0e6b
8 changed files with 97 additions and 38 deletions

View File

@ -64,8 +64,8 @@ void Error_Handler(void);
#define LED1_Pin GPIO_PIN_15
#define LED1_GPIO_Port GPIOB
#endif
#define LED2_Pin GPIO_PIN_9
#define LED2_GPIO_Port GPIOB
// #define LED2_Pin GPIO_PIN_9
// #define LED2_GPIO_Port GPIOB
#define BUT1_Pin GPIO_PIN_0
#define BUT1_GPIO_Port GPIOA
#define BUT1_EXTI_IRQn EXTI0_IRQn
@ -128,9 +128,31 @@ void Error_Handler(void);
#define BUT1_EXTI_IRQn EXTI0_IRQn
#endif
// GREEN LED
#define LED1_Pin GPIO_PIN_2
#define LED1_GPIO_Port GPIOB
// RED LED
#define LED2_Pin GPIO_PIN_7
#define LED2_GPIO_Port GPIOB
// GREEN LED
#define LED1_ON HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET )
#define LED1_OFF HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET)
// RED LED
#define LED2_ON HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET )
#define LED2_OFF HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET)
#define LED_GREEN_ON LED1_ON
#define LED_GREEN_OFF LED1_OFF
#define LED_RED_ON LED2_ON
#define LED_RED_OFF LED2_OFF
#define LED1_STATE HAL_GPIO_ReadPin(LED1_GPIO_Port, LED1_Pin)
#define LED1_TOGGLE HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin)
#define LED1_ON HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET )
#define LED1_OFF HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET)
#define LED1_STATE HAL_GPIO_ReadPin(LED1_GPIO_Port, LED1_Pin)

View File

@ -47,12 +47,12 @@ extern "C" {
/**
* @brief Verbose level for all trace logs
*/
#define VERBOSE_LEVEL VLEVEL_OFF
#define VERBOSE_LEVEL VLEVEL_L
/**
* @brief Enable trace logs
*/
#define APP_LOG_ENABLED 0
#define APP_LOG_ENABLED 1
/**
* @brief Activate monitoring (probes) of some internal RF signals for debug purpose
@ -75,7 +75,7 @@ extern "C" {
* @brief Enable/Disable MCU Debugger pins (dbg serial wires)
* @note by HW serial wires are ON by default, need to put them OFF to save power
*/
#define DEBUGGER_ENABLED 0
#define DEBUGGER_ENABLED 1
/**
* @brief Disable Low Power mode

View File

@ -133,7 +133,26 @@ void SystemApp_Init(void)
#if defined(STS_P2)
STS_TOF_VL53LX_PeopleCounting_Process_Init();
#endif
STS_Lamp_Bar_Self_Test();
#if defined(STS_T6)||defined(L8)
//STS_TOF_VL53LX_PresenceDetection_Process_Init();
//STS_Lamp_Bar_Self_Test_Simple();
// STS_Lamp_Bar_Self_Test();
LED_GREEN_ON;HAL_Delay(50);
LED_RED_ON;HAL_Delay(50);
LED_GREEN_OFF;HAL_Delay(50);
LED_RED_OFF;HAL_Delay(50);
LED_GREEN_ON;HAL_Delay(150);
LED_RED_ON;HAL_Delay(150);
LED_GREEN_OFF;HAL_Delay(150);
LED_RED_OFF;HAL_Delay(150);
LED_GREEN_ON;HAL_Delay(50);
LED_RED_ON;HAL_Delay(50);
LED_GREEN_OFF;HAL_Delay(50);
LED_RED_OFF;HAL_Delay(50);
#endif
/*Init low power manager*/
UTIL_LPM_Init();
/* Disable Stand-by mode */

View File

@ -1285,7 +1285,7 @@ static void SendTxData(void)
status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false);
if (LORAMAC_HANDLER_SUCCESS == status)
{
APP_LOG(TS_ON, VLEVEL_L, "SEND REQUEST\r\n");
APP_LOG(TS_ON, VLEVEL_M, "SEND REQUEST\r\n");
}
else if (LORAMAC_HANDLER_DUTYCYCLE_RESTRICTED == status)
{
@ -1398,10 +1398,10 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
APP_LOG(TS_OFF, VLEVEL_M, "OTAA =====================\r\n");
}
AppData.Port = 1;
AppData.BufferSize = 10;
//AppData.Buffer[0]=0x38;
//AppData.Buffer[1]=0x38;
UTIL_MEM_cpy_8((uint8_t*)AppData.Buffer, "YUNHORN168", 10);
AppData.BufferSize = 16;
// UTIL_MEM_cpy_8(AppData.Buffer, (uint8_t*)"YUNHORN168", 10);
UTIL_MEM_cpy_8((uint8_t*)AppData.Buffer, (uint8_t *)YUNHORN_STS_PRD_STRING, sizeof(YUNHORN_STS_PRD_STRING));
AppData.BufferSize = sizeof(YUNHORN_STS_PRD_STRING);
LmHandlerParams.IsTxConfirmed = true;
LmHandlerErrorStatus_t status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false);
if (status ==LORAMAC_HANDLER_SUCCESS ) LmHandlerParams.IsTxConfirmed = false;
@ -1414,7 +1414,7 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
APP_LOG(TS_OFF, VLEVEL_H, "###### U/L FRAME:JOIN | DR:%d | PWR:%d\r\n", joinParams->Datarate, joinParams->TxPower);
}
UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer);
// UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer);
/* USER CODE END OnJoinRequest_1 */
}

View File

@ -131,7 +131,7 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
fhmos_cfg.th_head_level_height_cm = 70; // default 700mm
fhmos_cfg.th_fall_duration_potential_15sec = 4; // 4*15=60 sec, 1 min.
fhmos_cfg.th_fall_duration_confirm_15sec = 8; // 8*15 = 120 sec, 2 min.
fhmos_cfg.th_fall_duration_confirm_15sec = 4; // 4*15 = 120 sec, 2 min.
fhmos_cfg.th_motionless_short_15sec = 8; // 8*15 = 120 sec , 2 min.
fhmos_cfg.th_motionless_long_15sec = 20; // 20*15 = 300 sec, 5 min.
@ -144,7 +144,7 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
0x46, // uint8_t fhmos_cfg_1; head level height cm
0x04, // uint8_t fhmos_cfg_2; 04*15 = 60 sec, 1 min. Fall potential
0x08, // uint8_t fhmos_cfg_3; 08*15 = 120 sec, 2 min. Fall confirmed
0x04, // uint8_t fhmos_cfg_3; 04*15 = 60 sec, 1 min. Fall confirmed
0x08, // uint8_t fhmos_cfg_4; 08*15 = 120 sec, = 2 min. motionless short
0x14, // uint8_t fhmos_cfg_5; 20*15 = 300 sec, = 5 min. motionless long
@ -2329,6 +2329,7 @@ void YunhornSTSDurationCheckTimer(void)
(15*fhmos_cfg.th_occupancy_overstay_15sec));
#endif
LED_RED_ON;
sts_lamp_bar_color = STS_OCCUPANCY_OVERSTAY_COLOR;
// APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor1 overstay set color to %d color:%s\r\n",sts_lamp_bar_color, (char*)code2color[sts_lamp_bar_color]);
over_threshold |= 1<<0;
@ -2350,6 +2351,9 @@ void YunhornSTSDurationCheckTimer(void)
fhmos_data.state_human_movement = STS_FHMOS_HUMAN_MOVEMENT_NO_OCCUPY;
sts_lamp_bar_color = STS_VACANT_COLOR;
LED_RED_OFF;
LED_GREEN_ON;
}
// tag for upload states or not
@ -2489,10 +2493,11 @@ void YunhornSTSDurationCheckTimer(void)
case STS_FHMOS_FALL_STATE_POTENTIAL:
if (over_confirmed_threshold)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\nFall state enter Confirm state .....\r\n");
APP_LOG(TS_OFF, VLEVEL_L, "\r\nFall state ---> Confirm state .....\r\n");
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_CONFIRMED;
fhmos_data.time_stamp_fall_confirmed = STS_Get_Date_Time_Stamp(); //uint8_t datetimestamp[8]={0};;
LED_GREEN_ON;
LED_RED_ON;
over_threshold |= 1<<6;
// upload state confirm message
@ -2517,14 +2522,18 @@ void YunhornSTSDurationCheckTimer(void)
// do nothing, wait for rising up or out of window or door open to release state
// if (sts_fhmos_bitmap_pending == 1)
//APP_LOG(TS_OFF, VLEVEL_M, "\r\nFall state KEPT .....\r\n");
LED_RED_ON;
break;
case STS_FHMOS_FALL_STATE_NORMAL:
if (over_potential_threshold)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\nFall state enter potential state .....\r\n");
APP_LOG(TS_OFF, VLEVEL_L, "\r\nFall state ---> potential state .....\r\n");
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_POTENTIAL;
LED_RED_OFF;
LED_GREEN_ON;
over_threshold |= 1<<7;
// upload state potential message
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
@ -2538,21 +2547,30 @@ void YunhornSTSDurationCheckTimer(void)
} else // sts_head_level_low ==0
{
//APP_LOG(TS_OFF, VLEVEL_M, "\r\n HEAD_LOW_LEVEL_STATE=%02x , door read =%s \r\n", sts_head_level_low, sts_hall1_read==0?"Door Closed":"Door Open");
//fhmos_data.head_low_level_start_time = 0;
fhmos_data.head_low_level_duration = 0;
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_NORMAL;
fhmos_data.state_fall_released = 1;
sts_fhmos_bitmap_pending = 0;
over_threshold &= ~0x40;
over_threshold &= ~0x80;
if ((last_sensor4_state > 1) && (fhmos_data.state_fall ==1)) {
APP_LOG(TS_OFF, VLEVEL_L, "\r\nFall state ---> Normal state .....\r\n");
}
LED_GREEN_ON;
LED_RED_OFF;
}
if (last_sensor4_state != fhmos_data.state_fall)
{
sts_sensor4_changed = 1;
last_sensor4_state = fhmos_data.state_fall;
}
@ -2651,7 +2669,7 @@ void YunhornSTSDurationCheckTimer(void)
//if ((over_threshold != 0 ) && (last_sts_cmb_result != sts_cmb_result))
if ((last_sts_cmb_result != sts_cmb_result))
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Over Threshold =0x%02x \r\n", over_threshold);
APP_LOG(TS_OFF, VLEVEL_L, "\r\n Over Threshold =0x%02x \r\n", over_threshold);
last_sts_cmb_result = sts_cmb_result;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);

View File

@ -40,7 +40,7 @@ volatile uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_
volatile uint32_t fhmos_fall_counter=0;
volatile uint32_t sts_low_threshold=1500, sts_high_threshold=2800, sts_occupancy_threshold=2300;
extern volatile uint8_t sts_head_level_low;
volatile sts_fhmos_sensor_config_t fhmos_cfg={70,4,8,8,20,80,20,25};
volatile sts_fhmos_sensor_config_t fhmos_cfg={70,4,4,8,20,80,20,25};
volatile sts_fhmos_sensor_cmd_t fhmos_cmd={0x0};
volatile sts_fhmos_sensor_ambient_height_t fhmos_bg={0x0}, fhmos_gesture={0x0}, fhmos_net={0x0};
volatile sts_fhmos_sensor_data_t fhmos_data={0};
@ -222,13 +222,13 @@ void STS_LMZ_Ambient_Height_Scan_Process(void)
//STS_TOF_L8_Process();
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ----------------------"
APP_LOG(TS_OFF, VLEVEL_L, "\r\n ----------------------"
"\r\n------Threshold %d cm--\r\n", fhmos_cfg.th_gesture_mask_off_height_cm);
for (uint8_t i = 0; i < 64; i++)
{
/* Print distance and status */
if (i%8==0) APP_LOG(TS_OFF, VLEVEL_M, "\r\nPosition from Floor [cm]| ");
if (i%8==0) APP_LOG(TS_OFF, VLEVEL_L, "\r\nPosition from Floor [cm]| ");
if ((Result.ZoneResult[i].NumberOfTargets > 0))
{
range_distance = (uint32_t)Result.ZoneResult[i].Distance[0];
@ -245,28 +245,28 @@ void STS_LMZ_Ambient_Height_Scan_Process(void)
//sts_mask_bitmap[(uint8_t)(i/8)] |= (fhmos_bg.maskoff[i])<<(7-i%8);
sts_mask_bitmap[(uint8_t)(i/8)] |= (fhmos_bg.maskoff[i])<<(i%8);
// if (i%8==0) APP_LOG(TS_OFF, VLEVEL_M, "\r\n");
APP_LOG(TS_OFF, VLEVEL_M, "|%3d ", fhmos_bg.h2cm[i]*2);
APP_LOG(TS_OFF, VLEVEL_L, "|%3d ", fhmos_bg.h2cm[i]*2);
}
else {
fhmos_bg.h2cm[i] = 0;
APP_LOG(TS_OFF, VLEVEL_M, "|%3d ", fhmos_bg.h2cm[i]);
APP_LOG(TS_OFF, VLEVEL_L, "|%3d ", fhmos_bg.h2cm[i]);
}
}
APP_LOG(TS_OFF, VLEVEL_M, "\r\n\n ------- Mask off matrix \r\n");
APP_LOG(TS_OFF, VLEVEL_L, "\r\n\n ------- Mask off matrix \r\n");
for (i=0; i<64; i++)
{
if (i%8==0) APP_LOG(TS_OFF, VLEVEL_M, "\r\n");
APP_LOG(TS_OFF, VLEVEL_M, "|%d ", (uint8_t)fhmos_bg.maskoff[i]);
if (i%8==0) APP_LOG(TS_OFF, VLEVEL_L, "\r\n");
APP_LOG(TS_OFF, VLEVEL_L, "|%d ", (uint8_t)fhmos_bg.maskoff[i]);
}
APP_LOG(TS_OFF, VLEVEL_M, "\r\nmask bitmap \r\n");
for (i=0; i<8; i++)
APP_LOG(TS_OFF, VLEVEL_M, "%02X\r\n",sts_mask_bitmap[i]);
APP_LOG(TS_OFF, VLEVEL_L, "%02X\r\n",sts_mask_bitmap[i]);
#endif
@ -309,37 +309,37 @@ void sts_generate_fall_gesture_map(void)
else {
fhmos_gesture.h2cm[i] = 0;
}
if (i%8==0) APP_LOG(TS_OFF, VLEVEL_M, "\r\n");
APP_LOG(TS_OFF, VLEVEL_M, "|%4d ", fhmos_gesture.h2cm[i]);
if (i%8==0) APP_LOG(TS_OFF, VLEVEL_L, "\r\n");
APP_LOG(TS_OFF, VLEVEL_L, "|%4d ", fhmos_gesture.h2cm[i]);
}
for (i = 0; i < 64; i++)
{
if (i%8==0) APP_LOG(TS_OFF, VLEVEL_M, "\r\n");
APP_LOG(TS_OFF, VLEVEL_M, "|%d ", fhmos_gesture.maskoff[i]);
if (i%8==0) APP_LOG(TS_OFF, VLEVEL_L, "\r\n");
APP_LOG(TS_OFF, VLEVEL_L, "|%d ", fhmos_gesture.maskoff[i]);
}
for (i=0; i<8; i++)
APP_LOG(TS_OFF, VLEVEL_M, "%02x",fhmos_gesture_bitmap[i]);
APP_LOG(TS_OFF, VLEVEL_L, "%02x",fhmos_gesture_bitmap[i]);
APP_LOG(TS_OFF, VLEVEL_M, "\r\n");
APP_LOG(TS_OFF, VLEVEL_L, "\r\n");
for (i = 0; i < 32; i++)
{
if (i%4 == 0) APP_LOG(TS_OFF, VLEVEL_M, "\r\n");
if (i%4 == 0) APP_LOG(TS_OFF, VLEVEL_L, "\r\n");
//h4 = MIN(fhmos_gesture.h2cm[2*i+0],sts_gesture_mask_cap_height_2cm)/8;
//l4 = MIN(fhmos_gesture.h2cm[2*i+1],sts_gesture_mask_cap_height_2cm)/8;
h4 = fhmos_gesture.h2cm[2*i+0];
l4 = fhmos_gesture.h2cm[2*i+1];
fhmos_gesture.cube[i] = ((h4&0x0f)<<4)|(l4&0x0f);
APP_LOG(TS_OFF, VLEVEL_M, " [%2d_%2d]", (fhmos_gesture.cube[i]>>4)&0x0f, (fhmos_gesture.cube[i]&0x0f));
APP_LOG(TS_OFF, VLEVEL_L, " [%2d_%2d]", (fhmos_gesture.cube[i]>>4)&0x0f, (fhmos_gesture.cube[i]&0x0f));
}
fhmos_gesture.head_level = 0xff&((sts_sensor_install_height - sts_fall_head_position)/10); // head level from floor in CM
fhmos_gesture.head_xy = head_xy&0xff;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Head level =%4d cm, Head_xy=%d X:Y = %2d : %2d \r\n", fhmos_gesture.head_level, head_xy, (head_xy%8), (head_xy/8));
APP_LOG(TS_OFF, VLEVEL_L, "\r\n Head level =%4d cm, Head_xy=%d X:Y = %2d : %2d \r\n", fhmos_gesture.head_level, head_xy, (head_xy%8), (head_xy/8));
#if 0
for (i=0; i<64; i++)
@ -352,7 +352,7 @@ void sts_generate_fall_gesture_map(void)
#endif
sts_fhmos_bitmap_pending = 1;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Fall Gesture bitmap Generated\r\n");
APP_LOG(TS_OFF, VLEVEL_L, "\r\n Fall Gesture bitmap Generated\r\n");
}
uint16_t MX_TOF_Ranging_Process(void)
{