forked from Blendman974/faceclaw
Refuse the flash with a reason when the glasses are in silent mode
Silent mode blanks the display and stops the firmware dispatching input while BLE and GATT stay up, so the create-prompt page is written, accepted, and never rendered. There is no touchpad event available to answer it with, and the flash ends after four attempts on "prompt page not acked", which tells the wearer nothing about what is wrong or what to do about it. readBattery was already performing a sid-0x09 settings read whose ack carries silentMode next to the battery, and the field was being discarded. readSettings is factored out so one read serves both callers, and requireNotSilent runs it before the prompt page is written. A positive report throws, and the existing error path turns the message into what the wearer sees: that the glasses are in silent mode, and that long-pressing both touchpads leaves it. It refuses only on a positive report. An arm that does not answer, and firmware whose ack omits the field, both fall through to the prompt exactly as before, so older firmware is unaffected and a missing answer can never block a flash. This replaces the phone-side confirmation fallback that was here before. An unacked page is not by itself evidence that the prompt was never displayed, and the on-lens step is what proves the glasses being flashed are the ones in front of you, so overriding it on a timeout gave up more than it was worth.
This commit is contained in:
3 files changed
+55
-95
No files matched your search
+53
-4
@@ -51,6 +51,15 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
|
||||
// Index 0 = decline, index 1 = approve. Kept short for the ~50-col grid.
|
||||
private static final String[] ITEMS = new String[] {"No, cancel", "Yes, flash"};
|
||||
|
||||
/**
|
||||
* Shown instead of a bare "prompt page not acked" timeout. Silent mode is
|
||||
* entered and left by the same gesture on the glasses and nothing here can
|
||||
* clear it, so the instruction has to travel with the error.
|
||||
*/
|
||||
private static final String SILENT_MODE_MESSAGE =
|
||||
"Your glasses are in silent mode, so they cannot show the confirmation prompt. "
|
||||
+ "Long-press both touchpads on the glasses to leave silent mode, then try again.";
|
||||
|
||||
private static final int HEARTBEAT_INTERVAL_MS = 4_000;
|
||||
private static final int SELECTION_TIMEOUT_MS = 120_000;
|
||||
private static final int CREATE_ACK_TIMEOUT_MS = 3_000;
|
||||
@@ -183,6 +192,12 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
|
||||
sendPrelude(rightAddress);
|
||||
|
||||
if (!skipPrompt) {
|
||||
// Ask before writing a page that cannot be answered: silent mode
|
||||
// blanks the display and stops the firmware dispatching input while
|
||||
// BLE stays up, so the create-prompt write is still accepted and the
|
||||
// flash would spend four attempts timing out on an error that says
|
||||
// nothing about the reason.
|
||||
requireNotSilent(rightAddress);
|
||||
showPrompt(rightAddress);
|
||||
startHeartbeat();
|
||||
emitState("prompting", "");
|
||||
@@ -376,6 +391,18 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
|
||||
}
|
||||
|
||||
private int readBattery(String address, String arm) throws InterruptedException {
|
||||
BleProtocol.BatterySnapshot snapshot = readSettings(address, arm);
|
||||
return snapshot == null ? -1 : snapshot.battery;
|
||||
}
|
||||
|
||||
/**
|
||||
* The sid-0x09 settings read behind both the battery gate and the
|
||||
* silent-mode check. One ack carries both fields, so neither caller needs
|
||||
* a query of its own. Returns null when the arm does not answer or the ack
|
||||
* carries no settings payload.
|
||||
*/
|
||||
private BleProtocol.BatterySnapshot readSettings(String address, String arm)
|
||||
throws InterruptedException {
|
||||
for (int attempt = 0; attempt < 2 && !cancelled; attempt++) {
|
||||
int magic = allocMagic();
|
||||
byte[] ack = writeAndAwaitAck(
|
||||
@@ -386,16 +413,38 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener {
|
||||
BleProtocol.buildSettingsQuery(magic),
|
||||
BATTERY_ACK_TIMEOUT_MS);
|
||||
if (ack == null) {
|
||||
emitLog("battery read attempt " + (attempt + 1) + " unacked: " + arm + " arm");
|
||||
emitLog("settings read attempt " + (attempt + 1) + " unacked: " + arm + " arm");
|
||||
continue;
|
||||
}
|
||||
BleProtocol.BatterySnapshot snapshot = BleProtocol.parseSettingsBattery(ack);
|
||||
if (snapshot != null) {
|
||||
return snapshot.battery;
|
||||
return snapshot;
|
||||
}
|
||||
emitLog("battery read ack had no battery field: " + arm + " arm");
|
||||
emitLog("settings read ack had no settings payload: " + arm + " arm");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuse the prompt only when the arm POSITIVELY reports silent mode. An
|
||||
* arm that does not answer, and firmware whose ack omits the field
|
||||
* (silentMode -1), both fall through to the prompt, so behavior on older
|
||||
* firmware is unchanged and a missing answer never blocks a flash.
|
||||
*/
|
||||
private void requireNotSilent(String address) throws InterruptedException {
|
||||
BleProtocol.BatterySnapshot snapshot = readSettings(address, "right");
|
||||
String state;
|
||||
if (snapshot == null) {
|
||||
state = "unknown (arm did not answer)";
|
||||
} else if (snapshot.silentMode < 0) {
|
||||
state = "unknown (ack omits the field)";
|
||||
} else {
|
||||
state = snapshot.silentMode > 0 ? "on" : "off";
|
||||
}
|
||||
emitLog("silent mode before prompt: " + state);
|
||||
if (snapshot != null && snapshot.silentMode > 0) {
|
||||
throw new IllegalStateException(SILENT_MODE_MESSAGE);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Write and wait for the matching ack; returns the ack's protobuf (may be empty), or null on timeout/write failure. */
|
||||
|
||||
Reference in new issue
Block a user