-
- All Implemented Interfaces:
-
android.os.Parcelable,no.nordicsemi.android.ble.callback.DataReceivedCallback,no.nordicsemi.android.ble.callback.profile.ProfileDataCallback,no.nordicsemi.android.ble.common.profile.csc.CyclingSpeedAndCadenceCallback,no.nordicsemi.android.ble.common.profile.csc.CyclingSpeedAndCadenceMeasurementCallback
public final class CyclingSpeedAndCadenceMeasurementResponse extends CyclingSpeedAndCadenceMeasurementDataCallback implements Parcelable
Response class that could be used as a result of a synchronous request. The data received are available through getters, instead of a callback.
Usage example:
try { CyclingSpeedAndCadenceResponse response = waitForNotification(characteristic) .awaitValid(CyclingSpeedAndCadenceResponse.class); float totalDistance = response.getTotalDistance(2340.0f); ... } catch (RequestFailedException e) { Log.w(TAG, "Request failed with status " + e.getStatus(), e); } catch (InvalidDataException e) { Log.w(TAG, "Invalid data received: " + e.getResponse().getRawData()); }
-
-
Field Summary
Fields Modifier and Type Field Description private longwheelRevolutionsprivate longcrankRevolutionspublic final static Parcelable.Creator<CyclingSpeedAndCadenceMeasurementResponse>CREATOR
-
Constructor Summary
Constructors Constructor Description CyclingSpeedAndCadenceMeasurementResponse()
-
Method Summary
Modifier and Type Method Description longgetWheelRevolutions()longgetCrankRevolutions()voidonWheelMeasurementReceived(@NonNull() BluetoothDevice device, long wheelRevolutions, int lastWheelEventTime)Method called when the data received had wheel revolution data present. voidonCrankMeasurementReceived(@NonNull() BluetoothDevice device, int crankRevolutions, int lastCrankEventTime)Method called when the data received had crank revolution data present. voidonDistanceChanged(@NonNull() BluetoothDevice device, float totalDistance, float distance, float speed)Callback called when the traveled distance and speed has changed. voidonCrankDataChanged(@NonNull() BluetoothDevice device, float crankCadence, float gearRatio)Callback called when the crank data (cadence or gear ratio) has changed. floatgetTotalDistance(float wheelCircumference)Returns the total distance since the device was reset. floatgetDistance(float wheelCircumference, CyclingSpeedAndCadenceMeasurementResponse previous)Returns the distance traveled since the given response was received. floatgetSpeed(float wheelCircumference, CyclingSpeedAndCadenceMeasurementResponse previous)Returns the average speed since the previous response was received. floatgetWheelCadence(CyclingSpeedAndCadenceMeasurementResponse previous)Returns average wheel cadence since the previous message was received. floatgetCrankCadence(CyclingSpeedAndCadenceMeasurementResponse previous)Returns average crank cadence since the previous message was received. floatgetGearRatio(CyclingSpeedAndCadenceMeasurementResponse previous)Returns the gear ratio (equal to wheel cadence / crank cadence). voidwriteToParcel(@NonNull() Parcel dest, int flags)-
Methods inherited from class no.nordicsemi.android.ble.common.callback.csc.CyclingSpeedAndCadenceMeasurementDataCallback
onDataReceived -
Methods inherited from class no.nordicsemi.android.ble.callback.profile.ProfileReadResponse
isValid, onInvalidDataReceived, writeToParcel -
Methods inherited from class no.nordicsemi.android.ble.response.ReadResponse
describeContents, getBluetoothDevice, getRawData, onDataReceived -
Methods inherited from class no.nordicsemi.android.ble.common.profile.csc.CyclingSpeedAndCadenceMeasurementCallback
onCrankMeasurementReceived, onWheelMeasurementReceived -
Methods inherited from class no.nordicsemi.android.ble.common.profile.csc.CyclingSpeedAndCadenceCallback
getWheelCircumference, onCrankDataChanged, onDistanceChanged -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
getWheelRevolutions
long getWheelRevolutions()
-
getCrankRevolutions
long getCrankRevolutions()
-
onWheelMeasurementReceived
void onWheelMeasurementReceived(@NonNull() BluetoothDevice device, long wheelRevolutions, int lastWheelEventTime)
Method called when the data received had wheel revolution data present.The default implementation calculates the total distance, distance since connection andcurrent speed and calls onDistanceChanged.
- Parameters:
device- the target device.wheelRevolutions- cumulative wheel revolutions since the CSC device was reset (UINT32).lastWheelEventTime- the last wheel event time in 1/1024 s (UINT16).
-
onCrankMeasurementReceived
void onCrankMeasurementReceived(@NonNull() BluetoothDevice device, int crankRevolutions, int lastCrankEventTime)
Method called when the data received had crank revolution data present.The default implementation calculates the crank cadence and gear ratio andcalls onCrankDataChanged
- Parameters:
device- the target device.crankRevolutions- cumulative crank revolutions since the CSC device was reset (UINT16).lastCrankEventTime- the last crank event time in 1/1024 s (UINT16).
-
onDistanceChanged
void onDistanceChanged(@NonNull() BluetoothDevice device, float totalDistance, float distance, float speed)
Callback called when the traveled distance and speed has changed.The distance and speed calculations are based on the wheel circumference obtainedwith getWheelCircumference. Make sure it returns the correct value.
- Parameters:
device- the target device.totalDistance- the total distance traveled since the measuring device was reset, in meters.distance- the distance traveled since the phone connected to the CSC device, in meters.speed- current speed, in meters per second.
-
onCrankDataChanged
void onCrankDataChanged(@NonNull() BluetoothDevice device, float crankCadence, float gearRatio)
Callback called when the crank data (cadence or gear ratio) has changed.
- Parameters:
device- the target device.crankCadence- new crank cadence, in revolutions per minute.gearRatio- new gear ratio.
-
getTotalDistance
float getTotalDistance(float wheelCircumference)
Returns the total distance since the device was reset.
- Parameters:
wheelCircumference- the wheel circumference in millimeters.
-
getDistance
float getDistance(float wheelCircumference, CyclingSpeedAndCadenceMeasurementResponse previous)
Returns the distance traveled since the given response was received.
- Parameters:
wheelCircumference- the wheel circumference in millimeters.previous- a previous response.
-
getSpeed
float getSpeed(float wheelCircumference, CyclingSpeedAndCadenceMeasurementResponse previous)
Returns the average speed since the previous response was received.
- Parameters:
wheelCircumference- the wheel circumference in millimeters.previous- a previous response.
-
getWheelCadence
float getWheelCadence(CyclingSpeedAndCadenceMeasurementResponse previous)
Returns average wheel cadence since the previous message was received.
- Parameters:
previous- a previous response.
-
getCrankCadence
float getCrankCadence(CyclingSpeedAndCadenceMeasurementResponse previous)
Returns average crank cadence since the previous message was received.
- Parameters:
previous- a previous response.
-
getGearRatio
float getGearRatio(CyclingSpeedAndCadenceMeasurementResponse previous)
Returns the gear ratio (equal to wheel cadence / crank cadence).
- Parameters:
previous- a previous response.
-
writeToParcel
void writeToParcel(@NonNull() Parcel dest, int flags)
-
-
-
-