跌倒报警算法修改
authorp15692025051 <846603105@qq.com>
Fri, 22 Dec 2023 07:36:21 +0000 (15:36 +0800)
committerp15692025051 <846603105@qq.com>
Fri, 22 Dec 2023 07:36:21 +0000 (15:36 +0800)
2.sdk/sdk/gui/lv_drivers/indev/my_xMotion.c

index 7d7e322..a736411 100644 (file)
@@ -298,6 +298,47 @@ short Gsensor_x[32];
 short Gsensor_y[32];
 short Gsensor_z[32];
 int Gsensor_xyz_len = 0;
+#define  FALL_DETECH_LOW_THRESHOLD 45
+#define FALL_COUNTER_THRESHOLD 5
+typedef struct
+{
+    float x;
+    float y;
+    float z;
+}acc_g_data_t;
+static uint16_t fall_counter = 0;
+uint8_t gsensor_sc7a20_fall_detect(acc_g_data_t * acc)
+{
+    double acc_square = (double)((acc->x) * (acc->x)) + (double)((acc->y) * (acc->y)) + (double)((acc->z) * (acc->z));
+
+    // if(MMIApi_IsOpenGsensorTestWin())
+    // {
+    //   memcpy(&s_sc7a20_test_info, acc, sizeof(acc_g_data_t));
+    // }
+
+    if(acc_square < FALL_DETECH_LOW_THRESHOLD )
+       {
+        fall_counter++;
+    }
+       else
+       {
+        fall_counter = 0;
+    }
+
+    if(fall_counter >= FALL_COUNTER_THRESHOLD)
+       {
+        fall_counter = 0;
+
+        // #if defined(GPS_CHIP_AT6558R_DEBUG) && !defined(ZMAEE_APP)
+        // // if(get_motion_status() == 1)//有运动才发跌倒报警
+               // //     _Gps_SendMessagetoClient(GPS_SOCKET_FALL_DOWN, 0);
+               // #endif
+               
+        return 1; 
+    }
+
+    return 0;
+}
 #if USE_HX3918
 extern void hx3918_set_gsen_fifo(short *x,short *y,short *z, int count);
 #endif
@@ -305,6 +346,7 @@ static void My_Motion_Main(VOID * argv)
 {
     uint16_t MsgId;
     lv_driver_msg_xmotion_t * pOsMsg;
+    acc_g_data_t s_acc = {0};
 #if XMOTION_TIMER_DEBUG
     UINT32 T1, T2;
 #endif
@@ -338,6 +380,14 @@ static void My_Motion_Main(VOID * argv)
             gpio_enable_edge_detect(my_xm_info.irq_pin, EDGE_FLAG_FALL);
 #endif
             Gsensor_xyz_len = xMotion_FIFO_Read_XYZ(Gsensor_x,Gsensor_y,Gsensor_z);
+            for(int i = 0;i< Gsensor_xyz_len;i++)
+            {
+                s_acc.x= Gsensor_x[i];
+                s_acc.y= Gsensor_y[i];
+                s_acc.z= Gsensor_z[i];
+                if(gsensor_sc7a20_fall_detect(&s_acc) == 1)//跌倒报警
+                                   mmi_gsensor_sensor_fall_alarm();    
+            }
 #if USE_HX3918
             hx3918_set_gsen_fifo(Gsensor_x,Gsensor_y,Gsensor_z,Gsensor_xyz_len);
 #endif