diff --git a/movement.c b/movement.c index adda773b..33eb231f 100644 --- a/movement.c +++ b/movement.c @@ -567,6 +567,24 @@ bool movement_set_accelerometer_background_rate(lis2dw_data_rate_t new_rate) { return false; } +uint8_t movement_get_accelerometer_motion_threshold(void) { + if (movement_state.has_lis2dw) return movement_state.accelerometer_motion_threshold; + else return 0; +} + +bool movement_set_accelerometer_motion_threshold(uint8_t new_threshold) { + if (movement_state.has_lis2dw) { + if (movement_state.accelerometer_motion_threshold != new_threshold) { + lis2dw_configure_wakeup_threshold(new_threshold); + movement_state.accelerometer_motion_threshold = new_threshold; + + return true; + } + } + + return false; +} + float movement_get_temperature(void) { float temperature_c = (float)0xFFFFFFFF; @@ -660,6 +678,7 @@ void app_init(void) { watch_rtc_set_date_time(date_time); } + if (movement_state.accelerometer_motion_threshold == 0) movement_state.accelerometer_motion_threshold = 32; movement_state.light_ticks = -1; movement_state.alarm_ticks = -1; @@ -738,7 +757,7 @@ void app_setup(void) { lis2dw_enable_stationary_motion_detection(); // stationary/motion detection mode keeps the data rate at 1.6 Hz even in sleep lis2dw_set_range(LIS2DW_RANGE_2_G); // Application note AN5038 recommends 2g range lis2dw_enable_sleep(); // allow acceleromter to sleep and wake on activity - lis2dw_configure_wakeup_threshold(32); // g threshold to wake up: (THS * FS / 64) where FS is "full scale" of ±2g. + lis2dw_configure_wakeup_threshold(movement_state.accelerometer_motion_threshold); // g threshold to wake up: (THS * FS / 64) where FS is "full scale" of ±2g. lis2dw_configure_6d_threshold(3); // 0-3 is 80, 70, 60, or 50 degrees. 50 is least precise, hopefully most sensitive? // set up interrupts: diff --git a/movement.h b/movement.h index dbee3830..56f67a49 100644 --- a/movement.h +++ b/movement.h @@ -294,6 +294,8 @@ typedef struct { bool has_lis2dw; // data rate for background accelerometer sensing lis2dw_data_rate_t accelerometer_background_rate; + // threshold for considering the wearer is in motion + uint8_t accelerometer_motion_threshold; } movement_state_t; void movement_move_to_face(uint8_t watch_face_index); @@ -380,6 +382,10 @@ bool movement_disable_tap_detection_if_available(void); lis2dw_data_rate_t movement_get_accelerometer_background_rate(void); bool movement_set_accelerometer_background_rate(lis2dw_data_rate_t new_rate); +// gets and sets the accelerometer motion threshold +uint8_t movement_get_accelerometer_motion_threshold(void); +bool movement_set_accelerometer_motion_threshold(uint8_t new_threshold); + // If the board has a temperature sensor, this function will give you the temperature in degrees celsius. // If the board has multiple temperature sensors, it will use the most accurate one available. // If the board has no temperature sensors, it will return 0xFFFFFFFF. diff --git a/watch-faces/sensor/accelerometer_status_face.c b/watch-faces/sensor/accelerometer_status_face.c index 8aa07361..0dbbfdcb 100644 --- a/watch-faces/sensor/accelerometer_status_face.c +++ b/watch-faces/sensor/accelerometer_status_face.c @@ -61,7 +61,7 @@ void accelerometer_status_face_activate(void *context) { movement_request_tick_frequency(4); // fetch current threshold from accelerometer - state->threshold = lis2dw_get_wakeup_threshold(); + state->threshold = movement_get_accelerometer_motion_threshold(); } bool accelerometer_status_face_loop(movement_event_t event, void *context) { @@ -87,7 +87,7 @@ bool accelerometer_status_face_loop(movement_event_t event, void *context) { } break; case EVENT_ALARM_BUTTON_UP: - lis2dw_configure_wakeup_threshold(state->new_threshold); + movement_set_accelerometer_motion_threshold(state->new_threshold); state->threshold = state->new_threshold; watch_clear_decimal_if_available(); state->is_setting = false;