diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java index 74f58095..bf85e6c2 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java @@ -20,18 +20,21 @@ import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; import android.content.Context; +import com.health.openscale.core.OpenScale; import com.health.openscale.core.datatypes.ScaleMeasurement; +import com.health.openscale.core.datatypes.ScaleUser; import com.health.openscale.core.utils.Converters; import java.util.UUID; +import timber.log.Timber; + public class BluetoothOneByone extends BluetoothCommunication { private final UUID WEIGHT_MEASUREMENT_SERVICE_BODY_COMPOSITION = UUID.fromString("0000181B-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC_BODY_COMPOSITION = UUID.fromString("00002A9C-0000-1000-8000-00805f9b34fb"); // read, indication private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"); private final UUID CMD_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"); // write only - private final UUID CMD_MEASUREMENT_CUSTOM_CHARACTERISTIC = UUID.fromString("0000fff4-0000-1000-8000-00805f9b34fb"); // notify only private final UUID WEIGHT_MEASUREMENT_CONFIG = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); public BluetoothOneByone(Context context) { @@ -50,7 +53,20 @@ public class BluetoothOneByone extends BluetoothCommunication { setIndicationOn(WEIGHT_MEASUREMENT_SERVICE_BODY_COMPOSITION, WEIGHT_MEASUREMENT_CHARACTERISTIC_BODY_COMPOSITION, WEIGHT_MEASUREMENT_CONFIG); break; case 1: - byte[] magicBytes = {(byte)0xfd,(byte)0x37,(byte)0x01,(byte)0x01,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00}; + ScaleUser currentUser = OpenScale.getInstance().getSelectedScaleUser(); + byte unit = 0x00; // kg + switch (currentUser.getScaleUnit()) { + case LB: + unit = 0x01; + break; + case ST: + unit = 0x02; + break; + } + byte group = 0x01; + byte[] magicBytes = {(byte)0xfd, (byte)0x37, unit, group, + (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, + (byte)0x00, (byte)0x00, (byte)0x00}; magicBytes[magicBytes.length - 1] = xorChecksum(magicBytes, 0, magicBytes.length - 1); writeBytes(WEIGHT_MEASUREMENT_SERVICE, CMD_MEASUREMENT_CHARACTERISTIC, magicBytes); @@ -84,6 +100,9 @@ public class BluetoothOneByone extends BluetoothCommunication { private void parseBytes(byte[] weightBytes) { float weight = Converters.fromUnsignedInt16Le(weightBytes, 11) / 100.0f; + int impedance = Converters.fromUnsignedInt24Le(weightBytes, 15); + + Timber.d("weight: %.2f, impedance: %d", weight, impedance); ScaleMeasurement scaleBtData = new ScaleMeasurement();