Commit 451545fc authored by aohui.li's avatar aohui.li

增加阈值mg转lsb函数

parent 3836be1c
......@@ -175,19 +175,41 @@ void lis2dw12_init()
// }
}
int lis2dw12_trans_mg2lsb(lis2dw12_fs_t fs, float mg)
{
if(fs == LIS2DW12_2g)
{
return mg / 1000.0 / ((2 * 2) / 64.0);
}
else if(fs == LIS2DW12_4g)
{
return mg * 4096 / 4;
}
else if(fs == LIS2DW12_8g)
{
return mg * 4096 / 8;
}
else
{
return mg * 4096 / 16;
}
lis2dw12_full_scale_set(&dev_ctx, fs);
}
static void lis2dw12_wake_config(void)
{
lis2dw12_reg_t int_route;
lis2dw12_fs_t fs;
lis2dw12_fs_t fs = LIS2DW12_2g, fs_get;
int val = 0;
/* Set full scale */
lis2dw12_full_scale_set(&dev_ctx, LIS2DW12_16g);
lis2dw12_full_scale_get(&dev_ctx, &fs);
ESP_LOGI(TAG, "LIS2DW12 full scale: %d", fs);
lis2dw12_full_scale_set(&dev_ctx, fs);
lis2dw12_full_scale_get(&dev_ctx, &fs_get);
ESP_LOGI(TAG, "LIS2DW12 full scale: %d", fs_get);
/* Configure power mode */
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_200Hz);
lis2dw12_data_rate_set(&dev_ctx, LIS2DW12_XL_ODR_1Hz6_LP_ONLY);
/* 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
......@@ -199,7 +221,9 @@ static void lis2dw12_wake_config(void)
/* Set wake-up threshold
* Set Wake-Up threshold: 1 LSb corresponds to FS_XL/2^6
*/
lis2dw12_wkup_threshold_set(&dev_ctx, 1);
val = lis2dw12_trans_mg2lsb(fs_get, 1000);
ESP_LOGI(TAG, "LIS2DW12 wakeup threshold: %d LSB", val);
lis2dw12_wkup_threshold_set(&dev_ctx, val);
/* Enable interrupt generation on Wake-Up INT1 pin */
lis2dw12_pin_int1_route_get(&dev_ctx, &int_route.ctrl4_int1_pad_ctrl);
int_route.ctrl4_int1_pad_ctrl.int1_wu = PROPERTY_ENABLE;
......
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