mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
More ant code clean up
This commit is contained in:
@@ -2,16 +2,12 @@ package com.ridelogger;
|
|||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import com.dsi.ant.plugins.antplus.pcc.defines.DeviceType;
|
import com.dsi.ant.plugins.antplus.pcc.defines.DeviceType;
|
||||||
import com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult;
|
|
||||||
import com.dsi.ant.plugins.antplus.pccbase.MultiDeviceSearch;
|
|
||||||
import com.dsi.ant.plugins.antplus.pccbase.MultiDeviceSearch.MultiDeviceSearchResult;
|
|
||||||
import com.ridelogger.formats.BaseFormat;
|
import com.ridelogger.formats.BaseFormat;
|
||||||
import com.ridelogger.formats.JsonFormat;
|
import com.ridelogger.formats.JsonFormat;
|
||||||
import com.ridelogger.listners.Base;
|
import com.ridelogger.listners.Base;
|
||||||
@@ -110,7 +106,6 @@ public class RideService extends Service
|
|||||||
private boolean rideStarted = false; //have we started logging the ride
|
private boolean rideStarted = false; //have we started logging the ride
|
||||||
private int sensor_index = 0; //current index of sensors
|
private int sensor_index = 0; //current index of sensors
|
||||||
private String emergencyNumbuer; //the number to send the messages to
|
private String emergencyNumbuer; //the number to send the messages to
|
||||||
private MultiDeviceSearch mSearch; //Ant+ device search class to init connections
|
|
||||||
private Timer timer; //timer class to control the periodic messages
|
private Timer timer; //timer class to control the periodic messages
|
||||||
private Timer timerUI; //timer class to control the periodic messages
|
private Timer timerUI; //timer class to control the periodic messages
|
||||||
private Base<?>[] sensors; //list of sensors tracking
|
private Base<?>[] sensors; //list of sensors tracking
|
||||||
@@ -229,47 +224,51 @@ public class RideService extends Service
|
|||||||
fileFormat.writeHeader();
|
fileFormat.writeHeader();
|
||||||
|
|
||||||
final Set<String> pairedAnts = settings.getStringSet(getString(R.string.PREF_PAIRED_ANTS), null);
|
final Set<String> pairedAnts = settings.getStringSet(getString(R.string.PREF_PAIRED_ANTS), null);
|
||||||
if(pairedAnts != null) {
|
|
||||||
|
if(pairedAnts != null && !pairedAnts.isEmpty()){
|
||||||
sensors = new Base<?>[pairedAnts.size() + 2];
|
sensors = new Base<?>[pairedAnts.size() + 2];
|
||||||
|
for(String deviceNumber: pairedAnts) {
|
||||||
|
DeviceType deviceType = DeviceType.getValueFromInt(settings.getInt(deviceNumber, 0));
|
||||||
|
switch (deviceType) {
|
||||||
|
case BIKE_CADENCE:
|
||||||
|
break;
|
||||||
|
case BIKE_POWER:
|
||||||
|
sensors[sensor_index++] = new Power(Integer.valueOf(deviceNumber), this);
|
||||||
|
break;
|
||||||
|
case BIKE_SPD:
|
||||||
|
break;
|
||||||
|
case BIKE_SPDCAD:
|
||||||
|
break;
|
||||||
|
case BLOOD_PRESSURE:
|
||||||
|
break;
|
||||||
|
case ENVIRONMENT:
|
||||||
|
break;
|
||||||
|
case WEIGHT_SCALE:
|
||||||
|
break;
|
||||||
|
case HEARTRATE:
|
||||||
|
sensors[sensor_index++] = new HeartRate(Integer.valueOf(deviceNumber), this);
|
||||||
|
break;
|
||||||
|
case STRIDE_SDM:
|
||||||
|
break;
|
||||||
|
case FITNESS_EQUIPMENT:
|
||||||
|
break;
|
||||||
|
case GEOCACHE:
|
||||||
|
case CONTROLLABLE_DEVICE:
|
||||||
|
break;
|
||||||
|
case UNKNOWN:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sensors = new Base<?>[2];
|
sensors = new Base<?>[4];
|
||||||
|
sensors[sensor_index++] = new HeartRate(0, this);
|
||||||
|
sensors[sensor_index++] = new Power(0, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
sensors[sensor_index++] = new Gps(this);
|
sensors[sensor_index++] = new Gps(this);
|
||||||
sensors[sensor_index++] = new Sensors(this);
|
sensors[sensor_index++] = new Sensors(this);
|
||||||
|
|
||||||
if(pairedAnts != null && !pairedAnts.isEmpty()){
|
|
||||||
// start the multi-device search
|
|
||||||
mSearch = new MultiDeviceSearch(
|
|
||||||
this,
|
|
||||||
EnumSet.allOf(DeviceType.class),
|
|
||||||
new MultiDeviceSearch.SearchCallbacks() {
|
|
||||||
public void onDeviceFound(final MultiDeviceSearchResult deviceFound)
|
|
||||||
{
|
|
||||||
if (!deviceFound.isAlreadyConnected()) {
|
|
||||||
if(pairedAnts == null || pairedAnts.contains(Integer.toString(deviceFound.getAntDeviceNumber()))) {
|
|
||||||
launchConnection(deviceFound);
|
|
||||||
pairedAnts.remove(Integer.toString(deviceFound.getAntDeviceNumber()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pairedAnts.isEmpty()) {
|
|
||||||
mSearch.close();
|
|
||||||
mSearch = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSearchStopped(RequestAccessResult arg0) {
|
|
||||||
mSearch = null;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new MultiDeviceSearch.RssiCallback() {
|
|
||||||
@Override
|
|
||||||
public void onRssiUpdate(final int resultId, final int rssi){}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rideStarted = true;
|
rideStarted = true;
|
||||||
|
|
||||||
@@ -392,11 +391,6 @@ public class RideService extends Service
|
|||||||
sensor.onDestroy();
|
sensor.onDestroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//stop the Ant+ search
|
|
||||||
if(mSearch != null) {
|
|
||||||
mSearch.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
//stop the phoneHome timer if we need to.
|
//stop the phoneHome timer if we need to.
|
||||||
if(timer != null) {
|
if(timer != null) {
|
||||||
@@ -415,42 +409,6 @@ public class RideService extends Service
|
|||||||
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
mNotificationManager.cancel(notifyID);
|
mNotificationManager.cancel(notifyID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//launch ant+ connection
|
|
||||||
public void launchConnection(MultiDeviceSearchResult result) {
|
|
||||||
switch (result.getAntDeviceType()) {
|
|
||||||
case BIKE_CADENCE:
|
|
||||||
break;
|
|
||||||
case BIKE_POWER:
|
|
||||||
sensors[sensor_index++] = new Power(result, this);
|
|
||||||
break;
|
|
||||||
case BIKE_SPD:
|
|
||||||
break;
|
|
||||||
case BIKE_SPDCAD:
|
|
||||||
break;
|
|
||||||
case BLOOD_PRESSURE:
|
|
||||||
break;
|
|
||||||
case ENVIRONMENT:
|
|
||||||
break;
|
|
||||||
case WEIGHT_SCALE:
|
|
||||||
break;
|
|
||||||
case HEARTRATE:
|
|
||||||
sensors[sensor_index++] = new HeartRate(result, this);
|
|
||||||
break;
|
|
||||||
case STRIDE_SDM:
|
|
||||||
break;
|
|
||||||
case FITNESS_EQUIPMENT:
|
|
||||||
break;
|
|
||||||
case GEOCACHE:
|
|
||||||
case CONTROLLABLE_DEVICE:
|
|
||||||
break;
|
|
||||||
case UNKNOWN:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import com.dsi.ant.plugins.antplus.pcc.defines.DeviceState;
|
|||||||
import com.dsi.ant.plugins.antplus.pccbase.PccReleaseHandle;
|
import com.dsi.ant.plugins.antplus.pccbase.PccReleaseHandle;
|
||||||
import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc.IDeviceStateChangeReceiver;
|
import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc.IDeviceStateChangeReceiver;
|
||||||
import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc.IPluginAccessResultReceiver;
|
import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc.IPluginAccessResultReceiver;
|
||||||
import com.dsi.ant.plugins.antplus.pccbase.MultiDeviceSearch.MultiDeviceSearchResult;
|
|
||||||
|
|
||||||
import com.ridelogger.RideService;
|
import com.ridelogger.RideService;
|
||||||
|
|
||||||
|
|
||||||
@@ -14,19 +12,22 @@ import com.ridelogger.RideService;
|
|||||||
* @author Chet Henry
|
* @author Chet Henry
|
||||||
* Listen to and log Ant+ events base class
|
* Listen to and log Ant+ events base class
|
||||||
*/
|
*/
|
||||||
public class Ant extends Base<Object>
|
public abstract class Ant extends Base<Object>
|
||||||
{
|
{
|
||||||
public PccReleaseHandle<?> releaseHandle; //Handle class
|
protected PccReleaseHandle<?> releaseHandle; //Handle class
|
||||||
public IPluginAccessResultReceiver<?> mResultReceiver; //Receiver class
|
public IPluginAccessResultReceiver<?> mResultReceiver; //Receiver class
|
||||||
|
protected int deviceNumber = 0;
|
||||||
|
|
||||||
|
|
||||||
//setup listeners and logging
|
//setup listeners and logging
|
||||||
public Ant(MultiDeviceSearchResult result, RideService mContext)
|
public Ant(int pDeviceNumber, RideService mContext)
|
||||||
{
|
{
|
||||||
super(mContext);
|
super(mContext);
|
||||||
|
deviceNumber = pDeviceNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IDeviceStateChangeReceiver mDeviceStateChangeReceiver = new IDeviceStateChangeReceiver()
|
public IDeviceStateChangeReceiver mDeviceStateChangeReceiver = new IDeviceStateChangeReceiver()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onDeviceStateChange(final DeviceState newDeviceState){
|
public void onDeviceStateChange(final DeviceState newDeviceState){
|
||||||
@@ -36,7 +37,11 @@ public class Ant extends Base<Object>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
abstract protected void requestAccess();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy()
|
public void onDestroy()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import com.dsi.ant.plugins.antplus.pcc.defines.DeviceState;
|
|||||||
import com.dsi.ant.plugins.antplus.pcc.defines.EventFlag;
|
import com.dsi.ant.plugins.antplus.pcc.defines.EventFlag;
|
||||||
import com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult;
|
import com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult;
|
||||||
import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc.IPluginAccessResultReceiver;
|
import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc.IPluginAccessResultReceiver;
|
||||||
import com.dsi.ant.plugins.antplus.pccbase.MultiDeviceSearch.MultiDeviceSearchResult;
|
|
||||||
import com.ridelogger.RideService;
|
import com.ridelogger.RideService;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
@@ -19,29 +18,45 @@ import java.util.EnumSet;
|
|||||||
*/
|
*/
|
||||||
public class HeartRate extends Ant
|
public class HeartRate extends Ant
|
||||||
{
|
{
|
||||||
public HeartRate(MultiDeviceSearchResult result, RideService mContext) {
|
public IPluginAccessResultReceiver<AntPlusHeartRatePcc> mResultReceiver;
|
||||||
super(result, mContext);
|
|
||||||
releaseHandle = AntPlusHeartRatePcc.requestAccess(context, result.getAntDeviceNumber(), 0, mResultReceiver, mDeviceStateChangeReceiver);
|
public HeartRate(int pDeviceNumber, RideService mContext) {
|
||||||
|
super(pDeviceNumber, mContext);
|
||||||
|
|
||||||
|
mResultReceiver = new IPluginAccessResultReceiver<AntPlusHeartRatePcc>() {
|
||||||
|
//Handle the result, connecting to events on success or reporting failure to user.
|
||||||
|
@Override
|
||||||
|
public void onResultReceived(AntPlusHeartRatePcc result, RequestAccessResult resultCode, DeviceState initialDeviceState)
|
||||||
|
{
|
||||||
|
if(resultCode == com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult.SUCCESS) {
|
||||||
|
deviceNumber = result.getAntDeviceNumber();
|
||||||
|
result.subscribeHeartRateDataEvent(
|
||||||
|
new IHeartRateDataReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onNewHeartRateData(final long estTimestamp, EnumSet<EventFlag> eventFlags, final int computedHeartRate, final long heartBeatCount, final BigDecimal heartBeatEventTime, final DataState dataState) {
|
||||||
|
alterCurrentData(RideService.HR, (float) computedHeartRate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else if(resultCode == com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult.SEARCH_TIMEOUT) {
|
||||||
|
requestAccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
requestAccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IPluginAccessResultReceiver<AntPlusHeartRatePcc> mResultReceiver = new IPluginAccessResultReceiver<AntPlusHeartRatePcc>() {
|
|
||||||
//Handle the result, connecting to events on success or reporting failure to user.
|
@Override
|
||||||
@Override
|
protected void requestAccess() {
|
||||||
public void onResultReceived(AntPlusHeartRatePcc result, RequestAccessResult resultCode, DeviceState initialDeviceState)
|
releaseHandle = AntPlusHeartRatePcc.requestAccess(context, deviceNumber, 0, mResultReceiver, mDeviceStateChangeReceiver);
|
||||||
{
|
}
|
||||||
if(resultCode == com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult.SUCCESS) {
|
|
||||||
result.subscribeHeartRateDataEvent(
|
|
||||||
new IHeartRateDataReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onNewHeartRateData(final long estTimestamp, EnumSet<EventFlag> eventFlags, final int computedHeartRate, final long heartBeatCount, final BigDecimal heartBeatEventTime, final DataState dataState) {
|
|
||||||
alterCurrentData(RideService.HR, (float) computedHeartRate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import com.dsi.ant.plugins.antplus.pcc.defines.DeviceState;
|
|||||||
import com.dsi.ant.plugins.antplus.pcc.defines.EventFlag;
|
import com.dsi.ant.plugins.antplus.pcc.defines.EventFlag;
|
||||||
import com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult;
|
import com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult;
|
||||||
import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc.IPluginAccessResultReceiver;
|
import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc.IPluginAccessResultReceiver;
|
||||||
import com.dsi.ant.plugins.antplus.pccbase.MultiDeviceSearch.MultiDeviceSearchResult;
|
|
||||||
import com.ridelogger.R;
|
import com.ridelogger.R;
|
||||||
import com.ridelogger.RideService;
|
import com.ridelogger.RideService;
|
||||||
|
|
||||||
@@ -29,161 +28,171 @@ import java.util.EnumSet;
|
|||||||
public class Power extends Ant
|
public class Power extends Ant
|
||||||
{
|
{
|
||||||
public BigDecimal wheelCircumferenceInMeters; //size of wheel to calculate speed
|
public BigDecimal wheelCircumferenceInMeters; //size of wheel to calculate speed
|
||||||
|
public IPluginAccessResultReceiver<AntPlusBikePowerPcc> mResultReceiver;
|
||||||
|
|
||||||
//setup listeners and logging
|
//setup listeners and logging
|
||||||
public Power(MultiDeviceSearchResult result, RideService mContext) {
|
public Power(int pDeviceNumber, RideService mContext) {
|
||||||
super(result, mContext);
|
super(pDeviceNumber, mContext);
|
||||||
releaseHandle = AntPlusBikePowerPcc.requestAccess(context, result.getAntDeviceNumber(), 0, mResultReceiver, mDeviceStateChangeReceiver);
|
|
||||||
wheelCircumferenceInMeters = new BigDecimal(
|
wheelCircumferenceInMeters = new BigDecimal(
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.PREF_WHEEL_SIZE), "2.096")
|
PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.PREF_WHEEL_SIZE), "2.096")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//Handle messages
|
||||||
|
mResultReceiver = new IPluginAccessResultReceiver<AntPlusBikePowerPcc>() {
|
||||||
|
//Handle the result, connecting to events on success or reporting failure to user.
|
||||||
|
@Override
|
||||||
|
public void onResultReceived(AntPlusBikePowerPcc result, RequestAccessResult resultCode, DeviceState initialDeviceState) {
|
||||||
|
if(resultCode == com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult.SUCCESS) {
|
||||||
|
deviceNumber = result.getAntDeviceNumber();
|
||||||
|
|
||||||
|
result.subscribeCalculatedPowerEvent(new ICalculatedPowerReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onNewCalculatedPower(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedPower) {
|
||||||
|
alterCurrentData(RideService.WATTS, calculatedPower.floatValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
result.subscribeCalculatedTorqueEvent(
|
||||||
|
new ICalculatedTorqueReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onNewCalculatedTorque(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedTorque) {
|
||||||
|
alterCurrentData(RideService.NM, calculatedTorque.floatValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
result.subscribeCalculatedCrankCadenceEvent(
|
||||||
|
new ICalculatedCrankCadenceReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onNewCalculatedCrankCadence(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedCrankCadence) {
|
||||||
|
alterCurrentData(RideService.CAD, calculatedCrankCadence.floatValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
result.subscribeCalculatedWheelSpeedEvent(
|
||||||
|
new CalculatedWheelSpeedReceiver(wheelCircumferenceInMeters) {
|
||||||
|
@Override
|
||||||
|
public void onNewCalculatedWheelSpeed(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedWheelSpeed)
|
||||||
|
{
|
||||||
|
alterCurrentData(RideService.KPH, calculatedWheelSpeed.floatValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
result.subscribeCalculatedWheelDistanceEvent(
|
||||||
|
new CalculatedWheelDistanceReceiver(wheelCircumferenceInMeters) {
|
||||||
|
@Override
|
||||||
|
public void onNewCalculatedWheelDistance(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedWheelDistance)
|
||||||
|
{
|
||||||
|
alterCurrentData(RideService.KM, calculatedWheelDistance.floatValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
result.subscribeInstantaneousCadenceEvent(
|
||||||
|
new IInstantaneousCadenceReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onNewInstantaneousCadence(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final int instantaneousCadence)
|
||||||
|
{
|
||||||
|
alterCurrentData(RideService.CAD, (float) instantaneousCadence);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
result.subscribeRawPowerOnlyDataEvent(
|
||||||
|
new IRawPowerOnlyDataReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onNewRawPowerOnlyData(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long powerOnlyUpdateEventCount, final int instantaneousPower, final long accumulatedPower)
|
||||||
|
{
|
||||||
|
alterCurrentData(RideService.WATTS, (float) instantaneousPower);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/*result.subscribePedalPowerBalanceEvent(
|
||||||
|
new IPedalPowerBalanceReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onNewPedalPowerBalance(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final boolean rightPedalIndicator, final int pedalPowerPercentage)
|
||||||
|
{
|
||||||
|
alterCurrentData(RideService.LTE, pedalPowerPercentage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
result.subscribeRawWheelTorqueDataEvent(
|
||||||
|
new IRawWheelTorqueDataReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onNewRawWheelTorqueData(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long wheelTorqueUpdateEventCount, final long accumulatedWheelTicks, final BigDecimal accumulatedWheelPeriod, final BigDecimal accumulatedWheelTorque)
|
||||||
|
{
|
||||||
|
alterCurrentData(RideService.NM, accumulatedWheelTorque);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
result.subscribeRawCrankTorqueDataEvent(
|
||||||
|
new IRawCrankTorqueDataReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onNewRawCrankTorqueData(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long crankTorqueUpdateEventCount, final long accumulatedCrankTicks, final BigDecimal accumulatedCrankPeriod, final BigDecimal accumulatedCrankTorque)
|
||||||
|
{
|
||||||
|
alterCurrentData(RideService.NM, accumulatedCrankTorque);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
result.subscribeTorqueEffectivenessEvent(
|
||||||
|
new ITorqueEffectivenessReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onNewTorqueEffectiveness(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long powerOnlyUpdateEventCount, final BigDecimal leftTorqueEffectiveness, final BigDecimal rightTorqueEffectiveness)
|
||||||
|
{
|
||||||
|
int[] keys = {
|
||||||
|
RideService.LTE,
|
||||||
|
RideService.RTE
|
||||||
|
};
|
||||||
|
|
||||||
|
float[] values = {
|
||||||
|
leftTorqueEffectiveness,
|
||||||
|
rightTorqueEffectiveness
|
||||||
|
}
|
||||||
|
|
||||||
|
alterCurrentData(keys, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
result.subscribePedalSmoothnessEvent(new IPedalSmoothnessReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onNewPedalSmoothness(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long powerOnlyUpdateEventCount, final boolean separatePedalSmoothnessSupport, final BigDecimal leftOrCombinedPedalSmoothness, final BigDecimal rightPedalSmoothness)
|
||||||
|
{
|
||||||
|
int[] keys = {
|
||||||
|
RideService.SNPLC,
|
||||||
|
RideService.SNPR
|
||||||
|
};
|
||||||
|
|
||||||
|
float[] values = {
|
||||||
|
leftOrCombinedPedalSmoothness,
|
||||||
|
rightPedalSmoothness
|
||||||
|
}
|
||||||
|
|
||||||
|
alterCurrentData(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);*/
|
||||||
|
} else if(resultCode == com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult.SEARCH_TIMEOUT) {
|
||||||
|
requestAccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
requestAccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void requestAccess() {
|
||||||
//Handle messages
|
releaseHandle = AntPlusBikePowerPcc.requestAccess(context, deviceNumber, 0, mResultReceiver, mDeviceStateChangeReceiver);
|
||||||
protected IPluginAccessResultReceiver<AntPlusBikePowerPcc> mResultReceiver = new IPluginAccessResultReceiver<AntPlusBikePowerPcc>() {
|
}
|
||||||
//Handle the result, connecting to events on success or reporting failure to user.
|
|
||||||
@Override
|
|
||||||
public void onResultReceived(AntPlusBikePowerPcc result, RequestAccessResult resultCode, DeviceState initialDeviceState) {
|
|
||||||
if(resultCode == com.dsi.ant.plugins.antplus.pcc.defines.RequestAccessResult.SUCCESS) {
|
|
||||||
result.subscribeCalculatedPowerEvent(new ICalculatedPowerReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onNewCalculatedPower(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedPower) {
|
|
||||||
alterCurrentData(RideService.WATTS, calculatedPower.floatValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
result.subscribeCalculatedTorqueEvent(
|
|
||||||
new ICalculatedTorqueReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onNewCalculatedTorque(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedTorque) {
|
|
||||||
alterCurrentData(RideService.NM, calculatedTorque.floatValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
result.subscribeCalculatedCrankCadenceEvent(
|
|
||||||
new ICalculatedCrankCadenceReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onNewCalculatedCrankCadence(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedCrankCadence) {
|
|
||||||
alterCurrentData(RideService.CAD, calculatedCrankCadence.floatValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
result.subscribeCalculatedWheelSpeedEvent(
|
|
||||||
new CalculatedWheelSpeedReceiver(wheelCircumferenceInMeters) {
|
|
||||||
@Override
|
|
||||||
public void onNewCalculatedWheelSpeed(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedWheelSpeed)
|
|
||||||
{
|
|
||||||
alterCurrentData(RideService.KPH, calculatedWheelSpeed.floatValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
result.subscribeCalculatedWheelDistanceEvent(
|
|
||||||
new CalculatedWheelDistanceReceiver(wheelCircumferenceInMeters) {
|
|
||||||
@Override
|
|
||||||
public void onNewCalculatedWheelDistance(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final BigDecimal calculatedWheelDistance)
|
|
||||||
{
|
|
||||||
alterCurrentData(RideService.KM, calculatedWheelDistance.floatValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
result.subscribeInstantaneousCadenceEvent(
|
|
||||||
new IInstantaneousCadenceReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onNewInstantaneousCadence(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final DataSource dataSource, final int instantaneousCadence)
|
|
||||||
{
|
|
||||||
alterCurrentData(RideService.CAD, (float) instantaneousCadence);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
result.subscribeRawPowerOnlyDataEvent(
|
|
||||||
new IRawPowerOnlyDataReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onNewRawPowerOnlyData(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long powerOnlyUpdateEventCount, final int instantaneousPower, final long accumulatedPower)
|
|
||||||
{
|
|
||||||
alterCurrentData(RideService.WATTS, (float) instantaneousPower);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
/*result.subscribePedalPowerBalanceEvent(
|
|
||||||
new IPedalPowerBalanceReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onNewPedalPowerBalance(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final boolean rightPedalIndicator, final int pedalPowerPercentage)
|
|
||||||
{
|
|
||||||
alterCurrentData(RideService.LTE, pedalPowerPercentage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
result.subscribeRawWheelTorqueDataEvent(
|
|
||||||
new IRawWheelTorqueDataReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onNewRawWheelTorqueData(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long wheelTorqueUpdateEventCount, final long accumulatedWheelTicks, final BigDecimal accumulatedWheelPeriod, final BigDecimal accumulatedWheelTorque)
|
|
||||||
{
|
|
||||||
alterCurrentData(RideService.NM, accumulatedWheelTorque);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
result.subscribeRawCrankTorqueDataEvent(
|
|
||||||
new IRawCrankTorqueDataReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onNewRawCrankTorqueData(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long crankTorqueUpdateEventCount, final long accumulatedCrankTicks, final BigDecimal accumulatedCrankPeriod, final BigDecimal accumulatedCrankTorque)
|
|
||||||
{
|
|
||||||
alterCurrentData(RideService.NM, accumulatedCrankTorque);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
result.subscribeTorqueEffectivenessEvent(
|
|
||||||
new ITorqueEffectivenessReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onNewTorqueEffectiveness(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long powerOnlyUpdateEventCount, final BigDecimal leftTorqueEffectiveness, final BigDecimal rightTorqueEffectiveness)
|
|
||||||
{
|
|
||||||
int[] keys = {
|
|
||||||
RideService.LTE,
|
|
||||||
RideService.RTE
|
|
||||||
};
|
|
||||||
|
|
||||||
float[] values = {
|
|
||||||
leftTorqueEffectiveness,
|
|
||||||
rightTorqueEffectiveness
|
|
||||||
}
|
|
||||||
|
|
||||||
alterCurrentData(keys, values);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
result.subscribePedalSmoothnessEvent(new IPedalSmoothnessReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onNewPedalSmoothness(final long estTimestamp, final EnumSet<EventFlag> eventFlags, final long powerOnlyUpdateEventCount, final boolean separatePedalSmoothnessSupport, final BigDecimal leftOrCombinedPedalSmoothness, final BigDecimal rightPedalSmoothness)
|
|
||||||
{
|
|
||||||
int[] keys = {
|
|
||||||
RideService.SNPLC,
|
|
||||||
RideService.SNPR
|
|
||||||
};
|
|
||||||
|
|
||||||
float[] values = {
|
|
||||||
leftOrCombinedPedalSmoothness,
|
|
||||||
rightPedalSmoothness
|
|
||||||
}
|
|
||||||
|
|
||||||
alterCurrentData(map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user