diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothFactory.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothFactory.java index 73f51be5..7c6b2797 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothFactory.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothFactory.java @@ -86,6 +86,9 @@ public class BluetoothFactory { // Trisa Body Analyze 4.0, aka Transtek GBF-1257-B return new BluetoothTrisaBodyAnalyze(context); } + if (deviceName.equals("000FatScale01")) { + return new BluetoothInlife(context); + } return null; } } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothInlife.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothInlife.java new file mode 100644 index 00000000..2dcdcc5b --- /dev/null +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothInlife.java @@ -0,0 +1,93 @@ +/* Copyright (C) 2018 Erik Johansson + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package com.health.openscale.core.bluetooth; + +import android.bluetooth.BluetoothGatt; +import android.bluetooth.BluetoothGattCharacteristic; +import android.content.Context; + +import com.health.openscale.core.datatypes.ScaleMeasurement; +import com.health.openscale.core.utils.Converters; + +import java.util.UUID; + +import timber.log.Timber; + +public class BluetoothInlife extends BluetoothCommunication { + private final UUID WEIGHT_SERVICE = BluetoothGattUuid.fromShortCode(0xfff0); + private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff1); + private final UUID WEIGHT_CMD_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff2); + + public BluetoothInlife(Context context) { + super(context); + } + + @Override + public String driverName() { + return "Inlinfe"; + } + + @Override + protected boolean nextInitCmd(int stateNr) { + switch (stateNr) { + case 0: + setNotificationOn(WEIGHT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, + BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); + break; + default: + return false; + } + + return true; + } + + @Override + protected boolean nextBluetoothCmd(int stateNr) { + return false; + } + + @Override + protected boolean nextCleanUpCmd(int stateNr) { + return false; + } + + @Override + public void onBluetoothDataChange(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic) { + final byte[] data = gattCharacteristic.getValue(); + + if (data == null || data.length != 14) { + return; + } + + if (data[0] != (byte)0x02 || data[data.length - 1] != (byte)0xaa) { + Timber.d("Wrong start or end byte"); + return; + } + + if (data[1] != (byte)0xdd) { + Timber.d("Measurement not done yet"); + return; + } + + float weight = Converters.fromUnsignedInt16Be(data, 2) / 10.0f; + + ScaleMeasurement measurement = new ScaleMeasurement(); + measurement.setWeight(weight); + + addScaleData(measurement); + } +}