This commit is contained in:
Yunhorn 2024-11-15 05:07:24 +08:00
parent beb751c456
commit 789bdb5e40
7 changed files with 113 additions and 42 deletions

View File

@ -114,7 +114,7 @@ int main(void)
MX_DMA_Init(); MX_DMA_Init();
MX_LoRaWAN_Init(); MX_LoRaWAN_Init();
} }
MX_TOF_Process();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
//MX_USART2_UART_Init(); //MX_USART2_UART_Init();
/* USER CODE END 2 */ /* USER CODE END 2 */

View File

@ -50,7 +50,7 @@ extern volatile sts_cfg_nvm_t sts_cfg_nvm;
extern volatile uint32_t rfac_timer; extern volatile uint32_t rfac_timer;
extern volatile uint32_t STS_TOFScanPeriod_msec, STS_TxPeriod_sec, STS_HeartBeatTimerPeriod_sec; 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 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 */ /* USER CODE END EV */
@ -536,7 +536,7 @@ void LoRaWAN_Init(void)
#endif #endif
#if defined(STS_P2)||defined(STS_T6)||defined(L8) #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); UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer);
#endif #endif
@ -562,9 +562,11 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
break; break;
#ifndef STS_R4 #ifndef STS_R4
#if 0
case BUT2_Pin: case BUT2_Pin:
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStopJoinEvent), CFG_SEQ_Prio_0); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaStopJoinEvent), CFG_SEQ_Prio_0);
break; break;
#endif
#endif #endif
case BUT3_Pin: case BUT3_Pin:
@ -572,9 +574,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
break; break;
#if (defined(VL53L0)||defined(VL53LX)||defined(L8)) #if (defined(VL53L0)||defined(VL53LX)||defined(L8))
case TOF_INT_EXTI_PIN: case TOF_INT_EXTI_PIN:
printf("\r\n ToF Event Detected=%d \r\n", ToF_EventDetected);
ToF_EventDetected = 1; ToF_EventDetected = 1;
printf("\r\n ToF Event Detected=%d \r\n", ToF_EventDetected);
break; break;
#endif #endif
default: default:
@ -768,6 +768,9 @@ static void SendTxData(void)
sts_r_sensor_data_t sts_r4_sensor_data={0}; sts_r_sensor_data_t sts_r4_sensor_data={0};
#elif defined(STS_M1) #elif defined(STS_M1)
sts_r_sensor_data_t sts_m1_sensor_data={0}; 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 #endif
if (LmHandlerIsBusy() == false) if (LmHandlerIsBusy() == false)
@ -799,7 +802,9 @@ static void SendTxData(void)
STS_M1_sensor_read(&sts_m1_sensor_data); STS_M1_sensor_read(&sts_m1_sensor_data);
#endif #endif
#ifdef STS_L8
STS_FHMOS_sensor_read(&sts_fhmos_data);
#endif
#ifdef VL53LX #ifdef VL53LX
#ifdef STS_P2 #ifdef STS_P2
@ -968,8 +973,12 @@ static void SendTxData(void)
#endif //STS_T6 #endif //STS_T6
#if defined(L8) #if defined(L8)
AppData.Buffer[i++] = 1; AppData.Buffer[i++] = 4;
AppData.Buffer[i++] = 8; //testing 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)); //(uint8_t)((sts_l8_sensor_data.tof_range_presence_state & 0xFF));
#endif //STS_T6 #endif //STS_T6
@ -1496,6 +1505,8 @@ void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity)
static void OnYunhornSTSWakeUpScanTimerEvent(void *context) static void OnYunhornSTSWakeUpScanTimerEvent(void *context)
{ {
#if defined(STS_P2)||defined(STS_T6)||defined(L8) #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_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), CFG_SEQ_Prio_0);
UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer);

View File

@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="962004915065611908" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1471382569511667853" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>
@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="962004915065611908" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1471382569511667853" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>

View File

@ -216,6 +216,19 @@ typedef struct sts_r_sensor_data
} sts_r_sensor_data_t; } 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 * @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_Message(uint8_t appDataPort, uint8_t appBufferSize, uint8_t *appDataBuffer);
void STS_SENSOR_Upload_AppData_Message(LmHandlerAppData_t stsAppdata); void STS_SENSOR_Upload_AppData_Message(LmHandlerAppData_t stsAppdata);
void STS_SENSOR_MEMS_Get_ID(uint16_t *devID); 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_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_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 OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity);
void OnYunhornSTSTxPeriodicityChanged(uint32_t periodicity); void OnYunhornSTSTxPeriodicityChanged(uint32_t periodicity);
void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_size); void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_size);

View File

@ -121,7 +121,7 @@ volatile uint8_t sensor_data_ready=0;
#if defined(STS_R1)||defined(STS_R5)||defined(STS_R4)||defined(STS_R1D) #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; 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) #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 #endif
static uint8_t outbuf[128]={0x0}; static uint8_t outbuf[128]={0x0};
@ -445,6 +445,8 @@ void STS_YunhornSTSEventP5_Process(void)
} }
#elif defined(L8) #elif defined(L8)
//STS_TOF_VL53L8X_Process(); //STS_TOF_VL53L8X_Process();
//STS_TOF_L8_Process();
printf("\r\n P5 process \r\n");
MX_TOF_Process(); MX_TOF_Process();
//MX_TOF_Ranging_Process(); //MX_TOF_Ranging_Process();
#endif #endif

View File

@ -34,6 +34,9 @@ extern "C" {
#elif defined(L8) #elif defined(L8)
#include "53l8a1_ranging_sensor.h" #include "53l8a1_ranging_sensor.h"
#include "app_tof_pin_conf.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 #endif
#include "stm32wlxx_nucleo.h" #include "stm32wlxx_nucleo.h"
@ -69,17 +72,38 @@ extern "C" {
#ifdef L8 #ifdef L8
/* for VL53L8A1 */ /* for VL53L8A1 */
#define RANGING_FREQUENCY (10U) /* Ranging frequency Hz (shall be consistent with TimingBudget value) */ #define RANGING_FREQUENCY (10U) /* Ranging frequency Hz (shall be consistent with TimingBudget value) */
#define LOW_THRESHOLD (200U) #define LOW_THRESHOLD (600U)
#define HIGH_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 ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
static RANGING_SENSOR_Capabilities_t Cap; static RANGING_SENSOR_Capabilities_t Cap;
static RANGING_SENSOR_ProfileConfig_t Profile; static RANGING_SENSOR_ProfileConfig_t Profile;
static RANGING_SENSOR_Result_t Result; static RANGING_SENSOR_Result_t Result;
static VL53L8CX_ResultsData L8CXResult; //static VL53L8CX_ResultsData L8CXResult;
static VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ //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_Init(void);
static void MX_53L8A1_ThresholdDetection_Process(void); static void MX_53L8A1_ThresholdDetection_Process(void);
@ -188,6 +212,7 @@ void MX_TOF_Process(void)
//sts_tof_vl53lx_peoplecount_subprocess(); //sts_tof_vl53lx_peoplecount_subprocess();
#ifdef L8 #ifdef L8
//MX_53L8A1_ThresholdDetection_Process(); //MX_53L8A1_ThresholdDetection_Process();
printf("\r\n Tof Process\r\n");
STS_TOF_L8_Process(); STS_TOF_L8_Process();
#endif #endif
@ -198,6 +223,8 @@ void MX_TOF_Process(void)
#ifdef L8 #ifdef L8
void STS_TOF_L8_Process(void) void STS_TOF_L8_Process(void)
{ {
printf("\r\n Tof L8 Process\r\n");
MX_53L8A1_ThresholdDetection_Process();
//while (1) //while (1)
{ {
/* interrupt mode */ /* interrupt mode */
@ -241,7 +268,7 @@ static void MX_53L8A1_ThresholdDetection_Init(void)
printf("VL53L8A1_RANGING_SENSOR_Init failed\n"); printf("VL53L8A1_RANGING_SENSOR_Init failed\n");
//while (1); //while (1);
} }
printf("\r\nVL53L8A1_RANGING_SENSOR_Init Success\r\n");
} }
static void MX_53L8A1_ThresholdDetection_Process(void) static void MX_53L8A1_ThresholdDetection_Process(void)
@ -283,8 +310,8 @@ static void MX_53L8A1_ThresholdDetection_Process(void)
printf("-------------------------------------------\n\r"); printf("-------------------------------------------\n\r");
printf("please put a target between %d and %d millimeters from the sensor\n\r", printf("please put a target between %d and %d millimeters from the sensor\n\r",
LOW_THRESHOLD, HIGH_THRESHOLD); LOW_THRESHOLD, HIGH_THRESHOLD);
#if 1 #if 0
//while (1) while (1)
{ {
/* interrupt mode */ /* interrupt mode */
if (ToF_EventDetected != 0) 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--) for (k = (zones_per_line - 1); k >= 0; k--)
{ {
if (Result->ZoneResult[j + k].NumberOfTargets > 0) if (Result->ZoneResult[j + k].NumberOfTargets > 0)
{ { uint16_t distance_i = (long)Result->ZoneResult[j + k].Distance[l];
if ((distance_i >LOW_THRESHOLD)&&(distance_i <HIGH_THRESHOLD))
for(i = 0; i < 16; i++) printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ", distance_i, (j+k),(long)Result->ZoneResult[j + k].Status[l]);
{ else printf("| %5s : %5s ", " ", " ");
#if 0 }
printf("Zone : %3d, Motion power : %3lu\n", i, Results. else
Results.motion_indicator.motion[motion_config.map_id[i]]); printf("| %5s : %5s ", " ", " ");
#endif }
#if 0 printf("\n");
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");
/* ---- origin /* ---- origin
printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ", printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ",
(long)Result->ZoneResult[j + k].Distance[l],(j+k), (long)Result->ZoneResult[j + k].Distance[l],(j+k),
(long)Result->ZoneResult[j + k].Status[l]); (long)Result->ZoneResult[j + k].Status[l]);
*/ */
int32_t roi_distance =(uint32_t)(Result->ZoneResult[j + k].Distance[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_low = (roi_distance - LOW_THRESHOLD)/10;
int16_t roi_high = (HIGH_THRESHOLD - roi_distance)/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 :%2d%5ld ", ".",(j+k), (uint32_t)Result->ZoneResult[j + k].Status[l]);
printf("| \033[38;5;10m%5s\033[0m : ", "."); printf("| \033[38;5;10m%5s\033[0m : ", ".");
} }
}
else
printf("| %5s : %5s ", ".", ".");
}
printf("|\n");
if ((Profile.EnableAmbient != 0) || (Profile.EnableSignal != 0)) if ((Profile.EnableAmbient != 0) || (Profile.EnableSignal != 0))
{ {
@ -430,7 +462,19 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
#endif #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) uint8_t IsInterruptDetected(uint16_t dev)
{ {
// To be filled with customer HW. This function should // To be filled with customer HW. This function should