mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-11 11:14:03 +02:00
delete static BT_STATUS_CODE imports
This commit is contained in:
@@ -31,11 +31,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_STATUS_CODE.BT_CONNECTION_ESTABLISHED;
|
|
||||||
import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_STATUS_CODE.BT_CONNECTION_LOST;
|
|
||||||
import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_STATUS_CODE.BT_NO_DEVICE_FOUND;
|
|
||||||
import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_STATUS_CODE.BT_UNEXPECTED_ERROR;
|
|
||||||
|
|
||||||
public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
||||||
private final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); // Standard SerialPortService ID
|
private final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); // Standard SerialPortService ID
|
||||||
|
|
||||||
@@ -86,7 +81,7 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
public void startSearching(String deviceName) {
|
public void startSearching(String deviceName) {
|
||||||
|
|
||||||
if (btAdapter == null) {
|
if (btAdapter == null) {
|
||||||
setBtStatus(BT_NO_DEVICE_FOUND);
|
setBtStatus(BT_STATUS_CODE.BT_NO_DEVICE_FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +96,7 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
// Get a BluetoothSocket to connect with the given BluetoothDevice
|
// Get a BluetoothSocket to connect with the given BluetoothDevice
|
||||||
btSocket = btDevice.createRfcommSocketToServiceRecord(uuid);
|
btSocket = btDevice.createRfcommSocketToServiceRecord(uuid);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
setBtStatus(BT_UNEXPECTED_ERROR, "Can't get a bluetooth socket");
|
setBtStatus(BT_STATUS_CODE.BT_UNEXPECTED_ERROR, "Can't get a bluetooth socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread socketThread = new Thread() {
|
Thread socketThread = new Thread() {
|
||||||
@@ -114,7 +109,7 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
btSocket.connect();
|
btSocket.connect();
|
||||||
|
|
||||||
// Bluetooth connection was successful
|
// Bluetooth connection was successful
|
||||||
setBtStatus(BT_CONNECTION_ESTABLISHED);
|
setBtStatus(BT_STATUS_CODE.BT_CONNECTION_ESTABLISHED);
|
||||||
|
|
||||||
btConnectThread = new BluetoothConnectedThread();
|
btConnectThread = new BluetoothConnectedThread();
|
||||||
btConnectThread.start();
|
btConnectThread.start();
|
||||||
@@ -122,7 +117,7 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
} catch (IOException connectException) {
|
} catch (IOException connectException) {
|
||||||
// Unable to connect; close the socket and get out
|
// Unable to connect; close the socket and get out
|
||||||
stopSearching();
|
stopSearching();
|
||||||
setBtStatus(BT_NO_DEVICE_FOUND);
|
setBtStatus(BT_STATUS_CODE.BT_NO_DEVICE_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -132,7 +127,7 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setBtStatus(BT_NO_DEVICE_FOUND);
|
setBtStatus(BT_STATUS_CODE.BT_NO_DEVICE_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -143,7 +138,7 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
btSocket.close();
|
btSocket.close();
|
||||||
btSocket = null;
|
btSocket = null;
|
||||||
} catch (IOException closeException) {
|
} catch (IOException closeException) {
|
||||||
setBtStatus(BT_UNEXPECTED_ERROR, "Can't close bluetooth socket");
|
setBtStatus(BT_STATUS_CODE.BT_UNEXPECTED_ERROR, "Can't close bluetooth socket");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,7 +180,7 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
btInStream = btSocket.getInputStream();
|
btInStream = btSocket.getInputStream();
|
||||||
btOutStream = btSocket.getOutputStream();
|
btOutStream = btSocket.getOutputStream();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
setBtStatus(BT_UNEXPECTED_ERROR, "Can't get bluetooth input or output stream " + e.getMessage());
|
setBtStatus(BT_STATUS_CODE.BT_UNEXPECTED_ERROR, "Can't get bluetooth input or output stream " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +207,7 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
cancel();
|
cancel();
|
||||||
setBtStatus(BT_CONNECTION_LOST);
|
setBtStatus(BT_STATUS_CODE.BT_CONNECTION_LOST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,7 +217,7 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
btString = btString.substring(0, btString.length() - 1); // delete newline '\n' of the string
|
btString = btString.substring(0, btString.length() - 1); // delete newline '\n' of the string
|
||||||
|
|
||||||
if (btString.charAt(0) != '$' && btString.charAt(2) != '$') {
|
if (btString.charAt(0) != '$' && btString.charAt(2) != '$') {
|
||||||
setBtStatus(BT_UNEXPECTED_ERROR, "Parse error of bluetooth string. String has not a valid format");
|
setBtStatus(BT_STATUS_CODE.BT_UNEXPECTED_ERROR, "Parse error of bluetooth string. String has not a valid format");
|
||||||
}
|
}
|
||||||
|
|
||||||
String btMsg = btString.substring(3, btString.length()); // message string
|
String btMsg = btString.substring(3, btString.length()); // message string
|
||||||
@@ -269,16 +264,16 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
|
|
||||||
return scaleBtData;
|
return scaleBtData;
|
||||||
} else {
|
} else {
|
||||||
setBtStatus(BT_UNEXPECTED_ERROR, "Error calculated checksum (" + checksum + ") and received checksum (" + btChecksum + ") is different");
|
setBtStatus(BT_STATUS_CODE.BT_UNEXPECTED_ERROR, "Error calculated checksum (" + checksum + ") and received checksum (" + btChecksum + ") is different");
|
||||||
}
|
}
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
setBtStatus(BT_UNEXPECTED_ERROR, "Error while decoding bluetooth date string (" + e.getMessage() + ")");
|
setBtStatus(BT_STATUS_CODE.BT_UNEXPECTED_ERROR, "Error while decoding bluetooth date string (" + e.getMessage() + ")");
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
setBtStatus(BT_UNEXPECTED_ERROR, "Error while decoding a number of bluetooth string (" + e.getMessage() + ")");
|
setBtStatus(BT_STATUS_CODE.BT_UNEXPECTED_ERROR, "Error while decoding a number of bluetooth string (" + e.getMessage() + ")");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
setBtStatus(BT_UNEXPECTED_ERROR, "Error unknown MCU command");
|
setBtStatus(BT_STATUS_CODE.BT_UNEXPECTED_ERROR, "Error unknown MCU command");
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -288,7 +283,7 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
try {
|
try {
|
||||||
btOutStream.write(bytes);
|
btOutStream.write(bytes);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
setBtStatus(BT_UNEXPECTED_ERROR, "Error while writing to bluetooth socket " + e.getMessage());
|
setBtStatus(BT_STATUS_CODE.BT_UNEXPECTED_ERROR, "Error while writing to bluetooth socket " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user