mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-21 07:51:46 +02:00
update Blesses library version to 2.0.11
This commit is contained in:
@@ -148,7 +148,7 @@ dependencies {
|
|||||||
// Simple CSV
|
// Simple CSV
|
||||||
implementation 'com.j256.simplecsv:simplecsv:2.6'
|
implementation 'com.j256.simplecsv:simplecsv:2.6'
|
||||||
// Blessed Android
|
// Blessed Android
|
||||||
implementation 'com.github.weliem:blessed-android:1.30'
|
implementation 'com.github.weliem:blessed-android:2.0.11'
|
||||||
// CustomActivityOnCrash
|
// CustomActivityOnCrash
|
||||||
implementation 'cat.ereza:customactivityoncrash:2.3.0'
|
implementation 'cat.ereza:customactivityoncrash:2.3.0'
|
||||||
// AppIntro
|
// AppIntro
|
||||||
|
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package com.health.openscale.core.bluetooth;
|
package com.health.openscale.core.bluetooth;
|
||||||
|
|
||||||
|
import static android.bluetooth.BluetoothGatt.GATT_SUCCESS;
|
||||||
|
import static android.content.Context.LOCATION_SERVICE;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
@@ -30,20 +33,19 @@ import androidx.core.content.ContextCompat;
|
|||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
import com.welie.blessed.BluetoothCentral;
|
import com.welie.blessed.BluetoothCentralManager;
|
||||||
import com.welie.blessed.BluetoothCentralCallback;
|
import com.welie.blessed.BluetoothCentralManagerCallback;
|
||||||
import com.welie.blessed.BluetoothPeripheral;
|
import com.welie.blessed.BluetoothPeripheral;
|
||||||
import com.welie.blessed.BluetoothPeripheralCallback;
|
import com.welie.blessed.BluetoothPeripheralCallback;
|
||||||
|
import com.welie.blessed.ConnectionState;
|
||||||
|
import com.welie.blessed.GattStatus;
|
||||||
|
import com.welie.blessed.HciStatus;
|
||||||
|
import com.welie.blessed.WriteType;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
import static android.bluetooth.BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT;
|
|
||||||
import static android.bluetooth.BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE;
|
|
||||||
import static android.content.Context.LOCATION_SERVICE;
|
|
||||||
import static com.welie.blessed.BluetoothPeripheral.GATT_SUCCESS;
|
|
||||||
|
|
||||||
public abstract class BluetoothCommunication {
|
public abstract class BluetoothCommunication {
|
||||||
public enum BT_STATUS {
|
public enum BT_STATUS {
|
||||||
RETRIEVE_SCALE_DATA,
|
RETRIEVE_SCALE_DATA,
|
||||||
@@ -67,7 +69,7 @@ public abstract class BluetoothCommunication {
|
|||||||
private Handler callbackBtHandler;
|
private Handler callbackBtHandler;
|
||||||
private Handler disconnectHandler;
|
private Handler disconnectHandler;
|
||||||
|
|
||||||
private BluetoothCentral central;
|
private BluetoothCentralManager central;
|
||||||
private BluetoothPeripheral btPeripheral;
|
private BluetoothPeripheral btPeripheral;
|
||||||
|
|
||||||
public BluetoothCommunication(Context context)
|
public BluetoothCommunication(Context context)
|
||||||
@@ -76,7 +78,7 @@ public abstract class BluetoothCommunication {
|
|||||||
this.disconnectHandler = new Handler();
|
this.disconnectHandler = new Handler();
|
||||||
this.stepNr = 0;
|
this.stepNr = 0;
|
||||||
this.stopped = false;
|
this.stopped = false;
|
||||||
this.central = new BluetoothCentral(context, bluetoothCentralCallback, new Handler(Looper.getMainLooper()));
|
this.central = new BluetoothCentralManager(context, bluetoothCentralCallback, new Handler(Looper.getMainLooper()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean needReConnect() {
|
protected boolean needReConnect() {
|
||||||
@@ -84,8 +86,8 @@ public abstract class BluetoothCommunication {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (btPeripheral != null) {
|
if (btPeripheral != null) {
|
||||||
int state = btPeripheral.getState();
|
ConnectionState state = btPeripheral.getState();
|
||||||
if (state == BluetoothProfile.STATE_CONNECTED || state == BluetoothProfile.STATE_CONNECTING) {
|
if (state.equals(BluetoothProfile.STATE_CONNECTED) || state.equals(BluetoothProfile.STATE_CONNECTING)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,7 +277,7 @@ public abstract class BluetoothCommunication {
|
|||||||
protected void writeBytes(UUID service, UUID characteristic, byte[] bytes, boolean noResponse) {
|
protected void writeBytes(UUID service, UUID characteristic, byte[] bytes, boolean noResponse) {
|
||||||
Timber.d("Invoke write bytes [" + byteInHex(bytes) + "] on " + BluetoothGattUuid.prettyPrint(characteristic));
|
Timber.d("Invoke write bytes [" + byteInHex(bytes) + "] on " + BluetoothGattUuid.prettyPrint(characteristic));
|
||||||
btPeripheral.writeCharacteristic(btPeripheral.getCharacteristic(service, characteristic), bytes,
|
btPeripheral.writeCharacteristic(btPeripheral.getCharacteristic(service, characteristic), bytes,
|
||||||
noResponse ? WRITE_TYPE_NO_RESPONSE : WRITE_TYPE_DEFAULT);
|
noResponse ? WriteType.WITHOUT_RESPONSE : WriteType.WITH_RESPONSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -421,8 +423,8 @@ public abstract class BluetoothCommunication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNotificationStateUpdate(BluetoothPeripheral peripheral, BluetoothGattCharacteristic characteristic, int status) {
|
public void onNotificationStateUpdate(BluetoothPeripheral peripheral, BluetoothGattCharacteristic characteristic, GattStatus status) {
|
||||||
if( status == GATT_SUCCESS) {
|
if( status.value == GATT_SUCCESS) {
|
||||||
if(peripheral.isNotifying(characteristic)) {
|
if(peripheral.isNotifying(characteristic)) {
|
||||||
Timber.d(String.format("SUCCESS: Notify set for %s", characteristic.getUuid()));
|
Timber.d(String.format("SUCCESS: Notify set for %s", characteristic.getUuid()));
|
||||||
resumeMachineState();
|
resumeMachineState();
|
||||||
@@ -433,8 +435,8 @@ public abstract class BluetoothCommunication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicWrite(BluetoothPeripheral peripheral, byte[] value, BluetoothGattCharacteristic characteristic, int status) {
|
public void onCharacteristicWrite(BluetoothPeripheral peripheral, byte[] value, BluetoothGattCharacteristic characteristic, GattStatus status) {
|
||||||
if( status == GATT_SUCCESS) {
|
if( status.value == GATT_SUCCESS) {
|
||||||
Timber.d(String.format("SUCCESS: Writing <%s> to <%s>", byteInHex(value), characteristic.getUuid().toString()));
|
Timber.d(String.format("SUCCESS: Writing <%s> to <%s>", byteInHex(value), characteristic.getUuid().toString()));
|
||||||
nextMachineStep();
|
nextMachineStep();
|
||||||
|
|
||||||
@@ -444,14 +446,14 @@ public abstract class BluetoothCommunication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicUpdate(final BluetoothPeripheral peripheral, byte[] value, final BluetoothGattCharacteristic characteristic, final int status) {
|
public void onCharacteristicUpdate(final BluetoothPeripheral peripheral, byte[] value, final BluetoothGattCharacteristic characteristic, GattStatus status) {
|
||||||
resetDisconnectTimer();
|
resetDisconnectTimer();
|
||||||
onBluetoothNotify(characteristic.getUuid(), value);
|
onBluetoothNotify(characteristic.getUuid(), value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Callback for central
|
// Callback for central
|
||||||
private final BluetoothCentralCallback bluetoothCentralCallback = new BluetoothCentralCallback() {
|
private final BluetoothCentralManagerCallback bluetoothCentralCallback = new BluetoothCentralManagerCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectedPeripheral(BluetoothPeripheral peripheral) {
|
public void onConnectedPeripheral(BluetoothPeripheral peripheral) {
|
||||||
@@ -463,18 +465,18 @@ public abstract class BluetoothCommunication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionFailed(BluetoothPeripheral peripheral, final int status) {
|
public void onConnectionFailed(BluetoothPeripheral peripheral, HciStatus status) {
|
||||||
Timber.e(String.format("connection '%s' failed with status %d", peripheral.getName(), status ));
|
Timber.e(String.format("connection '%s' failed with status %d", peripheral.getName(), status.value));
|
||||||
setBluetoothStatus(BT_STATUS.CONNECTION_LOST);
|
setBluetoothStatus(BT_STATUS.CONNECTION_LOST);
|
||||||
|
|
||||||
if (status == 8) {
|
if (status.value == 8) {
|
||||||
sendMessage(R.string.info_bluetooth_connection_error_scale_offline, 0);
|
sendMessage(R.string.info_bluetooth_connection_error_scale_offline, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnectedPeripheral(final BluetoothPeripheral peripheral, final int status) {
|
public void onDisconnectedPeripheral(final BluetoothPeripheral peripheral, HciStatus status) {
|
||||||
Timber.d(String.format("disconnected '%s' with status %d", peripheral.getName(), status));
|
Timber.d(String.format("disconnected '%s' with status %d", peripheral.getName(), status.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -534,7 +536,7 @@ public abstract class BluetoothCommunication {
|
|||||||
if (btPeripheral == null) {
|
if (btPeripheral == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (btPeripheral.getState() != BluetoothProfile.STATE_DISCONNECTED) {
|
if (btPeripheral.getState() != ConnectionState.DISCONNECTED) {
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
if (callbackBtHandler == null) {
|
if (callbackBtHandler == null) {
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
package com.health.openscale.core.bluetooth;
|
package com.health.openscale.core.bluetooth;
|
||||||
|
|
||||||
|
import android.bluetooth.le.ScanFilter;
|
||||||
import android.bluetooth.le.ScanResult;
|
import android.bluetooth.le.ScanResult;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.bluetooth.le.ScanFilter;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
import com.welie.blessed.BluetoothCentral;
|
import com.welie.blessed.BluetoothCentralManager;
|
||||||
import com.welie.blessed.BluetoothCentralCallback;
|
import com.welie.blessed.BluetoothCentralManagerCallback;
|
||||||
import com.welie.blessed.BluetoothPeripheral;
|
import com.welie.blessed.BluetoothPeripheral;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -28,8 +28,8 @@ public class BluetoothOKOK extends BluetoothCommunication {
|
|||||||
private static final int IDX_IMPEDANCE_LSB = 11;
|
private static final int IDX_IMPEDANCE_LSB = 11;
|
||||||
private static final int IDX_CHECKSUM = 12;
|
private static final int IDX_CHECKSUM = 12;
|
||||||
|
|
||||||
private BluetoothCentral central;
|
private BluetoothCentralManager central;
|
||||||
private final BluetoothCentralCallback btCallback = new BluetoothCentralCallback() {
|
private final BluetoothCentralManagerCallback btCallback = new BluetoothCentralManagerCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDiscoveredPeripheral(@NotNull BluetoothPeripheral peripheral, @NotNull ScanResult scanResult) {
|
public void onDiscoveredPeripheral(@NotNull BluetoothPeripheral peripheral, @NotNull ScanResult scanResult) {
|
||||||
SparseArray<byte[]> manufacturerSpecificData = scanResult.getScanRecord().getManufacturerSpecificData();
|
SparseArray<byte[]> manufacturerSpecificData = scanResult.getScanRecord().getManufacturerSpecificData();
|
||||||
@@ -63,7 +63,7 @@ public class BluetoothOKOK extends BluetoothCommunication {
|
|||||||
public BluetoothOKOK(Context context)
|
public BluetoothOKOK(Context context)
|
||||||
{
|
{
|
||||||
super(context);
|
super(context);
|
||||||
central = new BluetoothCentral(context, btCallback, new Handler(Looper.getMainLooper()));
|
central = new BluetoothCentralManager(context, btCallback, new Handler(Looper.getMainLooper()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -57,8 +57,8 @@ import com.health.openscale.core.bluetooth.BluetoothCommunication;
|
|||||||
import com.health.openscale.core.bluetooth.BluetoothFactory;
|
import com.health.openscale.core.bluetooth.BluetoothFactory;
|
||||||
import com.health.openscale.gui.utils.ColorUtil;
|
import com.health.openscale.gui.utils.ColorUtil;
|
||||||
import com.health.openscale.gui.utils.PermissionHelper;
|
import com.health.openscale.gui.utils.PermissionHelper;
|
||||||
import com.welie.blessed.BluetoothCentral;
|
import com.welie.blessed.BluetoothCentralManager;
|
||||||
import com.welie.blessed.BluetoothCentralCallback;
|
import com.welie.blessed.BluetoothCentralManagerCallback;
|
||||||
import com.welie.blessed.BluetoothPeripheral;
|
import com.welie.blessed.BluetoothPeripheral;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -76,7 +76,7 @@ public class BluetoothSettingsFragment extends Fragment {
|
|||||||
private TextView txtSearching;
|
private TextView txtSearching;
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
private Handler progressHandler;
|
private Handler progressHandler;
|
||||||
private BluetoothCentral central;
|
private BluetoothCentralManager central;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
@@ -123,7 +123,7 @@ public class BluetoothSettingsFragment extends Fragment {
|
|||||||
return formatDeviceName(device.getName(), device.getAddress());
|
return formatDeviceName(device.getName(), device.getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final BluetoothCentralCallback bluetoothCentralCallback = new BluetoothCentralCallback() {
|
private final BluetoothCentralManagerCallback bluetoothCentralCallback = new BluetoothCentralManagerCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDiscoveredPeripheral(BluetoothPeripheral peripheral, ScanResult scanResult) {
|
public void onDiscoveredPeripheral(BluetoothPeripheral peripheral, ScanResult scanResult) {
|
||||||
new Handler().post(new Runnable() {
|
new Handler().post(new Runnable() {
|
||||||
@@ -139,7 +139,7 @@ public class BluetoothSettingsFragment extends Fragment {
|
|||||||
deviceListView.removeAllViews();
|
deviceListView.removeAllViews();
|
||||||
foundDevices.clear();
|
foundDevices.clear();
|
||||||
|
|
||||||
central = new BluetoothCentral(requireContext(), bluetoothCentralCallback, new Handler(Looper.getMainLooper()));
|
central = new BluetoothCentralManager(requireContext(), bluetoothCentralCallback, new Handler(Looper.getMainLooper()));
|
||||||
central.scanForPeripherals();
|
central.scanForPeripherals();
|
||||||
|
|
||||||
txtSearching.setVisibility(View.VISIBLE);
|
txtSearching.setVisibility(View.VISIBLE);
|
||||||
|
Reference in New Issue
Block a user