1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-26 09:44:31 +02:00

first version of Bluetooth Hesley scale

This commit is contained in:
OliE
2018-01-21 13:25:44 +01:00
parent 09b3069268
commit 31746396fb
2 changed files with 115 additions and 1 deletions

View File

@@ -39,7 +39,9 @@ public abstract class BluetoothCommunication {
} }
public enum BT_MACHINE_STATE {BT_INIT_STATE, BT_CMD_STATE, BT_CLEANUP_STATE} public enum BT_MACHINE_STATE {BT_INIT_STATE, BT_CMD_STATE, BT_CLEANUP_STATE}
public enum BT_DEVICE_ID {CUSTOM_OPENSCALE, MI_SCALE_V1, MI_SCALE_V2, SANITAS_SBF70, MEDISANA_BS444, DIGOO_DGS038H, EXCELVANT_CF369BLE, YUNMAI_MINI, YUNMAI_SE, MGB, EXINGTECH_Y1, BEURER_BF700_800} public enum BT_DEVICE_ID {CUSTOM_OPENSCALE, MI_SCALE_V1, MI_SCALE_V2,
SANITAS_SBF70, MEDISANA_BS444, DIGOO_DGS038H, EXCELVANT_CF369BLE,
YUNMAI_MINI, YUNMAI_SE, MGB, EXINGTECH_Y1, BEURER_BF700_800, HESLEY}
protected Context context; protected Context context;
@@ -102,6 +104,8 @@ public abstract class BluetoothCommunication {
return new BluetoothExingtechY1(context); return new BluetoothExingtechY1(context);
case BEURER_BF700_800: case BEURER_BF700_800:
return new BluetoothBeurerBF700_800(context); return new BluetoothBeurerBF700_800(context);
case HESLEY:
return new BluetoothHesley(context);
} }
return null; return null;

View File

@@ -0,0 +1,110 @@
/* Copyright (C) 2018 olie.xdev <olie.xdev@googlemail.com>
*
* 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 android.widget.Toast;
import com.health.openscale.core.datatypes.ScaleMeasurement;
import java.util.Date;
import java.util.UUID;
public class BluetoothHesley extends BluetoothCommunication {
private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb");
private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff4-0000-1000-8000-00805f9b34fb"); // read, notify
private final UUID CMD_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"); // write only
private final UUID WEIGHT_MEASUREMENT_CONFIG = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
public BluetoothHesley(Context context) {
super(context);
}
@Override
public String deviceName() {
return "Hesley scale";
}
@Override
public String defaultDeviceName() {
return "YunChen";
}
@Override
boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
break;
case 1:
byte[] magicBytes = {(byte)0xa5, (byte)0x01, (byte)0x2c, (byte)0xab, (byte)0x50, (byte)0x5a, (byte)0x29};
writeBytes(WEIGHT_MEASUREMENT_SERVICE, CMD_MEASUREMENT_CHARACTERISTIC, magicBytes);
default:
return false;
}
return true;
}
@Override
boolean nextBluetoothCmd(int stateNr) {
return false;
}
@Override
boolean nextCleanUpCmd(int stateNr) {
return false;
}
@Override
public void onBluetoothDataChange(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic) {
final byte[] data = gattCharacteristic.getValue();
Toast.makeText(context, "Log Data: " + byteInHex(data), Toast.LENGTH_LONG).show();
if (data != null && data.length > 0) {
// if data is valid data
if (data[1] == (byte)0x01 && data.length == 20) {
parseBytes(data);
}
}
}
private void parseBytes(byte[] weightBytes) {
int bodyage = (int)(weightBytes[17]); // 10 ~ 99
float weight = (float) (((weightBytes[2] & 0xFF) << 8) | (weightBytes[3] & 0xFF)) / 100.0f; // kg
float fat = (float)(((weightBytes[4] & 0xFF) << 8) | (weightBytes[5] & 0xFF)) / 10.0f; // %
float water = (float)(((weightBytes[8] & 0xFF) << 8) | (weightBytes[9] & 0xFF)) / 10.0f; // %
float muscle = (float)(((weightBytes[10] & 0xFF) << 8) | (weightBytes[11] & 0xFF)) / 10.0f; // %
float bone = (float)(((weightBytes[12] & 0xFF) << 8) | (weightBytes[13] & 0xFF)) / 10.0f; // %
float calorie = (float)(((weightBytes[14] & 0xFF) << 8) | (weightBytes[15] & 0xFF)); // kcal
ScaleMeasurement scaleBtData = new ScaleMeasurement();
scaleBtData.setWeight(weight);
scaleBtData.setFat(fat);
scaleBtData.setMuscle(muscle);
scaleBtData.setWater(water);
scaleBtData.setBone(bone);
scaleBtData.setDateTime(new Date());
addScaleData(scaleBtData);
}
}