tuya_ble_sdk_demo/components/inv_mpu_driver/tuya_gesture_rec.c
/**
 * @brief calculate the sum of the absolute value of the acceleration difference
 * @param[in] accel_cur: current acceleration
 * @return the calculation result
 */
@brief calculate the sum of the absolute value of the acceleration difference
@param[in] accel_cur: current acceleration
@return the calculation result
@brief calculate the sum of the absolute value of the acceleration difference @param [ in ] accel_cur : current acceleration @return the calculation result
FLOAT_T __calc_accel_diff_abs_sum(FLOAT_T *accel_cur)
{
    UCHAR_T i;
    FLOAT_T diff = 0.0f;
    FLOAT_T diff_sum = 0.0f;
    FLOAT_T ret = 0.0f;
    for (i = 0; i < ACCEL_AXIS_NUM; i++)
    {
        diff = accel_cur[i] - accel_last[i];
        diff_sum += ((diff > 0) ? diff : (-diff));
        accel_last[i] = accel_cur[i];
    }
    for (i = 0; i < DATA_SMP_NUM - 1; i++)
    {
        sg_accel_diff_sum[i] = sg_accel_diff_sum[i + 1];
        ret += sg_accel_diff_sum[i];
    }
    sg_accel_diff_sum[DATA_SMP_NUM - 1] = diff_sum;
    ret = (ret + sg_accel_diff_sum[DATA_SMP_NUM - 1]) / DATA_SMP_NUM;
    return ret;
}
FLOAT_T __calc_accel_diff_abs_sum ( FLOAT_T * accel_cur ) { UCHAR_T i ; FLOAT_T diff = 0.0f ; FLOAT_T diff_sum = 0.0f ; FLOAT_T ret = 0.0f ; for ( i = 0 ; i < ACCEL_AXIS_NUM ; i ++ ) { diff = accel_cur [ i ] - accel_last [ i ] ; diff_sum += ( ( diff > 0 ) ? diff : ( - diff ) ) ; accel_last [ i ] = accel_cur [ i ] ; } for ( i = 0 ; i < DATA_SMP_NUM - 1 ; i ++ ) { sg_accel_diff_sum [ i ] = sg_accel_diff_sum [ i + 1 ] ; ret += sg_accel_diff_sum [ i ] ; } sg_accel_diff_sum [ DATA_SMP_NUM - 1 ] = diff_sum ; ret = ( ret + sg_accel_diff_sum [ DATA_SMP_NUM - 1 ] ) / DATA_SMP_NUM ; return ret ; }
@brief calculate the sum of the absolute value of the acceleration difference
 @param[in] accel_cur: current acceleration
 @return the calculation result
@brief calculate the sum of the absolute value of the acceleration difference @param [ in ] accel_cur : current acceleration @return the calculation result