Flasher only uses right lens for confirmation, rather than confusedly trying to check via each lens separately

This commit is contained in:
James Babcock committed 2026-08-25 21:14:50 -07:00
1 parent 97fad7ae2b
commit b74868bfb3
3 files changed
+17 -44

No files matched your search

@@ -26,6 +26,10 @@ import java.util.concurrent.TimeUnit;
* protobuf helpers (BleProtocol), but owns its own GATT connection and runs its * protobuf helpers (BleProtocol), but owns its own GATT connection and runs its
* whole lifecycle on a single worker thread. It expects the main app to be * whole lifecycle on a single worker thread. It expects the main app to be
* disconnected while it runs (onboarding, before flashing). * disconnected while it runs (onboarding, before flashing).
*
* Only the right arm is used: the lenses relay messages to each other, so
* anything sent to the right arm reaches both, and acks/events only ever come
* from the right arm anyway.
*/ */
public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
private static final String TAG = "FaceclawFlashPrompt"; private static final String TAG = "FaceclawFlashPrompt";
@@ -43,7 +47,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
private final Context context; private final Context context;
private final String rightAddress; private final String rightAddress;
private final String leftAddress;
private final String warningText; private final String warningText;
private final FaceclawBleManager bleManager; private final FaceclawBleManager bleManager;
private final Handler mainHandler = new Handler(Looper.getMainLooper()); private final Handler mainHandler = new Handler(Looper.getMainLooper());
@@ -58,7 +61,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
private volatile boolean cancelled = false; private volatile boolean cancelled = false;
private volatile boolean finished = false; private volatile boolean finished = false;
private volatile boolean rightConnected = false; private volatile boolean rightConnected = false;
private volatile boolean leftConnected = false;
private volatile boolean rightLost = false; private volatile boolean rightLost = false;
private volatile Boolean approved = null; private volatile Boolean approved = null;
private volatile ScheduledExecutorService heartbeatExecutor; private volatile ScheduledExecutorService heartbeatExecutor;
@@ -66,10 +68,9 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
private int nextMagic = 100; private int nextMagic = 100;
private int nextSeq = 0x40; private int nextSeq = 0x40;
public FaceclawFlashPromptCommunicator(Context context, String rightAddress, String leftAddress, String warningText) { public FaceclawFlashPromptCommunicator(Context context, String rightAddress, String warningText) {
this.context = context.getApplicationContext(); this.context = context.getApplicationContext();
this.rightAddress = rightAddress == null ? "" : rightAddress; this.rightAddress = rightAddress == null ? "" : rightAddress;
this.leftAddress = leftAddress == null ? "" : leftAddress;
this.warningText = warningText == null ? "" : warningText; this.warningText = warningText == null ? "" : warningText;
this.bleManager = new FaceclawBleManager(this.context); this.bleManager = new FaceclawBleManager(this.context);
this.bleManager.setListener(this); this.bleManager.setListener(this);
@@ -116,18 +117,8 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
} }
emitState("connecting", ""); emitState("connecting", "");
connectArm(rightAddress, "right"); connectArm(rightAddress);
rightConnected = true; rightConnected = true;
boolean haveLeft = !leftAddress.trim().isEmpty() && !leftAddress.equalsIgnoreCase(rightAddress);
if (haveLeft) {
try {
connectArm(leftAddress, "left");
leftConnected = true;
} catch (Exception e) {
emitLog("left arm connect failed (continuing on right only): " + e.getMessage());
}
}
if (cancelled) { if (cancelled) {
teardown(); teardown();
return; return;
@@ -135,14 +126,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
emitState("connected", ""); emitState("connected", "");
bringUpArm(rightAddress); bringUpArm(rightAddress);
if (leftConnected) {
try {
bringUpArm(leftAddress);
} catch (Exception e) {
emitLog("left arm prompt failed (continuing on right only): " + e.getMessage());
leftConnected = false;
}
}
startHeartbeat(); startHeartbeat();
emitState("prompting", ""); emitState("prompting", "");
@@ -158,7 +141,7 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
if (approved != null) { if (approved != null) {
boolean result = Boolean.TRUE.equals(approved); boolean result = Boolean.TRUE.equals(approved);
try { try {
sendShutdownBoth(); sendShutdown();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
emitResult(result); emitResult(result);
@@ -182,7 +165,7 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
} }
} }
private void connectArm(String address, String labelForLog) { private void connectArm(String address) {
if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) {
throw new IllegalStateException("connect failed: " + address); throw new IllegalStateException("connect failed: " + address);
} }
@@ -194,7 +177,7 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) {
throw new IllegalStateException("enableNotifications failed: " + address); throw new IllegalStateException("enableNotifications failed: " + address);
} }
emitLog("connected " + labelForLog + " arm"); emitLog("connected right arm");
} }
private void bringUpArm(String address) throws InterruptedException { private void bringUpArm(String address) throws InterruptedException {
@@ -301,9 +284,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
if (rightConnected) { if (rightConnected) {
writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, heartbeat); writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, heartbeat);
} }
if (leftConnected) {
writeFrame(leftAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, heartbeat);
}
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "heartbeat failed: " + e.getMessage()); Log.w(TAG, "heartbeat failed: " + e.getMessage());
} }
@@ -317,14 +297,11 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
} }
} }
private void sendShutdownBoth() { private void sendShutdown() {
byte[] shutdown = BleProtocol.buildShutdown(allocMagic(), 0); byte[] shutdown = BleProtocol.buildShutdown(allocMagic(), 0);
if (rightConnected) { if (rightConnected) {
writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, shutdown); writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, shutdown);
} }
if (leftConnected) {
writeFrame(leftAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, shutdown);
}
} }
private void teardown() { private void teardown() {
@@ -335,7 +312,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
} catch (Exception ignored) { } catch (Exception ignored) {
} }
rightConnected = false; rightConnected = false;
leftConnected = false;
} }
@Override @Override
@@ -355,10 +331,7 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
return; return;
} }
if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) { if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) {
// Async events (taps/selections) only ever come from the right arm. handleEvent(frame);
if (address.equalsIgnoreCase(rightAddress)) {
handleEvent(frame);
}
return; return;
} }
if (frame.msgSeq >= 0) { if (frame.msgSeq >= 0) {
@@ -407,8 +380,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
selectionLatch.countDown(); selectionLatch.countDown();
} }
} }
} else if (address.equalsIgnoreCase(leftAddress)) {
leftConnected = false;
} }
} }
+5 -3
View File
@@ -17,6 +17,9 @@ export type FlashPromptState =
* stock-firmware-compatible BLE path that shows the pre-flash confirmation on * stock-firmware-compatible BLE path that shows the pre-flash confirmation on
* the glasses and reports the user's Yes/No choice. Separate from * the glasses and reports the user's Yes/No choice. Separate from
* FaceclawCommunicatorBridge on purpose (different, minimal protocol subset). * FaceclawCommunicatorBridge on purpose (different, minimal protocol subset).
*
* Talks to the right arm only: the lenses relay messages between themselves,
* and acks/events always come from the right arm.
*/ */
export class FlashPromptCommunicator { export class FlashPromptCommunicator {
private readonly communicator: any; private readonly communicator: any;
@@ -25,14 +28,13 @@ export class FlashPromptCommunicator {
private readonly stateListeners = new Set<(state: FlashPromptState, detail: string) => void>(); private readonly stateListeners = new Set<(state: FlashPromptState, detail: string) => void>();
private readonly resultListeners = new Set<(approved: boolean) => void>(); private readonly resultListeners = new Set<(approved: boolean) => void>();
constructor(addresses: { right: string; left: string }, warningText: string) { constructor(rightAddress: string, warningText: string) {
const context = Utils.android.getApplicationContext(); const context = Utils.android.getApplicationContext();
if (!context) throw new Error("Android application context unavailable"); if (!context) throw new Error("Android application context unavailable");
this.communicator = new com.faceclaw.app.FaceclawFlashPromptCommunicator( this.communicator = new com.faceclaw.app.FaceclawFlashPromptCommunicator(
context, context,
addresses.right, rightAddress,
addresses.left,
warningText, warningText,
); );
this.listenerProxy = new com.faceclaw.app.FaceclawFlashPromptListener({ this.listenerProxy = new com.faceclaw.app.FaceclawFlashPromptListener({
+1 -1
View File
@@ -253,7 +253,7 @@ export class OnboardingFlashViewModel extends Observable {
private startCommunicator(addresses: { right: string; left: string }): void { private startCommunicator(addresses: { right: string; left: string }): void {
this.disposePrompt(); this.disposePrompt();
const prompt = new FlashPromptCommunicator(addresses, this.glassesWarning); const prompt = new FlashPromptCommunicator(addresses.right, this.glassesWarning);
this.prompt = prompt; this.prompt = prompt;
this.promptUnsubscribers.push( this.promptUnsubscribers.push(