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

Merge pull request #359 from gmarco/master

changed saving issue if scale does only scan weigth and then shut down
This commit is contained in:
OliE
2018-12-17 09:03:00 +01:00
committed by GitHub

View File

@@ -36,7 +36,6 @@ public class BluetoothSenssun extends BluetoothCommunication {
private final UUID CMD_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff2); // write only
private boolean scaleGotUserData;
long firstFixWeight = -1 ;
private byte WeightFatMus = 0;
private ScaleMeasurement measurement;
@@ -49,12 +48,27 @@ public class BluetoothSenssun extends BluetoothCommunication {
return "Senssun";
}
@Override
public void disconnect(boolean doCleanup) {
Timber.i("disconnect(and save Data - %s)", doCleanup);
saveUserData();
super.disconnect(doCleanup);
}
@Override
protected boolean doScanWhileConnecting() {
// Senssun seems to have problem connecting if scan is running (see ##309)
return false;
}
private void saveUserData(){
if ( isBitSet(WeightFatMus,2) ) {
addScaleData(measurement);
WeightFatMus=0;
setBtStatus(BT_STATUS_CODE.BT_CONNECTION_LOST);
}
}
private void sendUserData(){
if ( scaleGotUserData ){
return;
@@ -84,7 +98,6 @@ public class BluetoothSenssun extends BluetoothCommunication {
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC,
BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
sendUserData();
firstFixWeight = -1;
WeightFatMus = 0;
scaleGotUserData = false;
break;
@@ -114,13 +127,8 @@ public class BluetoothSenssun extends BluetoothCommunication {
if (data != null && !isBitSet(WeightFatMus, 3)) { //only if not saved
parseBytes(data);
Timber.d("WFM %02X %d ", WeightFatMus, (System.currentTimeMillis() - firstFixWeight));
if (isBitSet(WeightFatMus, 2) && firstFixWeight > 0) {
if (((System.currentTimeMillis() - firstFixWeight) > 2500 && WeightFatMus == (1 << 2)) //wait 1.5 seconds for Data
|| WeightFatMus == 0x07) { // got all Data to save
addScaleData(measurement);
WeightFatMus |= 1 << 3;
}
if (WeightFatMus == 0x07) {
disconnect(true);
}
}
}
@@ -146,7 +154,7 @@ public class BluetoothSenssun extends BluetoothCommunication {
if (!isBitSet(WeightFatMus,2)){
WeightFatMus |= 1 << 2 ;
firstFixWeight = System.currentTimeMillis() ;
}
sendUserData();