1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-29 11:10:35 +02:00

Add support for setting scale unit on 1byone scale

Also parse out impedance value. Unfortunately the scale does not
provide fat, bone etc. directly. It is instead calculated by the app.

Issue #159
This commit is contained in:
Erik Johansson
2018-04-24 23:07:00 +02:00
parent b9c76a48b4
commit 0447fc2c31

View File

@@ -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();