Commit 2e4cd5d8 authored by aohui.li's avatar aohui.li

增加持续时间转为lsb函数

parent 451545fc
......@@ -196,10 +196,31 @@ int lis2dw12_trans_mg2lsb(lis2dw12_fs_t fs, float mg)
lis2dw12_full_scale_set(&dev_ctx, fs);
}
int lis2dw12_trans_duration2lsb(lis2dw12_odr_t odr, uint16_t continuous_ms)
{
uint16_t val = 0;
if(continuous_ms == 0)
{
return 0;
}
if(odr == LIS2DW12_XL_ODR_1Hz6_LP_ONLY)
{
val = (int)(continuous_ms / 1000.0 / (1.0/1.6));
}
else if(odr == LIS2DW12_XL_ODR_200Hz)
{
val = (int)(continuous_ms / 1000.0 / (1.0/200));
}
return val;
}
static void lis2dw12_wake_config(void)
{
lis2dw12_reg_t int_route;
lis2dw12_fs_t fs = LIS2DW12_2g, fs_get;
lis2dw12_odr_t odr = LIS2DW12_XL_ODR_200Hz;
int val = 0;
/* Set full scale */
lis2dw12_full_scale_set(&dev_ctx, fs);
......@@ -209,7 +230,7 @@ static void lis2dw12_wake_config(void)
lis2dw12_power_mode_set(&dev_ctx,
LIS2DW12_CONT_LOW_PWR_LOW_NOISE_12bit);
/* Set Output Data Rate */
lis2dw12_data_rate_set(&dev_ctx, LIS2DW12_XL_ODR_1Hz6_LP_ONLY);
lis2dw12_data_rate_set(&dev_ctx, odr);
/* Apply high-pass digital filter on Wake-Up function */
lis2dw12_filter_path_set(&dev_ctx, LIS2DW12_HIGH_PASS_ON_OUT);
/* Apply high-pass digital filter on Wake-Up function
......@@ -217,11 +238,13 @@ static void lis2dw12_wake_config(void)
* is generated for each X,Y,Z filtered data exceeding the
* configured threshold
*/
lis2dw12_wkup_dur_set(&dev_ctx, 0);
val = lis2dw12_trans_duration2lsb(odr, 2000);
ESP_LOGI(TAG, "LIS2DW12 wakeup duration: %d LSB", val);
lis2dw12_wkup_dur_set(&dev_ctx, val);
/* Set wake-up threshold
* Set Wake-Up threshold: 1 LSb corresponds to FS_XL/2^6
*/
val = lis2dw12_trans_mg2lsb(fs_get, 1000);
val = lis2dw12_trans_mg2lsb(fs_get, 800);
ESP_LOGI(TAG, "LIS2DW12 wakeup threshold: %d LSB", val);
lis2dw12_wkup_threshold_set(&dev_ctx, val);
/* Enable interrupt generation on Wake-Up INT1 pin */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment