1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-18 22:41:44 +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 final UUID CMD_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff2); // write only
private boolean scaleGotUserData; private boolean scaleGotUserData;
long firstFixWeight = -1 ;
private byte WeightFatMus = 0; private byte WeightFatMus = 0;
private ScaleMeasurement measurement; private ScaleMeasurement measurement;
@@ -49,14 +48,29 @@ public class BluetoothSenssun extends BluetoothCommunication {
return "Senssun"; return "Senssun";
} }
@Override
public void disconnect(boolean doCleanup) {
Timber.i("disconnect(and save Data - %s)", doCleanup);
saveUserData();
super.disconnect(doCleanup);
}
@Override @Override
protected boolean doScanWhileConnecting() { protected boolean doScanWhileConnecting() {
// Senssun seems to have problem connecting if scan is running (see ##309) // Senssun seems to have problem connecting if scan is running (see ##309)
return false; return false;
} }
private void sendUserData() { private void saveUserData(){
if (scaleGotUserData) { if ( isBitSet(WeightFatMus,2) ) {
addScaleData(measurement);
WeightFatMus=0;
setBtStatus(BT_STATUS_CODE.BT_CONNECTION_LOST);
}
}
private void sendUserData(){
if ( scaleGotUserData ){
return; return;
} }
final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser(); final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser();
@@ -84,7 +98,6 @@ public class BluetoothSenssun extends BluetoothCommunication {
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC,
BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
sendUserData(); sendUserData();
firstFixWeight = -1;
WeightFatMus = 0; WeightFatMus = 0;
scaleGotUserData = false; scaleGotUserData = false;
break; break;
@@ -114,13 +127,8 @@ public class BluetoothSenssun extends BluetoothCommunication {
if (data != null && !isBitSet(WeightFatMus, 3)) { //only if not saved if (data != null && !isBitSet(WeightFatMus, 3)) { //only if not saved
parseBytes(data); parseBytes(data);
Timber.d("WFM %02X %d ", WeightFatMus, (System.currentTimeMillis() - firstFixWeight)); if (WeightFatMus == 0x07) {
if (isBitSet(WeightFatMus, 2) && firstFixWeight > 0) { disconnect(true);
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;
}
} }
} }
} }
@@ -144,9 +152,9 @@ public class BluetoothSenssun extends BluetoothCommunication {
float weight = Converters.fromUnsignedInt16Be(weightBytes, 2) / 10.0f; // kg float weight = Converters.fromUnsignedInt16Be(weightBytes, 2) / 10.0f; // kg
measurement.setWeight(weight); measurement.setWeight(weight);
if (!isBitSet(WeightFatMus, 2)) { if (!isBitSet(WeightFatMus,2)){
WeightFatMus |= 1 << 2 ; WeightFatMus |= 1 << 2 ;
firstFixWeight = System.currentTimeMillis() ;
} }
sendUserData(); sendUserData();