]> git.earman.xyz Git - sensor-watch.git/commitdiff
implement INT2, accelerometer test shows sleep state on LED
authorjoeycastillo <joeycastillo@utexas.edu>
Wed, 9 Oct 2024 06:05:12 +0000 (02:05 -0400)
committerjoeycastillo <joeycastillo@utexas.edu>
Wed, 9 Oct 2024 06:05:12 +0000 (02:05 -0400)
watch-faces/demo/accel_interrupt_count_face.c
watch-library/shared/driver/lis2dw.c
watch-library/shared/driver/lis2dw.h

index 9628418116843dae17aae83a3d27aff2657bc6b2..420980cf82882fde856039f2d73296f961a46f97 100644 (file)
@@ -36,6 +36,15 @@ void accel_interrupt_handler(void) {
     (*ptr_to_count)++;
 }
 
+void sleep_interrupt_handler(void);
+void sleep_interrupt_handler(void) {
+    if (HAL_GPIO_A3_read()) {
+        movement_force_led_on(255, 0, 0);
+    } else {
+        movement_force_led_on(0, 255, 0);
+    }
+}
+
 static void _accel_interrupt_count_face_update_display(accel_interrupt_count_state_t *state) {
     char buf[7];
 
@@ -56,7 +65,8 @@ static void _accel_interrupt_count_face_update_display(accel_interrupt_count_sta
 static void _accel_interrupt_count_face_configure_threshold(uint8_t threshold) {
     lis2dw_enable_sleep();
     lis2dw_configure_wakeup_threshold(threshold);
-    lis2dw_configure_int1(LIS2DW_CTRL4_INT1_WU);
+    // lis2dw_configure_int1(LIS2DW_CTRL4_INT1_WU);
+    lis2dw_configure_int2(LIS2DW_CTRL5_INT2_SLEEP_CHG);
     lis2dw_enable_interrupts();
 }
 
@@ -92,6 +102,7 @@ void accel_interrupt_count_face_activate(void *context) {
 
     state->running = true;
     watch_register_interrupt_callback(HAL_GPIO_A4_pin(), accel_interrupt_handler, INTERRUPT_TRIGGER_RISING);
+    watch_register_interrupt_callback(HAL_GPIO_A3_pin(), sleep_interrupt_handler, INTERRUPT_TRIGGER_BOTH);
 }
 
 bool accel_interrupt_count_face_loop(movement_event_t event, void *context) {
index 7dbe8a4f570e1123ae8865b8d377dd957660ebd1..c5b45793534af66b9a9d9e01f5a0e3a89b222152 100644 (file)
@@ -237,6 +237,10 @@ void lis2dw_configure_int1(uint8_t sources) {
     watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL4_INT1, sources);
 }
 
+void lis2dw_configure_int2(uint8_t sources) {
+    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL5_INT2, sources);
+}
+
 void lis2dw_enable_interrupts(void) {
     uint8_t configuration = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL7);
     watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL7, configuration | LIS2DW_CTRL7_VAL_INTERRUPTS_ENABLE);
index d6379c07e830a9c85ea14f2971691e88a7d64e4a..e80236de774d56a530c20c2b204571410d194afa 100644 (file)
@@ -347,6 +347,8 @@ void lis2dw_configure_wakeup_threshold(uint8_t threshold);
 
 void lis2dw_configure_int1(uint8_t sources);
 
+void lis2dw_configure_int2(uint8_t sources);
+
 void lis2dw_enable_interrupts(void);
 
 void lis2dw_disable_interrupts(void);