mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-13 20:24:14 +02:00
Merge branch 'refs/heads/MY4836'
# Conflicts: # android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothFactory.java # android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOKOK2.java # android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package com.health.openscale.core.bluetooth;
|
package com.health.openscale.core.bluetooth;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -118,7 +119,7 @@ public class BluetoothFactory {
|
|||||||
if (deviceName.equals("ADV") || deviceName.equals("Chipsea-BLE")) {
|
if (deviceName.equals("ADV") || deviceName.equals("Chipsea-BLE")) {
|
||||||
return new BluetoothOKOK(context);
|
return new BluetoothOKOK(context);
|
||||||
}
|
}
|
||||||
if (deviceName.isEmpty()) {
|
if (deviceName.equals("NoName OkOk")) {
|
||||||
return new BluetoothOKOK2(context);
|
return new BluetoothOKOK2(context);
|
||||||
}
|
}
|
||||||
if (deviceName.equals("BF105") || deviceName.equals("BF720")) {
|
if (deviceName.equals("BF105") || deviceName.equals("BF720")) {
|
||||||
@@ -153,4 +154,11 @@ public class BluetoothFactory {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String convertNoNameToDeviceName(SparseArray<byte[]> manufacturerSpecificData) {
|
||||||
|
String deviceName = null;
|
||||||
|
deviceName = BluetoothOKOK2.convertNoNameToDeviceName(manufacturerSpecificData);
|
||||||
|
|
||||||
|
return deviceName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.health.openscale.core.bluetooth;
|
package com.health.openscale.core.bluetooth;
|
||||||
|
|
||||||
|
import static com.health.openscale.core.utils.Converters.WeightUnit.LB;
|
||||||
|
import static com.health.openscale.core.utils.Converters.WeightUnit.ST;
|
||||||
|
|
||||||
import android.bluetooth.le.ScanFilter;
|
import android.bluetooth.le.ScanFilter;
|
||||||
import android.bluetooth.le.ScanResult;
|
import android.bluetooth.le.ScanResult;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -35,9 +38,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
import static com.health.openscale.core.utils.Converters.WeightUnit.LB;
|
|
||||||
import static com.health.openscale.core.utils.Converters.WeightUnit.ST;
|
|
||||||
|
|
||||||
public class BluetoothOKOK2 extends BluetoothCommunication {
|
public class BluetoothOKOK2 extends BluetoothCommunication {
|
||||||
private static final int IDX_WEIGHT_MSB = 0;
|
private static final int IDX_WEIGHT_MSB = 0;
|
||||||
private static final int IDX_WEIGHT_LSB = 1;
|
private static final int IDX_WEIGHT_LSB = 1;
|
||||||
@@ -66,6 +66,21 @@ public class BluetoothOKOK2 extends BluetoothCommunication {
|
|||||||
central = new BluetoothCentralManager(context, btCallback, new Handler(Looper.getMainLooper()));
|
central = new BluetoothCentralManager(context, btCallback, new Handler(Looper.getMainLooper()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String convertNoNameToDeviceName(SparseArray<byte[]> manufacturerSpecificData) {
|
||||||
|
int vendorIndex = -1;
|
||||||
|
for (int i = 0; i < manufacturerSpecificData.size(); i++) {
|
||||||
|
int vendorId = manufacturerSpecificData.keyAt(i);
|
||||||
|
if ((vendorId & 0xff) == 0xc0) { // 0x00c0-->0xffc0
|
||||||
|
vendorIndex = vendorId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vendorIndex == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "NoName OkOk";
|
||||||
|
}
|
||||||
|
|
||||||
private final BluetoothCentralManagerCallback btCallback = new BluetoothCentralManagerCallback() {
|
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) {
|
||||||
@@ -157,8 +172,6 @@ public class BluetoothOKOK2 extends BluetoothCommunication {
|
|||||||
byte[] mask = new byte[13];
|
byte[] mask = new byte[13];
|
||||||
mask[IDX_MAC_1] = mask[IDX_MAC_2] = mask[IDX_MAC_3] = mask[IDX_MAC_4] = mask[IDX_MAC_5] = mask[IDX_MAC_6] = (byte) 0xff;
|
mask[IDX_MAC_1] = mask[IDX_MAC_2] = mask[IDX_MAC_3] = mask[IDX_MAC_4] = mask[IDX_MAC_5] = mask[IDX_MAC_6] = (byte) 0xff;
|
||||||
|
|
||||||
// TODO: verify setAdvertisingDataTypeWithData on API33+
|
|
||||||
// b.setAdvertisingDataTypeWithData(ScanRecord.DATA_TYPE_MANUFACTURER_SPECIFIC_DATA, data, mask);
|
|
||||||
for (int i = 0x00; i <= 0xff; i++) {
|
for (int i = 0x00; i <= 0xff; i++) {
|
||||||
ScanFilter.Builder b = new ScanFilter.Builder();
|
ScanFilter.Builder b = new ScanFilter.Builder();
|
||||||
b.setDeviceAddress(macAddress);
|
b.setDeviceAddress(macAddress);
|
||||||
|
@@ -322,11 +322,19 @@ public class BluetoothSettingsFragment extends Fragment {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BluetoothDeviceView deviceView = new BluetoothDeviceView(context);
|
String deviceName = device.getName();
|
||||||
deviceView.setDeviceName(formatDeviceName(bleScanResult.getDevice()));
|
if (deviceName == null) {
|
||||||
|
deviceName = BluetoothFactory.convertNoNameToDeviceName(bleScanResult.getScanRecord().getManufacturerSpecificData());
|
||||||
|
}
|
||||||
|
if (deviceName == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String name = device.getName() != null ? device.getName() : "";
|
BluetoothDeviceView deviceView = new BluetoothDeviceView(context);
|
||||||
BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(context, name);
|
deviceView.setDeviceName(formatDeviceName(deviceName, device.getAddress()));
|
||||||
|
deviceView.setAlias(deviceName);
|
||||||
|
|
||||||
|
BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(context, deviceName);
|
||||||
if (btDevice != null) {
|
if (btDevice != null) {
|
||||||
Timber.d("Found supported device %s (driver: %s)",
|
Timber.d("Found supported device %s (driver: %s)",
|
||||||
formatDeviceName(device), btDevice.driverName());
|
formatDeviceName(device), btDevice.driverName());
|
||||||
@@ -394,6 +402,7 @@ public class BluetoothSettingsFragment extends Fragment {
|
|||||||
private TextView deviceName;
|
private TextView deviceName;
|
||||||
private ImageView deviceIcon;
|
private ImageView deviceIcon;
|
||||||
private String deviceAddress;
|
private String deviceAddress;
|
||||||
|
private String deviceAlias;
|
||||||
|
|
||||||
public BluetoothDeviceView(Context context) {
|
public BluetoothDeviceView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -423,6 +432,14 @@ public class BluetoothSettingsFragment extends Fragment {
|
|||||||
addView(deviceName);
|
addView(deviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAlias(String alias) {
|
||||||
|
deviceAlias = alias;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAlias() {
|
||||||
|
return deviceAlias;
|
||||||
|
}
|
||||||
|
|
||||||
public void setDeviceAddress(String address) {
|
public void setDeviceAddress(String address) {
|
||||||
deviceAddress = address;
|
deviceAddress = address;
|
||||||
}
|
}
|
||||||
@@ -481,10 +498,10 @@ public class BluetoothSettingsFragment extends Fragment {
|
|||||||
|
|
||||||
prefs.edit()
|
prefs.edit()
|
||||||
.putString(PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, device.getAddress())
|
.putString(PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, device.getAddress())
|
||||||
.putString(PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME, device.getName())
|
.putString(PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME, getAlias())
|
||||||
.apply();
|
.apply();
|
||||||
|
|
||||||
Timber.d("Saved Bluetooth device " + device.getName() + " with address " + device.getAddress());
|
Timber.d("Saved Bluetooth device " + getAlias() + " with address " + device.getAddress());
|
||||||
|
|
||||||
stopBluetoothDiscovery();
|
stopBluetoothDiscovery();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user