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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user