1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-18 22:41:44 +02:00

Skeleton for inlife scale (#352)

This commit is contained in:
Erik Johansson
2018-11-20 11:06:08 +01:00
parent 9767ec2309
commit 967d720478
2 changed files with 96 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -0,0 +1,93 @@
/* Copyright (C) 2018 Erik Johansson <erik@ejohansson.se>
*
* 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 <http://www.gnu.org/licenses/>
*/
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);
}
}