1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-17 14:10:54 +02:00

fixed Mi scale v1 bug with RxAndroidBle library

This commit is contained in:
oliexdev
2019-01-27 17:41:45 +01:00
parent 2fe3be9e43
commit d5ba8b5bd8
2 changed files with 11 additions and 34 deletions

View File

@@ -305,7 +305,7 @@ public abstract class BluetoothCommunication {
/** /**
* Read bytes from a Bluetooth device. * Read bytes from a Bluetooth device.
* *
* @note onBluetoothRead() will be triggered if read command was successful. * @note onBluetoothRead() will be triggered if read command was successful. nextMachineStep() needs to manually called!
*@param characteristic the Bluetooth UUID characteristic *@param characteristic the Bluetooth UUID characteristic
*/ */
protected void readBytes(UUID characteristic) { protected void readBytes(UUID characteristic) {

View File

@@ -24,7 +24,6 @@ import com.health.openscale.core.OpenScale;
import com.health.openscale.core.datatypes.ScaleMeasurement; import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser; import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.Converters; import com.health.openscale.core.utils.Converters;
import com.polidea.rxandroidble2.RxBleClient;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@@ -65,6 +64,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
setBtMachineState(BT_MACHINE_STATE.BT_CMD_STATE); setBtMachineState(BT_MACHINE_STATE.BT_CMD_STATE);
} else { } else {
Timber.d("Current year and scale year is different"); Timber.d("Current year and scale year is different");
nextMachineStateStep();
} }
} }
@@ -99,8 +99,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
switch (stateNr) { switch (stateNr) {
case 0: case 0:
// read device time // read device time
readBytes( readBytes(BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME);
BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME);
break; break;
case 1: case 1:
// set current time // set current time
@@ -114,21 +113,13 @@ public class BluetoothMiScale extends BluetoothCommunication {
byte[] dateTimeByte = {(byte)(year), (byte)(year >> 8), month, day, hour, min, sec, 0x03, 0x00, 0x00}; byte[] dateTimeByte = {(byte)(year), (byte)(year >> 8), month, day, hour, min, sec, 0x03, 0x00, 0x00};
writeBytes( writeBytes(BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME, dateTimeByte);
BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME, dateTimeByte);
break; break;
case 2: case 2:
// set notification on for weight measurement history
setNotificationOn(
WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC
);
break;
case 3:
// Set on history weight measurement // Set on history weight measurement
byte[] magicBytes = new byte[]{(byte)0x01, (byte)0x96, (byte)0x8a, (byte)0xbd, (byte)0x62}; byte[] magicBytes = new byte[]{(byte)0x01, (byte)0x96, (byte)0x8a, (byte)0xbd, (byte)0x62};
writeBytes( writeBytes(WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, magicBytes);
WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, magicBytes);
break; break;
default: default:
return false; return false;
@@ -142,34 +133,22 @@ public class BluetoothMiScale extends BluetoothCommunication {
switch (stateNr) { switch (stateNr) {
case 0: case 0:
// set notification on for weight measurement history // set notification on for weight measurement history
setNotificationOn( setNotificationOn(WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC);
WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC
);
break; break;
case 1: case 1:
// set notification on for weight measurement // set notification on for weight measurement
setNotificationOn( setNotificationOn(BluetoothGattUuid.CHARACTERISTIC_WEIGHT_MEASUREMENT);
BluetoothGattUuid.CHARACTERISTIC_WEIGHT_MEASUREMENT
);
break; break;
case 2: case 2:
// configure scale to get only last measurements // configure scale to get only last measurements
int uniqueNumber = getUniqueNumber(); int uniqueNumber = getUniqueNumber();
byte[] userIdentifier = new byte[]{(byte)0x01, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)}; byte[] userIdentifier = new byte[]{(byte)0x01, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)};
writeBytes( writeBytes(WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier);
WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier);
break; break;
case 3: case 3:
// set notification on for weight measurement history
setNotificationOn(
WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC
);
break;
case 4:
// invoke receiving history data // invoke receiving history data
writeBytes( writeBytes(WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x02});
WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x02});
break; break;
default: default:
return false; return false;
@@ -184,16 +163,14 @@ public class BluetoothMiScale extends BluetoothCommunication {
switch (stateNr) { switch (stateNr) {
case 0: case 0:
// send stop command to mi scale // send stop command to mi scale
writeBytes( writeBytes(WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x03});
WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x03});
break; break;
case 1: case 1:
// acknowledge that you received the last history data // acknowledge that you received the last history data
int uniqueNumber = getUniqueNumber(); int uniqueNumber = getUniqueNumber();
byte[] userIdentifier = new byte[]{(byte)0x04, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)}; byte[] userIdentifier = new byte[]{(byte)0x04, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)};
writeBytes( writeBytes(WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier);
WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier);
break; break;
default: default:
return false; return false;