forked from Blendman974/faceclaw
Increase screen size a little bit past 576x288, to exercise the corresponding new firmware
This commit is contained in:
1 parent
e96011ef47
commit
818f33ce33
9 files changed
+171
-55
No files matched your search
+100
-14
@@ -28,9 +28,10 @@ import java.util.Map;
|
||||
public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
private static final String TAG = "FaceclawComm";
|
||||
|
||||
// A single full-screen image container. Earlier firmware capped image tiles at
|
||||
// 288x144, which forced a 2x2 tile layout; the custom firmware lifts that limit,
|
||||
// so the dashboard is now one 576x288 container.
|
||||
// The EvenHub image container is a transport/reconstruction carrier only.
|
||||
// Its 576x288 allocation remains large enough for the compressed 580x300
|
||||
// logical image and the firmware's packed-4bpp shadow; the CFW presents that
|
||||
// shadow directly instead of asking EvenHub/LVGL to composite this geometry.
|
||||
private static final BleProtocol.ImageTileOptions DASHBOARD_TILE =
|
||||
new BleProtocol.ImageTileOptions("img00", 10, 0, 0, 576, 288);
|
||||
|
||||
@@ -79,6 +80,9 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
private long lastFaceclawWakeLeaseQueuedAtMs;
|
||||
private int faceclawWakeControlGeneration;
|
||||
private int faceclawWakeControlSentCount;
|
||||
private long lastFaceclawFramebufferLeaseQueuedAtMs;
|
||||
private int faceclawFramebufferControlGeneration;
|
||||
private int faceclawFramebufferControlSentCount;
|
||||
private int faceclawWakePendingNonce = -1;
|
||||
|
||||
private long reconnectAfterMs;
|
||||
@@ -185,6 +189,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
releaseFaceclawFramebufferLease();
|
||||
Thread threadToJoin;
|
||||
synchronized (lock) {
|
||||
userDisconnectRequested = true;
|
||||
@@ -1098,6 +1103,11 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
audioCaptureActive = false;
|
||||
faceclawWakePendingNonce = -1;
|
||||
lastFaceclawWakeLeaseQueuedAtMs = 0;
|
||||
lastFaceclawFramebufferLeaseQueuedAtMs = 0;
|
||||
enqueueFaceclawFramebufferControlLocked(
|
||||
BleProtocol.FACECLAW_FB_OP_ACQUIRE,
|
||||
true
|
||||
);
|
||||
if (faceclawWakeLeaseEnabled) {
|
||||
enqueueFaceclawWakeControlLocked(
|
||||
BleProtocol.FACECLAW_WAKE_OP_ACQUIRE,
|
||||
@@ -1295,6 +1305,14 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
maybeFinishNoChangeDesiredFrame();
|
||||
|
||||
synchronized (lock) {
|
||||
if (sessionReady
|
||||
&& now - lastFaceclawFramebufferLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS
|
||||
&& !hasPendingOrInflightKindLocked("framebuffer-lease-control")) {
|
||||
enqueueFaceclawFramebufferControlLocked(
|
||||
BleProtocol.FACECLAW_FB_OP_ACQUIRE,
|
||||
false
|
||||
);
|
||||
}
|
||||
if (faceclawWakeLeaseEnabled
|
||||
&& sessionReady
|
||||
&& now - lastFaceclawWakeLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS
|
||||
@@ -1787,18 +1805,12 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
}
|
||||
|
||||
private void enqueueWarmupLocked() {
|
||||
int width;
|
||||
int height;
|
||||
synchronized (desiredTilesLock) {
|
||||
width = desiredWidth;
|
||||
height = desiredHeight;
|
||||
}
|
||||
// A blank full-size raw BMP: warmup primes the firmware image path with
|
||||
// a frame shaped like the real ones, without flashing stale content.
|
||||
byte[] bmp = (width > 0 && height > 0)
|
||||
? BmpUtil.build4bppBmpFromPacked(new byte[((width + 1) >> 1) * height], width, height)
|
||||
: new byte[] {0};
|
||||
BleProtocol.ImageTileOptions tile = DASHBOARD_TILE;
|
||||
// Warm up the legacy container with a carrier-sized blank BMP. Real
|
||||
// 580x300 frames use mode 6 and are intentionally independent of this
|
||||
// geometry; a mismatched raw BMP would be rejected by the stock loader.
|
||||
byte[] bmp = BmpUtil.build4bppBmpFromPacked(
|
||||
new byte[((tile.width + 1) >> 1) * tile.height], tile.width, tile.height);
|
||||
int sessionId = nextMapSessionId();
|
||||
List<BleProtocol.ImageFragment> fragments = BleImageOptimizer.planImageFragments(bmp, ConnectionOptions.IMAGE_FRAGMENT_SIZE);
|
||||
for (BleProtocol.ImageFragment fragment : fragments) {
|
||||
@@ -2200,6 +2212,80 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire/renew or release CFW's independent direct-framebuffer repaint
|
||||
* guard on both arms. It is separate from the optional idle-wake lease:
|
||||
* every Faceclaw display session needs this guard while its EvenHub layout
|
||||
* contains swipe-capturing stock widgets.
|
||||
*/
|
||||
private int enqueueFaceclawFramebufferControlLocked(int operation, boolean priority) {
|
||||
clearMessagesOfKindLocked("framebuffer-lease-control");
|
||||
final int generation = ++faceclawFramebufferControlGeneration;
|
||||
faceclawFramebufferControlSentCount = 0;
|
||||
if (operation == BleProtocol.FACECLAW_FB_OP_ACQUIRE) {
|
||||
lastFaceclawFramebufferLeaseQueuedAtMs = SystemClock.elapsedRealtime();
|
||||
}
|
||||
Runnable onSent = () -> {
|
||||
if (faceclawFramebufferControlGeneration == generation) {
|
||||
faceclawFramebufferControlSentCount += 1;
|
||||
}
|
||||
};
|
||||
OutboundMessage right = messageBuilder.faceclawFramebufferControl(operation, false);
|
||||
OutboundMessage left = messageBuilder.faceclawFramebufferControl(operation, true);
|
||||
right.onSent = onSent;
|
||||
left.onSent = onSent;
|
||||
if (priority) {
|
||||
pendingMessages.addFirst(left);
|
||||
pendingMessages.addFirst(right);
|
||||
} else {
|
||||
pendingMessages.addLast(right);
|
||||
pendingMessages.addLast(left);
|
||||
}
|
||||
logLine("queue " + right.label + " + L");
|
||||
return generation;
|
||||
}
|
||||
|
||||
private boolean waitForFaceclawFramebufferControlDelivery(int generation, long timeoutMs) {
|
||||
long deadline = SystemClock.elapsedRealtime() + Math.max(0, timeoutMs);
|
||||
synchronized (lock) {
|
||||
while (running
|
||||
&& sessionReady
|
||||
&& faceclawFramebufferControlGeneration == generation
|
||||
&& faceclawFramebufferControlSentCount < 2) {
|
||||
long remaining = deadline - SystemClock.elapsedRealtime();
|
||||
if (remaining <= 0) {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
lock.wait(Math.min(remaining, 100));
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return faceclawFramebufferControlGeneration == generation
|
||||
&& faceclawFramebufferControlSentCount >= 2;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean releaseFaceclawFramebufferLease() {
|
||||
int generation;
|
||||
synchronized (lock) {
|
||||
if (!running || !sessionReady) {
|
||||
return true;
|
||||
}
|
||||
generation = enqueueFaceclawFramebufferControlLocked(
|
||||
BleProtocol.FACECLAW_FB_OP_RELEASE,
|
||||
true
|
||||
);
|
||||
}
|
||||
interruptibleSleep.interrupt();
|
||||
return waitForFaceclawFramebufferControlDelivery(
|
||||
generation,
|
||||
FACECLAW_WAKE_CONTROL_WAIT_MS
|
||||
);
|
||||
}
|
||||
|
||||
private void clearMessagesOfKindLocked(String kind) {
|
||||
Iterator<OutboundMessage> pendingIterator = pendingMessages.iterator();
|
||||
while (pendingIterator.hasNext()) {
|
||||
|
||||
+5
-8
@@ -79,7 +79,7 @@ public final class BleImageOptimizer {
|
||||
public final byte[] packed;
|
||||
public final int width;
|
||||
public final int height;
|
||||
final byte[] payload; // bytes actually streamed: mode-6 zlib(rle(4bpp)) when it shrinks, else a raw BMP
|
||||
final byte[] payload; // bytes actually streamed: mode-6 zlib(rle(4bpp))
|
||||
final int sessionId;
|
||||
List<BleProtocol.ImageFragment> fragments = Collections.emptyList();
|
||||
|
||||
@@ -408,19 +408,16 @@ public final class BleImageOptimizer {
|
||||
}
|
||||
|
||||
/**
|
||||
* RLE- then zlib-compress headerless 4bpp pixels for CFW load_image_z mode 6 when
|
||||
* it shrinks the payload. Wire format: [6][zlib(rle(4bpp pixels))]. A raw BMP
|
||||
* (starts 'B') is sent when compression does not help; that is the only spot
|
||||
* where BMP framing is still built.
|
||||
* RLE- then zlib-compress headerless 4bpp pixels for CFW load_image_z mode 6.
|
||||
* Wire format: [6][zlib(rle(4bpp pixels))]. Always use mode 6: the logical
|
||||
* image can be larger than its EvenHub carrier, so a raw BMP fallback would
|
||||
* carry dimensions the legacy container loader cannot accept.
|
||||
*/
|
||||
static byte[] maybeCompress(byte[] packed, int width, int height) {
|
||||
if (packed == null || packed.length == 0) {
|
||||
return packed;
|
||||
}
|
||||
byte[] z = deflate(rleEncode(packed));
|
||||
if (z == null || z.length + 1 >= packed.length) {
|
||||
return BmpUtil.build4bppBmpFromPacked(packed, width, height);
|
||||
}
|
||||
byte[] out = new byte[z.length + 1];
|
||||
out[0] = 6;
|
||||
System.arraycopy(z, 0, out, 1, z.length);
|
||||
|
||||
@@ -42,6 +42,8 @@ public class BleProtocol {
|
||||
public static final int FACECLAW_WAKE_OP_RELEASE = 2;
|
||||
public static final int FACECLAW_WAKE_OP_CLAIM = 3;
|
||||
public static final int FACECLAW_WAKE_OP_READY = 4;
|
||||
public static final int FACECLAW_FB_OP_ACQUIRE = 5;
|
||||
public static final int FACECLAW_FB_OP_RELEASE = 6;
|
||||
private static final int FACECLAW_WAKE_EVENT = 1;
|
||||
private static final int FACECLAW_WAKE_PROTOCOL_VERSION = 1;
|
||||
// UI_FOREGROUND_EVEN_AI_ID: the stock "Even AI" assistant app. It is a
|
||||
@@ -399,7 +401,7 @@ public class BleProtocol {
|
||||
* Firmware versions and the CFW capability advertisement 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/1 img576 imgz xordelta stereo", which
|
||||
* field 100, a string like "EVENCFW/5 img576 img580 ... directfb fbguard", which
|
||||
* stock firmware never sends. Returns null when the ack carries none of it.
|
||||
*/
|
||||
public static FirmwareInfo parseSettingsFirmwareInfo(byte[] pb) {
|
||||
|
||||
@@ -210,4 +210,18 @@ public class MessageBuilder {
|
||||
leftArm
|
||||
);
|
||||
}
|
||||
|
||||
public OutboundMessage faceclawFramebufferControl(int operation, boolean leftArm) {
|
||||
return new OutboundMessage(
|
||||
"framebuffer-lease-control",
|
||||
"framebuffer lease op=" + operation + (leftArm ? " L" : " R"),
|
||||
BleProtocol.SID_UI_SETTING,
|
||||
BleProtocol.FLAG_REQUEST,
|
||||
0,
|
||||
BleProtocol.buildFaceclawWakeControl(operation, 0),
|
||||
ACK_TIMEOUT_MS,
|
||||
-1,
|
||||
leftArm
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user