Skip to content

Commit

Permalink
re-report CSC measurement once when standing still
Browse files Browse the repository at this point in the history
  • Loading branch information
dakhnod committed Aug 20, 2024
1 parent 2dfbc5a commit 681da3d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ble/services/cycling_speed_cadence/ble_cycling_speed_cadence.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include "nrf_log.h"
#include "feature_config.h"

// a CSC measurement that is unchanged (bike standing still) will be re-reported this amount of times
#define STANDSTILL_REPORT_COUNT_LIMIT 1

uint16_t ble_csc_connection_handle = BLE_CONN_HANDLE_INVALID;

uint16_t ble_csc_service_handle = BLE_GATT_HANDLE_INVALID;
Expand All @@ -18,6 +21,7 @@ uint16_t ble_csc_measurement_cccd_handle = BLE_GATT_HANDLE_INVALID;
uint32_t last_revolution_count = 0;
uint32_t last_reported_revolution_count = 0xFFFFFFFF;
uint16_t last_revolution_time = 0;
uint8_t standstill_report_count = 0xFF;

APP_TIMER_DEF(measurement_report_timer);

Expand Down Expand Up @@ -70,11 +74,14 @@ void ble_csc_measurement_report(){
void measurement_timer_timeout_handler(void *context){
// no change in revolution count, no report needed
if(last_revolution_count == last_reported_revolution_count){
return;
if(standstill_report_count >= STANDSTILL_REPORT_COUNT_LIMIT){
return;
}
standstill_report_count++;
}

ble_csc_measurement_report();
last_reported_revolution_count = last_revolution_count;
ble_csc_measurement_report();
}

void ble_csc_timer_init(){
Expand Down Expand Up @@ -233,6 +240,7 @@ void ble_csc_on_ble_evt(ble_evt_t *p_ble_evt)

void ble_csc_handle_sensor_trigger(uint32_t trigger_count){
last_revolution_count = trigger_count;
standstill_report_count = 0;
last_revolution_time = get_time_units();
}

Expand Down

0 comments on commit 681da3d

Please sign in to comment.