forked from upstream-mirrors/OpenTracks
Addressed comments.
Merge from head.
This commit is contained in:
@@ -22,8 +22,8 @@ import android.preference.Preference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
/**
|
||||
* A preference for a ANT device pairing.
|
||||
* Currently this shows the id and lets the user clear that id for future pairing.
|
||||
* A preference for an ANT device pairing.
|
||||
* Currently this shows the ID and lets the user clear that ID for future pairing.
|
||||
* TODO: Support pairing from this preference.
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
@@ -45,9 +45,7 @@ public class AntPreference extends Preference {
|
||||
if (sensorId == 0) {
|
||||
setSummary(R.string.settings_ant_not_paired);
|
||||
} else {
|
||||
setSummary(
|
||||
String.format(
|
||||
getContext().getString(R.string.settings_ant_paired), sensorId));
|
||||
setSummary(String.format(getContext().getString(R.string.settings_ant_paired), sensorId));
|
||||
}
|
||||
|
||||
// Add actions to allow repairing.
|
||||
|
||||
@@ -136,17 +136,24 @@ public class MyTracksProvider extends ContentProvider {
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
if (oldVersion < 17) {
|
||||
// Wipe the old data.
|
||||
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
|
||||
+ newVersion + ", which will destroy all old data");
|
||||
db.execSQL("DROP TABLE IF EXISTS " + TRACKPOINTS_TABLE);
|
||||
db.execSQL("DROP TABLE IF EXISTS " + TRACKS_TABLE);
|
||||
db.execSQL("DROP TABLE IF EXISTS " + WAYPOINTS_TABLE);
|
||||
onCreate(db);
|
||||
} else if (oldVersion >= 17) {
|
||||
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
|
||||
+ newVersion + ", adding sensor column.");
|
||||
db.execSQL("ALTER TABLE " + TRACKPOINTS_TABLE
|
||||
+ " ADD " + TrackPointsColumns.SENSOR + " BLOB");
|
||||
} else {
|
||||
// Incremental updates go here.
|
||||
// Each time you increase the DB version, add a corresponding if clause.
|
||||
|
||||
// Sensor data.
|
||||
if (oldVersion <= 17) {
|
||||
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
|
||||
+ newVersion + ", adding sensor column.");
|
||||
db.execSQL("ALTER TABLE " + TRACKPOINTS_TABLE
|
||||
+ " ADD " + TrackPointsColumns.SENSOR + " BLOB");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -644,7 +644,6 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||
splitManager = new SplitManager(this);
|
||||
|
||||
sensorManager = SensorManagerFactory.getSensorManager(this);
|
||||
prefManager = new PreferenceManager(this);
|
||||
registerLocationListener();
|
||||
|
||||
@@ -731,7 +730,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
splitManager.shutdown();
|
||||
splitManager = null;
|
||||
if (sensorManager != null) {
|
||||
sensorManager.onDestroy();
|
||||
sensorManager.shutdown();
|
||||
sensorManager = null;
|
||||
}
|
||||
|
||||
@@ -1080,6 +1079,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
showNotification();
|
||||
registerLocationListener();
|
||||
splitManager.restore();
|
||||
sensorManager = SensorManagerFactory.getSensorManager(this);
|
||||
if (sensorManager != null) {
|
||||
sensorManager.onStartTrack();
|
||||
}
|
||||
@@ -1128,6 +1128,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
|
||||
if (sensorManager != null) {
|
||||
sensorManager.shutdown();
|
||||
sensorManager = null;
|
||||
}
|
||||
|
||||
releaseWakeLock();
|
||||
|
||||
+17
-20
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.services.sensors;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracksConstants;
|
||||
import static com.google.android.apps.mytracks.MyTracksConstants.TAG;
|
||||
import com.google.android.apps.mytracks.MyTracksSettings;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
@@ -37,13 +37,13 @@ public class AntDirectSensorManager extends AntSensorManager {
|
||||
/*
|
||||
* These constants are defined by the ANT+ heart rate monitor spec.
|
||||
*/
|
||||
public static final byte HRM_CHANNEL = (byte) 0;
|
||||
public static final byte NETWORK_NUMBER = (byte) 1;
|
||||
public static final byte HEART_RATE_DEVICE_TYPE = (byte) 120;
|
||||
public static final byte POWER_DEVICE_TYPE = (byte) 11;
|
||||
public static final byte MANUFACTURER_ID = (byte) 1;
|
||||
public static final short CHANNEL_PERIOD = (short) 8070;
|
||||
public static final byte RF_FREQUENCY = (byte) 57;
|
||||
public static final byte HRM_CHANNEL = 0;
|
||||
public static final byte NETWORK_NUMBER = 1;
|
||||
public static final byte HEART_RATE_DEVICE_TYPE = 120;
|
||||
public static final byte POWER_DEVICE_TYPE = 11;
|
||||
public static final byte MANUFACTURER_ID = 1;
|
||||
public static final short CHANNEL_PERIOD = 8070;
|
||||
public static final byte RF_FREQUENCY = 57;
|
||||
|
||||
private short deviceNumberHRM;
|
||||
|
||||
@@ -59,8 +59,7 @@ public class AntDirectSensorManager extends AntSensorManager {
|
||||
deviceNumberHRM =
|
||||
(short) prefs.getInt(context.getString(R.string.ant_heart_rate_sensor_id_key), 0);
|
||||
}
|
||||
Log.i(MyTracksConstants.TAG,
|
||||
"Pairing with heart rate monitor: " + deviceNumberHRM);
|
||||
Log.i(TAG, "Pairing with heart rate monitor: " + deviceNumberHRM);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,7 +71,7 @@ public class AntDirectSensorManager extends AntSensorManager {
|
||||
antDecodeHRM(antMessage);
|
||||
break;
|
||||
default:
|
||||
Log.d(MyTracksConstants.TAG, "Unhandled message: " + channel);
|
||||
Log.d(TAG, "Unhandled message: " + channel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +92,7 @@ public class AntDirectSensorManager extends AntSensorManager {
|
||||
handleChannelId(antMessage);
|
||||
break;
|
||||
default:
|
||||
Log.e(MyTracksConstants.TAG,
|
||||
"Unexpected message id: " + antMessage[3]);
|
||||
Log.e(TAG, "Unexpected message id: " + antMessage[3]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +100,7 @@ public class AntDirectSensorManager extends AntSensorManager {
|
||||
if (deviceNumberHRM == WILDCARD) {
|
||||
getAntReceiver().ANTRequestMessage(HRM_CHANNEL,
|
||||
AntMesg.MESG_CHANNEL_ID_ID);
|
||||
Log.d(MyTracksConstants.TAG, "Requesting channel id id.");
|
||||
Log.d(TAG, "Requesting channel id id.");
|
||||
}
|
||||
|
||||
setSensorState(Sensor.SensorState.CONNECTED);
|
||||
@@ -122,7 +120,7 @@ public class AntDirectSensorManager extends AntSensorManager {
|
||||
deviceNumberHRM =
|
||||
(short) (((int) antMessage[3] & 0xFF |
|
||||
((int) (antMessage[4] & 0xFF) << 8)) & 0xFFFF);
|
||||
Log.i(MyTracksConstants.TAG, "Found device id: " + deviceNumberHRM);
|
||||
Log.i(TAG, "Found device id: " + deviceNumberHRM);
|
||||
|
||||
SharedPreferences prefs = context.getSharedPreferences(
|
||||
MyTracksSettings.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
@@ -132,16 +130,15 @@ public class AntDirectSensorManager extends AntSensorManager {
|
||||
}
|
||||
|
||||
private void handleMessageResponse(byte[] antMessage) {
|
||||
if (antMessage[3] == AntMesg.MESG_EVENT_ID
|
||||
&& antMessage[4] == AntDefine.EVENT_RX_SEARCH_TIMEOUT) {
|
||||
if (antMessage[3] == AntMesg.MESG_EVENT_ID &&
|
||||
antMessage[4] == AntDefine.EVENT_RX_SEARCH_TIMEOUT) {
|
||||
// Search timeout
|
||||
Log.w(MyTracksConstants.TAG, "Search timed out. Unassigning channel.");
|
||||
Log.w(TAG, "Search timed out. Unassigning channel.");
|
||||
getAntReceiver().ANTUnassignChannel((byte) 0);
|
||||
setSensorState(Sensor.SensorState.DISCONNECTED);
|
||||
} else if (antMessage[3] == AntMesg.MESG_UNASSIGN_CHANNEL_ID) {
|
||||
setSensorState(Sensor.SensorState.DISCONNECTED);
|
||||
Log.i(MyTracksConstants.TAG,
|
||||
"Disconnected from the sensor: " + getSensorState());
|
||||
Log.i(TAG, "Disconnected from the sensor: " + getSensorState());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-7
@@ -48,15 +48,15 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
private boolean status;
|
||||
|
||||
// Flag to know if the ANT App was interrupted
|
||||
// TODO this code path is not used but probably should be.
|
||||
private boolean antInterrupted = false;
|
||||
// TODO: This code path is not used but probably should be.
|
||||
private boolean antInterrupted;
|
||||
|
||||
/**
|
||||
* The data from the sensors.
|
||||
*/
|
||||
protected SensorDataSet sensorData = null;
|
||||
protected SensorDataSet sensorData;
|
||||
|
||||
protected Context context = null;
|
||||
protected Context context;
|
||||
|
||||
private static final boolean DEBUGGING = false;
|
||||
|
||||
@@ -133,7 +133,7 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
// already called before
|
||||
if (antInterrupted == false) {
|
||||
status = antReceiver.enable();
|
||||
if (status == false) {
|
||||
if (!status) {
|
||||
Log.e(MyTracksConstants.TAG, "Can not enable ANT interface");
|
||||
} else {
|
||||
Log.i(MyTracksConstants.TAG, "Powering on Radio");
|
||||
@@ -208,8 +208,7 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
}
|
||||
|
||||
// Set search timeout to 30 seconds (low priority search))
|
||||
if (!antReceiver.ANTSetLowPriorityChannelSearchTimeout(channelNumber,
|
||||
(byte) 12)) {
|
||||
if (!antReceiver.ANTSetLowPriorityChannelSearchTimeout(channelNumber, (byte) 12)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -45,21 +45,19 @@ public class SensorManagerFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
String sensor = prefs.getString(context.getString(R.string.sensor_type_key),
|
||||
null);
|
||||
String sensor = prefs.getString(context.getString(R.string.sensor_type_key), null);
|
||||
Log.i(MyTracksConstants.TAG, "Creating sensor of type: " + sensor);
|
||||
|
||||
if (sensor == null) {
|
||||
return null;
|
||||
} else if (sensor.equals(context.getString(R.string.ant_sensor_type))) {
|
||||
return new AntDirectSensorManager(context);
|
||||
} else if (sensor.equals(
|
||||
context.getString(R.string.srm_ant_bridge_sensor_type))) {
|
||||
} else if (sensor.equals(context.getString(R.string.srm_ant_bridge_sensor_type))) {
|
||||
return new AntSRMSensorManager(context);
|
||||
} else if (sensor.equals(context.getString(R.string.zephyr_sensor_type))) {
|
||||
return new ZephyrSensorManager(context);
|
||||
} else {
|
||||
Log.w(MyTracksConstants.TAG, "Unable to find sensor type: " + sensor);
|
||||
Log.w(MyTracksConstants.TAG, "Unable to find sensor type: " + sensor);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -35,6 +35,7 @@ public class ZephyrMessageParser implements MessageParser {
|
||||
}
|
||||
Log.w(MyTracksConstants.TAG, "Got zephyr data: " + sb);
|
||||
// The provided units are 1/16 strides per minute.
|
||||
// TODO: Fix the cadence calculation.
|
||||
// int cadence = SensorUtils.unsignedShortToInt(buffer, 56);
|
||||
// Heart Rate
|
||||
Sensor.SensorData.Builder b = Sensor.SensorData.newBuilder()
|
||||
|
||||
Reference in New Issue
Block a user