1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-20 07:21:40 +02:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate
2018-04-18 20:56:47 +02:00
14 changed files with 79 additions and 66 deletions

View File

@@ -146,7 +146,7 @@ public class BluetoothBeurerSanitas extends BluetoothCommunication {
}
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
@@ -245,7 +245,7 @@ public class BluetoothBeurerSanitas extends BluetoothCommunication {
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
switch (stateNr) {
case 0:
@@ -274,7 +274,7 @@ public class BluetoothBeurerSanitas extends BluetoothCommunication {
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
switch (stateNr) {
case 0:
// Force disconnect

View File

@@ -55,7 +55,8 @@ public abstract class BluetoothCommunication {
private Queue<BluetoothGattDescriptor> descriptorRequestQueue;
private Queue<BluetoothGattCharacteristic> characteristicRequestQueue;
private Boolean openRequest;
private boolean openRequest;
private final Object lock = new Object();
public BluetoothCommunication(Context context)
{
@@ -126,7 +127,7 @@ public abstract class BluetoothCommunication {
* @param stateNr the current step number
* @return false if no next step is available otherwise true
*/
abstract boolean nextInitCmd(int stateNr);
abstract protected boolean nextInitCmd(int stateNr);
/**
* State machine for the normal/command process of the Bluetooth device.
@@ -136,7 +137,7 @@ public abstract class BluetoothCommunication {
* @param stateNr the current step number
* @return false if no next step is available otherwise true
*/
abstract boolean nextBluetoothCmd(int stateNr);
abstract protected boolean nextBluetoothCmd(int stateNr);
/**
* Set the next command number of the current state.
@@ -165,7 +166,7 @@ public abstract class BluetoothCommunication {
* @param stateNr the current step number
* @return false if no next step is available otherwise true
*/
abstract boolean nextCleanUpCmd(int stateNr);
abstract protected boolean nextCleanUpCmd(int stateNr);
/**
* Method is triggered if a Bluetooth data is read from a device.
@@ -192,9 +193,10 @@ public abstract class BluetoothCommunication {
* @param btMachineState the machine state that should be set.
*/
protected void setBtMachineState(BT_MACHINE_STATE btMachineState) {
this.btMachineState = btMachineState;
handleRequests();
synchronized (lock) {
this.btMachineState = btMachineState;
handleRequests();
}
}
/**
@@ -209,7 +211,7 @@ public abstract class BluetoothCommunication {
.getCharacteristic(characteristic);
gattCharacteristic.setValue(bytes);
synchronized (openRequest) {
synchronized (lock) {
characteristicRequestQueue.add(gattCharacteristic);
handleRequests();
}
@@ -244,7 +246,7 @@ public abstract class BluetoothCommunication {
BluetoothGattDescriptor gattDescriptor = gattCharacteristic.getDescriptor(descriptor);
gattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
synchronized (openRequest) {
synchronized (lock) {
descriptorRequestQueue.add(gattDescriptor);
handleRequests();
}
@@ -264,7 +266,7 @@ public abstract class BluetoothCommunication {
BluetoothGattDescriptor gattDescriptor = gattCharacteristic.getDescriptor(descriptor);
gattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
synchronized (openRequest) {
synchronized (lock) {
descriptorRequestQueue.add(gattDescriptor);
handleRequests();
}
@@ -284,7 +286,7 @@ public abstract class BluetoothCommunication {
BluetoothGattDescriptor gattDescriptor = gattCharacteristic.getDescriptor(descriptor);
gattDescriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
synchronized (openRequest) {
synchronized (lock) {
descriptorRequestQueue.add(gattDescriptor);
handleRequests();
}
@@ -332,6 +334,9 @@ public abstract class BluetoothCommunication {
public void connect(String hwAddress) {
btAdapter.cancelDiscovery();
// Don't do any cleanup if disconnected before fully connected
btMachineState = BT_MACHINE_STATE.BT_CLEANUP_STATE;
BluetoothDevice device = btAdapter.getRemoteDevice(hwAddress);
bluetoothGatt = device.connectGatt(context, false, gattCallback);
}
@@ -344,9 +349,13 @@ public abstract class BluetoothCommunication {
return;
}
if (btMachineState != BT_MACHINE_STATE.BT_CLEANUP_STATE && doCleanup) {
setBtMachineState(BT_MACHINE_STATE.BT_CLEANUP_STATE);
nextMachineStateStep();
if (doCleanup) {
synchronized (lock) {
if (btMachineState != BT_MACHINE_STATE.BT_CLEANUP_STATE) {
setBtMachineState(BT_MACHINE_STATE.BT_CLEANUP_STATE);
nextMachineStateStep();
}
}
}
bluetoothGatt.disconnect();
@@ -381,7 +390,7 @@ public abstract class BluetoothCommunication {
}
private void handleRequests() {
synchronized (openRequest) {
synchronized (lock) {
// check for pending request
if (openRequest) {
return; // yes, do nothing
@@ -433,14 +442,16 @@ public abstract class BluetoothCommunication {
@Override
public void onServicesDiscovered(final BluetoothGatt gatt, int status) {
cmdStepNr = 0;
initStepNr = 0;
cleanupStepNr = 0;
synchronized (lock) {
cmdStepNr = 0;
initStepNr = 0;
cleanupStepNr = 0;
// Clear from possible previous setups
characteristicRequestQueue = new LinkedList<>();
descriptorRequestQueue = new LinkedList<>();
openRequest = false;
// Clear from possible previous setups
characteristicRequestQueue = new LinkedList<>();
descriptorRequestQueue = new LinkedList<>();
openRequest = false;
}
try {
// Sleeping a while after discovering services fixes connection problems.
@@ -460,7 +471,7 @@ public abstract class BluetoothCommunication {
public void onDescriptorWrite(BluetoothGatt gatt,
BluetoothGattDescriptor descriptor,
int status) {
synchronized (openRequest) {
synchronized (lock) {
openRequest = false;
handleRequests();
}
@@ -470,7 +481,7 @@ public abstract class BluetoothCommunication {
public void onCharacteristicWrite(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
int status) {
synchronized (openRequest) {
synchronized (lock) {
openRequest = false;
handleRequests();
}
@@ -480,8 +491,8 @@ public abstract class BluetoothCommunication {
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
int status) {
onBluetoothDataRead(gatt, characteristic, status);
synchronized (openRequest) {
synchronized (lock) {
onBluetoothDataRead(gatt, characteristic, status);
openRequest = false;
handleRequests();
}
@@ -490,7 +501,9 @@ public abstract class BluetoothCommunication {
@Override
public void onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {
onBluetoothDataChange(gatt, characteristic);
synchronized (lock) {
onBluetoothDataChange(gatt, characteristic);
}
}
}
}

View File

@@ -47,17 +47,17 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
}
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
return false;
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
return false;
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
return false;
}

View File

@@ -56,7 +56,7 @@ public class BluetoothDigooDGSO38H extends BluetoothCommunication {
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
//Tell device to send us weight measurements
@@ -68,7 +68,7 @@ public class BluetoothDigooDGSO38H extends BluetoothCommunication {
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
switch (stateNr) {
default:
return false;
@@ -76,7 +76,7 @@ public class BluetoothDigooDGSO38H extends BluetoothCommunication {
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
switch (stateNr) {
default:

View File

@@ -46,12 +46,12 @@ public class BluetoothExcelvanCF369BLE extends BluetoothCommunication {
}
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
return false;
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
switch (stateNr) {
case 0:
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
@@ -87,7 +87,7 @@ public class BluetoothExcelvanCF369BLE extends BluetoothCommunication {
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
return false;
}

View File

@@ -43,7 +43,7 @@ public class BluetoothExingtechY1 extends BluetoothCommunication {
}
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
@@ -69,12 +69,12 @@ public class BluetoothExingtechY1 extends BluetoothCommunication {
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
return false;
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
return false;
}

View File

@@ -41,7 +41,7 @@ public class BluetoothHesley extends BluetoothCommunication {
}
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
@@ -58,12 +58,12 @@ public class BluetoothHesley extends BluetoothCommunication {
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
return false;
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
return false;
}

View File

@@ -54,19 +54,19 @@ public class BluetoothIhealthHS3 extends BluetoothCommunication {
}
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
Log.w("openscale","ihealthHS3 - nextInitCmd - returning false");
return false;
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
Log.w("openscale","ihealthHS3 - nextBluetoothCmd - returning false");
return false;
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
Log.w("openscale","ihealthHS3 - nextCleanUpCmd - returning false");
return false;
}

View File

@@ -84,7 +84,7 @@ public class BluetoothMGB extends BluetoothCommunication {
}
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
setNotificationOn(uuid_service, uuid_char_ctrl, uuid_desc_ctrl);
@@ -125,13 +125,13 @@ public class BluetoothMGB extends BluetoothCommunication {
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
return false;
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
return false;
}

View File

@@ -46,12 +46,12 @@ public class BluetoothMedisanaBS444 extends BluetoothCommunication {
}
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
return false;
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
switch (stateNr) {
case 0:
// set indication on for feature characteristic
@@ -89,7 +89,7 @@ public class BluetoothMedisanaBS444 extends BluetoothCommunication {
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
return false;
}

View File

@@ -98,7 +98,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
// read device time
@@ -136,7 +136,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
switch (stateNr) {
case 0:
// set notification on for weight measurement history
@@ -173,7 +173,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
switch (stateNr) {
case 0:

View File

@@ -85,7 +85,7 @@ public class BluetoothMiScale2 extends BluetoothCommunication {
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
// set scale units
@@ -119,7 +119,7 @@ public class BluetoothMiScale2 extends BluetoothCommunication {
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
switch (stateNr) {
case 0:
// configure scale to get only last measurements
@@ -148,7 +148,7 @@ public class BluetoothMiScale2 extends BluetoothCommunication {
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
switch (stateNr) {
case 0:

View File

@@ -45,7 +45,7 @@ public class BluetoothOneByone extends BluetoothCommunication {
}
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
setIndicationOn(WEIGHT_MEASUREMENT_SERVICE_BODY_COMPOSITION, WEIGHT_MEASUREMENT_CHARACTERISTIC_BODY_COMPOSITION, WEIGHT_MEASUREMENT_CONFIG);
@@ -69,12 +69,12 @@ public class BluetoothOneByone extends BluetoothCommunication {
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
return false;
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
return false;
}

View File

@@ -52,7 +52,7 @@ public class BluetoothYunmaiSE_Mini extends BluetoothCommunication {
}
@Override
boolean nextInitCmd(int stateNr) {
protected boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
byte[] userId = Converters.toUnsignedInt16Be(getUniqueNumber());
@@ -94,12 +94,12 @@ public class BluetoothYunmaiSE_Mini extends BluetoothCommunication {
}
@Override
boolean nextBluetoothCmd(int stateNr) {
protected boolean nextBluetoothCmd(int stateNr) {
return false;
}
@Override
boolean nextCleanUpCmd(int stateNr) {
protected boolean nextCleanUpCmd(int stateNr) {
return false;
}