forked from Blendman974/faceclaw
Switch from capability strings to numeric versioning for firmwares
This commit is contained in:
1 parent
a57b3b2cbc
commit
b0cf1e4f67
19 files changed
+293
-236
No files matched your search
@@ -77,7 +77,6 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
new java.util.concurrent.CopyOnWriteArrayList<>();
|
||||
private final java.util.List<FaceclawMicStatusListener> micStatusListeners =
|
||||
new java.util.concurrent.CopyOnWriteArrayList<>();
|
||||
private volatile String lastFirmwareCapabilities = "";
|
||||
private volatile Thread workerThread;
|
||||
private volatile boolean running;
|
||||
private volatile boolean userDisconnectRequested;
|
||||
@@ -130,7 +129,14 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
private int faceclawFramebufferControlGeneration;
|
||||
private int faceclawFramebufferControlSentCount;
|
||||
private int faceclawWakePendingNonce = -1;
|
||||
private boolean cfwCleanupSupported;
|
||||
/**
|
||||
* The last firmware-info read said the glasses run Faceclaw's custom
|
||||
* firmware. Gates the private modes (cleanup, texture cache, ...) so stock
|
||||
* or third-party firmware never sees them; the TS side checks the actual
|
||||
* revision and disconnects on a mismatch, so no per-feature gating is
|
||||
* needed here.
|
||||
*/
|
||||
private boolean customFirmwareDetected;
|
||||
private boolean cfwCleanupDelivered;
|
||||
private int lastCfwCleanupAckMagic;
|
||||
|
||||
@@ -260,9 +266,6 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
// firmware frees the cache with the fb lease, and after any resync the
|
||||
// cheap safe assumption is an empty cache (glyphs re-upload lazily).
|
||||
private final TextureCacheState textureCache = new TextureCacheState();
|
||||
private boolean textureCacheSupported;
|
||||
private boolean textureImagesSupported;
|
||||
private boolean fwTextSupported;
|
||||
|
||||
private final ArrayDeque<OutboundMessage> pendingMessages = new ArrayDeque<>();
|
||||
private final ArrayDeque<OutboundMessage> inFlightMessages = new ArrayDeque<>();
|
||||
@@ -819,11 +822,6 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/** The CFW capability token string from the last firmware-info read ("" before one arrives). */
|
||||
public String getFirmwareCapabilities() {
|
||||
return lastFirmwareCapabilities;
|
||||
}
|
||||
|
||||
public void addAmbientLightListener(FaceclawAmbientLightListener listener) {
|
||||
if (listener != null) {
|
||||
ambientLightListeners.add(listener);
|
||||
@@ -1327,7 +1325,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
if (cfwCleanupDelivered) {
|
||||
return true;
|
||||
}
|
||||
if (!cfwCleanupSupported || !running || !sessionReady
|
||||
if (!customFirmwareDetected || !running || !sessionReady
|
||||
|| shutdownRequested || !fixedLayoutCreated) {
|
||||
logLine("skip CFW cleanup; mode 11 unavailable or image path not ready");
|
||||
return false;
|
||||
@@ -1960,7 +1958,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
logLine("session ready");
|
||||
synchronized (lock) {
|
||||
// Query settings promptly on the first session so firmware
|
||||
// version/capabilities (and battery) arrive without waiting for
|
||||
// version/extension (and battery) arrive without waiting for
|
||||
// the input-quiet battery poll. The settings response doubles as
|
||||
// the firmware-compatibility check surfaced during onboarding.
|
||||
if (!firmwareInfoQueried) {
|
||||
@@ -2849,7 +2847,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
// ink out of the baked deltas. Uploads (mode 12) ride ahead of the
|
||||
// image message on the ordered transport. Falls through to the plain
|
||||
// paths whenever the planner has nothing to draw.
|
||||
if (textureCacheSupported && connectionOptions.TEXTURE_CACHE_FRAMES
|
||||
if (customFirmwareDetected && connectionOptions.TEXTURE_CACHE_FRAMES
|
||||
&& draws != null && draws.length > 0 && packed.length > 0) {
|
||||
byte[] deltaBase = (connectionOptions.INCREMENTAL_FRAMES && lastEnqueuedPacked.length > 0
|
||||
&& lastEnqueuedWidth == width && lastEnqueuedHeight == height)
|
||||
@@ -2858,8 +2856,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
TexturePlanner.Result tex = TexturePlanner.plan(
|
||||
deltaBase, packed, width, height, draws, textureCache,
|
||||
nextImageFrameId,
|
||||
connectionOptions.MULTI_RECT_FRAMES, ConnectionOptions.MULTI_RECT_MAX_RECTS,
|
||||
textureImagesSupported, fwTextSupported);
|
||||
connectionOptions.MULTI_RECT_FRAMES, ConnectionOptions.MULTI_RECT_MAX_RECTS);
|
||||
if (tex != null) {
|
||||
nextImageFrameId = tex.nextFid;
|
||||
for (byte[] upload : tex.uploads) {
|
||||
@@ -3078,12 +3075,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
}
|
||||
BleProtocol.FirmwareInfo firmwareInfo = BleProtocol.parseSettingsFirmwareInfo(message.ackPayload);
|
||||
if (firmwareInfo != null) {
|
||||
lastFirmwareCapabilities = firmwareInfo.capabilities == null ? "" : firmwareInfo.capabilities;
|
||||
cfwCleanupSupported = hasCapability(firmwareInfo.capabilities, "cleanup11");
|
||||
textureCacheSupported = hasCapability(firmwareInfo.capabilities, "texcache12")
|
||||
&& hasCapability(firmwareInfo.capabilities, "texstr14");
|
||||
textureImagesSupported = hasCapability(firmwareInfo.capabilities, "teximg13");
|
||||
fwTextSupported = hasCapability(firmwareInfo.capabilities, "font15");
|
||||
customFirmwareDetected = firmwareInfo.isFaceclawFirmware();
|
||||
emitFirmwareInfo(firmwareInfo);
|
||||
}
|
||||
};
|
||||
@@ -3685,14 +3677,6 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
// the very cause of the session teardown that got us here.
|
||||
}
|
||||
|
||||
private static boolean hasCapability(String capabilities, String token) {
|
||||
if (capabilities == null || token == null || token.isEmpty()) return false;
|
||||
for (String capability : capabilities.trim().split("\\s+")) {
|
||||
if (token.equals(capability)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void emitRingEvent(String kind, String containerName, int eventType, int eventSource, int systemExitReasonCode, int frameId) {
|
||||
final FaceclawBleCommunicatorListener current = listener;
|
||||
if (current == null) {
|
||||
@@ -3839,7 +3823,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
}
|
||||
mainHandler.post(() -> {
|
||||
try {
|
||||
current.onFirmwareInfo(info.leftVersion, info.rightVersion, info.capabilities);
|
||||
current.onFirmwareInfo(info.leftVersion, info.rightVersion, info.extension);
|
||||
} catch (Throwable t) {
|
||||
Log.w(TAG, "listener onFirmwareInfo failed", t);
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,5 +11,5 @@ public interface FaceclawBleCommunicatorListener {
|
||||
void onEvenAppConflict(String message);
|
||||
void onFrameMetrics(int paintMs, int transmitMs, int tileCount);
|
||||
void onFrameFinished(int frameId, String outcome);
|
||||
void onFirmwareInfo(String leftVersion, String rightVersion, String capabilities);
|
||||
void onFirmwareInfo(String leftVersion, String rightVersion, String extension);
|
||||
}
|
||||
@@ -12,8 +12,8 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Connects to the glasses (stock-firmware compatible), reads the device-info /
|
||||
* settings response, and reports the firmware versions plus the CFW capability
|
||||
* string (empty on stock firmware). Used by onboarding to decide whether to
|
||||
* settings response, and reports the firmware versions plus the firmware-
|
||||
* extension string (empty on stock firmware). Used by onboarding to decide whether to
|
||||
* flash. Reuses FaceclawBleManager + BleProtocol; owns its own connection and
|
||||
* runs on a single worker thread. Shows nothing on the lens.
|
||||
*/
|
||||
@@ -119,9 +119,9 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener {
|
||||
BleProtocol.FirmwareInfo info = BleProtocol.parseSettingsFirmwareInfo(ack);
|
||||
String left = info == null ? "" : info.leftVersion;
|
||||
String right = info == null ? "" : info.rightVersion;
|
||||
String caps = info == null ? "" : info.capabilities;
|
||||
emitLog("device-info: L=" + left + " R=" + right + " caps=[" + caps + "]");
|
||||
emitResult(left, right, caps);
|
||||
String extension = info == null ? "" : info.extension;
|
||||
emitLog("device-info: L=" + left + " R=" + right + " ext=[" + extension + "]");
|
||||
emitResult(left, right, extension);
|
||||
} catch (Exception e) {
|
||||
String message = cancelled ? "Cancelled." : (e.getMessage() == null ? e.toString() : e.getMessage());
|
||||
emitError(message);
|
||||
@@ -161,7 +161,7 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener {
|
||||
|
||||
emitState("querying", label);
|
||||
// Session prelude, then a settings/device-info read (both arms'
|
||||
// versions and the CFW capability string ride back in one response).
|
||||
// versions and the firmware-extension string ride back in one response).
|
||||
if (writeAndAwaitAck(address, BleProtocol.PRELUDE_ACK_SID, BleProtocol.FLAG_REQUEST,
|
||||
BleProtocol.PRELUDE_ACK_MAGIC, BleProtocol.PRELUDE_F5872_PAYLOAD,
|
||||
ConnectionOptions.PRELUDE_TIMEOUT_MS) == null) {
|
||||
@@ -329,11 +329,11 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void emitResult(String left, String right, String caps) {
|
||||
private void emitResult(String left, String right, String extension) {
|
||||
mainHandler.post(() -> {
|
||||
FaceclawDeviceInfoProbeListener current = listener;
|
||||
if (current != null) {
|
||||
current.onResult(left, right, caps);
|
||||
current.onResult(left, right, extension);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ public interface FaceclawDeviceInfoProbeListener {
|
||||
/** Lifecycle: connecting, querying. */
|
||||
void onState(String state, String detail);
|
||||
|
||||
/** Terminal success: firmware versions and the CFW capability string (may be empty). */
|
||||
void onResult(String leftVersion, String rightVersion, String capabilities);
|
||||
/** Terminal success: firmware versions and the firmware-extension string (empty on stock). */
|
||||
void onResult(String leftVersion, String rightVersion, String extension);
|
||||
|
||||
/** Terminal failure (couldn't connect or read the version). */
|
||||
void onError(String message);
|
||||
|
||||
@@ -50,16 +50,15 @@ public class BleProtocol {
|
||||
public static final int FACECLAW_WAKE_CONTROL_FIELD = 101;
|
||||
public static final int FACECLAW_WAKE_EVENT_FIELD = 102;
|
||||
/**
|
||||
* CFW mic_control (EVENCFW/16, caps tokens micctl/micmc/micraw): host
|
||||
* writes an ['M','C',ver,op,...] record as settings field 103; each temple
|
||||
* CFW mic_control: host writes an ['M','C',ver,op,...] record as settings
|
||||
* field 103; each temple
|
||||
* reports a 21-byte ['M','C',ver,...] status as field 104, both appended
|
||||
* to settings read responses and as standalone commandId=3 pushes.
|
||||
*/
|
||||
public static final int FACECLAW_MIC_CONTROL_FIELD = 103;
|
||||
public static final int FACECLAW_MIC_STATUS_FIELD = 104;
|
||||
/**
|
||||
* CFW als_sensor (EVENCFW/18, caps token als16): ambient-light reports on
|
||||
* settings-channel field 105, 24-byte ['A','L',ver,reason,...] records from
|
||||
* CFW als_sensor: ambient-light reports on settings-channel field 105, 24-byte ['A','L',ver,reason,...] records from
|
||||
* the master temple (decoded in app/native/ambient-light.ts).
|
||||
*/
|
||||
public static final int FACECLAW_ALS_REPORT_FIELD = 105;
|
||||
@@ -475,7 +474,7 @@ public class BleProtocol {
|
||||
return body;
|
||||
}
|
||||
|
||||
/** Field 106: RB/version 1/flags/percentage, from CFW ringbat17. */
|
||||
/** Field 106: RB/version 1/flags/percentage, from the CFW ring-battery cache. */
|
||||
public static RingBatterySnapshot parseRingBattery(byte[] pb) {
|
||||
if (pb == null) return null;
|
||||
byte[] body = readFieldBytes(stripTrailingCrc(pb), 106);
|
||||
@@ -585,11 +584,14 @@ public class BleProtocol {
|
||||
}
|
||||
|
||||
/**
|
||||
* Firmware versions and the CFW capability advertisement from a settings
|
||||
* Firmware versions and the firmware-extension string from a settings
|
||||
* READ ack. Versions are fields 5/6 of the deviceReceiveRequestFromApp
|
||||
* submessage (field 4); the custom firmware additionally appends top-level
|
||||
* field 100, a string like "EVENCFW/6 img576 img640 ... directfb fbguard", which
|
||||
* stock firmware never sends. Returns null when the ack carries none of it.
|
||||
* submessage (field 4); Faceclaw's custom firmware additionally appends
|
||||
* top-level field 100 with its revision ("Faceclaw/<n>"; older builds sent
|
||||
* "EVENCFW/<ver> <tokens>"), which stock firmware never sends. Returns null
|
||||
* when the ack carries none of it. Compatibility is judged on the TS side
|
||||
* (app/g2/firmware-compat.ts); Java only needs to know whether the firmware
|
||||
* is ours at all.
|
||||
*/
|
||||
public static FirmwareInfo parseSettingsFirmwareInfo(byte[] pb) {
|
||||
byte[] root = stripTrailingCrc(pb);
|
||||
@@ -599,11 +601,11 @@ public class BleProtocol {
|
||||
}
|
||||
String leftVersion = readStringFieldValue(request, 5);
|
||||
String rightVersion = readStringFieldValue(request, 6);
|
||||
String capabilities = readStringFieldValue(root, 100);
|
||||
if (leftVersion.isEmpty() && rightVersion.isEmpty() && capabilities.isEmpty()) {
|
||||
String extension = readStringFieldValue(root, 100);
|
||||
if (leftVersion.isEmpty() && rightVersion.isEmpty() && extension.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return new FirmwareInfo(leftVersion, rightVersion, capabilities);
|
||||
return new FirmwareInfo(leftVersion, rightVersion, extension);
|
||||
}
|
||||
|
||||
public static byte[] wrapEvenHub(int cmd, int magic, int innerFieldNumber, byte[] inner) {
|
||||
@@ -1120,14 +1122,28 @@ public class BleProtocol {
|
||||
}
|
||||
|
||||
public static final class FirmwareInfo {
|
||||
/** Prefix of the firmware-extension string on Faceclaw's custom firmware. */
|
||||
public static final String FACECLAW_EXTENSION_PREFIX = "Faceclaw/";
|
||||
|
||||
final String leftVersion;
|
||||
final String rightVersion;
|
||||
final String capabilities;
|
||||
/** Raw field-100 string ("" on stock firmware). */
|
||||
final String extension;
|
||||
|
||||
FirmwareInfo(String leftVersion, String rightVersion, String capabilities) {
|
||||
FirmwareInfo(String leftVersion, String rightVersion, String extension) {
|
||||
this.leftVersion = leftVersion;
|
||||
this.rightVersion = rightVersion;
|
||||
this.capabilities = capabilities;
|
||||
this.extension = extension == null ? "" : extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the glasses run Faceclaw's custom firmware (any revision).
|
||||
* Whether the revision is the one this app needs is decided on the TS
|
||||
* side, which disconnects on a mismatch; this only guards the private
|
||||
* modes against stock or third-party firmware in the meantime.
|
||||
*/
|
||||
public boolean isFaceclawFirmware() {
|
||||
return extension.trim().startsWith(FACECLAW_EXTENSION_PREFIX);
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-12
@@ -118,15 +118,14 @@ public final class TexturePlanner {
|
||||
/**
|
||||
* Plan a cached-draw update. previous is the delta base (the frame the
|
||||
* shadow currently holds), or null/mismatched for a full-frame keyframe.
|
||||
* allowImages requires the teximg13 capability; allowFwText requires
|
||||
* font15. Returns null when the plain paths should run instead (no
|
||||
* replayable draws, or identical frames).
|
||||
* Returns null when the plain paths should run instead (no replayable
|
||||
* draws, or identical frames).
|
||||
*/
|
||||
public static Result plan(
|
||||
byte[] previous, byte[] next, int width, int height,
|
||||
SurfaceCompositor.ScreenDraw[] draws,
|
||||
TextureCacheState cache, int fidStart,
|
||||
boolean allowMultiRect, int maxRects, boolean allowImages, boolean allowFwText) {
|
||||
boolean allowMultiRect, int maxRects) {
|
||||
if (next == null || draws == null || draws.length == 0 || width <= 0 || height <= 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -171,14 +170,12 @@ public final class TexturePlanner {
|
||||
List<FwPunch> fwPunches = new ArrayList<>();
|
||||
int fwGlyphCount = 0;
|
||||
int fwBaked = 0;
|
||||
if (allowFwText) {
|
||||
for (SurfaceCompositor.ScreenDraw draw : draws) {
|
||||
if (draw.kind != SurfaceCompositor.ScreenDraw.KIND_FWTEXT) continue;
|
||||
fwBaked += planFwRun(draw, rects, next, stride, width, height, fwSubs, fwPunches);
|
||||
}
|
||||
fwGlyphCount = fwPunches.size();
|
||||
bakedCandidates += fwBaked;
|
||||
for (SurfaceCompositor.ScreenDraw draw : draws) {
|
||||
if (draw.kind != SurfaceCompositor.ScreenDraw.KIND_FWTEXT) continue;
|
||||
fwBaked += planFwRun(draw, rects, next, stride, width, height, fwSubs, fwPunches);
|
||||
}
|
||||
fwGlyphCount = fwPunches.size();
|
||||
bakedCandidates += fwBaked;
|
||||
for (SurfaceCompositor.ScreenDraw draw : draws) {
|
||||
if (draw.kind == SurfaceCompositor.ScreenDraw.KIND_GLYPH) {
|
||||
GlyphAtlas.Glyph atlas = GlyphAtlas.get(draw.fontId, draw.encoding);
|
||||
@@ -204,7 +201,6 @@ public final class TexturePlanner {
|
||||
}
|
||||
selected.add(new Selected(draw, atlas, null, gx, top));
|
||||
} else {
|
||||
if (!allowImages) continue; // firmware lacks teximg13: stays baked
|
||||
ImageAtlas.Entry atlas = ImageAtlas.get(draw.imageId);
|
||||
if (atlas == null) continue;
|
||||
if (!intersectsAny(rects, draw.x, draw.y, atlas.width, atlas.height)) {
|
||||
|
||||
Reference in new issue
Block a user