forked from Blendman974/faceclaw
Refactor connection options into a config class
This commit is contained in:
1 parent
e853f0ea5d
commit
da2b44dfe1
3 files changed
+10
-8
No files matched your search
@@ -43,14 +43,13 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
private static final int HEARTBEAT_URGENT_MS = 6_000;
|
private static final int HEARTBEAT_URGENT_MS = 6_000;
|
||||||
private static final int BATTERY_REFRESH_INTERVAL_MS = 5 * 60_000;
|
private static final int BATTERY_REFRESH_INTERVAL_MS = 5 * 60_000;
|
||||||
private static final int BATTERY_INPUT_QUIET_MS = 5_000;
|
private static final int BATTERY_INPUT_QUIET_MS = 5_000;
|
||||||
private static final int WINDOW_SIZE = 5;
|
|
||||||
private static final int IMAGE_FRAGMENT_SIZE = 3800;
|
private static final int IMAGE_FRAGMENT_SIZE = 3800;
|
||||||
private static final int IMAGE_RETRY_DELAY_MS = 10_000;
|
private static final int IMAGE_RETRY_DELAY_MS = 2_000;
|
||||||
private static final boolean IMAGE_FRAGMENT_NO_ACK = false;
|
private static final boolean IMAGE_FRAGMENT_NO_ACK = false;
|
||||||
private static final int MAX_CONSECUTIVE_ACK_TIMEOUTS = 8;
|
private static final int MAX_CONSECUTIVE_ACK_TIMEOUTS = 8;
|
||||||
private static final int EVEN_APP_WRITE_FAILURE_WINDOW_MS = 15_000;
|
private static final int EVEN_APP_WRITE_FAILURE_WINDOW_MS = 15_000;
|
||||||
private static final int IDLE_SLEEP_MS = 100;
|
private static final int IDLE_SLEEP_MS = 100;
|
||||||
private static final int RECONNECT_DELAY_MS = 5_000;
|
private static final int RECONNECT_DELAY_MS = 2_000;
|
||||||
|
|
||||||
private static final BleProtocol.ImageTileOptions[] DASHBOARD_TILES = new BleProtocol.ImageTileOptions[] {
|
private static final BleProtocol.ImageTileOptions[] DASHBOARD_TILES = new BleProtocol.ImageTileOptions[] {
|
||||||
new BleProtocol.ImageTileOptions("img00", 10, 0, 0, 288, 144),
|
new BleProtocol.ImageTileOptions("img00", 10, 0, 0, 288, 144),
|
||||||
@@ -546,6 +545,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH);
|
bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH);
|
||||||
|
|
||||||
bleManager.requestMtu(address, DESIRED_MTU, CONNECT_TIMEOUT_MS);
|
bleManager.requestMtu(address, DESIRED_MTU, CONNECT_TIMEOUT_MS);
|
||||||
|
|
||||||
if (!bleManager.discoverServices(address, SERVICES_TIMEOUT_MS)) {
|
if (!bleManager.discoverServices(address, SERVICES_TIMEOUT_MS)) {
|
||||||
throw new IllegalStateException("discoverServices failed: " + address);
|
throw new IllegalStateException("discoverServices failed: " + address);
|
||||||
}
|
}
|
||||||
@@ -631,7 +631,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
return IDLE_SLEEP_MS;
|
return IDLE_SLEEP_MS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sessionReady && inFlightMessages.size() < WINDOW_SIZE && !pendingMessages.isEmpty()) {
|
if (sessionReady && inFlightMessages.size() < connectionOptions.WINDOW_SIZE && !pendingMessages.isEmpty()) {
|
||||||
OutboundMessage pending = pendingMessages.peekFirst();
|
OutboundMessage pending = pendingMessages.peekFirst();
|
||||||
messageToWrite = pendingMessages.removeFirst();
|
messageToWrite = pendingMessages.removeFirst();
|
||||||
Log.i(TAG, "sending pending message: " + messageToWrite.label);
|
Log.i(TAG, "sending pending message: " + messageToWrite.label);
|
||||||
|
|||||||
@@ -222,20 +222,21 @@ public class FaceclawBleManager {
|
|||||||
if (frames == null || frames.isEmpty()) {
|
if (frames == null || frames.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Log.i(TAG, "Called writeFrames with writeType=" + writeType + ", " + frames.size() + " frames totaling " + frames.stream().mapToInt(frame -> frame != null ? frame.length : 0).sum() + " bytes");
|
|
||||||
|
|
||||||
|
long startMs = System.currentTimeMillis();
|
||||||
synchronized (gattLock(address)) {
|
synchronized (gattLock(address)) {
|
||||||
BluetoothGatt gatt = requireGatt(address);
|
BluetoothGatt gatt = requireGatt(address);
|
||||||
BluetoothGattCharacteristic characteristic = requireCharacteristic(gatt, characteristicUuid);
|
BluetoothGattCharacteristic characteristic = requireCharacteristic(gatt, characteristicUuid);
|
||||||
|
|
||||||
for (int i = 0; i < frames.size(); i++) {
|
for (int i = 0; i < frames.size(); i++) {
|
||||||
Log.i(TAG, "writeFrames starting frame " + i);
|
|
||||||
byte[] frame = frames.get(i);
|
byte[] frame = frames.get(i);
|
||||||
if (!startWrite(gatt, characteristic, address, frame, writeType, timeoutMs)) {
|
if (!startWrite(gatt, characteristic, address, frame, writeType, timeoutMs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int totalSize = frames.stream().mapToInt(frame -> frame != null ? frame.length : 0).sum();
|
||||||
|
Log.i(TAG, "writeFrames wrote " + frames.size() + " frames totaling " + totalSize + " bytes in " + (System.currentTimeMillis() - startMs) + "ms");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
package com.faceclaw.app;
|
package com.faceclaw.app;
|
||||||
|
|
||||||
public class ConnectionOptions {
|
public class ConnectionOptions {
|
||||||
final boolean sendImagesToLeft = true;
|
final boolean sendImagesToLeft = false;
|
||||||
final boolean skipSessionIds = true;
|
final boolean skipSessionIds = false;
|
||||||
|
final int WINDOW_SIZE = 5;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user