| 1 |
package com.ridelogger.listners; |
| 2 |
|
| 3 |
import com.dsi.ant.plugins.antplus.pcc.AntPlusHeartRatePcc; |
| 4 |
import com.dsi.ant.plugins.antplus.pcc.AntPlusHeartRatePcc.DataState; |
| 5 |
import com.dsi.ant.plugins.antplus.pcc.AntPlusHeartRatePcc.IHeartRateDataReceiver; |
| 6 |
import com.dsi.ant.plugins.antplus.pcc.defines.DeviceState; |
| 7 |
import com.dsi.ant.plugins.antplus.pcc.defines.EventFlag; |
| 8 |
import com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult; |
| 9 |
import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc.IPluginAccessResultReceiver; |
| 10 |
import com.ridelogger.RideService; |
| 11 |
import java.math.BigDecimal; |
| 12 |
import java.util.EnumSet; |
| 13 |
|
| 14 |
/** |
| 15 |
* HeartRate |
| 16 |
* @author Chet Henry |
| 17 |
* Listen to and log Ant+ HearRate events |
| 18 |
*/ |
| 19 |
public class HeartRate extends Ant |
| 20 |
{ |
| 21 |
public IPluginAccessResultReceiver<AntPlusHeartRatePcc> mResultReceiver; |
| 22 |
|
| 23 |
public HeartRate(int pDeviceNumber, RideService mContext) { |
| 24 |
super(pDeviceNumber, mContext); |
| 25 |
|
| 26 |
mResultReceiver = new IPluginAccessResultReceiver<AntPlusHeartRatePcc>() { |
| 27 |
//Handle the result, connecting to events on success or reporting failure to user. |
| 28 |
@Override |
| 29 |
public void onResultReceived(AntPlusHeartRatePcc result, RequestAccessResult resultCode, DeviceState initialDeviceState) |
| 30 |
{ |
| 31 |
if(resultCode == com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult.SUCCESS) { |
| 32 |
deviceNumber = result.getAntDeviceNumber(); |
| 33 |
result.subscribeHeartRateDataEvent( |
| 34 |
new IHeartRateDataReceiver() { |
| 35 |
@Override |
| 36 |
public void onNewHeartRateData(final long estTimestamp, EnumSet<EventFlag> eventFlags, final int computedHeartRate, final long heartBeatCount, final BigDecimal heartBeatEventTime, final DataState dataState) { |
| 37 |
alterCurrentData(RideService.HR, (float) computedHeartRate); |
| 38 |
} |
| 39 |
} |
| 40 |
); |
| 41 |
} else if(resultCode == com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult.SEARCH_TIMEOUT) { |
| 42 |
if(deviceNumber != 0) { |
| 43 |
requestAccess(); |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
requestAccess(); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
@Override |
| 56 |
protected void requestAccess() { |
| 57 |
releaseHandle = AntPlusHeartRatePcc.requestAccess(context, deviceNumber, 0, mResultReceiver, mDeviceStateChangeReceiver); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
@Override |
| 65 |
public void zeroReadings() |
| 66 |
{ |
| 67 |
alterCurrentData(RideService.HR, (float) 0.0); |
| 68 |
} |
| 69 |
} |