diff --git a/movement.c b/movement.c index 15f74edd..fd8fa140 100644 --- a/movement.c +++ b/movement.c @@ -521,9 +521,6 @@ void movement_set_alarm_enabled(bool value) { void movement_enable_tap_detection_if_available(void) { #ifdef HAS_ACCELEROMETER - // disable event on INT1/A3 (normally tracks orientation changes) - eic_disable_event(HAL_GPIO_A3_pin()); - // configure tap duration threshold and enable Z axis lis2dw_configure_tap_threshold(0, 0, 12, LIS2DW_REG_TAP_THS_Z_Z_AXIS_ENABLE); lis2dw_configure_tap_duration(10, 2, 2); @@ -553,10 +550,6 @@ void movement_disable_tap_detection_if_available(void) { eic_disable_interrupt(HAL_GPIO_A3_pin()); // ...disable Z axis (not sure if this is needed, does this save power?)... lis2dw_configure_tap_threshold(0, 0, 0, 0); - // ...re-enable tracking of orientation changes... - lis2dw_configure_int1(LIS2DW_CTRL4_INT1_6D); - // ...and re-enable the event. - eic_enable_event(HAL_GPIO_A3_pin()); #endif } @@ -716,31 +709,11 @@ void app_setup(void) { // set up interrupts: // INT1 is wired to pin A3. We'll configure the accelerometer to output an interrupt on INT1 when it detects an orientation change. - lis2dw_configure_int1(LIS2DW_CTRL4_INT1_6D); - HAL_GPIO_A3_in(); - HAL_GPIO_A3_pmuxen(HAL_GPIO_PMUX_EIC); - eic_configure_pin(HAL_GPIO_A3_pin(), INTERRUPT_TRIGGER_RISING, false); - // but rather than hooking it up to an interrupt callback, we'll have it trigger an event. - eic_enable_event(HAL_GPIO_A3_pin()); - - // that event will increment a counter on TC2. So let's set that up: - if (!tc_is_enabled(2)) { - // TC2 clocked from GCLK3, the 1024 Hz clock. No further division. - tc_init(2, GENERIC_CLOCK_3, TC_PRESCALER_DIV1); - } - // COUNT16 mode, count up to 65535 orientation changes (we will reset before it overflows) - tc_set_counter_mode(2, TC_COUNTER_MODE_16BIT); - // run in standby (we spend most of our time in standby) - tc_set_run_in_standby(2, true); - // finally set the event action to count up when an event is received. - tc_set_event_action(2, TC_EVENT_ACTION_COUNT); - // enable TC2! - tc_enable(2); - - // now configure the event system: - // on channel 0, route the INT3 event generator to the TC2 event user. Run in standby, on the asynchronous path. - evsys_configure_channel(0, EVSYS_ID_GEN_EIC_EXTINT_3, EVSYS_ID_USER_TC2_EVU, true, true); - // this concludes the setup for orientation tracking. + /// TODO: We had routed this interrupt to TC2 to count orientation changes, but TC2 consumed too much power. + /// Orientation changes helped with sleep tracking; would love to bring this back if we can find a low power solution. + /// For now, commenting these lines out; check commit 27f0c629d865f4bc56bc6e678da1eb8f4b919093 for power-hungry but working code. + // lis2dw_configure_int1(LIS2DW_CTRL4_INT1_6D); + // HAL_GPIO_A3_in(); // next: INT2 is wired to pin A4. We'll configure the accelerometer to output the sleep state on INT2. // a falling edge on INT2 indicates the accelerometer has woken up. diff --git a/movement_activity.c b/movement_activity.c index 0b08c158..f5c20ec7 100644 --- a/movement_activity.c +++ b/movement_activity.c @@ -45,10 +45,12 @@ void _movement_log_data(void) { // Movement tracks active minutes when deciding whether to sleep. data_point.bit.active_minutes = active_minutes; - // orientation changes are counted in TC2. stash them in the data point... - data_point.bit.orientation_changes = tc_count16_get_count(2); - // ...and then reset the number of orientation changes. - tc_count16_set_count(2, 0); + if (tc_is_enabled(2)) { + // orientation changes are counted in TC2. stash them in the data point... + data_point.bit.orientation_changes = tc_count16_get_count(2); + // ...and then reset the number of orientation changes. + tc_count16_set_count(2, 0); + } // log the temperature thermistor_driver_enable(); diff --git a/watch-faces/demo/accel_interrupt_count_face.c b/watch-faces/demo/accel_interrupt_count_face.c index c357191a..32b99255 100644 --- a/watch-faces/demo/accel_interrupt_count_face.c +++ b/watch-faces/demo/accel_interrupt_count_face.c @@ -47,7 +47,8 @@ static void _accel_interrupt_count_face_update_display(accel_interrupt_count_sta else watch_display_text(WATCH_POSITION_TOP_RIGHT, " A"); // Orientation changes / active minutes - uint16_t orientation_changes = tc_count16_get_count(2); + uint16_t orientation_changes = 0; + if (tc_is_enabled(2)) orientation_changes = tc_count16_get_count(2); sprintf(buf, "%-3u/%2d", orientation_changes > 999 ? 999 : orientation_changes, active_minutes); watch_display_text(WATCH_POSITION_BOTTOM, buf); } diff --git a/watch-faces/sensor/activity_logging_face.h b/watch-faces/sensor/activity_logging_face.h index 8cf62f1d..0a0e3726 100644 --- a/watch-faces/sensor/activity_logging_face.h +++ b/watch-faces/sensor/activity_logging_face.h @@ -37,7 +37,7 @@ * Default behavior is to show the last 100 data points. Format is: * - Top left is display title (LOG or AC for Activity) * - Top right is index backwards in the data log. - * - Bottom left is the number of orientation changes in the five minutes logged. + * - Bottom left is the number of orientation changes in the five minutes logged. (currently non-functional) * - Bottom right is number of stationary minutes (0 to 5) * * A short press of the Light button reveals the time (bottom row) and date (top right) of the data point.