]> git.earman.xyz Git - sensor-watch.git/commitdiff
lis2dw: reasonable defaults when initializing
authorJoey Castillo <joeycastillo@utexas.edu>
Sat, 19 Feb 2022 19:03:10 +0000 (14:03 -0500)
committerJoey Castillo <joeycastillo@utexas.edu>
Sat, 19 Feb 2022 19:05:38 +0000 (14:05 -0500)
apps/accelerometer-test/app.c
movement/watch_faces/sensor/accelerometer_data_acquisition_face.c
watch-library/shared/driver/lis2dw.c

index 4a64e355f15fcdf24216ddee0610ea5698bbea70..a52fbbfd71f4ee0183815570a88f16565ce5b642 100644 (file)
@@ -36,10 +36,10 @@ void app_init(void) {
 
     watch_enable_i2c();
     lis2dw_begin();
-    lis2dw_set_low_power_mode(LIS2DW_LP_MODE_2); // lowest power 14-bit mode, 25 Hz is 3.5 µA @ 1.8V w/ low noise, 3µA without
-    lis2dw_set_low_noise_mode(true); // consumes a little more power
-    lis2dw_set_range(LIS2DW_CTRL6_VAL_RANGE_4G);
-    lis2dw_set_data_rate(LIS2DW_DATA_RATE_25_HZ); // is this enough for training?
+    lis2dw_set_data_rate(LIS2DW_DATA_RATE_25_HZ);
+    lis2dw_set_range(LIS2DW_RANGE_4_G);
+    lis2dw_set_low_noise_mode(true);
+    lis2dw_enable_fifo();
 
     lis2dw_enable_fifo();
 
index d965ec2e5c0fecf348f1785d7e713a7d402b45b5..ea50ad270517e0a1ffc51a33754803e61806602f 100644 (file)
@@ -28,6 +28,7 @@
 
 static const char activity_types[][3] = {
     "ID",   // Idle
+    "OF",   // Off-wrist
     "SL",   // Sleeping
     "WH",   // Washing Hands
     "WA",   // Walking
@@ -281,7 +282,13 @@ static void advance_current_setting(accelerometer_data_acquisition_state_t *stat
 
 static void start_reading(accelerometer_data_acquisition_state_t *state) {
     (void) state;
-    printf("TODO: Activate I2C bus and turn on accelerometer\n");
+    watch_enable_i2c();
+    lis2dw_begin();
+    lis2dw_set_data_rate(LIS2DW_DATA_RATE_25_HZ);
+    lis2dw_set_range(LIS2DW_RANGE_4_G);
+    lis2dw_set_low_noise_mode(true);
+    lis2dw_enable_fifo();
+
     printf("TODO: Write header\n");
 }
 
@@ -301,5 +308,6 @@ static void finish_reading(accelerometer_data_acquisition_state_t *state) {
         state->next_available_page++;
         state->pos = 0;
     }
-    printf("TODO: Turn off accelerometer and disable I2C bus\n");
+    lis2dw_set_data_rate(LIS2DW_DATA_RATE_POWERDOWN);
+    watch_disable_i2c();
 }
index f273fab34c4d1d0f4475a01a01efa99a397152de..0b788fcae5aa191f1dc865d66bdda42769e0394e 100644 (file)
@@ -31,12 +31,8 @@ bool lis2dw_begin(void) {
     }
     watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL2, LIS2DW_CTRL2_VAL_BOOT);
     watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL2, LIS2DW_CTRL2_VAL_SOFT_RESET);
-    // Start at lowest possible data rate and lowest possible power mode
-    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1, LIS2DW_CTRL1_VAL_ODR_LOWEST | LIS2DW_CTRL1_VAL_MODE_LOW_POWER | LIS2DW_CTRL1_VAL_LPMODE_1);
     // Enable block data update (output registers not updated until MSB and LSB have been read) and address autoincrement
     watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL2, LIS2DW_CTRL2_VAL_BDU | LIS2DW_CTRL2_VAL_IF_ADD_INC);
-    // Set range to ±2G
-    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6, LIS2DW_CTRL6_VAL_RANGE_2G);
 
     return true;
 }