Skip to content

Commit

Permalink
Group 13 Changes (thanhpd#40)
Browse files Browse the repository at this point in the history
Changes to remove technical debts
  • Loading branch information
vhd1 authored Feb 16, 2024
2 parents 0b8e259 + 23796bb commit 82b381e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public void clearTrackPoints() {
}
}

@Override
public void onSampledInTrackPoint(@NonNull TrackPoint trackPoint, @NonNull TrackStatistics trackStatistics) {
if (isResumed()) {
ChartPoint point = ChartPoint.create(trackStatistics, trackPoint, trackPoint.getSpeed(), chartByDistance, viewBinding.chartView.getUnitSystem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,27 @@ public class BluetoothConnectionManager implements Driver {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
switch (newState) {
case BluetoothProfile.STATE_CONNECTING ->
Log.i(TAG, gatt.getDevice() + ": connecting to sensor");
case BluetoothProfile.STATE_CONNECTED -> {
case BluetoothProfile.STATE_CONNECTING:
Log.i(TAG, gatt.getDevice() + ": connecting to sensor");
break;
case BluetoothProfile.STATE_CONNECTED:
Log.i(TAG, gatt.getDevice() + ": connected to sensor; discovering services");
gatt.discoverServices();
}
case BluetoothProfile.STATE_DISCONNECTING ->
Log.i(TAG, gatt.getDevice() + ": disconnecting from sensor: ");
case BluetoothProfile.STATE_DISCONNECTED -> {
//This is also triggered, if no connection was established (ca. 30s)
break;
case BluetoothProfile.STATE_DISCONNECTING:
Log.i(TAG, gatt.getDevice() + ": disconnecting from sensor");
break;
case BluetoothProfile.STATE_DISCONNECTED:
// This is also triggered if no connection was established (ca. 30s)
Log.i(TAG, gatt.getDevice() + ": disconnected from sensor: trying to reconnect");
if (gatt.connect()) {
if (!gatt.connect()) {
Log.e(TAG, gatt.getDevice() + ": could not trigger reconnect for sensor");
}
clearData();
}
break;
default:
Log.w(TAG, "Unknown connection state: " + newState);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public static Data parseCyclingPower(BluetoothGattCharacteristic characteristic)

int index = 0;
int flags1 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, index++);
int flags2 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, index++);
boolean hasPedalPowerBalance = (flags1 & 0x01) > 0;
boolean hasAccumulatedTorque = (flags1 & 0x04) > 0;
boolean hasWheel = (flags1 & 16) > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public static Data parseRunningSpeedAndCadence(String sensorName, @NonNull Bluet
int flags = characteristic.getValue()[0];
boolean hasStrideLength = (flags & 0x01) > 0;
boolean hasTotalDistance = (flags & 0x02) > 0;
boolean hasStatus = (flags & 0x03) > 0; // walking vs running

Speed speed = null;
Cadence cadence = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
*/
public class BluetoothUtils {

private BluetoothUtils() {
throw new IllegalStateException("Utility class");
}

public static final UUID CLIENT_CHARACTERISTIC_CONFIG_UUID = new UUID(0x290200001000L, 0x800000805f9b34fbL);

public static final ServiceMeasurementUUID BATTERY = new ServiceMeasurementUUID(
new UUID(0x180F00001000L, 0x800000805f9b34fbL),
new UUID(0x2A1900001000L, 0x800000805f9b34fbL)
);

new UUID(0x2A1900001000L, 0x800000805f9b34fbL));

private static final String TAG = BluetoothUtils.class.getSimpleName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PressureSensorUtils {

private static final float EXPONENTIAL_SMOOTHING = 0.3f;

private static final float p0 = SensorManager.PRESSURE_STANDARD_ATMOSPHERE;
private static final float P0_STANDARD_ATMOSPHERE_PRESSURE = SensorManager.PRESSURE_STANDARD_ATMOSPHERE;

private PressureSensorUtils() {
}
Expand All @@ -40,8 +40,8 @@ public static AltitudeChange computeChangesWithSmoothing_m(AtmosphericPressure l

@VisibleForTesting
public static AltitudeChange computeChanges(AtmosphericPressure lastAcceptedSensorValue, AtmosphericPressure currentSensorValue) {
float lastSensorValue_m = SensorManager.getAltitude(p0, lastAcceptedSensorValue.getHPA());
float currentSensorValue_m = SensorManager.getAltitude(p0, currentSensorValue.getHPA());
float lastSensorValue_m = SensorManager.getAltitude(P0_STANDARD_ATMOSPHERE_PRESSURE, lastAcceptedSensorValue.getHPA());
float currentSensorValue_m = SensorManager.getAltitude(P0_STANDARD_ATMOSPHERE_PRESSURE, currentSensorValue.getHPA());

float altitudeChange_m = currentSensorValue_m - lastSensorValue_m;
if (Math.abs(altitudeChange_m) < ALTITUDE_CHANGE_DIFF_M) {
Expand All @@ -64,6 +64,6 @@ public static AltitudeChange computeChanges(AtmosphericPressure lastAcceptedSens
*/
@VisibleForTesting
public static AtmosphericPressure getBarometricPressure(float altitude_m) {
return AtmosphericPressure.ofHPA((float) (p0 * Math.pow(1.0 - 0.0065 * altitude_m / 288.15, 5.255f)));
return AtmosphericPressure.ofHPA((float) (P0_STANDARD_ATMOSPHERE_PRESSURE * Math.pow(1.0 - 0.0065 * altitude_m / 288.15, 5.255f)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,11 @@ public void reset() {
sensorDataSet.reset();
}

@Deprecated
@VisibleForTesting
public void onChanged(Raw<?> data) {
listener.onChange(data);
}

public GPSManager getGpsManager() {
return gpsManager;
}
Expand Down

0 comments on commit 82b381e

Please sign in to comment.