From 70581f5c24497d66924639ec54a35fc0c8cbd1c1 Mon Sep 17 00:00:00 2001 From: Marco Gittler Date: Sun, 25 Nov 2018 16:01:07 +0100 Subject: [PATCH 1/5] added initial Support for Senssun --- .../core/bluetooth/BluetoothFactory.java | 3 + .../core/bluetooth/BluetoothSenssun.java | 186 ++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java 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 65feaf7b..e809c78d 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 @@ -73,6 +73,9 @@ public class BluetoothFactory { if (name.equals("Health Scale".toLowerCase(Locale.US))) { return new BluetoothOneByone(context); } + if (name.equals("SENSSUN FAT".toLowerCase(Locale.US))) { + return new BluetoothSenssun(context); + } if (name.startsWith("SANITAS SBF70".toLowerCase(Locale.US)) || name.startsWith("sbf75")) { return new BluetoothBeurerSanitas(context, BluetoothBeurerSanitas.DeviceType.SANITAS_SBF70_70); } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java new file mode 100644 index 00000000..9256bd62 --- /dev/null +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java @@ -0,0 +1,186 @@ +/* Copyright (C) 2018 Marco Gittler +* +* 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.OpenScale; +import com.health.openscale.core.datatypes.ScaleMeasurement; +import com.health.openscale.core.datatypes.ScaleUser; +import com.health.openscale.core.utils.Converters; + +import java.util.Date; +import java.util.UUID; + +import timber.log.Timber; + +public class BluetoothSenssun extends BluetoothCommunication { + private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"); + private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"); // read, notify + private final UUID CMD_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff2-0000-1000-8000-00805f9b34fb"); // write only + + + private Date lastWeighted= new Date(); + private ScaleUser user; + private int gotData; + private int FatMus=0; + private ScaleMeasurement measurement; + + public BluetoothSenssun(Context context) { + super(context); + } + + @Override + public String driverName() { + return "Senssun"; + } + + private void sendUserData(){ + final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser(); + + byte gender = selectedUser.getGender().isMale() ? (byte)0x01 : (byte)0xf1; // 00 - male; 01 - female + byte height = (byte)(((int)selectedUser.getBodyHeight()) & 0xff); // cm + byte age = (byte)(selectedUser.getAge() & 0xff); + + int userId = selectedUser.getId(); + + Timber.d("Request Saved User Measurements "); + byte cmdByte[] = {(byte)0xa5,(byte)0x10,gender,age,height,(byte)0,(byte)0x0,(byte)0x0d2,(byte)0x00}; + + byte verify = 0; + for(int i=1;i Date: Sun, 25 Nov 2018 19:03:05 +0100 Subject: [PATCH 2/5] Use BluetoothGattUuid.fromShortCode --- .../health/openscale/core/bluetooth/BluetoothSenssun.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java index 9256bd62..8aac9123 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java @@ -31,9 +31,9 @@ import java.util.UUID; import timber.log.Timber; public class BluetoothSenssun extends BluetoothCommunication { - private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"); // read, notify - private final UUID CMD_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff2-0000-1000-8000-00805f9b34fb"); // write only + private final UUID WEIGHT_MEASUREMENT_SERVICE = BluetoothGattUuid.fromShortCode(0xfff0); + private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff1); // read, notify + private final UUID CMD_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff2); // write only private Date lastWeighted= new Date(); From 197c863cfd7e558423baa7a2c1ba50081c740f0b Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 25 Nov 2018 19:03:25 +0100 Subject: [PATCH 3/5] Remove unused variables --- .../com/health/openscale/core/bluetooth/BluetoothSenssun.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java index 8aac9123..ac31872d 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java @@ -35,9 +35,6 @@ public class BluetoothSenssun extends BluetoothCommunication { private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff1); // read, notify private final UUID CMD_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff2); // write only - - private Date lastWeighted= new Date(); - private ScaleUser user; private int gotData; private int FatMus=0; private ScaleMeasurement measurement; From 00362865a30f90e7a283938265579aa907d29924 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 25 Nov 2018 19:07:36 +0100 Subject: [PATCH 4/5] Whitespace fixes --- .../core/bluetooth/BluetoothSenssun.java | 150 +++++++++--------- 1 file changed, 72 insertions(+), 78 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java index ac31872d..ea783450 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java @@ -36,7 +36,7 @@ public class BluetoothSenssun extends BluetoothCommunication { private final UUID CMD_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff2); // write only private int gotData; - private int FatMus=0; + private int FatMus = 0; private ScaleMeasurement measurement; public BluetoothSenssun(Context context) { @@ -49,23 +49,23 @@ public class BluetoothSenssun extends BluetoothCommunication { } private void sendUserData(){ - final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser(); + final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser(); - byte gender = selectedUser.getGender().isMale() ? (byte)0x01 : (byte)0xf1; // 00 - male; 01 - female - byte height = (byte)(((int)selectedUser.getBodyHeight()) & 0xff); // cm - byte age = (byte)(selectedUser.getAge() & 0xff); + byte gender = selectedUser.getGender().isMale() ? (byte)0x01 : (byte)0xf1; // 00 - male; 01 - female + byte height = (byte)(((int)selectedUser.getBodyHeight()) & 0xff); // cm + byte age = (byte)(selectedUser.getAge() & 0xff); - int userId = selectedUser.getId(); + int userId = selectedUser.getId(); - Timber.d("Request Saved User Measurements "); - byte cmdByte[] = {(byte)0xa5,(byte)0x10,gender,age,height,(byte)0,(byte)0x0,(byte)0x0d2,(byte)0x00}; + Timber.d("Request Saved User Measurements "); + byte cmdByte[] = {(byte)0xa5, (byte)0x10, gender, age, height, (byte)0, (byte)0x0, (byte)0x0d2, (byte)0x00}; - byte verify = 0; - for(int i=1;i Date: Sun, 25 Nov 2018 19:21:22 +0100 Subject: [PATCH 5/5] Minor cleanup --- .../core/bluetooth/BluetoothSenssun.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java index ea783450..3353a796 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSenssun.java @@ -51,11 +51,9 @@ public class BluetoothSenssun extends BluetoothCommunication { private void sendUserData(){ final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser(); - byte gender = selectedUser.getGender().isMale() ? (byte)0x01 : (byte)0xf1; // 00 - male; 01 - female - byte height = (byte)(((int)selectedUser.getBodyHeight()) & 0xff); // cm - byte age = (byte)(selectedUser.getAge() & 0xff); - - int userId = selectedUser.getId(); + byte gender = selectedUser.getGender().isMale() ? (byte)0x01 : (byte)0xf1; + byte height = (byte) selectedUser.getBodyHeight(); // cm + byte age = (byte) selectedUser.getAge(); Timber.d("Request Saved User Measurements "); byte cmdByte[] = {(byte)0xa5, (byte)0x10, gender, age, height, (byte)0, (byte)0x0, (byte)0x0d2, (byte)0x00}; @@ -76,13 +74,13 @@ public class BluetoothSenssun extends BluetoothCommunication { setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); sendUserData(); - gotData=0; + gotData = 0; break; case 1: - //wait for answer - break; + //wait for answer + break; default: - // Finish init if everything is done + // Finish init if everything is done return false; } return true; @@ -107,7 +105,7 @@ public class BluetoothSenssun extends BluetoothCommunication { @Override protected boolean nextCleanUpCmd(int stateNr) { - return false; + return false; } @Override @@ -120,13 +118,13 @@ public class BluetoothSenssun extends BluetoothCommunication { if (data != null) { parseBytes(data); if (measurement != null && measurement.getWeight() != 0.0 && gotData == 0) { - Timber.d("meas: %s",measurement.toString()); + Timber.d("meas: %s", measurement); addScaleData(measurement); gotData = 1; nextMachineStateStep(); } if (measurement != null && measurement.getWeight() != 0.0 && FatMus == 0x03 && gotData != 2) { - Timber.d("meas: %s",measurement.toString()); + Timber.d("meas: %s", measurement); addScaleData(measurement); gotData = 2; } @@ -137,8 +135,8 @@ public class BluetoothSenssun extends BluetoothCommunication { if (measurement == null) { measurement = new ScaleMeasurement(); } - int type = (int)weightBytes[6] & 0xff; - Timber.d("type %02X",type); + int type = weightBytes[6] & 0xff; + Timber.d("type %02X", type); switch (type) { case 0xaa: float weight = Converters.fromUnsignedInt16Be(weightBytes, 2) / 10.0f; // kg @@ -168,7 +166,6 @@ public class BluetoothSenssun extends BluetoothCommunication { case 0xe2: //date break; - default: } //measurement.setDateTime(lastWeighted);