MCPcopy Create free account
hub / github.com/XCSoar/XCSoar / BluetoothSensor

Class BluetoothSensor

android/src/BluetoothSensor.java:43–293  ·  view source on GitHub ↗

Read Bluetooth LE sensor values and report them to a #SensorListener.

Source from the content-addressed store, hash-verified

41 * #SensorListener.
42 */
43public final class BluetoothSensor
44 extends BluetoothGattCallback
45 implements AndroidSensor
46{
47 private final SensorListener listener;
48 private final SafeDestruct safeDestruct = new SafeDestruct();
49
50 private final BluetoothGatt gatt;
51
52 private int state = STATE_LIMBO;
53
54 private BluetoothGattCharacteristic currentEnableNotification;
55 private final Queue<BluetoothGattCharacteristic> enableNotificationQueue =
56 new LinkedList<BluetoothGattCharacteristic>();
57
58 private boolean haveFlytecMovement = false;
59 private double flytecGroundSpeed, flytecTrack;
60 private int flytecSatellites = 0;
61
62 public BluetoothSensor(Context context, BluetoothDevice device,
63 SensorListener listener)
64 throws IOException
65 {
66 this.listener = listener;
67
68 if (Build.VERSION.SDK_INT >= 23)
69 gatt = device.connectGatt(context, true, this, BluetoothDevice.TRANSPORT_LE);
70 else
71 gatt = device.connectGatt(context, true, this);
72
73 if (gatt == null)
74 throw new IOException("Bluetooth GATT connect failed");
75 }
76
77 @Override
78 public void close() {
79 safeDestruct.beginShutdown();
80 gatt.close();
81 safeDestruct.finishShutdown();
82 }
83
84 @Override
85 public int getState() {
86 return state;
87 }
88
89 private void setStateSafe(int _state) {
90 if (_state == state)
91 return;
92
93 state = _state;
94
95 if (safeDestruct.increment()) {
96 try {
97 listener.onSensorStateChanged();
98 } finally {
99 safeDestruct.decrement();
100 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected