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

add basic Yunmai Mini scale support (currently only weight and fat)

This commit is contained in:
OliE
2017-10-01 14:55:13 +02:00
parent 085c85b67f
commit c37f71939a
15 changed files with 167 additions and 3 deletions

View File

@@ -38,7 +38,7 @@ public abstract class BluetoothCommunication {
BT_CONNECTION_LOST, BT_NO_DEVICE_FOUND, BT_UNEXPECTED_ERROR, BT_SCALE_MESSAGE
};
public enum BT_MACHINE_STATE {BT_INIT_STATE, BT_CMD_STATE, BT_CLEANUP_STATE}
public enum BT_DEVICE_ID {CUSTOM_OPENSCALE, MI_SCALE_V1, SANITAS_SBF70, MEDISANA_BS444, DIGOO_DGS038H, EXCELVANT_CF369BLE}
public enum BT_DEVICE_ID {CUSTOM_OPENSCALE, MI_SCALE_V1, SANITAS_SBF70, MEDISANA_BS444, DIGOO_DGS038H, EXCELVANT_CF369BLE, YUNMAI_MINI}
protected Context context;
@@ -89,6 +89,8 @@ public abstract class BluetoothCommunication {
return new BluetoothDigooDGSO38H(context);
case EXCELVANT_CF369BLE:
return new BluetoothExcelvanCF369BLE(context);
case YUNMAI_MINI:
return new BluetoothYunmaiMini(context);
}
return null;

View File

@@ -0,0 +1,162 @@
/* Copyright (C) 2017 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.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.health.openscale.core.OpenScale;
import com.health.openscale.core.datatypes.ScaleData;
import com.health.openscale.core.datatypes.ScaleUser;
import java.util.Date;
import java.util.Random;
import java.util.UUID;
public class BluetoothYunmaiMini extends BluetoothCommunication {
private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb");
private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000ffe4-0000-1000-8000-00805f9b34fb");
private final UUID WEIGHT_CMD_SERVICE = UUID.fromString("0000ffe5-0000-1000-8000-00805f9b34fb");
private final UUID WEIGHT_CMD_CHARACTERISTIC = UUID.fromString("0000ffe9-0000-1000-8000-00805f9b34fb");
private final UUID WEIGHT_MEASUREMENT_CONFIG = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
public BluetoothYunmaiMini(Context context) {
super(context);
}
@Override
public String deviceName() {
return "Yunmai Mini";
}
@Override
public String defaultDeviceName() {
return "YUNMAI-SIGNAL-M1US";
}
@Override
public boolean checkDeviceName(String btDeviceName) {
if (btDeviceName.startsWith("YUNMAI-SIGNAL-M")) {
return true;
}
return false;
}
@Override
boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
int user_id = getUniqueNumber();
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
byte sex = selectedUser.isMale() ? (byte)0x01 : (byte)0x02;
byte display_unit = selectedUser.scale_unit == 0 ? (byte) 0x01 : (byte) 0x02;
byte[] user_add_or_query = new byte[]{(byte)0x0d, (byte)0x12, (byte)0x10, (byte)0x01, (byte)0x00, (byte) 0x00, (byte) ((user_id & 0xFF00) >> 8), (byte) ((user_id & 0xFF) >> 0), (byte)selectedUser.body_height, (byte)sex, (byte) selectedUser.getAge(), (byte) 0x55, (byte) 0x5a, (byte) 0x00, (byte)0x00, (byte) display_unit, (byte) 0x03, (byte) 0x00 };
user_add_or_query[17] = xor_checksum(user_add_or_query);
writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, user_add_or_query);
break;
case 1:
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
break;
case 2:
byte[] magic_bytes = new byte[]{(byte)0x0d, (byte)0x05, (byte)0x13, (byte)0x00, (byte)0x16};
writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, magic_bytes);
break;
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();
if (data != null && data.length > 0) {
// if finished weighting?
if (data[3] == 0x02) {
parseBytes(data);
}
}
}
private void parseBytes(byte[] weightBytes) {
long unix_timestamp = ((weightBytes[5] & 0xFF) << 24) | ((weightBytes[6] & 0xFF) << 16) | ((weightBytes[7] & 0xFF) << 8) | (weightBytes[8] & 0xFF);
Date btDate = new Date();
btDate.setTime(unix_timestamp*1000);
float weight = (float) (((weightBytes[13] & 0xFF) << 8) | (weightBytes[14] & 0xFF)) / 100.0f;
float fat = (float)(((weightBytes[17] & 0xFF) << 8) | (weightBytes[18] & 0xFF)) / 100.0f;
ScaleData scaleBtData = new ScaleData();
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
scaleBtData.setConvertedWeight(weight, selectedUser.scale_unit);
scaleBtData.setFat(fat);
scaleBtData.setDateTime(btDate);
addScaleData(scaleBtData);
}
private int getUniqueNumber() {
int uniqueNumber;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
uniqueNumber = prefs.getInt("uniqueNumber", 0x00);
if (uniqueNumber == 0x00) {
Random r = new Random();
uniqueNumber = r.nextInt(65535 - 100 + 1) + 100;
prefs.edit().putInt("uniqueNumber", uniqueNumber).commit();
}
int userId = prefs.getInt("selectedUserId", -1);
return uniqueNumber + userId;
}
private byte xor_checksum(byte[] data) {
byte checksum = 0x00;
for (int i=0; i<data.length-1; i++) {
checksum ^= data[i];
}
return checksum;
}
}

View File

@@ -105,12 +105,12 @@ public class DataEntryActivity extends Activity {
waterMeasurement = new WaterMeasurementView(context);
muscleMeasurement = new MuscleMeasurementView(context);
fatMeasurement = new FatMeasurementView(context);
boneMeasurementView = new BoneMeasurementView(context);
waistMeasurement = new WaistMeasurementView(context);
wHtRMeasurementView = new WHtRMeasurementView(context);
hipMeasurement = new HipMeasurementView(context);
whrMeasurementView = new WHRMeasurementView(context);
bmrMeasurementView = new BMRMeasurementView(context);
boneMeasurementView = new BoneMeasurementView(context);
commentMeasurement = new CommentMeasurementView(context);
dateMeasurement = new DateMeasurementView(context);
timeMeasurement = new TimeMeasurementView(context);
@@ -121,12 +121,12 @@ public class DataEntryActivity extends Activity {
dataEntryMeasurements.add(waterMeasurement);
dataEntryMeasurements.add(muscleMeasurement);
dataEntryMeasurements.add(fatMeasurement);
dataEntryMeasurements.add(boneMeasurementView);
dataEntryMeasurements.add(waistMeasurement);
dataEntryMeasurements.add(wHtRMeasurementView);
dataEntryMeasurements.add(hipMeasurement);
dataEntryMeasurements.add(whrMeasurementView);
dataEntryMeasurements.add(bmrMeasurementView);
dataEntryMeasurements.add(boneMeasurementView);
dataEntryMeasurements.add(commentMeasurement);
dataEntryMeasurements.add(dateMeasurement);
dataEntryMeasurements.add(timeMeasurement);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 795 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 405 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 405 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 524 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 804 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB