1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-20 07:21:40 +02:00

fix bluetooth mi scale bug if no device is in range

This commit is contained in:
OliE
2017-03-16 17:03:10 +01:00
parent 015ce484d6
commit 3c64530ed8
5 changed files with 17 additions and 14 deletions

View File

@@ -8,7 +8,7 @@ android {
applicationId "com.health.openscale" applicationId "com.health.openscale"
minSdkVersion 18 minSdkVersion 18
targetSdkVersion 22 // don't set target sdk > 22 otherwise bluetooth le discovery need permission to ACCESS_COARSE_LOCATION targetSdkVersion 22 // don't set target sdk > 22 otherwise bluetooth le discovery need permission to ACCESS_COARSE_LOCATION
versionCode 11 versionCode 12
versionName "1.4.3" versionName "1.4.3"
} }

View File

@@ -67,21 +67,22 @@ public class BluetoothMiScale extends BluetoothCommunication {
scanCallback = new BluetoothAdapter.LeScanCallback() scanCallback = new BluetoothAdapter.LeScanCallback()
{ {
@Override @Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
{ if (device.getAddress().replace(":", "").toUpperCase().startsWith("880F10") ||
if (device.getName().equals(btDeviceName)) { device.getAddress().replace(":", "").toUpperCase().startsWith("C80F10") ) // Xiaomi
Log.d("BluetoothMiScale", "Mi Scale found trying to connect..."); {
if (device.getName().equals(btDeviceName)) {
Log.d("BluetoothMiScale", "Mi Scale found trying to connect...");
if (scanRecord.length > 30) {
final byte[] weightData = Arrays.copyOfRange(scanRecord, 21, 31); final byte[] weightData = Arrays.copyOfRange(scanRecord, 21, 31);
weightData[0] = 0x62; // Set weight remove to false to come through parse bytes weightData[0] = 0x62; // Set weight remove to false to come through parse bytes
parseBytes(weightData); parseBytes(weightData);
bluetoothGatt = device.connectGatt(context, false, gattCallback);
searchHandler.removeCallbacksAndMessages(null);
btAdapter.stopLeScan(scanCallback);
} }
bluetoothGatt = device.connectGatt(context, false, gattCallback);
searchHandler.removeCallbacksAndMessages(null);
btAdapter.stopLeScan(scanCallback);
} }
} }
}; };

View File

@@ -88,7 +88,8 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_weight="90" android:layout_weight="90"
android:stretchColumns="1"> android:stretchColumns="1"
android:id="@+id/tableLayoutMeasurements">
<TableRow <TableRow
android:layout_width="fill_parent" android:layout_width="fill_parent"

View File

@@ -79,7 +79,8 @@
<TableLayout <TableLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:stretchColumns="1"> android:stretchColumns="1"
android:id="@+id/tableLayoutMeasurements">
<TableRow <TableRow
android:layout_width="fill_parent" android:layout_width="fill_parent"

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation"> <resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<string-array name="bt_device_entries"> <string-array name="bt_device_entries">
<item>Xiaomi Mi Scale</item> <item>Xiaomi Mi Scale v1</item>
<item>openScale Custom Scale</item> <item>openScale Custom Scale</item>
</string-array> </string-array>