diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java index 9d9daf4b..8210e379 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java @@ -2243,6 +2243,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { return; } long ackedAtMs = SystemClock.elapsedRealtime(); + FaceclawBleManager.recordDisplayFrameSent(); BleImageOptimizer.ImageUpdateStats stats = imageUpdateStats.remove(message.imageUpdateId); if (stats != null && stats.firstWriteStartedAtMs > 0) { emitFrameMetrics(stats.paintMs, (int) Math.max(0, ackedAtMs - stats.firstWriteStartedAtMs), stats.tileCount); diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java index 179f6e04..09f2fe55 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java @@ -21,6 +21,7 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; @SuppressLint("MissingPermission") public class FaceclawBleManager { @@ -51,6 +52,23 @@ public class FaceclawBleManager { private volatile FaceclawBleListener listener; + // Process-wide outbound-traffic totals, sampled by the phone UI's BLE + // bandwidth indicator. Static so counts from every manager instance and + // isolate land in the same totals. + private static final AtomicLong outboundMessages = new AtomicLong(); + private static final AtomicLong outboundBytes = new AtomicLong(); + private static final AtomicLong displayFramesSent = new AtomicLong(); + + /** Called by the communicator when a display frame's last message is acked. */ + public static void recordDisplayFrameSent() { + displayFramesSent.incrementAndGet(); + } + + /** Running totals of outbound BLE traffic since process start: [messages, bytes, display frames]. */ + public static long[] sampleOutboundTraffic() { + return new long[] { outboundMessages.get(), outboundBytes.get(), displayFramesSent.get() }; + } + public FaceclawBleManager(Context context) { this.context = context.getApplicationContext(); BluetoothManager bluetoothManager = (BluetoothManager) this.context.getSystemService(Context.BLUETOOTH_SERVICE); @@ -250,8 +268,10 @@ public class FaceclawBleManager { if (!startWrite(gatt, characteristic, address, frame, writeType, timeoutMs)) { return false; } + outboundBytes.addAndGet(frame != null ? frame.length : 0); } } + outboundMessages.incrementAndGet(); 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; diff --git a/CHANGELOG b/CHANGELOG index b4e87e9b..04e5556c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ * Add support for the short-then-long-press gesture * Update EvenHub compatibility layer to include new functions from 0.0.14 * EvenHub permissions dialog scrolls when it overflows +* Add "Show BLE bandwidth usage" option to developer settings ## 0.6.2 - 2026-08-30 * Preview Only mode works diff --git a/app/app.css b/app/app.css index 72804c5e..dd7b3f05 100644 --- a/app/app.css +++ b/app/app.css @@ -98,6 +98,13 @@ Button.-primary { font-size: 13; } +/* Developer BLE-bandwidth totals overlaid on the main page's bottom edge. */ +.ble-bandwidth-indicator { + color: #777777; + font-size: 12; + padding: 2 8; +} + /* * Stands in for the lens preview when showing it would be misleading (silent * mode, or a disconnect explained by a flat battery). Sized by the view model diff --git a/app/apps/pinball/pinball-app.worker.ts b/app/apps/pinball/pinball-app.worker.ts index 65bf6348..b3598ecf 100644 --- a/app/apps/pinball/pinball-app.worker.ts +++ b/app/apps/pinball/pinball-app.worker.ts @@ -71,7 +71,7 @@ const GRAVITY = 240; const DRAG_PER_S = 0.12; const MAX_SPEED = 600; const PHYSICS_DT = 1 / 120; -const RENDER_TICK_MS = 110; +const RENDER_TICK_MS = 50; /** Launch speed by power setting (index = power - 1). */ const LAUNCH_SPEEDS = [320, 380, 440, 500, 560] as const; const BUMPER_KICK = 340; diff --git a/app/native/ble-traffic.ts b/app/native/ble-traffic.ts new file mode 100644 index 00000000..38a76ecc --- /dev/null +++ b/app/native/ble-traffic.ts @@ -0,0 +1,16 @@ +declare const com: any; + +export interface BleTrafficSample { + /** Outbound messages (writeFrames calls) since process start. */ + messages: number; + /** Outbound payload bytes (sum of frame sizes) since process start. */ + bytes: number; + /** Display frames whose last message was acked, since process start. */ + frames: number; +} + +/** Running totals of outbound BLE traffic, counted process-wide in FaceclawBleManager. */ +export function sampleBleTraffic(): BleTrafficSample { + const raw = com.faceclaw.app.FaceclawBleManager.sampleOutboundTraffic(); + return { messages: Number(raw[0]), bytes: Number(raw[1]), frames: Number(raw[2]) }; +} diff --git a/app/phone-ui/main-page.xml b/app/phone-ui/main-page.xml index 7dc9a3d3..9b8584fe 100644 --- a/app/phone-ui/main-page.xml +++ b/app/phone-ui/main-page.xml @@ -64,6 +64,14 @@ + +