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 c13b0240..0d38e59a 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 @@ -27,15 +27,14 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Random; @SuppressLint("MissingPermission") public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private static final String TAG = "FaceclawComm"; - // The EvenHub image container is a memory carrier only. Its 576x288 geometry - // gives the firmware separate 165888-byte display and reconstruction - // allocations: CFW reuses the former for its 640x480 packed-4bpp shadow and - // leaves the latter wholly available for compressed incoming messages. + // Local metadata for custom-command bookkeeping, not an EvenHub container. + // Submitted frames supply pixel geometry; the stock layout only captures input. private static final BleProtocol.ImageTileOptions DASHBOARD_TILE = new BleProtocol.ImageTileOptions("img00", 10, 0, 0, 576, 288); @@ -77,7 +76,6 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { new java.util.concurrent.CopyOnWriteArrayList<>(); private final java.util.List micStatusListeners = new java.util.concurrent.CopyOnWriteArrayList<>(); - private volatile String lastFirmwareCapabilities = ""; private volatile Thread workerThread; private volatile boolean running; private volatile boolean userDisconnectRequested; @@ -130,7 +128,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; @@ -162,6 +167,8 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private long lastShutdownExitAtMs = 0; private int headsetBattery = -1; private int headsetCharging = -1; + private int ringBattery = -1; + private int ringCharging = -1; // Silent mode: 1 = on, 0 = off, -1 = not yet known. See updateSilentModeLocked. private int silentMode = -1; private int wearState = -1; @@ -176,6 +183,38 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private volatile FaceclawAudioPacketListener audioPacketListener; private PowerManager.WakeLock g2ScreenWakeLock; + // BLE bandwidth benchmark (Developer app). Streams no-op image payloads + // (CFW mode 7 with an unused sub-op: parsed, acked, and discarded — stock + // firmware likewise ignores unknown image modes) for a fixed duration with + // a selectable message size and pipeline window, then reports throughput. + // While active, desired-frame sends are held back and heartbeats are + // satisfied by the benchmark's own acks, so the stream is the only image + // traffic. All state below is guarded by `lock`; results are read with + // getBandwidthBenchmarkStatus() and survive until the next run starts. + private boolean benchmarkActive; + private boolean benchmarkAborted; + private final Random benchmarkRandom = new Random(); + private int benchmarkMessageSize; + private int benchmarkWindowSize; + private int benchmarkDurationMs; + private int benchmarkLinkMode; + private boolean benchmarkLinkPending; + private long benchmarkReadyAtMs; + private long benchmarkStartAtMs; // first benchmark write; 0 until then + private long benchmarkDeadlineAtMs; // start + duration; MAX_VALUE until first write + private long benchmarkLastAckAtMs; + private long benchmarkEndAtMs; // 0 while running; set when the run drains + private int benchmarkMessagesSent; + private int benchmarkMessagesAcked; + private int benchmarkTimeouts; + private long benchmarkPayloadBytesAcked; + private long benchmarkWireBytesAcked; + // A timed-out benchmark message aborts the run, but its already-in-flight + // peers still time out one by one; keep the window comfortably below + // MAX_CONSECUTIVE_ACK_TIMEOUTS so a dead run can't escalate into a + // transport-failure reconnect all by itself. + private static final int BENCHMARK_MAX_WINDOW = 6; + private final BroadcastReceiver phoneLockReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { emitPhoneLockStateIfChanged(true); @@ -226,11 +265,9 @@ 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 pendingMessages = new ArrayDeque<>(); + private final CfwTransport[] cfwTransports = { new CfwTransport(), new CfwTransport() }; private final ArrayDeque inFlightMessages = new ArrayDeque<>(); private OutboundMessage prewrittenMessage; private List prewrittenFrames = Collections.emptyList(); @@ -580,6 +617,200 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { interruptibleSleep.interrupt(); } + /** + * Start the BLE bandwidth benchmark: stream messageSize-byte no-op image + * payloads for durationMs, keeping up to windowSize messages awaiting ack + * at once, then leave the results for getBandwidthBenchmarkStatus(). + * Returns false when a run is already active or the image path is not + * ready. The duration clock starts at the first benchmark write, so + * traffic already queued ahead of the run doesn't count against it. + */ + public boolean startBandwidthBenchmark(int messageSize, int windowSize, int durationMs) { + return startBandwidthBenchmarkWithLinkMode(messageSize, windowSize, durationMs, 0); + } + + // 0: current link; 1: re-request HIGH; 2: request 2M; 3: both. + public boolean startBandwidthBenchmarkWithLinkMode(int messageSize, int windowSize, + int durationMs, int linkMode) { + synchronized (lock) { + if (benchmarkActive || !running || !sessionReady || !fixedLayoutCreated + || shutdownRequested || chargingMode) { + logLine("skip bandwidth benchmark; already running or image path not ready"); + return false; + } + benchmarkMessageSize = Math.max(2, Math.min(messageSize, ConnectionOptions.IMAGE_FRAGMENT_SIZE)); + benchmarkWindowSize = Math.max(1, Math.min(windowSize, BENCHMARK_MAX_WINDOW)); + benchmarkDurationMs = Math.max(1_000, durationMs); + benchmarkLinkMode = linkMode & 3; + benchmarkLinkPending = true; + benchmarkReadyAtMs = Long.MAX_VALUE; + benchmarkStartAtMs = 0; + benchmarkDeadlineAtMs = Long.MAX_VALUE; + benchmarkLastAckAtMs = 0; + benchmarkEndAtMs = 0; + benchmarkMessagesSent = 0; + benchmarkMessagesAcked = 0; + benchmarkTimeouts = 0; + benchmarkPayloadBytesAcked = 0; + benchmarkWireBytesAcked = 0; + benchmarkAborted = false; + benchmarkActive = true; + logLine("bandwidth benchmark start: size=" + benchmarkMessageSize + + "B window=" + benchmarkWindowSize + " duration=" + benchmarkDurationMs + + "ms linkMode=" + benchmarkLinkMode); + } + interruptibleSleep.interrupt(); + return true; + } + + /** + * Cancel an in-progress benchmark (benchmark page closed). Queued no-op + * messages are dropped; in-flight ones drain through their normal acks. + */ + public void cancelBandwidthBenchmark() { + synchronized (lock) { + if (!benchmarkActive) { + return; + } + clearMessagesOfKindLocked("bandwidth"); + finishBenchmarkLocked(true, "cancelled"); + } + interruptibleSleep.interrupt(); + } + + /** Status/results of the current or most recent benchmark run, as JSON. */ + public String getBandwidthBenchmarkStatus() { + synchronized (lock) { + String state = benchmarkActive + ? (benchmarkStartAtMs == 0 ? "starting" : "running") + : (benchmarkEndAtMs != 0 ? "done" : "idle"); + long end = benchmarkActive ? SystemClock.elapsedRealtime() : benchmarkEndAtMs; + long elapsed = benchmarkStartAtMs == 0 ? 0 : Math.max(0, end - benchmarkStartAtMs); + try { + org.json.JSONObject status = new org.json.JSONObject(); + status.put("state", state); + status.put("messageSize", benchmarkMessageSize); + status.put("windowSize", benchmarkWindowSize); + status.put("linkMode", benchmarkLinkMode); + status.put("elapsedMs", elapsed); + status.put("messagesSent", benchmarkMessagesSent); + status.put("messagesAcked", benchmarkMessagesAcked); + status.put("timeouts", benchmarkTimeouts); + status.put("payloadBytesAcked", benchmarkPayloadBytesAcked); + status.put("wireBytesAcked", benchmarkWireBytesAcked); + status.put("aborted", benchmarkAborted); + return status.toString(); + } catch (org.json.JSONException e) { + return "{\"state\":\"idle\"}"; + } + } + } + + /** Pending + in-flight benchmark no-op messages. */ + private int benchmarkOutstandingLocked() { + int count = 0; + for (OutboundMessage message : pendingMessages) { + if ("bandwidth".equals(message.kind)) count++; + } + for (OutboundMessage message : inFlightMessages) { + if ("bandwidth".equals(message.kind)) count++; + } + return count; + } + + /** + * Keep the benchmark stream fed: top the pending queue up so the send + * window never starves, stop enqueueing once the run expires (or a message + * times out), and finish the run when the last outstanding message drains. + */ + private void maintainBenchmarkLocked(long now) { + if (!sessionReady || !fixedLayoutCreated || shutdownRequested) { + finishBenchmarkLocked(true, "session no longer ready"); + return; + } + if (benchmarkLinkPending || now < benchmarkReadyAtMs) { + return; + } + if (benchmarkAborted || now >= benchmarkDeadlineAtMs) { + // The run is over: drop queued-but-unsent no-ops (sending them + // would stretch the run past its deadline) and finish once the + // in-flight tail has acked or timed out. + Iterator pendingIterator = pendingMessages.iterator(); + while (pendingIterator.hasNext()) { + OutboundMessage queued = pendingIterator.next(); + if ("bandwidth".equals(queued.kind)) { + pendingIterator.remove(); + magicPool.release(queued.sid, queued.magic, queued.label, "benchmark over"); + } + } + if (benchmarkOutstandingLocked() == 0) { + finishBenchmarkLocked(false, "complete"); + } + return; + } + // One more than the window so a fresh message is always ready to write + // the moment an ack frees a slot. + for (int outstanding = benchmarkOutstandingLocked(); outstanding <= benchmarkWindowSize; outstanding++) { + enqueueBenchmarkMessageLocked(); + } + } + + private void finishBenchmarkLocked(boolean aborted, String reason) { + if (!benchmarkActive) { + return; + } + benchmarkActive = false; + benchmarkAborted |= aborted; + // Prefer the last ack as the end time so drain lag after the deadline + // doesn't dilute the throughput figure. + benchmarkEndAtMs = benchmarkLastAckAtMs != 0 ? benchmarkLastAckAtMs : SystemClock.elapsedRealtime(); + logLine("bandwidth benchmark " + (benchmarkAborted ? "aborted" : "finished") + " (" + reason + "): " + + benchmarkMessagesAcked + "/" + benchmarkMessagesSent + " acked, " + + benchmarkPayloadBytesAcked + "B payload, " + benchmarkTimeouts + " timeouts"); + } + + private void enqueueBenchmarkMessageLocked() { + // Fresh bytes per message: the transport's persistent compression history + // would compress even a random payload if we reused it across the run. + byte[] payload = new byte[benchmarkMessageSize]; + benchmarkRandom.nextBytes(payload); + payload[0] = 7; // CFW diagnostic-control mode... + payload[1] = (byte) 0x7f; // ...with an unused sub-op: acked, no effect + OutboundMessage message = messageBuilder.imagePayload( + "bandwidth", + DASHBOARD_TILE, + nextMapSessionId(), + payload, + "bandwidth no-op " + payload.length + "B", + connectionOptions.sendImagesToLeft); + final int payloadBytes = payload.length; + // Logical custom-message bytes; excludes length tag and packet framing. + final int wireBytes = message.message.length; + message.onSent = () -> { + benchmarkMessagesSent++; + if (benchmarkStartAtMs == 0) { + benchmarkStartAtMs = SystemClock.elapsedRealtime(); + benchmarkDeadlineAtMs = benchmarkStartAtMs + benchmarkDurationMs; + } + }; + message.onAck = () -> { + long ackedAtMs = SystemClock.elapsedRealtime(); + benchmarkMessagesAcked++; + benchmarkPayloadBytesAcked += payloadBytes; + benchmarkWireBytesAcked += wireBytes; + benchmarkLastAckAtMs = ackedAtMs; + // No-op payloads ride the image path, so the firmware resets its + // heartbeat timer on them just like real image messages. + lastHeartbeatAckedAtMs = ackedAtMs; + }; + message.onTimeout = () -> { + benchmarkTimeouts++; + benchmarkAborted = true; + logLine("bandwidth benchmark ack timeout"); + }; + pendingMessages.addLast(message); + } + public void addImuListener(FaceclawImuListener listener) { if (listener != null) { imuListeners.add(listener); @@ -592,11 +823,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); @@ -1100,7 +1326,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; @@ -1432,6 +1658,33 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { if (!BleProtocol.NOTIFY_CHAR_UUID.equals(uuid)) { return; } + if (data.length >= 7 && (data[6] & 255) == CfwTransport.SID) { + CfwTransport.Ack[] acks = CfwTransport.parseAcks(data); + if (acks == null) return; + synchronized (lock) { + lastIncomingAtMs = SystemClock.elapsedRealtime(); + for (CfwTransport.Ack ack : acks) { + for (OutboundMessage message : inFlightMessages) { + String ingress = message.isLeftArmMessage ? leftAddress : rightAddress; + if (message.sid == CfwTransport.SID && address.equalsIgnoreCase(ingress) && message.magic == ack.streamId) { + message.acceptCfwAck(ack); + Log.i(TAG, "CFW " + (ack.nack ? "NACK" : "ACK") + " id=" + ack.streamId + + " ordinal=" + ack.messageId + " lens=" + ack.lens + " txseq=" + (data[2] & 255) + + " redundant=" + (ack != acks[0]) + + " size=" + ack.size + " crc=" + ack.checksum + + " expected=" + message.message.length + "/" + message.cfwChecksum + + " ackedLenses=" + message.cfwAckLenses + + " ageMs=" + (lastIncomingAtMs - message.sentAtMs)); + message.ackPayload = Arrays.copyOf(data, data.length); + break; + } + } + } + drainCfwAcknowledgementsLocked(); + } + interruptibleSleep.interrupt(); + return; + } Log.d(TAG, "onNotification: address=" + address + " characteristicUuid=" + characteristicUuid + " data.length=" + data.length); BleProtocol.ParsedFrame frame = BleProtocol.parseFrame(data); int decodedWearState = BleProtocol.parseWearState(frame); @@ -1461,17 +1714,44 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { ); faceclawWakeNotification = true; lastConnectionOrInputAtMs = lastIncomingAtMs; + // The event type says which gesture woke the glasses: TS + // gives a head-up the Glanceboard and a double tap the + // regular UI. The claim handshake is the same for both. + boolean headUp = BleProtocol.parseFaceclawWakeEventCode(frame.pb) + == BleProtocol.FACECLAW_WAKE_EVENT_HEAD_UP; event = new G2Event( "display-wake", "", - BleProtocol.EVENT_DOUBLE_CLICK, + headUp ? BleProtocol.EVENT_HEAD_UP : BleProtocol.EVENT_DOUBLE_CLICK, 0, 0 ); - logLine("claimed deferred dashboard wake nonce=" + wakeNonce); + logLine("claimed deferred dashboard wake nonce=" + wakeNonce + + (headUp ? " (head-up)" : "")); } } if (!faceclawWakeNotification + && shutdownRequested + && frame.ok + && frame.sid == BleProtocol.SID_UI_SETTING + && address.equalsIgnoreCase(rightAddress)) { + // CFW idle-gesture forwarding (firmware revision 2+): with no + // EvenHub page the stock display thread drops taps, long + // presses and releases; the CFW reports them on the settings + // sid while our wake lease is held. Deliver them as the + // sys-events a live page would have produced, so TS treats a + // sleep-time tap or hold exactly like one during soft sleep + // (the Glanceboard). + BleProtocol.FaceclawGestureEvent gesture = BleProtocol.parseFaceclawGestureEvent(frame.pb); + if (gesture != null) { + lastConnectionOrInputAtMs = lastIncomingAtMs; + event = new G2Event("sys-event", "", gesture.eventType, gesture.eventSource, 0); + logLine("idle gesture forwarded by CFW: type=" + gesture.eventType + + " source=" + gesture.eventSource); + } + } + if (!faceclawWakeNotification + && event == null && shutdownRequested && address.equalsIgnoreCase(rightAddress) && BleProtocol.isDisplayWakeStateChange(frame)) { @@ -1490,6 +1770,17 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { if (!faceclawWakeNotification && frame.ok && frame.sid == BleProtocol.SID_UI_SETTING) { + // Mode-17 query notifications; settings READs are handled by + // createBatteryQueryMessageLocked so headset/ring update together. + if (address.equalsIgnoreCase(rightAddress) + && (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT)) { + BleProtocol.RingBatterySnapshot ring = BleProtocol.parseRingBattery(frame.pb); + if (ring != null) { + ringBattery = ring.battery; + ringCharging = ring.charging; + emitBatteryState(headsetBattery, headsetCharging); + } + } // CFW mic status (field 104) rides both standalone pushes and // settings read acks, from each temple on its own link. byte[] micStatus = BleProtocol.parseFaceclawMicStatus(frame.pb); @@ -1534,6 +1825,15 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { && address.equalsIgnoreCase(rightAddress) && (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT)) { event = G2Event.decode(frame); + if (event != null + && "sys-event".equals(event.kind) + && event.eventType == BleProtocol.EVENT_HEAD_UP) { + // CFW forwards the IMU head-up while our page is on screen + // (soft sleep). Surface it as the same wake-only input the + // deferred head-up wake produces from a dark display. + event = new G2Event("display-wake", "", BleProtocol.EVENT_HEAD_UP, event.eventSource, 0); + logLine("head-up forwarded by CFW while page on screen"); + } if (event != null) { // Pure IMU samples arrive continuously; don't let them count // as user input (which would starve battery polling). @@ -1703,6 +2003,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { audioCaptureActive = false; faceclawWakePendingNonce = -1; cfwCleanupDelivered = false; + for (CfwTransport transport : cfwTransports) transport.reset(); lastCfwCleanupAckMagic = 0; lastFaceclawWakeLeaseQueuedAtMs = 0; lastFaceclawFramebufferLeaseQueuedAtMs = 0; @@ -1722,7 +2023,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) { @@ -1954,6 +2255,33 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private long driveSession() { //Log.d(TAG, "driveSession called (pendingMessages.size=" + pendingMessages.size() + " inFlightMessages.size=" + inFlightMessages.size() + ")"); while (true) { + // Run on the sender thread, outside `lock`: Bluetooth API calls can + // wait on the global GATT lock, and callbacks need the session lock. + // Keep negotiation outside the timed stream. A fixed settling period + // is only an experiment boundary; HCI must confirm actual parameters. + int linkMode = -1; + String[] benchmarkAddresses = null; + synchronized (lock) { + if (benchmarkActive && benchmarkLinkPending) { + benchmarkLinkPending = false; + linkMode = benchmarkLinkMode; + benchmarkAddresses = new String[] {leftAddress, rightAddress}; + } + } + if (benchmarkAddresses != null) { + for (String address : benchmarkAddresses) { + try { + bleManager.prepareBenchmarkLink(address, linkMode); + } catch (RuntimeException error) { + logLine("benchmark link request failed: " + safeMessage(error)); + } + } + synchronized (lock) { + // Cancellation/new-run races leave the new run pending; its + // own preparation will replace this deadline before sending. + benchmarkReadyAtMs = SystemClock.elapsedRealtime() + 1_000; + } + } OutboundMessage messageToWrite = null; OutboundMessage messageToPrewrite = null; long now = SystemClock.elapsedRealtime(); @@ -1961,6 +2289,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { maybeFinishNoChangeDesiredFrame(); synchronized (lock) { + drainCfwAcknowledgementsLocked(); if (cfwCleanupDelivered) { /* Successful mode 11 must be the last Faceclaw write. Drop * anything a late external producer attempted to enqueue @@ -1988,11 +2317,36 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { } if (!inFlightMessages.isEmpty()) { OutboundMessage oldest = inFlightMessages.peekFirst(); + List replay = CfwMessageWindow.replayWindow(inFlightMessages, now); + if (!replay.isEmpty()) { + logLine("CFW recovery: replay " + replay.size() + + " unresolved message(s) from id=" + replay.get(0).magic); + for (OutboundMessage candidate : replay) { + if (candidate.cfwRetries >= CfwMessageWindow.MAX_RETRIES) { + handleTransportFailure("CFW recovery retry limit"); + return 0; + } + logLine("CFW replay id=" + candidate.magic + " label=" + candidate.label + + " cause=" + (candidate.cfwRetryPending ? "NACK" + : candidate.cfwAckLenses == CfwTransport.BOTH ? "ordered tail" : "missing ACK") + + " ackedLenses=" + candidate.cfwAckLenses + + " ageMs=" + (now - candidate.sentAtMs)); + inFlightMessages.remove(candidate); + magicPool.release(candidate.sid, candidate.magic, candidate.label, "CFW replay"); + candidate.prepareCfwReplay(magicPool.allocate()); + } + for (int i = replay.size() - 1; i >= 0; --i) pendingMessages.addFirst(replay.get(i)); + return 0; + } if (oldest != null && oldest.ackDeadlineAtMs <= now) { Log.i(TAG, "message timed out: " + oldest.label); inFlightMessages.removeFirst(); - logLine("message timed out: " + oldest.label); + logLine("message timed out: " + oldest.label + " sid=" + oldest.sid + + " id=" + oldest.magic + " ackedLenses=" + oldest.cfwAckLenses + + " ageMs=" + (now - oldest.sentAtMs)); magicPool.release(oldest.sid, oldest.magic, oldest.label, "timeout"); + if (oldest.sid == CfwTransport.SID) + cfwTransports[oldest.isLeftArmMessage ? 0 : 1].reset(); handleAckTimeoutLocked(oldest); return 0; } @@ -2050,9 +2404,15 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { enqueueCompassControlLocked(false, wanted); } + if (benchmarkActive) { + maintainBenchmarkLocked(now); + } + // Up to WINDOW_SIZE messages may be in flight at once (full - // pipelining); a slot frees when an ack arrives. - boolean windowHasRoom = inFlightMessages.size() < Math.max(1, connectionOptions.WINDOW_SIZE); + // pipelining); a slot frees when an ack arrives. An active + // bandwidth benchmark measures its own selected window instead. + boolean windowHasRoom = inFlightMessages.size() + < Math.max(1, benchmarkActive ? benchmarkWindowSize : connectionOptions.WINDOW_SIZE); // A frame ready to send right now: don't inject a fresh // heartbeat in front of it (the image's own ack resets the // firmware heartbeat timer, so the heartbeat is redundant). @@ -2063,11 +2423,15 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { // window unprotected and a heartbeat that came due there // cost the frame a full ack round trip (measured 124ms on // frame#232 of the 2026-08-20 02:27 capture). + // A benchmark run counts as image traffic here for the same + // reason: its acks reset the firmware heartbeat timer, so a + // fresh heartbeat in front of it is redundant. boolean imageWaiting = !shutdownRequested && fixedLayoutCreated && !hasPendingOrInflightKindLocked("heartbeat") - && now >= imageRetryAfterMs - && (hasPendingImageLocked() - || !getDesiredFingerprint().equals(lastEnqueuedFingerprint)); + && (benchmarkActive + || (now >= imageRetryAfterMs + && (hasPendingImageLocked() + || !getDesiredFingerprint().equals(lastEnqueuedFingerprint)))); noteImageStallLocked(now, windowHasRoom); if (messageToPrewrite == null && handleHeartbeat(imageWaiting)) { return ConnectionOptions.IDLE_SLEEP_MS; @@ -2076,7 +2440,8 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { if (messageToPrewrite == null && sessionReady && windowHasRoom && !pendingMessages.isEmpty()) { messageToWrite = pendingMessages.removeFirst(); Log.i(TAG, "sending pending message: " + messageToWrite.label); - } else if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated + } else if (messageToPrewrite == null && !shutdownRequested && !benchmarkActive + && fixedLayoutCreated && windowHasRoom && !hasPendingImageLocked() && now >= imageRetryAfterMs && !getDesiredFingerprint().equals(lastEnqueuedFingerprint)) { @@ -2145,7 +2510,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { } private boolean canPrewriteCandidate(OutboundMessage message) { - if (message == null || !message.isLeftArmMessage) { + if (message == null || message.sid == CfwTransport.SID || !message.isLeftArmMessage) { return false; } if (!"image".equals(message.kind)) { @@ -2240,6 +2605,11 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { frames = Collections.singletonList(prewrittenFrames.get(prewrittenFrames.size() - 1)); prewrittenMessage = null; prewrittenFrames = Collections.emptyList(); + } else if (message.sid == CfwTransport.SID) { + if (message.cfwRetries > 0) cfwTransports[message.isLeftArmMessage ? 0 : 1].reset(); + frames = cfwTransports[message.isLeftArmMessage ? 0 : 1].encode( + message.message, message.magic, CfwTransport.BOTH, + bleManager.getNegotiatedMtu(writeAddress)); } else { frames = BleProtocol.framePb( message.message, @@ -2267,6 +2637,8 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { } } + if (!result && message.sid == CfwTransport.SID) + cfwTransports[message.isLeftArmMessage ? 0 : 1].reset(); return result; } @@ -2354,6 +2726,18 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { } + /** Also drain on the worker: a clear/timeout may have removed a blocking + * head since the last notification. Fully ACKed controls must never reach + * the generic timeout path just because no further BLE reply arrived. */ + private void drainCfwAcknowledgementsLocked() { + while (true) { + OutboundMessage first = CfwMessageWindow.acknowledgedHead(inFlightMessages); + if (first == null) return; + lastAckAtMs = SystemClock.elapsedRealtime(); + resolveAckLocked(first, first.ackPayload); + } + } + private void resolveAckLocked(int sid, int magic, byte[] pb) { Iterator iterator = inFlightMessages.iterator(); while (iterator.hasNext()) { @@ -2375,6 +2759,12 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { message.onAck.run(); } consecutiveAckTimeouts = 0; + // onAck may have just satisfied a waiter blocked on lock.wait() (e.g. + // awaitEvenHubSessionReady polling fixedLayoutCreated/displayedFingerprint + // after a create-layout or image ack). Without this, that waiter only + // notices on its own up-to-100ms poll tick, adding avoidable latency to + // every EvenHub wake. Always called with lock held (see call site). + lock.notifyAll(); } private void logImageUpdateSendLandmarkLocked(OutboundMessage message) { @@ -2432,10 +2822,10 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { } private void enqueueCreateLayoutLocked() { - // New session/container: re-assert the firmware-debug-flags overlay once + // New session: re-assert the firmware-debug-flags overlay once // the layout is ready (the mode-7 send is gated on this having reset). firmwareDebugFlagsLastSent = -1; - OutboundMessage message = messageBuilder.createLayout(DASHBOARD_TILE); + OutboundMessage message = messageBuilder.createLayout(); message.onAck = () -> { startupProbePending = false; clearMessagesOfKindLocked("startup-text-probe"); @@ -2480,10 +2870,9 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { } /** - * Send the CFW mode-7 diagnostic-flag control op to the dashboard container: + * Send the CFW mode-7 diagnostic-flag control op through the private stream: * [7][2] to show the on-glasses debug-flag overlay, [7][1] to hide it. Uses the - * arbitrary-payload image path (no bmp/dedup/frame-timing interaction) and does - * nothing on stock firmware (which ignores unknown image modes). + * arbitrary-payload custom path (no bmp/dedup/frame-timing interaction). */ private void enqueueFirmwareDebugFlagsLocked() { boolean show = firmwareDebugFlagsEnabled; @@ -2567,7 +2956,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) @@ -2576,8 +2965,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) { @@ -2585,7 +2973,6 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { } BleImageOptimizer.TileImagePlan plan = new BleImageOptimizer.TileImagePlan( 0, DASHBOARD_TILE, packed, width, height, nextMapSessionId(), tex.payload); - plan.fragments = BleImageOptimizer.planImageFragments(plan.payload, ConnectionOptions.IMAGE_FRAGMENT_SIZE); FrameTimings.getInstance().spanEnd(frameId, "texture-plan"); String texLog = "texture update " + (tex.fullFrame ? "full" : ("rects=" + tex.rectCount)) + " glyphs=" + tex.drawnGlyphs + " runs=" + tex.runCount @@ -2648,7 +3035,6 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { BleImageOptimizer.TileImagePlan plan = incrementalPayload != null ? new BleImageOptimizer.TileImagePlan(0, DASHBOARD_TILE, packed, width, height, nextMapSessionId(), incrementalPayload) : new BleImageOptimizer.TileImagePlan(0, DASHBOARD_TILE, packed, width, height, nextMapSessionId()); - plan.fragments = BleImageOptimizer.planImageFragments(plan.payload, ConnectionOptions.IMAGE_FRAGMENT_SIZE); FrameTimings.getInstance().spanEnd(frameId, "compress-and-plan"); if (incrementalLog != null) { FrameTimings.getInstance().log(frameId, incrementalLog); @@ -2656,15 +3042,26 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { finishEnqueueDesiredImageLocked(plan, fingerprint, paintMs, frameId); } - /** Shared tail of enqueueDesiredImageLocked: enqueue fragments, advance the delta base, log. */ + /** Queue complete private commands, advance the delta base, and retain frame/ACK bookkeeping. */ private void finishEnqueueDesiredImageLocked( BleImageOptimizer.TileImagePlan plan, String fingerprint, int paintMs, int frameId) { int updateId = nextImageUpdateId++; - int messageCount = plan.fragments.size(); + List commands = new ArrayList<>(); + if (plan.payload.length <= CfwTransport.MAX_MESSAGE) { + commands.add(plan.payload); + } else { + // A noisy full frame can exceed the stream record limit. Repaint it + // with independently decodable RLE bands below the decoded-message limit. + commands.addAll(BleImageOptimizer.encodeFullFrameBands( + plan.packed, plan.width, plan.height, nextImageFrameId)); + for (int i = 0; i < commands.size(); i++) { + nextImageFrameId = nextImageFrameId >= 0xfffe ? 1 : nextImageFrameId + 1; + } + } + int messageCount = commands.size(); imageUpdateStats.put(updateId, new BleImageOptimizer.ImageUpdateStats(paintMs, 1, frameId)); - for (int i = 0; i < plan.fragments.size(); i++) { - BleProtocol.ImageFragment fragment = plan.fragments.get(i); - enqueueImageFragmentLocked(plan, fragment, fingerprint, updateId, i + 1, messageCount, true); + for (int i = 0; i < commands.size(); i++) { + enqueueCustomImageLocked(plan, commands.get(i), fingerprint, updateId, i + 1, messageCount); } // This frame is now the base for the next delta (it will be the firmware // shadow once applied), even though it hasn't been acked yet — that is what @@ -2704,16 +3101,16 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { logLine("queue " + message.label); } - private void enqueueImageFragmentLocked( + private void enqueueCustomImageLocked( BleImageOptimizer.TileImagePlan plan, - BleProtocol.ImageFragment fragment, + byte[] payload, String fingerprint, int updateId, int messageNumber, - int messageCount, - boolean requestAck + int messageCount ) { - OutboundMessage message = messageBuilder.imageFragment(fragment, plan, requestAck, connectionOptions.sendImagesToLeft); + OutboundMessage message = messageBuilder.customMessage("image", payload, + "image " + plan.tile.name + "#" + messageNumber, plan.tileIndex, connectionOptions.sendImagesToLeft); message.setImageUpdatePosition(updateId, messageNumber, messageCount); message.onAck = () -> { imageRetryAfterMs = 0; @@ -2777,6 +3174,10 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private OutboundMessage createBatteryQueryMessageLocked() { OutboundMessage message = messageBuilder.batteryQuery(); message.onAck = () -> { + BleProtocol.RingBatterySnapshot ring = BleProtocol.parseRingBattery(message.ackPayload); + // Old firmware and missing/malformed extensions must clear any prior reading. + ringBattery = ring == null ? -1 : ring.battery; + ringCharging = ring == null ? -1 : ring.charging; BleProtocol.BatterySnapshot snapshot = BleProtocol.parseSettingsBattery(message.ackPayload); if (snapshot != null) { headsetBattery = snapshot.battery; @@ -2792,12 +3193,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); } }; @@ -3339,6 +3735,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { Log.e(TAG, "Transport failure: "+reason); synchronized (lock) { maybeEmitEvenAppConflictLocked(reason); + finishBenchmarkLocked(true, "transport failure"); sessionReady = false; fixedLayoutCreated = false; startupProbePending = false; @@ -3361,6 +3758,8 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { } private void resetSessionStateLocked() { + ringBattery = -1; + ringCharging = -1; sessionReady = false; shutdownRequested = false; fixedLayoutCreated = false; @@ -3388,6 +3787,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { lastFaceclawWakeLeaseQueuedAtMs = 0; faceclawWakeControlSentCount = 0; cfwCleanupDelivered = false; + for (CfwTransport transport : cfwTransports) transport.reset(); lastCfwCleanupAckMagic = 0; wearState = -1; displayedFingerprint = ""; @@ -3396,14 +3796,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) { @@ -3528,13 +3920,15 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { } private void emitBatteryState(int headsetBattery, int headsetCharging) { + final int reportedRingBattery = ringBattery; + final int reportedRingCharging = ringCharging; final FaceclawBleCommunicatorListener current = listener; if (current == null) { return; } mainHandler.post(() -> { try { - current.onBatteryState(headsetBattery, headsetCharging); + current.onBatteryState(headsetBattery, headsetCharging, reportedRingBattery, reportedRingCharging); } catch (Throwable t) { Log.w(TAG, "listener onBatteryState failed", t); } @@ -3548,7 +3942,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); } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicatorListener.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicatorListener.java index 594bde9a..8a6ed3d0 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicatorListener.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicatorListener.java @@ -4,12 +4,12 @@ public interface FaceclawBleCommunicatorListener { void onLog(String line); void onStateChange(String phase, String status); void onRingEvent(String kind, String containerName, int eventType, int eventSource, int systemExitReasonCode, int frameId); - void onBatteryState(int headsetBattery, int headsetCharging); + void onBatteryState(int headsetBattery, int headsetCharging, int ringBattery, int ringCharging); void onSilentMode(boolean silent); void onWearState(boolean wearing); void onPhoneLockState(boolean locked); 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); } 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 09f2fe55..b8ecc1df 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 @@ -42,6 +42,7 @@ public class FaceclawBleManager { private final ConcurrentHashMap servicesStatuses = new ConcurrentHashMap<>(); private final ConcurrentHashMap mtuLatches = new ConcurrentHashMap<>(); + private final ConcurrentHashMap negotiatedMtus = new ConcurrentHashMap<>(); private final ConcurrentHashMap mtuStatuses = new ConcurrentHashMap<>(); private final ConcurrentHashMap descriptorLatches = new ConcurrentHashMap<>(); @@ -99,6 +100,29 @@ public class FaceclawBleManager { } } + /** + * Android's bond state for this address (BluetoothDevice.BOND_NONE / + * BOND_BONDING / BOND_BONDED), or -1 when it cannot be determined. + * BOND_BONDING covers the whole OS pairing flow, including a pairing + * dialog that is still waiting for the user. + */ + public int getBondState(String address) { + if (address == null || address.trim().isEmpty()) { + return -1; + } + try { + BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address); + return device == null ? -1 : device.getBondState(); + } catch (Throwable t) { + return -1; + } + } + + /** Whether a GATT client for this address is open, i.e. no disconnect callback has arrived for it. */ + public boolean isConnected(String address) { + return address != null && gattClients.containsKey(address); + } + public boolean connect(String address, int timeoutMs) { if (address == null || address.trim().isEmpty()) { throw new IllegalArgumentException("address is required"); @@ -142,6 +166,7 @@ public class FaceclawBleManager { connectLatches.remove(address); connectResults.remove(address); gattClients.remove(address, gatt); + negotiatedMtus.remove(address); gatt.disconnect(); gatt.close(); return false; @@ -160,6 +185,28 @@ public class FaceclawBleManager { } } + /** One-shot benchmark preferences; success is established by callbacks/HCI, not submission. */ + public void prepareBenchmarkLink(String address, int mode) { + synchronized (gattLock(address)) { + BluetoothGatt gatt = requireGatt(address); + if ((mode & 1) != 0) { + boolean accepted = gatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH); + Log.i(TAG, "benchmark HIGH address=" + address + " submitted=" + accepted); + } + if ((mode & 2) != 0) { + Log.i(TAG, "benchmark request 2M address=" + address); + gatt.setPreferredPhy(BluetoothDevice.PHY_LE_2M_MASK, + BluetoothDevice.PHY_LE_2M_MASK, BluetoothDevice.PHY_OPTION_NO_PREFERRED); + } + gatt.readPhy(); + } + } + + public int getNegotiatedMtu(String address) { + Integer mtu = negotiatedMtus.get(address); + return mtu == null ? 23 : mtu; + } + public boolean requestMtu(String address, int mtu, int timeoutMs) { synchronized (gattLock(address)) { CountDownLatch latch = new CountDownLatch(1); @@ -350,6 +397,7 @@ public class FaceclawBleManager { Object gattLock = gattLock(address); synchronized (gattLock) { BluetoothGatt gatt = gattClients.remove(address); + negotiatedMtus.remove(address); if (gatt == null) { return; } @@ -423,6 +471,7 @@ public class FaceclawBleManager { Object gattLock = gattLock(address); synchronized (gattLock) { gattClients.remove(address, gatt); + negotiatedMtus.remove(address); gatt.close(); } dispatchConnectionState(address, false); @@ -442,6 +491,7 @@ public class FaceclawBleManager { @Override public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) { String address = gatt.getDevice().getAddress(); + if (status == BluetoothGatt.GATT_SUCCESS) negotiatedMtus.put(address, mtu); mtuStatuses.put(address, status); CountDownLatch latch = mtuLatches.remove(address); if (latch != null) { @@ -451,7 +501,14 @@ public class FaceclawBleManager { @Override public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) { - Log.i(TAG, "onPhyRead: txPhy=" + txPhy + " rxPhy=" + rxPhy + " status=" + status); + Log.i(TAG, "onPhyRead: address=" + gatt.getDevice().getAddress() + + " txPhy=" + txPhy + " rxPhy=" + rxPhy + " status=" + status); + } + + @Override + public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) { + Log.i(TAG, "onPhyUpdate: address=" + gatt.getDevice().getAddress() + + " txPhy=" + txPhy + " rxPhy=" + rxPhy + " status=" + status); } @Override diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.java index f5c0f51c..c4ad3efe 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.java @@ -1,25 +1,41 @@ package com.faceclaw.app; +import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothGatt; import android.content.Context; import android.os.Handler; import android.os.Looper; +import android.os.SystemClock; import android.util.Log; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.CountDownLatch; 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. */ public class FaceclawDeviceInfoProbe implements FaceclawBleListener { private static final String TAG = "FaceclawDeviceInfo"; private static final int QUERY_TIMEOUT_MS = 4_000; + /** Connect + auth attempts per arm; a link that drops mid-pairing is retried once the bond settles. */ + private static final int ARM_ATTEMPTS = 3; + private static final int ARM_RETRY_DELAY_MS = 1_000; + /** + * Upper bound on waiting for the auth success while Android reports the arm + * as BOND_BONDING — i.e. an OS pairing dialog may be sitting there waiting + * for the user, which can take a lot longer than the normal 30 s window. + */ + private static final int PAIRING_WAIT_CAP_MS = 90_000; + /** After a fresh bond, how long the firmware gets to notify success on its own before the request is re-sent. */ + private static final int POST_BOND_GRACE_MS = 2_000; + private static final int POLL_MS = 250; private final Context context; private final String rightAddress; @@ -36,6 +52,17 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener { private byte[] awaitPb = null; private CountDownLatch awaitLatch = null; + /** + * Security-auth wait, kept separate from the generic ack wait: only the + * firmware's SUCCESS result (empty result message) may satisfy it. The + * firmware answers the request as soon as it arrives, but with a + * non-success result until the link is encrypted; accepting that first + * reply as "the ack" is what let the probe move on to the other arm while + * Android's pairing dialog for this one was still up. + */ + private final Set authMagics = new HashSet<>(); + private CountDownLatch authLatch = null; + /** * A sid-0x09 frame that carried firmware versions without matching the * awaited magic — some firmware pushes the settings snapshot on a magic it @@ -92,16 +119,52 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener { return; } - byte[] ack = probeArm(rightAddress, "right"); + boolean haveLeft = !leftAddress.trim().isEmpty() && !leftAddress.equalsIgnoreCase(rightAddress); + + // Bring up and authenticate BOTH arms before asking for versions. + // Each arm is its own peripheral with its own bond, so on a fresh + // phone each raises its own pairing prompt; completing both here + // means the flash step (and the app proper) find both bonds in + // place. Strictly one arm at a time: Android pairs with one device + // at a time, and a second arm connected while the first was still + // pairing has been seen to drop within a second and never pair + // (2026-09-11 logcat). + boolean rightAuthenticated = bringUpArm(rightAddress, "right"); + boolean leftAuthenticated = false; + if (haveLeft && !cancelled) { + leftAuthenticated = bringUpArm(leftAddress, "left"); + } + if (cancelled) { + emitError("Cancelled."); + return; + } + if (!bleManager.isConnected(rightAddress)) { + // The right lens may have dropped while the left one paired; + // it is bonded by now, so this comes back quickly. + emitLog("right lens disconnected while the left lens was set up; reconnecting"); + rightAuthenticated = bringUpArm(rightAddress, "right"); + if (cancelled) { + emitError("Cancelled."); + return; + } + } + + byte[] ack = null; + String rightFailure = null; + try { + ack = queryArm(rightAddress, "right", rightAuthenticated); + } catch (IllegalStateException e) { + rightFailure = e.getMessage() == null ? e.toString() : e.getMessage(); + emitLog("right-lens query failed: " + rightFailure); + } // The right lens is the documented control endpoint, but a silent // right lens has been observed on stock 2.2.9 even after a // successful security auth — run the same probe against the left // lens rather than giving up, and log which lens answered. - if (ack == null && !cancelled && !leftAddress.trim().isEmpty() - && !leftAddress.equalsIgnoreCase(rightAddress)) { + if (ack == null && !cancelled && haveLeft) { emitLog("right lens did not answer the settings query; probing the left lens"); try { - ack = probeArm(leftAddress, "left"); + ack = queryArm(leftAddress, "left", leftAuthenticated); } catch (Exception e) { emitLog("left-lens probe failed: " + (e.getMessage() == null ? e.toString() : e.getMessage())); } @@ -111,17 +174,18 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener { return; } if (ack == null) { - throw new IllegalStateException( - "no response to the device-info query on either lens — check `adb logcat -s " + throw new IllegalStateException(rightFailure != null + ? rightFailure + : "no response to the device-info query on either lens — check `adb logcat -s " + TAG + "` for the frame trace"); } 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); @@ -134,34 +198,223 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener { } /** - * Connect + authenticate + prelude + settings read on one lens. Returns the - * settings ack protobuf, an unsolicited settings push that carried firmware - * versions, or null when the lens never answered the read. Throws on - * connect or prelude failure; the caller wraps the fallback lens's attempt + * Connect to one arm and complete its security-auth exchange, retrying + * when the link drops mid-pairing. Returns whether the auth success was + * seen (false = connected but unconfirmed, tolerated because the custom + * firmware's response to the exchange is not yet hardware-verified); + * throws when the arm cannot be brought up at all. + */ + private boolean bringUpArm(String address, String label) throws InterruptedException { + String lastFailure = null; + for (int attempt = 1; attempt <= ARM_ATTEMPTS && !cancelled; attempt++) { + if (attempt > 1) { + // A link Android dropped while it was still pairing comes back + // once the bond settles; reconnecting sooner just fails again. + waitForBondToSettle(address, label); + if (cancelled) { + break; + } + emitLog("retrying the " + label + " lens (attempt " + attempt + "/" + ARM_ATTEMPTS + "): " + lastFailure); + Thread.sleep(ARM_RETRY_DELAY_MS); + } + emitState("connecting", label); + try { + connectArm(address); + } catch (IllegalStateException e) { + lastFailure = e.getMessage() == null ? e.toString() : e.getMessage(); + emitLog(label + " lens: " + lastFailure); + continue; + } + if (cancelled) { + break; + } + + // Firmware 2.2.9 answers no queries until the security-auth + // exchange completes over an encrypted link; on a phone with no + // existing bond this is also what triggers SMP pairing (and its OS + // prompt), so it must come before the prelude and query. + emitState("authenticating", label); + AuthResult result = authenticate(address, label); + if (result == AuthResult.SUCCESS) { + return true; + } + if (result == AuthResult.UNCONFIRMED) { + return false; + } + lastFailure = "link dropped during authentication"; + } + if (cancelled) { + return false; + } + throw new IllegalStateException("could not connect to the " + label + " lens (" + address + "): " + + lastFailure + " — if Android showed a Bluetooth pairing request, accept it and try again"); + } + + private enum AuthResult { SUCCESS, UNCONFIRMED, LINK_DROPPED } + + /** + * Send the sid-0x80 authentication request and wait for the firmware's + * SUCCESS notification, which only arrives once the link is encrypted. + * On an unbonded phone that means waiting through Android's pairing flow + * (BOND_BONDING, possibly with a dialog up), so the wait is extended while + * the OS reports pairing in progress and the request is re-sent once + * after a fresh bond in case the pre-pairing write was dropped. Bond + * state is polled rather than awaited via broadcast; 250 ms granularity + * is plenty here. + */ + private AuthResult authenticate(String address, String label) throws InterruptedException { + long start = SystemClock.elapsedRealtime(); + long deadline = start + ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS; + long hardDeadline = start + PAIRING_WAIT_CAP_MS; + CountDownLatch latch = new CountDownLatch(1); + synchronized (lock) { + authMagics.clear(); + authLatch = latch; + } + int initialBond = bleManager.getBondState(address); + emitLog("security auth: " + label + " lens, Android bond state " + bondStateName(initialBond)); + try { + int sends = 0; + boolean lastSendFailed = false; + long nextSendAt = start; + long bondedAt = -1; + boolean resentAfterBond = false; + boolean loggedBonding = false; + while (!cancelled) { + long now = SystemClock.elapsedRealtime(); + int bond = bleManager.getBondState(address); + + if (bond == BluetoothDevice.BOND_BONDING) { + // OS pairing in progress — the firmware will answer once the + // link is encrypted. Don't write, don't give up, don't move + // on to the other arm. + if (!loggedBonding) { + emitLog("Android is pairing with the " + label + " lens; waiting for the user to accept"); + loggedBonding = true; + } + if (now >= hardDeadline) { + break; + } + } else { + if (bond == BluetoothDevice.BOND_BONDED && initialBond != BluetoothDevice.BOND_BONDED + && bondedAt < 0) { + bondedAt = now; + emitLog("Android bond established with the " + label + " lens; waiting for the auth success"); + deadline = Math.max(deadline, now + ConnectionOptions.SECURITY_AUTH_SOFT_TIMEOUT_MS); + } + boolean wantSend = sends == 0 + || (lastSendFailed && sends < 3 && now >= nextSendAt) + || (bondedAt >= 0 && !resentAfterBond && now - bondedAt >= POST_BOND_GRACE_MS); + if (wantSend) { + if (bondedAt >= 0) { + resentAfterBond = true; + if (sends > 0) { + emitLog("re-sending the auth request after pairing (" + label + " lens)"); + } + } + lastSendFailed = !sendAuthRequest(address); + sends++; + nextSendAt = SystemClock.elapsedRealtime() + ARM_RETRY_DELAY_MS; + if (lastSendFailed && !bleManager.isConnected(address)) { + return AuthResult.LINK_DROPPED; + } + } + if (now >= deadline) { + break; + } + } + + if (latch.await(POLL_MS, TimeUnit.MILLISECONDS)) { + emitLog("security auth complete: " + label + " lens (" + address + ")"); + return AuthResult.SUCCESS; + } + if (!bleManager.isConnected(address)) { + emitLog("security auth: " + label + " lens disconnected while waiting" + + (bond == BluetoothDevice.BOND_BONDING ? " (Android was still pairing)" : "")); + return AuthResult.LINK_DROPPED; + } + } + if (cancelled) { + return AuthResult.UNCONFIRMED; + } + emitLog("security auth unconfirmed: " + label + " lens (" + address + "), Android bond state " + + bondStateName(bleManager.getBondState(address))); + return AuthResult.UNCONFIRMED; + } finally { + synchronized (lock) { + authLatch = null; + authMagics.clear(); + } + } + } + + private boolean sendAuthRequest(String address) { + int magic = allocMagic(); + int seq; + synchronized (lock) { + authMagics.add(magic); + seq = nextSeq++ & 0xff; + } + byte[] payload = BleProtocol.buildAuthenticationRequest(magic); + emitLog(String.format("tx %s sid=0x%02x flag=0x%02x magic=%d seq=0x%02x len=%d", + address, BleProtocol.SID_SECURITY_AUTH, BleProtocol.FLAG_SECURITY_AUTH, magic, seq, payload.length)); + List frames = BleProtocol.framePb(payload, BleProtocol.SID_SECURITY_AUTH, BleProtocol.FLAG_SECURITY_AUTH, seq); + boolean written; + try { + written = bleManager.writeFrames( + address, BleProtocol.WRITE_CHAR_UUID, frames, ConnectionOptions.WRITE_TYPE, ConnectionOptions.WRITE_TIMEOUT_MS); + } catch (IllegalStateException e) { + // "Not connected" — the link went away underneath us. + written = false; + } + if (!written) { + emitLog("tx write FAILED sid=0x80 (" + address + ")"); + } + return written; + } + + /** Block while Android reports this arm as BOND_BONDING (pairing dialog up / SMP in flight). */ + private void waitForBondToSettle(String address, String label) throws InterruptedException { + long cap = SystemClock.elapsedRealtime() + PAIRING_WAIT_CAP_MS; + boolean logged = false; + while (!cancelled && bleManager.getBondState(address) == BluetoothDevice.BOND_BONDING + && SystemClock.elapsedRealtime() < cap) { + if (!logged) { + emitLog("waiting for Android to finish pairing with the " + label + " lens before reconnecting"); + logged = true; + } + Thread.sleep(POLL_MS); + } + } + + private static String bondStateName(int state) { + switch (state) { + case BluetoothDevice.BOND_NONE: + return "none"; + case BluetoothDevice.BOND_BONDING: + return "bonding"; + case BluetoothDevice.BOND_BONDED: + return "bonded"; + default: + return "unknown"; + } + } + + /** + * Prelude + settings read on an already connected/authenticated lens. + * Returns the settings ack protobuf, an unsolicited settings push that + * carried firmware versions, or null when the lens never answered the read. + * Throws on prelude failure; the caller wraps the fallback lens's attempt * so its failure cannot mask the primary lens's outcome. */ - private byte[] probeArm(String address, String label) throws InterruptedException { - emitState("connecting", label); - connectArm(address); - if (cancelled) { - return null; - } - - // Firmware 2.2.9 answers no queries until the security-auth exchange - // completes over an encrypted link; on a phone with no existing bond - // this is also what triggers SMP pairing (and its OS prompt), so it - // must come before the prelude and query. Soft: this probe also runs - // against the custom firmware, whose response to the exchange is not - // yet hardware-verified, so an unconfirmed auth falls through. - emitState("authenticating", label); - boolean authenticated = authenticate(address); + private byte[] queryArm(String address, String label, boolean authenticated) throws InterruptedException { if (cancelled) { return null; } 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) { @@ -191,15 +444,6 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener { return null; } - private boolean authenticate(String address) throws InterruptedException { - int magic = allocMagic(); - byte[] ack = writeAndAwaitAck(address, BleProtocol.SID_SECURITY_AUTH, BleProtocol.FLAG_SECURITY_AUTH, - magic, BleProtocol.buildAuthenticationRequest(magic), ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS); - boolean success = ack != null && BleProtocol.isAuthenticationSuccess(ack, magic); - emitLog(success ? "security auth complete: " + address : "security auth unconfirmed: " + address); - return success; - } - private void connectArm(String address) { if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { throw new IllegalStateException("connect failed"); @@ -284,7 +528,32 @@ public class FaceclawDeviceInfoProbe implements FaceclawBleListener { unsolicitedSettingsPb = frame.pb; } if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) { - return; // async event, not an ack + // Async event, not an ack. This includes the lens's own periodic + // sid-0x80 notifies (device-chosen magic, non-empty result). + return; + } + if (frame.sid == BleProtocol.SID_SECURITY_AUTH) { + boolean success = false; + boolean ours = false; + synchronized (lock) { + if (authLatch != null) { + ours = authMagics.contains(frame.msgSeq); + for (int magic : authMagics) { + if (BleProtocol.isAuthenticationSuccess(frame.pb, magic)) { + success = true; + authLatch.countDown(); + break; + } + } + } + } + if (ours && !success) { + // Expected before the link is encrypted: the firmware answers + // the request straight away with a non-success result and + // sends the real success once pairing/encryption completes. + emitLog("auth reply for magic " + frame.msgSeq + " is not the success result; still waiting"); + } + return; } synchronized (lock) { if (awaitLatch != null && frame.sid == awaitSid && frame.msgSeq == awaitMagic) { @@ -329,11 +598,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); } }); } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbeListener.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbeListener.java index 0288df31..fe02f55d 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbeListener.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbeListener.java @@ -4,11 +4,11 @@ package com.faceclaw.app; public interface FaceclawDeviceInfoProbeListener { void onLog(String line); - /** Lifecycle: connecting, querying. */ + /** Lifecycle: connecting/authenticating for each arm, then 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); diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.java index 6fc488d1..bb3e952d 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.java @@ -3,6 +3,7 @@ package com.faceclaw.app; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.net.Uri; import android.provider.Settings; import android.util.Log; @@ -47,19 +48,26 @@ public final class FaceclawEvenAppDetector { return hasNotfication; } - public static void openEvenAppSettings(Context context) { + /** Returns "opened", "not-installed", or "failed" for the phone UI. */ + public static String openEvenAppSettings(Context context) { if (context == null) { - return; + return "failed"; } Context appContext = context.getApplicationContext(); - Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); - intent.setData(Uri.parse("package:" + EVEN_PACKAGE_NAME)); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { + // Settings may launch successfully and then immediately close for a + // missing package, so check before starting the activity. + appContext.getPackageManager().getApplicationInfo(EVEN_PACKAGE_NAME, 0); + Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + intent.setData(Uri.parse("package:" + EVEN_PACKAGE_NAME)); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); appContext.startActivity(intent); - } catch (Throwable t) { + return "opened"; + } catch (PackageManager.NameNotFoundException e) { + return "not-installed"; + } catch (Exception t) { Log.w(TAG, "failed to open Even app settings", t); - openNotificationAccessSettings(appContext); + return "failed"; } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.java index f8d2ed6f..44e38a0b 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.java @@ -22,7 +22,12 @@ public class FaceclawForegroundService extends Service { public static final String ACTION_STOP = "com.faceclaw.app.action.STOP"; public static final String EXTRA_TEXT = "text"; - private static final String CHANNEL_ID = "faceclaw-dashboard"; + // Channel id was bumped from "faceclaw-dashboard" when the badge setting + // changed: Android freezes a channel's showBadge flag at creation, so the + // old channel (which let Samsung's launcher count the pinned notification + // as a red "1" badge) is deleted on upgrade rather than reused. + private static final String LEGACY_CHANNEL_ID = "faceclaw-dashboard"; + private static final String CHANNEL_ID = "faceclaw-connection"; private static final int NOTIFICATION_ID = 4201; @Override @@ -43,7 +48,7 @@ public class FaceclawForegroundService extends Service { ensureNotificationChannel(); Notification notification = buildNotification( - text != null && !text.trim().isEmpty() ? text : "Keeping the dashboard connected" + text != null && !text.trim().isEmpty() ? text : "Connected to glasses" ); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { @@ -69,14 +74,18 @@ public class FaceclawForegroundService extends Service { NotificationChannel channel = new NotificationChannel( CHANNEL_ID, - "Faceclaw dashboard", + "Glasses connection", NotificationManager.IMPORTANCE_LOW ); - channel.setDescription("Keeps the Faceclaw dashboard connected to the glasses."); + channel.setDescription("Keeps Faceclaw connected to the glasses."); + // The pinned status notification must not count toward the launcher + // icon's notification badge. + channel.setShowBadge(false); NotificationManager manager = getSystemService(NotificationManager.class); if (manager != null) { manager.createNotificationChannel(channel); + manager.deleteNotificationChannel(LEGACY_CHANNEL_ID); } } @@ -96,7 +105,7 @@ public class FaceclawForegroundService extends Service { : new Notification.Builder(this); return builder - .setContentTitle("faceclaw dashboard") + .setContentTitle("Faceclaw") .setContentText(text) .setSmallIcon(getApplicationInfo().icon) .setContentIntent(contentIntent) diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.java index eb97b21e..c8775f40 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.database.ContentObserver; import android.graphics.Bitmap; import android.media.AudioManager; import android.media.MediaDescription; @@ -27,6 +28,8 @@ import java.util.HashSet; import java.util.Set; public class FaceclawMediaController { + private static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners"; + private final Context appContext; private final Object lock = new Object(); private final Handler mainHandler = new Handler(Looper.getMainLooper()); @@ -70,9 +73,27 @@ public class FaceclawMediaController { } }; + /** + * Fires when the user grants or revokes notification-listener access in + * system settings. Session access depends on that grant, so the sessions + * listener is (re)registered and the state re-emitted whenever it changes; + * otherwise a grant made after start() would never be noticed. + */ + private final ContentObserver notificationAccessObserver = new ContentObserver(mainHandler) { + @Override + public void onChange(boolean selfChange) { + synchronized (lock) { + if (!started) return; + syncSessionsListenerLocked(); + refreshActiveControllerLocked(null); + } + } + }; + private volatile FaceclawMediaControllerListener listener; private MediaController activeController; private boolean started; + private boolean sessionsListenerRegistered; private Set ignoredPackages = new HashSet<>(); public FaceclawMediaController(Context context) { @@ -96,26 +117,48 @@ public class FaceclawMediaController { return; } started = true; - if (!isNotificationAccessEnabled()) { - emitStateLocked(); - return; - } - if (sessionManager != null) { - try { - sessionManager.addOnActiveSessionsChangedListener( - sessionsChangedListener, - listenerComponent, - mainHandler - ); - } catch (SecurityException ignored) { - emitStateLocked(); - return; - } + try { + appContext.getContentResolver().registerContentObserver( + Settings.Secure.getUriFor(ENABLED_NOTIFICATION_LISTENERS), + false, + notificationAccessObserver + ); + } catch (Exception e) { + Log.w("FaceclawMedia", "notification access observer registration failed", e); } + syncSessionsListenerLocked(); refreshActiveControllerLocked(null); } } + /** + * Keep the active-sessions listener registered exactly while notification + * access is granted. Registration throws SecurityException without the + * grant, so this is retried from the settings observer rather than only + * attempted once at start(). + */ + private void syncSessionsListenerLocked() { + if (sessionManager == null) return; + boolean accessEnabled = started && isNotificationAccessEnabled(); + if (accessEnabled && !sessionsListenerRegistered) { + try { + sessionManager.addOnActiveSessionsChangedListener( + sessionsChangedListener, + listenerComponent, + mainHandler + ); + sessionsListenerRegistered = true; + } catch (SecurityException ignored) { + } + } else if (!accessEnabled && sessionsListenerRegistered) { + try { + sessionManager.removeOnActiveSessionsChangedListener(sessionsChangedListener); + } catch (SecurityException ignored) { + } + sessionsListenerRegistered = false; + } + } + /** Apply the complete preference set and immediately choose an allowed session. */ public void setIgnoredPackagesJson(String packagesJson) { Set packages = new HashSet<>(); @@ -139,12 +182,11 @@ public class FaceclawMediaController { return; } started = false; - if (sessionManager != null) { - try { - sessionManager.removeOnActiveSessionsChangedListener(sessionsChangedListener); - } catch (SecurityException ignored) { - } + try { + appContext.getContentResolver().unregisterContentObserver(notificationAccessObserver); + } catch (Exception ignored) { } + syncSessionsListenerLocked(); setActiveControllerLocked(null); emitStateLocked(); } @@ -377,7 +419,7 @@ public class FaceclawMediaController { private boolean isNotificationAccessEnabled() { String enabledListeners = Settings.Secure.getString( appContext.getContentResolver(), - "enabled_notification_listeners" + ENABLED_NOTIFICATION_LISTENERS ); if (enabledListeners == null || enabledListeners.isEmpty()) { return false; diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java index 12680324..37a53d58 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java @@ -13,6 +13,7 @@ import com.k2fsa.sherpa.onnx.OfflineRecognizer; import com.k2fsa.sherpa.onnx.OfflineRecognizerConfig; import com.k2fsa.sherpa.onnx.OfflineRecognizerResult; import com.k2fsa.sherpa.onnx.OfflineStream; +import com.k2fsa.sherpa.onnx.OfflineWhisperModelConfig; import java.io.File; import java.nio.charset.StandardCharsets; @@ -61,12 +62,43 @@ public class FaceclawVoiceController { "decoder_model_merged.ort", "tokens.txt" }; + // Second on-device model: sherpa-onnx's offline Whisper backend (base.en, + // int8-quantized -- see the model-choice note in asr-model.ts). Directory + // shared with the TS-side download flow, same convention as ASR_MODEL_DIR. + // + // On every call, sherpa-onnx (offline-recognizer-whisper-impl.h, v1.13.0) + // runs Whisper's encoder over the whole buffer plus 1000 frames (~10s) of + // zero tail padding, capped at 30s. Re-decoding on Moonshine's + // TRANSCRIPT_DECODE_INTERVAL_MS live-partial cadence would repeat that + // encode, growing with the utterance, roughly 1.4x/second while the user is + // still speaking, so onboardModelKind gates that loop off for Whisper -- + // see processRecognizer(). Whisper is also known to hallucinate text on + // near-silent input; recognizeTranscriptSegment() gates that too. + private static final String ASR_WHISPER_MODEL_DIR = "sherpa-onnx-whisper-base-en-int8"; + private static final String[] ASR_WHISPER_MODEL_FILES = { + "base.en-encoder.int8.onnx", + "base.en-decoder.int8.onnx", + "base.en-tokens.txt" + }; + // Below this peak amplitude (pre-normalization, of a full-scale +/-1.0f + // buffer) a segment is treated as silence and never reaches the Whisper + // recognizer at all, rather than risking a hallucinated non-answer. Picked + // conservatively low (well under typical mic noise floor already seen in + // this pipeline's normalization target) -- UNTESTED on real hardware, tune + // against real glasses captures rather than trusting this number. + private static final float WHISPER_SILENCE_PEAK_THRESHOLD = 0.01f; private enum VoiceInputMode { - ONBOARD, // on-phone Moonshine transcription + ONBOARD, // on-phone transcription (Moonshine or Whisper; see onboardModelKind) CLOUD // decode locally, emit PCM for a cloud recognizer on the TS side } + /** Which on-device model ONBOARD mode uses. Set via setOnboardModelKind() before start(). */ + private enum OnboardModelKind { + MOONSHINE, + WHISPER + } + private final Context appContext; private final Handler mainHandler = new Handler(Looper.getMainLooper()); private final Object lock = new Object(); @@ -86,6 +118,7 @@ public class FaceclawVoiceController { private volatile boolean usePhoneMic; private boolean activePhoneMic; private VoiceInputMode mode = VoiceInputMode.CLOUD; + private volatile OnboardModelKind onboardModelKind = OnboardModelKind.MOONSHINE; private OfflineRecognizer recognizer; private FaceclawLc3Decoder lc3Decoder; private final float[] transcriptSamples = new float[TRANSCRIPT_SEGMENT_MAX_SAMPLES]; @@ -150,6 +183,17 @@ public class FaceclawVoiceController { this.saveRecordings = saveRecordings; } + /** + * Which on-device model {@link #start}("onboard") should load: "whisper" + * selects the second on-device model (sherpa-onnx offline Whisper); any + * other value (including null/absent) keeps the existing Moonshine model, + * so callers that never call this see unchanged behavior. Must be set + * before {@link #start}; has no effect in CLOUD mode. + */ + public void setOnboardModelKind(String kind) { + this.onboardModelKind = "whisper".equals(kind) ? OnboardModelKind.WHISPER : OnboardModelKind.MOONSHINE; + } + /** * When true, watch the decoded PCM and fire {@code onSpeechEnd} once the * speaker stops. Used by hands-free ("Hey Even") capture, which has no @@ -222,20 +266,26 @@ public class FaceclawVoiceController { } public void start(String requestedMode) { + start(requestedMode, 0); + } + + public void start(String requestedMode, int captureId) { synchronized (lock) { if (started) { emitStatus("Voice control is already listening."); + emitStopped(captureId); return; } if (!usePhoneMic && (communicator == null || !communicator.isSessionReady())) { emitStatus("Voice control needs an active G2 connection."); + emitStopped(captureId); return; } mode = parseMode(requestedMode); activePhoneMic = usePhoneMic; started = true; audioStarted = false; - workerThread = new Thread(this::runLoop, "FaceclawVoiceController"); + workerThread = new Thread(() -> runLoop(captureId), "FaceclawVoiceController"); workerThread.start(); } } @@ -306,18 +356,19 @@ public class FaceclawVoiceController { return VoiceInputMode.ONBOARD; } - private void runLoop() { + private void runLoop(int captureId) { try { deleteLegacyKwsFiles(); VoiceInputMode currentMode = mode; + OnboardModelKind currentOnboardKind = onboardModelKind; if (currentMode == VoiceInputMode.ONBOARD) { - File modelDir = findAsrModelDir(); + File modelDir = findAsrModelDir(currentOnboardKind); if (modelDir == null) { emitStatus("Voice model not downloaded (see Settings > Voice)."); return; } emitStatus("Loading transcription model..."); - recognizer = new OfflineRecognizer(buildRecognizerConfig(modelDir)); + recognizer = new OfflineRecognizer(buildRecognizerConfig(modelDir, currentOnboardKind)); resetTranscriptState(); lastTranscript = ""; } @@ -387,6 +438,7 @@ public class FaceclawVoiceController { audioStarted = false; workerThread = null; } + emitStopped(captureId); } } @@ -453,32 +505,48 @@ public class FaceclawVoiceController { return b.array(); } - private OfflineRecognizerConfig buildRecognizerConfig(File modelDir) { + private OfflineRecognizerConfig buildRecognizerConfig(File modelDir, OnboardModelKind kind) { + OfflineModelConfig.Builder modelConfig = OfflineModelConfig.builder() + .setNumThreads(1); + if (kind == OnboardModelKind.WHISPER) { + modelConfig + .setWhisper(OfflineWhisperModelConfig.builder() + .setEncoder(new File(modelDir, "base.en-encoder.int8.onnx").getAbsolutePath()) + .setDecoder(new File(modelDir, "base.en-decoder.int8.onnx").getAbsolutePath()) + .setLanguage("en") + .setTask("transcribe") + .build()) + .setTokens(new File(modelDir, "base.en-tokens.txt").getAbsolutePath()); + } else { + modelConfig + .setMoonshine(OfflineMoonshineModelConfig.builder() + .setEncoder(new File(modelDir, "encoder_model.ort").getAbsolutePath()) + .setMergedDecoder(new File(modelDir, "decoder_model_merged.ort").getAbsolutePath()) + .build()) + .setTokens(new File(modelDir, "tokens.txt").getAbsolutePath()); + } return OfflineRecognizerConfig.builder() .setFeatureConfig(FeatureConfig.builder() .setSampleRate(SAMPLE_RATE) .setFeatureDim(FEATURE_DIM) .build()) - .setModelConfig(OfflineModelConfig.builder() - .setMoonshine(OfflineMoonshineModelConfig.builder() - .setEncoder(new File(modelDir, "encoder_model.ort").getAbsolutePath()) - .setMergedDecoder(new File(modelDir, "decoder_model_merged.ort").getAbsolutePath()) - .build()) - .setTokens(new File(modelDir, "tokens.txt").getAbsolutePath()) - .setNumThreads(1) - .build()) + .setModelConfig(modelConfig.build()) .build(); } /** - * The Moonshine model directory, populated by the download flow in - * asr-model.ts (releases before 0.5.0 copied the same files out of the - * APK, so upgraded installs are already complete). Null when any file is + * The on-device model directory for the given kind, populated by the + * download flow in asr-model.ts (releases before 0.5.0 copied the + * Moonshine files out of the APK directly, so upgraded installs are + * already complete for that model). Null when any expected file is * missing, i.e. the model still needs to be downloaded. */ - private File findAsrModelDir() { - File modelDir = new File(appContext.getFilesDir(), ASR_ROOT + File.separator + ASR_MODEL_DIR); - for (String fileName : ASR_MODEL_FILES) { + private File findAsrModelDir(OnboardModelKind kind) { + boolean whisper = kind == OnboardModelKind.WHISPER; + String dirName = whisper ? ASR_WHISPER_MODEL_DIR : ASR_MODEL_DIR; + String[] fileNames = whisper ? ASR_WHISPER_MODEL_FILES : ASR_MODEL_FILES; + File modelDir = new File(appContext.getFilesDir(), ASR_ROOT + File.separator + dirName); + for (String fileName : fileNames) { File file = new File(modelDir, fileName); if (!file.exists() || file.length() == 0) { return null; @@ -658,6 +726,16 @@ public class FaceclawVoiceController { private void processRecognizer(float[] samples) { appendTranscriptSamples(samples); + // Each Whisper call re-encodes the whole buffer plus ~10s of tail + // padding (see the ASR_WHISPER_* comment above), + // so it skips the live-partial redecode Moonshine does on this + // interval and only decodes when a segment commits (8s buffer fill) + // or the utterance ends (decodeTranscript(true) in runLoop()). This + // means no live preview text while speaking in Whisper mode -- status + // stays "Listening..." until release. This is a deliberate tradeoff. + if (onboardModelKind == OnboardModelKind.WHISPER) { + return; + } long now = SystemClock.elapsedRealtime(); if (transcriptSampleCount >= TRANSCRIPT_MIN_SAMPLES && now - lastTranscriptDecodeAtMs >= TRANSCRIPT_DECODE_INTERVAL_MS) { @@ -767,6 +845,14 @@ public class FaceclawVoiceController { return ""; } float[] segment = Arrays.copyOf(transcriptSamples, sampleCount); + // Whisper hallucinates text on near-silent input (a known quirk of the + // model, not this pipeline); gate it on the PRE-normalization peak, since + // normalizePeak() below would otherwise amplify true silence right up to + // the target level and hide the very thing being checked for. Moonshine + // does not share this failure mode in practice, so it is left unchanged. + if (onboardModelKind == OnboardModelKind.WHISPER && peakAmplitude(segment) < WHISPER_SILENCE_PEAK_THRESHOLD) { + return ""; + } normalizePeak(segment); OfflineStream offlineStream = currentRecognizer.createStream(); try { @@ -780,7 +866,7 @@ public class FaceclawVoiceController { } } - private static void normalizePeak(float[] samples) { + private static float peakAmplitude(float[] samples) { float peak = 0f; for (float s : samples) { float a = Math.abs(s); @@ -788,6 +874,11 @@ public class FaceclawVoiceController { peak = a; } } + return peak; + } + + private static void normalizePeak(float[] samples) { + float peak = peakAmplitude(samples); if (peak <= 0f) { return; } @@ -805,7 +896,7 @@ public class FaceclawVoiceController { (committedTranscriptSampleCount + transcriptSampleCount) / (double) SAMPLE_RATE; String preview = text.length() <= TRANSCRIPT_LOG_PREVIEW_CHARS ? text : text.substring(0, TRANSCRIPT_LOG_PREVIEW_CHARS) + "..."; - Log.i(TAG, "Moonshine decode final=" + isFinal + Log.i(TAG, (onboardModelKind == OnboardModelKind.WHISPER ? "Whisper" : "Moonshine") + " decode final=" + isFinal + " audioSec=" + String.format(java.util.Locale.US, "%.2f", totalAudioSec) + " segmentAudioSec=" + String.format(java.util.Locale.US, "%.2f", segmentSampleCount / (double) SAMPLE_RATE) + " textLen=" + text.length() + " text=\"" + preview + "\""); @@ -930,6 +1021,13 @@ public class FaceclawVoiceController { mainHandler.post(currentListener::onSpeechEnd); } + private void emitStopped(int captureId) { + FaceclawVoiceControllerListener currentListener = listener; + if (currentListener != null) { + mainHandler.post(() -> currentListener.onStopped(captureId)); + } + } + /** * Decides when a hands-free utterance is over, so "Hey Even" capture can * stop without a button release. diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceControllerListener.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceControllerListener.java index c60ec655..95c5826f 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceControllerListener.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceControllerListener.java @@ -10,6 +10,9 @@ public interface FaceclawVoiceControllerListener { */ void onTranscript(String text, boolean isFinal); + /** Capture has finished, after the final transcript or a startup/recognition error. */ + void onStopped(int captureId); + /** * Decoded microphone audio: 16 kHz mono signed 16-bit little-endian PCM. * Emitted in every mode so raw-PCM consumers (levels, recording, captions) diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.java index 8e8f96ef..cb0da66f 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.java @@ -60,6 +60,10 @@ public final class FaceclawWearBridge { public static final String PATH_PREFIX = "/faceclaw"; public static final String PATH_STATE = "/faceclaw/state"; public static final String PATH_STATE_REQUEST = "/faceclaw/state/request"; + /** Watch -> phone: the watch's own battery; carries no seq and is never acked. */ + public static final String PATH_WATCH_BATTERY = "/faceclaw/battery"; + /** Phone -> watch: answered with PATH_WATCH_BATTERY even while the watch app is closed. */ + public static final String PATH_WATCH_BATTERY_REQUEST = "/faceclaw/battery/request"; public static final String PATH_ACK = "/faceclaw/ack"; public static final String PATH_EVENT = "/faceclaw/event"; @@ -284,6 +288,10 @@ public final class FaceclawWearBridge { boolean delivered = dispatchMessage(path, json, nodeId); if (delivered) return; + // A battery report answers a poll the dashboard sent; with no + // dashboard to receive it, it is simply dropped (the dashboard polls + // again when it starts), and the watch does not expect an ack. + if (PATH_WATCH_BATTERY.equals(path)) return; // No JS listener yet: tell the watch so it can explain why nothing is // happening. Only state requests are kept for replay (see class doc); diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/BleImageOptimizer.java b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/BleImageOptimizer.java index ec8eac4a..b9336cee 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/BleImageOptimizer.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/BleImageOptimizer.java @@ -1,11 +1,9 @@ package com.faceclaw.app; -import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.zip.Deflater; import android.util.Log; public final class BleImageOptimizer { @@ -79,7 +77,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)) + final byte[] payload; // bytes actually streamed: mode-6 rle(4bpp) final int sessionId; List fragments = Collections.emptyList(); @@ -113,7 +111,7 @@ public final class BleImageOptimizer { * Build a mode-3 bounding-box incremental payload, or null when a full * update should be sent instead (frames not comparable, or the changed * region spans the whole screen). Wire format: - * [3][left/4][top/2][width/4][height/2][fid_lo][fid_hi][zlib(rle(headerless 4bpp region))] + * [3][left/4][top/2][width/4][height/2][fid_lo][fid_hi][rle(headerless 4bpp region)] * The region is top-down rows of the NEW frame, stride width/2 bytes. The * box is aligned so left/width are multiples of 4 pixels and top/height * multiples of 2 rows, letting each coordinate fit one byte and avoiding @@ -260,7 +258,7 @@ public final class BleImageOptimizer { /** * Encode one CFW mode-3 rectangle delta: - * [3][left/4][top/2][width/4][height/2][fid_lo][fid_hi][zlib(rle(box pixels))] + * [3][left/4][top/2][width/4][height/2][fid_lo][fid_hi][rle(box pixels)] * left/width must be multiples of 4 (=> left>>1, width>>1 are whole bytes), top/ * height multiples of 2. The box pixels are top-down rows of `next` (4bpp packed, * width>>1 bytes/row), run-length encoded before deflate. Shared by the single-bbox @@ -273,7 +271,7 @@ public final class BleImageOptimizer { for (int y = 0; y < boxHeight; y++) { System.arraycopy(next, (top + y) * stride + (left >> 1), region, y * regionStride, regionStride); } - byte[] compressed = deflate(rleEncode(region)); + byte[] compressed = rleEncode(region); byte[] out = new byte[7 + compressed.length]; out[0] = 3; out[1] = (byte) (left / 4); @@ -286,6 +284,22 @@ public final class BleImageOptimizer { return out; } + /** A full repaint in independently decodable commands below the uint16 record limit. */ + static List encodeFullFrameBands(byte[] packed, int width, int height, int firstFid) { + if (width <= 0 || width > 640 || (width & 3) != 0 || height <= 0 || height > 480 + || (height & 1) != 0 || packed.length != width * height / 2) { + throw new IllegalArgumentException("unsupported custom framebuffer dimensions"); + } + List commands = new ArrayList<>(); + int fid = firstFid; + for (int top = 0; top < height; top += 64) { + commands.add(encodeMode3Rect(packed, width / 2, 0, top, width, + Math.min(64, height - top), fid)); + fid = fid >= 0xfffe ? 1 : fid + 1; + } + return commands; + } + /** * A CFW mode-8 multi-segment payload (`[8][count]` then per-rect * `[len16][mode-3 submsg]`) carrying several tight rectangle deltas instead of @@ -310,8 +324,7 @@ public final class BleImageOptimizer { } // Break-even tuning for the rect splitter. Splitting adds ~15 fixed bytes per - // rect (seglen + mode-3 header + fid + zlib framing) and loses cross-rect - // dictionary sharing, so only split across gaps big enough to pay for that. + // rect (seglen + mode-3 header + fid), so only split across gaps big enough to pay for that. // Gaps are in the changed-mask's native units: whole 4bpp bytes (2px) for // columns, rows for the vertical bands. Kept above the 4px/2px box alignment so // aligned rects never overlap. @@ -461,8 +474,8 @@ public final class BleImageOptimizer { } /** - * 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 + * Run-length encode headerless 4bpp pixels for CFW load_image_z mode 6. + * Wire format: [6][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. */ @@ -470,7 +483,7 @@ public final class BleImageOptimizer { if (packed == null || packed.length == 0) { return packed; } - byte[] z = deflate(rleEncode(packed)); + byte[] z = rleEncode(packed); byte[] out = new byte[z.length + 1]; out[0] = 6; System.arraycopy(z, 0, out, 1, z.length); @@ -479,7 +492,7 @@ public final class BleImageOptimizer { /** * Run-length encode packed 4bpp pixels for CFW modes 3 and 6, whose payload is - * zlib(rle(pixels)) rather than zlib(pixels). Runs are over the pixel NIBBLES of + * RLE tokens; deflate belongs to the transport. Runs are over the pixel NIBBLES of * {@code pix} in wire order (high nibble = left pixel), including the pad nibble * that ends each row at odd widths — i.e. {@code pix} read as 2*length nibbles. * One token is: @@ -527,35 +540,6 @@ public final class BleImageOptimizer { return (i & 1) != 0 ? (b & 0x0f) : (b >> 4); } - // Level 6: BEST_COMPRESSION cost 18-109ms per frame on the BLE worker, - // but BEST_SPEED inflated typical payloads from ~2.7KB past the 3800-byte - // fragment boundary, adding a whole extra ack round trip (~350ms). The - // default level keeps payloads under one fragment at about half the CPU. - // One long-lived Deflater per thread: constructing one allocates and - // initializes a native zlib stream, which is measurable at per-frame rates. - private static final ThreadLocal DEFLATER = - new ThreadLocal() { - @Override protected Deflater initialValue() { - return new Deflater(Deflater.DEFAULT_COMPRESSION); - } - }; - - private static byte[] deflate(byte[] data) { - Deflater deflater = DEFLATER.get(); - try { - deflater.setInput(data); - deflater.finish(); - ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(64, data.length / 3)); - byte[] buf = new byte[4096]; - while (!deflater.finished()) { - out.write(buf, 0, deflater.deflate(buf)); - } - return out.toByteArray(); - } finally { - deflater.reset(); - } - } - public static final class ImageUpdateStats { final int paintMs; final int tileCount; diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/BleProtocol.java b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/BleProtocol.java index 686e0ae8..6031f24d 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/BleProtocol.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/BleProtocol.java @@ -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; @@ -72,6 +71,19 @@ public class BleProtocol { public static final int FACECLAW_WEAR_OP_QUERY = 7; public static final int CFW_IMAGE_MODE_CLEANUP = 11; private static final int FACECLAW_WAKE_EVENT = 1; + // Field-102 deferred wake from the IMU head-up (Faceclaw firmware revision + // 3+); same nonce handshake as the double-tap wake event 1. + public static final int FACECLAW_WAKE_EVENT_HEAD_UP = 5; + // Field-102 idle-gesture events (Faceclaw firmware revision 2+): gestures the + // stock display thread drops while no app is on screen, forwarded while the + // wake lease is held. Their last two bytes are the raw touch source and 0. + public static final int FACECLAW_GESTURE_EVENT_TAP = 2; + public static final int FACECLAW_GESTURE_EVENT_LONG_PRESS = 3; + public static final int FACECLAW_GESTURE_EVENT_LONG_PRESS_RELEASE = 4; + // The display thread's raw touch sources, as the firmware reports them. + private static final int FACECLAW_RAW_SOURCE_LEFT_TEMPLE = 0; + private static final int FACECLAW_RAW_SOURCE_RIGHT_TEMPLE = 1; + private static final int FACECLAW_RAW_SOURCE_RING = 4; private static final int FACECLAW_WAKE_PROTOCOL_VERSION = 1; // UI_FOREGROUND_EVEN_AI_ID: the stock "Even AI" assistant app. It is a // FOREGROUND app, whereas EvenHub (and therefore faceclaw) is the @@ -112,6 +124,9 @@ public class BleProtocol { public static final int EVENT_RING_LONG_PRESS_RELEASE = 10; // CFW extension: G2 2.2.9 tap-then-hold gesture forwarded to the phone. public static final int EVENT_SHORT_THEN_LONG_PRESS = 11; + // CFW extension (firmware revision 3+): the IMU head-up, forwarded as a + // sys-event while an EvenHub page is on screen (soft sleep). + public static final int EVENT_HEAD_UP = 12; public static final int EVENT_SOURCE_GLASSES_R = 1; public static final int EVENT_SOURCE_RING = 2; @@ -170,13 +185,11 @@ public class BleProtocol { } - public static byte[] buildCreateMixedImagePage(int magic, ImageTileOptions[] tiles) { + /** Retain the text container for forwarded inputs, without an image container. */ + public static byte[] buildCreateInputPage(int magic) { List innerParts = new ArrayList<>(); - innerParts.add(encodeVarintField(1, 1 + tiles.length)); + innerParts.add(encodeVarintField(1, 1)); innerParts.add(encodeMessageField(3, encodeTextObject("dashboard", 1, 0, 0, 576, 288, " ", true))); - for (ImageTileOptions tile : tiles) { - innerParts.add(encodeMessageField(4, encodeImageObject(tile))); - } innerParts.add(encodeVarintField(5, 10000)); byte[] inner = concat(innerParts); return wrapEvenHub(0, magic, 3, inner); @@ -475,24 +488,127 @@ public class BleProtocol { return body; } + /** 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); + if (body == null || body.length != 5 || body[0] != 'R' || body[1] != 'B' + || body[2] != 1) return null; + int flags = body[3] & 0xff; + int level = body[4] & 0xff; + if ((flags & ~7) != 0) return null; + if ((flags & 2) != 0) { + if ((flags & 1) == 0 || level > 100) return null; + return new RingBatterySnapshot(level, (flags & 4) != 0 ? 1 : 0); + } + if (level != 255 || (flags & 4) != 0) return null; + return new RingBatterySnapshot(-1, -1); + } + + public static final class RingBatterySnapshot { + final int battery; + final int charging; + RingBatterySnapshot(int battery, int charging) { + this.battery = battery; + this.charging = charging; + } + } + /** - * Return the uint16 wake nonce from a CFW field-102 notification, or -1 - * when this is an ordinary settings frame. + * Return the uint16 wake nonce from a CFW field-102 deferred-wake + * notification (double tap or head-up), or -1 when this is an ordinary + * settings frame (idle-gesture events included). */ public static int parseFaceclawWakeEvent(byte[] pb) { + byte[] event = faceclawWakeEventBytes(pb); + return event == null ? -1 : (event[4] & 0xff) | ((event[5] & 0xff) << 8); + } + + /** + * Which gesture a CFW deferred-wake notification reports: 1 (double tap) + * or FACECLAW_WAKE_EVENT_HEAD_UP; -1 when the frame is not a wake event. + */ + public static int parseFaceclawWakeEventCode(byte[] pb) { + byte[] event = faceclawWakeEventBytes(pb); + return event == null ? -1 : (event[3] & 0xff); + } + + private static byte[] faceclawWakeEventBytes(byte[] pb) { if (pb == null) { - return -1; + return null; } byte[] event = readFieldBytes(stripTrailingCrc(pb), FACECLAW_WAKE_EVENT_FIELD); if (event == null || event.length != 6 || event[0] != 'F' || event[1] != 'C' - || (event[2] & 0xff) != FACECLAW_WAKE_PROTOCOL_VERSION - || (event[3] & 0xff) != FACECLAW_WAKE_EVENT) { - return -1; + || (event[2] & 0xff) != FACECLAW_WAKE_PROTOCOL_VERSION) { + return null; } - return (event[4] & 0xff) | ((event[5] & 0xff) << 8); + int code = event[3] & 0xff; + return code == FACECLAW_WAKE_EVENT || code == FACECLAW_WAKE_EVENT_HEAD_UP ? event : null; + } + + /** An idle gesture from a CFW field-102 notification, in EvenHub sys-event terms. */ + public static final class FaceclawGestureEvent { + public final int eventType; + public final int eventSource; + + FaceclawGestureEvent(int eventType, int eventSource) { + this.eventType = eventType; + this.eventSource = eventSource; + } + } + + /** + * Decode a CFW field-102 idle-gesture event (tap, long press, release + * while no app is on screen) into the EvenHub sys-event type and source + * the same gesture would carry from a live page, or null when the frame + * is not one (ordinary settings frames and the double-tap wake event + * included). + */ + public static FaceclawGestureEvent parseFaceclawGestureEvent(byte[] pb) { + if (pb == null) { + return null; + } + byte[] event = readFieldBytes(stripTrailingCrc(pb), FACECLAW_WAKE_EVENT_FIELD); + if (event == null + || event.length != 6 + || event[0] != 'F' + || event[1] != 'C' + || (event[2] & 0xff) != FACECLAW_WAKE_PROTOCOL_VERSION) { + return null; + } + int eventType; + switch (event[3] & 0xff) { + case FACECLAW_GESTURE_EVENT_TAP: + eventType = EVENT_CLICK; + break; + case FACECLAW_GESTURE_EVENT_LONG_PRESS: + eventType = EVENT_RING_LONG_PRESS; + break; + case FACECLAW_GESTURE_EVENT_LONG_PRESS_RELEASE: + eventType = EVENT_RING_LONG_PRESS_RELEASE; + break; + default: + return null; + } + int eventSource; + switch (event[4] & 0xff) { + case FACECLAW_RAW_SOURCE_LEFT_TEMPLE: + eventSource = EVENT_SOURCE_GLASSES_L; + break; + case FACECLAW_RAW_SOURCE_RIGHT_TEMPLE: + eventSource = EVENT_SOURCE_GLASSES_R; + break; + case FACECLAW_RAW_SOURCE_RING: + eventSource = EVENT_SOURCE_RING; + break; + default: + eventSource = 0; + break; + } + return new FaceclawGestureEvent(eventType, eventSource); } /** @@ -559,11 +675,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/"; older builds sent + * "EVENCFW/ "), 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); @@ -573,11 +692,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) { @@ -1094,14 +1213,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); } } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/CfwMessageWindow.java b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/CfwMessageWindow.java new file mode 100644 index 00000000..c342b066 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/CfwMessageWindow.java @@ -0,0 +1,38 @@ +package com.faceclaw.app; + +import java.util.ArrayList; +import java.util.List; + +/** Ordered completion and go-back-N recovery for the custom-message window. */ +final class CfwMessageWindow { + // Flappy capture: p99 ACK 63ms, max 77ms. Leave room for full-frame + // processing while recovering a lost reply well before the stock timeout. + static final int ACK_TIMEOUT_MS = 500; + static final int MAX_RETRIES = 3; + + private CfwMessageWindow() {} + + static OutboundMessage acknowledgedHead(Iterable messages) { + for (OutboundMessage message : messages) { + if (message.sid != CfwTransport.SID) continue; + return !message.cfwRetryPending && message.cfwAckLenses == CfwTransport.BOTH ? message : null; + } + return null; + } + + static List replayWindow(Iterable messages, long nowMs) { + List replay = new ArrayList<>(); + boolean failed = false; + for (OutboundMessage message : messages) { + if (message.sid != CfwTransport.SID) continue; + failed |= message.cfwRetryPending || (message.cfwAckLenses != CfwTransport.BOTH + && message.ackDeadlineAtMs > 0 && message.ackDeadlineAtMs <= nowMs); + replay.add(message); + } + // A lost ACK, first fragment, or NACK can leave an older attempt + // unresolved. Replaying only the named failure strands that older + // attempt at the head until its timeout. Rewind the unresolved window. + if (!failed) replay.clear(); + return replay; + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/CfwTransport.java b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/CfwTransport.java new file mode 100644 index 00000000..e921b3fb --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/CfwTransport.java @@ -0,0 +1,141 @@ +package com.faceclaw.app; + +import java.io.ByteArrayOutputStream; +import java.util.zip.Deflater; +import java.util.ArrayList; +import java.util.List; + +/** Faceclaw/10 records: clear flags, wire length and decoded CRC; persistent zlib body. */ +public final class CfwTransport { + public static final int SID = 0xf0; + public static final int BOTH = 3; + public static final int MAX_MESSAGE = 65535; + public static final int COMPRESSED = 4, RESET_CONTEXT = 8; + private final Deflater deflater = new Deflater(); + private boolean resetPending = true; + private int previousLenses; + + public CfwTransport() {} + + public synchronized void reset() { + deflater.reset(); + resetPending = true; + previousLenses = 0; + } + + /** Compress only when writing, in exactly the order seen by the receiver. */ + public synchronized List encode(byte[] message, int streamId, int lenses, int mtu) { + validate(message, streamId, lenses, mtu); + if (previousLenses != lenses) reset(); + boolean reset = resetPending; + deflater.setInput(message); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] chunk = new byte[4096]; + int count; + do { + count = deflater.deflate(chunk, 0, chunk.length, Deflater.SYNC_FLUSH); + out.write(chunk, 0, count); + } while (count == chunk.length); + byte[] body = out.toByteArray(); + int flags = lenses | COMPRESSED | (reset ? RESET_CONTEXT : 0); + if (body.length == 0) flags &= ~COMPRESSED; // repeated empty sync flush + if (body.length > MAX_MESSAGE) { + // Incompressible maximum-size records still fit as raw records. + // The attempted deflate advanced history: reset both ends before reuse. + reset(); + body = message; + flags = lenses | RESET_CONTEXT; + } else { + resetPending = false; + previousLenses = lenses; + } + return frameRecord(body, crc(message), streamId, flags, mtu); + } + + private static void validate(byte[] message, int streamId, int lenses, int mtu) { + if (message == null || message.length > MAX_MESSAGE || streamId < 0 || streamId > 255 + || lenses < 1 || lenses > BOTH || mtu < 23 || mtu > 517) + throw new IllegalArgumentException("invalid CFW stream parameters"); + } + + /** One logical command per stream for now. Packets are bounded by actual ATT MTU. */ + public static List frame(byte[] message, int streamId, int lenses, int mtu) { + validate(message, streamId, lenses, mtu); + return frameRecord(message, crc(message), streamId, lenses | RESET_CONTEXT, mtu); + } + + private static List frameRecord(byte[] body, int checksum, int streamId, int flags, int mtu) { + int lenses = flags & BOTH; + int capacity = Math.min(252, mtu - 14); + byte[] stream = new byte[body.length + 5]; + stream[0] = (byte) flags; + stream[1] = (byte) body.length; + stream[2] = (byte) (body.length >>> 8); + stream[3] = (byte) checksum; + stream[4] = (byte) (checksum >>> 8); + System.arraycopy(body, 0, stream, 5, body.length); + List packets = new ArrayList<>(); + for (int offset = 0, index = 0; offset < stream.length; offset += capacity, index++) { + int count = Math.min(capacity, stream.length - offset); + byte[] packet = new byte[count + 11]; + packet[0] = (byte) 0xaa; + packet[1] = 0x21; + packet[2] = (byte) (streamId + index); + packet[3] = (byte) (count + 3); + packet[4] = packet[5] = 1; + packet[6] = (byte) SID; + packet[8] = (byte) (lenses | (offset == 0 ? 0x80 : 0) + | (offset + count == stream.length ? 0x40 : 0)); + System.arraycopy(stream, offset, packet, 9, count); + int crc = crc(packet, 8, count + 1); + packet[packet.length - 2] = (byte) crc; + packet[packet.length - 1] = (byte) (crc >>> 8); + packets.add(packet); + } + return packets; + } + + public static int crc(byte[] data) { return crc(data, 0, data.length); } + private static int crc(byte[] data, int offset, int count) { + int crc = 0xffff; + for (int i = offset; i < offset + count; i++) { + crc ^= (data[i] & 255) << 8; + for (int bit = 0; bit < 8; bit++) + crc = ((crc << 1) ^ ((crc & 0x8000) != 0 ? 0x1021 : 0)) & 65535; + } + return crc; + } + private static int u16(byte[] data, int offset) { + return (data[offset] & 255) | ((data[offset + 1] & 255) << 8); + } + public static Ack parseAck(byte[] packet) { + Ack[] acks = parseAcks(packet); + return acks == null ? null : acks[0]; + } + /** Primary ACK followed by up to three explicit preceding successes from + * the same processing lens. Validate the entire packet before applying any. */ + public static Ack[] parseAcks(byte[] packet) { + if (packet == null || packet.length < 19 || packet.length > 40 + || (packet.length - 19) % 7 != 0 || (packet[0] & 255) != 0xaa + || packet[1] != 0x12 || (packet[3] & 255) != packet.length - 8 || packet[4] != 1 || packet[5] != 1 + || (packet[6] & 255) != SID || packet[7] != 0 || (packet[8] != 1 && packet[8] != 3) + || (packet[12] != 1 && packet[12] != 2) + || (packet[8] == 3 && packet.length != 19) + || crc(packet, 8, packet.length - 10) != u16(packet, packet.length - 2)) return null; + Ack[] acks = new Ack[1 + (packet.length - 19) / 7]; + acks[0] = new Ack(packet[8] == 3, packet[9] & 255, u16(packet, 10), packet[12], u16(packet, 13), u16(packet, 15)); + for (int i = 1, offset = 17; i < acks.length; i++, offset += 7) + acks[i] = new Ack(false, packet[offset] & 255, u16(packet, offset + 1), + packet[12], u16(packet, offset + 3), u16(packet, offset + 5)); + return acks; + } + public static final class Ack { + public final boolean nack; + public final int streamId, messageId, lens, size, checksum; + Ack(boolean nack, int streamId, int messageId, int lens, int size, int checksum) { + this.nack = nack; + this.streamId = streamId; this.messageId = messageId; this.lens = lens; + this.size = size; this.checksum = checksum; + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/MessageBuilder.java b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/MessageBuilder.java index 82a7ca44..8377dcc4 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/MessageBuilder.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/MessageBuilder.java @@ -72,35 +72,18 @@ public class MessageBuilder { String label, boolean leftArm ) { - BleProtocol.ImageFragment fragment = - new BleProtocol.ImageFragment(0, payload, payload.length); - int magic = magicPool.allocate(); - return new OutboundMessage( - kind, - label, - BleProtocol.SID_EVENHUB, - BleProtocol.FLAG_REQUEST, - magic, - BleProtocol.buildImageRawData(tile, sessionId, payload.length, fragment, magic), - ACK_TIMEOUT_MS, - -1, - leftArm - ); + // Keep these arguments for source compatibility with existing callers; + // the private command no longer carries a tile, session, or image header. + return customMessage(kind, payload, label, -1, leftArm); } - public OutboundMessage imageFragment(BleProtocol.ImageFragment fragment, BleImageOptimizer.TileImagePlan plan, boolean requestAck, boolean leftArm) { - int magic = requestAck ? magicPool.allocate() : 0; - return new OutboundMessage( - "image", - "image " + plan.tile.name + "#" + fragment.index, - BleProtocol.SID_EVENHUB, - BleProtocol.FLAG_REQUEST, - magic, - BleProtocol.buildImageRawData(plan.tile, plan.sessionId, plan.payload.length, fragment, magic), - ACK_TIMEOUT_MS, - plan.tileIndex, - leftArm - ); + public OutboundMessage customMessage(String kind, byte[] payload, String label, + int tileIndex, boolean leftArm) { + if (payload == null || payload.length > CfwTransport.MAX_MESSAGE) + throw new IllegalArgumentException("CFW message exceeds uint16 length"); + int streamId = magicPool.allocate(); + return new OutboundMessage(kind, label, CfwTransport.SID, 0, streamId, payload, + CfwMessageWindow.ACK_TIMEOUT_MS, tileIndex, leftArm); } public OutboundMessage cfwCleanup( @@ -179,7 +162,7 @@ public class MessageBuilder { ); } - public OutboundMessage createLayout(BleProtocol.ImageTileOptions... tiles) { + public OutboundMessage createLayout() { int magic = magicPool.allocate(); return new OutboundMessage( "create-layout", @@ -187,7 +170,7 @@ public class MessageBuilder { BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, magic, - BleProtocol.buildCreateMixedImagePage(magic, tiles), + BleProtocol.buildCreateInputPage(magic), ACK_TIMEOUT_MS, -1, false diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/OutboundMessage.java b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/OutboundMessage.java index 509b1397..bfdcd5cf 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/OutboundMessage.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/OutboundMessage.java @@ -6,12 +6,16 @@ public final class OutboundMessage { final String label; final int sid; final int flag; - final int magic; + int magic; final byte[] message; final int ackTimeoutMs; final int tileIndex; final boolean isLeftArmMessage; + int cfwAckLenses, cfwRetries; + boolean cfwRetryPending; + final int cfwChecksum; + int imageUpdateId; int imageMessageNumber; int imageMessageCount; @@ -30,11 +34,35 @@ public final class OutboundMessage { this.flag = flag; this.magic = magic; this.message = message == null ? new byte[0] : Arrays.copyOf(message, message.length); + this.cfwChecksum = sid == CfwTransport.SID ? CfwTransport.crc(this.message) : 0; this.ackTimeoutMs = ackTimeoutMs; this.tileIndex = tileIndex; this.isLeftArmMessage = isLeftArmMessage; } + /** NACK names this attempt's stream/message sequence, even without a decoded size. */ + boolean acceptCfwAck(CfwTransport.Ack ack) { + if (ack == null || sid != CfwTransport.SID || magic != ack.streamId + || ack.messageId != 0 || (ack.lens != 1 && ack.lens != 2)) return false; + if (ack.nack) { + cfwRetryPending = true; + return false; + } + if (message.length != ack.size || cfwChecksum != ack.checksum) return false; + cfwAckLenses |= ack.lens; + return !cfwRetryPending && cfwAckLenses == CfwTransport.BOTH; + } + + /** Replace an attempt atomically under the communicator lock. */ + void prepareCfwReplay(int streamId) { + magic = streamId; + ++cfwRetries; + cfwAckLenses = 0; + cfwRetryPending = false; + ackDeadlineAtMs = 0; + ackPayload = new byte[0]; + } + void setImageUpdatePosition(int updateId, int messageNumber, int messageCount) { this.imageUpdateId = updateId; this.imageMessageNumber = messageNumber; diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/TextureCacheState.java b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/TextureCacheState.java index 0f0da3ee..23cebc1d 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/TextureCacheState.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/TextureCacheState.java @@ -7,31 +7,31 @@ import java.util.List; import java.util.Map; /** - * Phone-side model of the CFW's flat 64 KiB texture cache (zlib_glue mode 12). + * Phone-side model of the CFW's flat 256 KiB texture cache (zlib_glue mode 18). * The firmware holds only bytes; every structural decision — where font * tables and glyph images live, what is resident, when to start over — is - * made here. Layout per font: a 96-entry uint16 offset table (chars 32..127) + * made here. Layout per font: a 96-entry uint32 offset table (chars 32..127) * whose entries are written lazily as each glyph is uploaded; glyph images * are the GlyphAtlas cached bytes ([w][h][4bpp RLE]). * * Allocation is a bump pointer with reset-on-full: the realistic working set * (a few fonts' tables plus ~hundreds of glyphs at tens of bytes each) is far - * below 64 KiB, so eviction sophistication buys nothing. After a reset the + * below 256 KiB, so eviction sophistication buys nothing. After a reset the * firmware cache still holds stale bytes; that is safe because a draw only * ever references (font table entry, glyph image) pairs uploaded in the - * current generation — stale table entries are never named in a mode-14 + * current generation — stale table entries are never named in a mode-20 * string. * - * Upload entries accumulate as complete [offset u16][len u16][data] records - * and drain into one or more standalone mode-12 payloads, each independently + * Upload entries accumulate as complete [offset u32][len u16][data] records + * and drain into one or more standalone mode-18 payloads, each independently * valid, enqueued ahead of the image message that references them (the * transport is FIFO, so no ack round-trip is needed before use). * * Not thread-safe by itself: the communicator calls it under its own lock. */ public final class TextureCacheState { - public static final int CACHE_SIZE = 65536; - private static final int FONT_TABLE_BYTES = 96 * 2; + public static final int CACHE_SIZE = 262144; + private static final int FONT_TABLE_BYTES = 96 * 4; private int allocEnd = 0; private final Map fontTableOffsets = new HashMap<>(); @@ -64,7 +64,7 @@ public final class TextureCacheState { /** * Bytes currently allocated out of CACHE_SIZE, for logging/tuning (a * sudden drop in the frame log means a reset-on-full re-upload cycle — - * the signal that the 64 KiB budget is being outgrown). + * the signal that the 256 KiB budget is being outgrown). */ public int usedBytes() { return allocEnd; @@ -78,9 +78,9 @@ public final class TextureCacheState { /** * Ensure a glyph image (and its font table slot) is resident, queuing the - * mode-12 upload entries for anything newly placed. Returns the glyph's + * mode-18 upload entries for anything newly placed. Returns the glyph's * image offset, or -1 when the cache is full (caller resets and retries) - * or the encoding is outside the mode-14 table (32..127). + * or the encoding is outside the mode-20 table (32..127). */ public int ensureGlyph(int fontId, int encoding, GlyphAtlas.Glyph glyph) { if (glyph == null || encoding < 32 || encoding > 127) return -1; @@ -104,13 +104,14 @@ public final class TextureCacheState { glyphOffsets.put(key, offset); addEntry(offset, glyph.cachedBytes); - addEntry(table + 2 * (encoding - 32), - new byte[]{(byte) (offset & 0xff), (byte) ((offset >> 8) & 0xff)}); + addEntry(table + 4 * (encoding - 32), + new byte[]{(byte) offset, (byte) (offset >> 8), + (byte) (offset >> 16), (byte) (offset >> 24)}); return offset; } /** - * Ensure an ImageAtlas entry is resident (mode-13 draws reference it by + * Ensure an ImageAtlas entry is resident (mode-19 draws reference it by * raw cache offset; no table involved). Returns the image offset, or -1 * when the cache is full (caller resets and retries). */ @@ -127,12 +128,14 @@ public final class TextureCacheState { } private void addEntry(int offset, byte[] data) { - byte[] entry = new byte[4 + data.length]; + byte[] entry = new byte[6 + data.length]; entry[0] = (byte) (offset & 0xff); entry[1] = (byte) ((offset >> 8) & 0xff); - entry[2] = (byte) (data.length & 0xff); - entry[3] = (byte) ((data.length >> 8) & 0xff); - System.arraycopy(data, 0, entry, 4, data.length); + entry[2] = (byte) ((offset >> 16) & 0xff); + entry[3] = (byte) ((offset >> 24) & 0xff); + entry[4] = (byte) (data.length & 0xff); + entry[5] = (byte) ((data.length >> 8) & 0xff); + System.arraycopy(data, 0, entry, 6, data.length); pendingEntries.add(entry); pendingBytes += entry.length; } @@ -147,7 +150,7 @@ public final class TextureCacheState { } /** - * Drain the queued entries into complete mode-12 payloads ([12][entries]), + * Drain the queued entries into complete mode-18 payloads ([18][entries]), * each at most maxPayloadBytes so a payload fits one BLE image message * without fragmentation. A single entry larger than the cap still gets its * own payload (the transport can fragment it). @@ -162,7 +165,7 @@ public final class TextureCacheState { } if (current == null) { current = new ByteArrayOutputStream(Math.min(maxPayloadBytes, 4 + entry.length)); - current.write(12); + current.write(18); } current.write(entry, 0, entry.length); } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/TexturePlanner.java b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/TexturePlanner.java index 4ea07987..ac700cc2 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/TexturePlanner.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/TexturePlanner.java @@ -7,7 +7,7 @@ import java.util.List; /** * Plans a screen update that ships text and icons as on-glasses cached draws - * instead of pixels (CFW modes 12/13/14; see g2flash/patches/zlib_glue.c and + * instead of pixels (CFW modes 18/19/20; see g2flash/patches/zlib_glue.c and * texture_cache.c). * * Approach: dirty rects come from comparing the fully composited old and new @@ -19,8 +19,8 @@ import java.util.List; * occlusion/clipping, and draw-on-draw overlap). A draw that passes and is * (or can be made) resident in the texture cache is replayed on-glasses: its * written pixels are punched to 0 in the delta rect content — which is what - * makes text and icons nearly free to compress — and re-emitted as a mode-14 - * string or mode-13 image sub-message in the same atomic mode-8 batch, so + * makes text and icons nearly free to compress — and re-emitted as a mode-20 + * string or mode-19 image sub-message in the same atomic mode-8 batch, so * the shadow after apply equals the full composite exactly. Everything else * stays baked. * @@ -30,7 +30,7 @@ import java.util.List; public final class TexturePlanner { private TexturePlanner() {} - /** Cap on mode-14 string sub-messages (mode-8 count is a u8). */ + /** Cap on mode-20 string sub-messages (mode-8 count is a u8). */ private static final int MAX_GLYPH_RUNS = 180; /** * Soft cap on cached-glyph selection per update, before run grouping. @@ -38,21 +38,21 @@ public final class TexturePlanner { * screens draw everything; the run budget is the real bound. */ private static final int MAX_SELECTED_GLYPHS = 4600; - /** Cap on mode-13 image sub-messages per update. */ + /** Cap on mode-19 image sub-messages per update. */ private static final int MAX_IMAGE_DRAWS = 60; /** Cap on mode-15 builtin-font string sub-messages per update. */ private static final int MAX_FWTEXT_RUNS = 80; - /** Mode-12 payload size that fits one BLE image message comfortably. */ + /** Mode-18 payload size that fits one BLE image message comfortably. */ private static final int UPLOAD_PAYLOAD_MAX = 3600; /** Max x-adjust control bytes between two glyphs before starting a new run. */ private static final int MAX_ADJUST_BYTES = 4; - /** Options: identity LUT (top 15) + transparent, for mode-13 image draws. */ + /** Options: identity LUT (top 15) + transparent, for mode-19 image draws. */ private static final int IMAGE_DRAW_OPTIONS = 0x1f; public static final class Result { /** Complete image payload: a mode-8 batch of rect deltas + cached draws. */ public final byte[] payload; - /** Mode-12 upload payloads to enqueue BEFORE the image message. */ + /** Mode-18 upload payloads to enqueue BEFORE the image message. */ public final List uploads; /** Next mode-3 frame id (deltas consumed some). */ public final int nextFid; @@ -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 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)) { @@ -239,7 +235,7 @@ public final class TexturePlanner { : ensureResident(cache, selected); bakedCandidates += selected.size() - drawable.size(); - // Group glyphs into mode-14 runs; leftover-budget glyphs bake. + // Group glyphs into mode-20 runs; leftover-budget glyphs bake. List glyphDrawable = new ArrayList<>(); List imageDrawable = new ArrayList<>(); for (Selected sel : drawable) { @@ -509,7 +505,7 @@ public final class TexturePlanner { /** * Whether every in-panel nonzero pixel of the cached image equals the - * packed new frame — the mode-13 transparent draw writes exactly those. + * packed new frame — the mode-19 transparent draw writes exactly those. */ private static boolean imageMatchesComposite(byte[] packed, int stride, int width, int height, ImageAtlas.Entry atlas, int left, int top) { @@ -596,24 +592,26 @@ public final class TexturePlanner { return Collections.emptyList(); // unreachable } - /** Mode-13 cached-image draw: [13][offset u16][x u16][y u16][options u8]. */ + /** Mode-19 cached-image draw: [19][offset u32][x u16][y u16][options u8]. */ private static byte[] encodeImageDraw(TextureCacheState cache, Selected sel) { int offset = cache.ensureImage(sel.draw.imageId, sel.imageAtlas); // resident: returns the offset - byte[] sub = new byte[8]; - sub[0] = 13; + byte[] sub = new byte[10]; + sub[0] = 19; sub[1] = (byte) (offset & 0xff); sub[2] = (byte) ((offset >> 8) & 0xff); - sub[3] = (byte) (sel.draw.x & 0xff); - sub[4] = (byte) ((sel.draw.x >> 8) & 0xff); - sub[5] = (byte) (sel.draw.y & 0xff); - sub[6] = (byte) ((sel.draw.y >> 8) & 0xff); - sub[7] = (byte) IMAGE_DRAW_OPTIONS; + sub[3] = (byte) ((offset >> 16) & 0xff); + sub[4] = (byte) ((offset >> 24) & 0xff); + sub[5] = (byte) (sel.draw.x & 0xff); + sub[6] = (byte) ((sel.draw.x >> 8) & 0xff); + sub[7] = (byte) (sel.draw.y & 0xff); + sub[8] = (byte) ((sel.draw.y >> 8) & 0xff); + sub[9] = (byte) IMAGE_DRAW_OPTIONS; return sub; } /** - * Group selected glyphs into mode-14 string sub-messages: - * [14][fontTable u16][x u16][y u16][options u8][strlen u8][string] + * Group selected glyphs into mode-20 string sub-messages: + * [20][fontTable u32][x u16][y u16][options u8][strlen u8][string] * One run per (font, line y, top color) span; within a run, control bytes * 1..31 adjust x by -10..+20 to hit each glyph's exact position, and each * glyph advances x by its cached width. Order across runs is free: every @@ -664,17 +662,19 @@ public final class TexturePlanner { } if (!runGlyphs.isEmpty()) { byte[] stringBytes = string.toByteArray(); - byte[] run = new byte[9 + stringBytes.length]; - run[0] = 14; + byte[] run = new byte[11 + stringBytes.length]; + run[0] = 20; run[1] = (byte) (fontTable & 0xff); run[2] = (byte) ((fontTable >> 8) & 0xff); - run[3] = (byte) (first.gx & 0xff); - run[4] = (byte) ((first.gx >> 8) & 0xff); - run[5] = (byte) (first.draw.y & 0xff); - run[6] = (byte) ((first.draw.y >> 8) & 0xff); - run[7] = (byte) (first.top | 0x10); // top color + transparent - run[8] = (byte) stringBytes.length; - System.arraycopy(stringBytes, 0, run, 9, stringBytes.length); + run[3] = (byte) ((fontTable >> 16) & 0xff); + run[4] = (byte) ((fontTable >> 24) & 0xff); + run[5] = (byte) (first.gx & 0xff); + run[6] = (byte) ((first.gx >> 8) & 0xff); + run[7] = (byte) (first.draw.y & 0xff); + run[8] = (byte) ((first.draw.y >> 8) & 0xff); + run[9] = (byte) (first.top | 0x10); // top color + transparent + run[10] = (byte) stringBytes.length; + System.arraycopy(stringBytes, 0, run, 11, stringBytes.length); outRuns.add(run); drawn.addAll(runGlyphs); i = j; diff --git a/App_Resources/Android/src/main/java/com/k2fsa/sherpa/onnx/OfflineModelConfig.java b/App_Resources/Android/src/main/java/com/k2fsa/sherpa/onnx/OfflineModelConfig.java index 0d916bf8..ee130387 100644 --- a/App_Resources/Android/src/main/java/com/k2fsa/sherpa/onnx/OfflineModelConfig.java +++ b/App_Resources/Android/src/main/java/com/k2fsa/sherpa/onnx/OfflineModelConfig.java @@ -162,7 +162,7 @@ public class OfflineModelConfig { public static class Builder { private OfflineTransducerModelConfig transducer = new OfflineTransducerModelConfig(); private OfflineParaformerModelConfig paraformer = new OfflineParaformerModelConfig(); - private OfflineWhisperModelConfig whisper = new OfflineWhisperModelConfig(); + private OfflineWhisperModelConfig whisper = OfflineWhisperModelConfig.builder().build(); private OfflineFireRedAsrModelConfig fireRedAsr = new OfflineFireRedAsrModelConfig(); private OfflineMoonshineModelConfig moonshine = OfflineMoonshineModelConfig.builder().build(); private OfflineNemoEncDecCtcModelConfig nemo = new OfflineNemoEncDecCtcModelConfig(); @@ -191,6 +191,11 @@ public class OfflineModelConfig { return this; } + public Builder setWhisper(OfflineWhisperModelConfig whisper) { + this.whisper = whisper; + return this; + } + public Builder setTokens(String tokens) { this.tokens = tokens; return this; @@ -228,16 +233,6 @@ class OfflineParaformerModelConfig { private final QnnConfig qnnConfig = new QnnConfig(); } -class OfflineWhisperModelConfig { - private final String encoder = ""; - private final String decoder = ""; - private final String language = "en"; - private final String task = "transcribe"; - private final int tailPaddings = 1000; - private final boolean enableTokenTimestamps = false; - private final boolean enableSegmentTimestamps = false; -} - class OfflineFireRedAsrModelConfig { private final String encoder = ""; private final String decoder = ""; diff --git a/App_Resources/Android/src/main/java/com/k2fsa/sherpa/onnx/OfflineWhisperModelConfig.java b/App_Resources/Android/src/main/java/com/k2fsa/sherpa/onnx/OfflineWhisperModelConfig.java new file mode 100644 index 00000000..51245a2b --- /dev/null +++ b/App_Resources/Android/src/main/java/com/k2fsa/sherpa/onnx/OfflineWhisperModelConfig.java @@ -0,0 +1,114 @@ +package com.k2fsa.sherpa.onnx; + +/** + * Config for sherpa-onnx's offline (non-streaming) Whisper backend. + * + * Field names and types here are load-bearing: the native JNI glue reads + * them by name via reflection (GetFieldID), not through the getters below, + * so they must match sherpa-onnx's own OfflineWhisperModelConfig exactly + * (verified against sherpa-onnx/jni/offline-recognizer.cc at the pinned + * release tag: it unconditionally reads encoder, decoder, language, task, + * tailPaddings, enableTokenTimestamps and enableSegmentTimestamps off the + * OfflineModelConfig's "whisper" field). This mirrors the + * OfflineMoonshineModelConfig.java pattern already used in this package. + */ +public class OfflineWhisperModelConfig { + private final String encoder; + private final String decoder; + private final String language; + private final String task; + private final int tailPaddings; + private final boolean enableTokenTimestamps; + private final boolean enableSegmentTimestamps; + + private OfflineWhisperModelConfig(Builder builder) { + this.encoder = builder.encoder; + this.decoder = builder.decoder; + this.language = builder.language; + this.task = builder.task; + this.tailPaddings = builder.tailPaddings; + this.enableTokenTimestamps = builder.enableTokenTimestamps; + this.enableSegmentTimestamps = builder.enableSegmentTimestamps; + } + + public static Builder builder() { + return new Builder(); + } + + public String getEncoder() { + return encoder; + } + + public String getDecoder() { + return decoder; + } + + public String getLanguage() { + return language; + } + + public String getTask() { + return task; + } + + public int getTailPaddings() { + return tailPaddings; + } + + public boolean getEnableTokenTimestamps() { + return enableTokenTimestamps; + } + + public boolean getEnableSegmentTimestamps() { + return enableSegmentTimestamps; + } + + public static class Builder { + private String encoder = ""; + private String decoder = ""; + private String language = "en"; + private String task = "transcribe"; + private int tailPaddings = 1000; + private boolean enableTokenTimestamps = false; + private boolean enableSegmentTimestamps = false; + + public Builder setEncoder(String encoder) { + this.encoder = encoder; + return this; + } + + public Builder setDecoder(String decoder) { + this.decoder = decoder; + return this; + } + + public Builder setLanguage(String language) { + this.language = language; + return this; + } + + public Builder setTask(String task) { + this.task = task; + return this; + } + + public Builder setTailPaddings(int tailPaddings) { + this.tailPaddings = tailPaddings; + return this; + } + + public Builder setEnableTokenTimestamps(boolean enableTokenTimestamps) { + this.enableTokenTimestamps = enableTokenTimestamps; + return this; + } + + public Builder setEnableSegmentTimestamps(boolean enableSegmentTimestamps) { + this.enableSegmentTimestamps = enableSegmentTimestamps; + return this; + } + + public OfflineWhisperModelConfig build() { + return new OfflineWhisperModelConfig(this); + } + } +} diff --git a/App_Resources/Android/src/main/res/values/strings.xml b/App_Resources/Android/src/main/res/values/strings.xml new file mode 100644 index 00000000..10b97c80 --- /dev/null +++ b/App_Resources/Android/src/main/res/values/strings.xml @@ -0,0 +1,7 @@ + + + + Faceclaw + Faceclaw + diff --git a/CHANGELOG b/CHANGELOG index 8825e13a..2ab4edad 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,10 +1,58 @@ # Changelog -## 0.6.6 - Future -* Navigate and terminal app: App-specific screen size/position setting +## 0.7.1 - Unreleased + +* Add Wear OS watch battery indicator to the top bar and Glanceboard +* Glanceboard tap setting includes a Disable option +* Refinements to builtin games +* Optimize bluetooth message transport +* Short-the-long gesture from screen off activates the glanceboard +* Glanceboard has a 2x3 layout option + +## 0.7.0 - 2026-09-12 + +### Major Features + +* Add Glanceboard + +The Glanceboard is a customizable dashboard, which opens when you single-tap +or long-press-and-hold while the screen is off, then closes automatically. The +idea is that this is where you put things that you want to keep accessible +while you're not actively using the glasses. The glanceboard has four slots +for widgets, and has a system card widget (time, notifications, etc) and +widgets for music, calendar, terminals, and more. + +* Add "AI Chat" app + +This is a conversational-style way to use the voice assistant that was already +built in. Rather than say the wake word each time, while in the AI Chat app, +you press-and-hold the ring to start speaking and release to send. + +* Significantly increase speed + +This version reconfigures the glasses' Bluetooth radio link, increasing +transfer speed by 3-10x. This makes the user interface a lot snappier overall, +and will enable better animations and graphics in future versions. There is a +new Flappy game, to demonstrate that we can now reasonably handle 30fps +full-screen animation. This does increase battery usage, but not by very much; +based on the specs of the bluetooth chip used, this is estiamted to consume an +extra 5% battery per day. + +### Smaller Features and Bug Fixes + +* After starting in Preview mode, connecting glasses walks you through the custom firmware flashing process in the same way as regular onboarding +* Messaging in the flasher distinguishes between downgrading from stock firmwares where that's been validated and veresions where it hasn't, and considers 2.2.10 validated +* Navigate and Terminal apps have their own config setting for screen-size * Transcribe app: Scrolling; automatic reconnection; insert newlines * Notifications: Add notification filters * Phone screen preview: Add rotation option; improve landscape layout +* Add brightness control to the system context menu +* Add R1 ring battery to the top bar +* Battery indicators have new styling and more customization options +* Add magnetometer calibration debug info to the Compass app +* Nightscout app has alert thresholds for canula age, cartridge volume, pump battery, time since last loop, shown in the top bar +* Terminal app: Icons in the app-switcher sidebar show terminal activity +* Speed up wake wake from sleep (https://github.com/jimrandomh/faceclaw/pull/24) ## 0.6.5 - 2026-09-04 * Changed context menu gestures: — for system, ●— for app context menu. @@ -62,4 +110,3 @@ ## 0.6 - 2026-08-29 - Start keeping a changelog and making signed binaries via GitHub Releases - diff --git a/README.md b/README.md index 7e7d87b8..a8f40e87 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ import it into the new version. slow) or with an Anthropic or OpenAI model (requires an API key), or using your own long-running OpenClaw agent. * **Multitasking**, with an app-switcher sidebar and app launcher. + * **Glanceboard**, a dashboard with widgets that you can quickly view with a + tap or tap-and-hold from the screen-off state. * **Mostly-compatible with EvenHub apps.** * **A lock screen**; glasses lock automatically when you take them off and unlock when you unlock your phone. @@ -86,23 +88,14 @@ import it into the new version. * **Power management**: the glasses go to sleep properly when the screen is off, and wake when you double-tap the ring or speak the wakeword, allowing battery life similar to the stock Even app. - * **Connection management** with auto-reconnect, and autodetection of - conflict with the official Even Realities app. - * **A Wear OS watch app** that replaces (and outdoes) the R1 ring: tap, + * **A Wear OS watch app** that complements (or replaces) the R1 ring: tap, swipe, hold and crown gestures, side buttons, app launching and window switching, voice or keyboard queries to the assistant with the reply on your wrist, typing into apps, and glasses status/lock/display control. - * **On-phone screen mirroring with touch control**: tap what you see on the - mirror (sidebar icons, launcher cells), or use the phone's own touchpad, - d-pad and Back/Menu buttons — the same spatial scheme as the watch — plus a - compact ring simulator. A display-mode picker (576×288 band, 576×480 tall, - or the full 640×480 panel with an auto-hiding sidebar) and a brightness - slider with an Auto toggle sit beside the mirror. - * **Bluetooth pairing** that scans for nearby glasses and identifies each - pair before connecting: model, frame shape, and colour decoded from the - advertised serial (with product photos), left and right arms matched to - each other by that serial, an estimated distance so the pair in your hand - sorts first, and the optional R1 ring. + * **On-phone screen mirroring**: Shows the glasses screen contents and + provides a phone-screen touch area equivalent to the R1 ring or the Wear OS + watch app. This can also be used to try out the app without pairing or + flashing a real pair of glasses. * **Dual-language NativeScript architecture**, with Java for the multithreaded Android API and bluetooth stack bits, Typescript for the bits you want to hack on. @@ -175,7 +168,8 @@ it getting paused, throttled to low CPU usage, etc. Be bold. Modify Faceclaw into the app that you want it to be for yourself, without worrying about whether other people will like your version. Then if you think your changes might be useful to others, make a pull request at -https://github.com/jimrandomh/faceclaw. +https://github.com/jimrandomh/faceclaw. Consider joining the Discord server +to talk to other developer: https://discord.gg/XVFDFSwek3 The Typescript and Java code in this repository runs on your phone, not on the glasses themselves, and (with the narrow exception of the firmware-updating diff --git a/app/app.css b/app/app.css index faa23972..d95f977e 100644 --- a/app/app.css +++ b/app/app.css @@ -52,7 +52,8 @@ TextField { color: #f0f0f0; } -.system-name-modal TextField { +.system-name-modal TextField, +.system-name-modal TextView { background-color: #ffffff; color: #222222; } @@ -132,6 +133,14 @@ Button.-primary { border-radius: 8; } +/* The modal stays light in dark mode (setting editor and keyboard-input + * panel); the .ns-dark pairing outguns the theme's dark-mode recolour of + * Label/.h2 so the title doesn't go white-on-light-gray. */ +.system-name-modal Label, +.ns-dark .system-name-modal Label { + color: #222222; +} + /* Modal behind the action bar's warning triangle: the problem-status warnings * that used to sit inline on the main page, each with its fix-it button. * The width is set from the view model (near-full-width on phones, capped on diff --git a/app/apps/ai-chat/ai-chat-app.ts b/app/apps/ai-chat/ai-chat-app.ts new file mode 100644 index 00000000..195477a2 --- /dev/null +++ b/app/apps/ai-chat/ai-chat-app.ts @@ -0,0 +1,166 @@ +import { GrayImage, type UiFont } from "../../graphics/image"; +import { getDefaultSmallFont } from "../../graphics/ui-fonts"; +import { truncateText, wrapText } from "../../graphics/textwrap"; +import { ASSISTANT_MODEL_VALUES, assistantModelLabel, resolveAssistantModel } from "../../assistant/models"; +import type { AssistantTranscriptEntry } from "../../assistant/session"; +import type { AssistantConversations, ReasoningLevel } from "../../assistant/conversations"; +import { anthropicApiKeySetting, assistantBackendSetting, openAiApiKeySetting } from "../../ui/dashboard-settings"; +import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_LONG_PRESS, gestureHints, type InputEvent } from "../../ui/gestures"; +import type { Layer, LayerContext } from "../../ui/layers"; +import type { MenuItem } from "../../ui/menu"; +import { WindowMenuLayer } from "../../ui/window-menu"; +import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window"; +import { shell } from "../../ui/shell/shell"; +import { VoiceDraft } from "./voice-draft"; + +class AiChatLayer implements Layer { + readonly acceptsDirectional = true; + private firstLine: number | null = null; // null follows the streaming tail + private maxFirstLine = 0; + private selectedId = ""; + private requestRender = () => {}; + private readonly wrappedEntries = new WeakMap(); + readonly draft: VoiceDraft; + + constructor(private readonly conversations: AssistantConversations, options: InProcessAppOptions) { + this.draft = new VoiceDraft(options.actions, () => shell.prepareChatVoiceCapture(), + () => this.requestRender(), (text) => this.send(text)); + } + start(render: () => void): () => void { + this.requestRender = render; + return this.conversations.onChanged(() => render()); + } + send(text: string): void { + this.firstLine = null; + shell.sendToAssistant(text, false); + } + paint(ctx: LayerContext): GrayImage { + const size = ctx.stack.getBaseSize(); + const image = new GrayImage(size.width, size.height); + const font = getDefaultSmallFont(); + const step = font.lineHeight + 3; + const left = 12; + const width = size.width - 28; + const record = this.conversations.current(); + if (this.selectedId !== record.id) { this.selectedId = record.id; this.firstLine = null; } + const transcript = record.session?.transcript ?? record.history?.transcript ?? []; + const title = this.conversations.title(); + image.drawText(font, left, 6, truncateText(font, title, width), 180); + const label = assistantBackendSetting.get() === "external" ? "External agent" : + `${assistantModelLabel(record.model)} · ${record.reasoning === "default" ? "default reasoning" : record.reasoning}`; + const footer = wrapText(font, `${label} ${gestureHints([ + [GESTURE_CLICK, "menu"], [GESTURE_DOUBLE_CLICK, "back"], [GESTURE_LONG_PRESS, "hold to talk"], + ])}`, width); + const footerY = size.height - step * footer.length; + const footerTop = footerY - step * 3 - 12; + const historyTop = step + 16; + const visible = Math.max(1, Math.floor((footerTop - historyTop - 8) / step)); + const lines: { text: string; color: number }[] = []; + for (const entry of transcript) { + if (!entry.text) continue; + let wrapped = this.wrappedEntries.get(entry); + if (!wrapped || wrapped.font !== font || wrapped.width !== width || wrapped.text !== entry.text) { + wrapped = { font, width, text: entry.text, + lines: wrapText(font, `${entry.role === "user" ? "You" : "AI"}: ${entry.text}`, width - 8) }; + this.wrappedEntries.set(entry, wrapped); + } + for (const text of wrapped.lines) { + lines.push({ text, color: entry.role === "user" ? 175 : 245 }); + } + lines.push({ text: "", color: 0 }); + } + if (!lines.length) lines.push({ text: "Hold to talk to your assistant.", color: 175 }, + { text: "Voice and chat share this conversation.", color: 150 }); + this.maxFirstLine = Math.max(0, lines.length - visible); + const first = this.firstLine === null ? this.maxFirstLine : Math.min(this.firstLine, this.maxFirstLine); + for (let row = 0; row < visible; row++) { + const line = lines[first + row]; + if (line) image.drawText(font, left, historyTop + row * step, line.text, line.color); + } + if (this.maxFirstLine > 0) { + const track = visible * step; + const thumb = Math.max(8, Math.floor(track * visible / lines.length)); + image.fillRect(size.width - 5, historyTop + Math.floor((track - thumb) * first / this.maxFirstLine), 2, thumb, 110); + } + image.fillRect(left, footerTop, width, 1, 65); + const state = this.draft.active ? this.draft.status : record.session?.status || this.draft.status; + if (state) image.drawText(font, left, footerTop + 5, truncateText(font, state, width), 160); + const pending = wrapText(font, this.draft.text || (this.draft.active ? "Listening..." : "Hold to speak; release to send"), width); + pending.slice(-2).forEach((text, i) => image.drawText(font, left, footerTop + step * (i + 1) + 5, text, 220)); + footer.forEach((text, i) => image.drawText(font, left + width - font.measureText(text), footerY + i * step, text, 120)); + return image; + } + handleInput(event: InputEvent): void { + switch (event.type) { + case "scroll-up": case "swipe-up": + this.firstLine = Math.max(0, (this.firstLine ?? this.maxFirstLine) - 3); return; + case "scroll-down": case "swipe-down": { + const next = (this.firstLine ?? this.maxFirstLine) + 3; + this.firstLine = next >= this.maxFirstLine ? null : next; return; + } + case "long-press": + if (!this.conversations.current().session?.isTurnActive()) { + if (!shell.isAssistantAvailable()) { shell.showAlert("Set an API key or download the on-phone model in Settings."); return; } + void this.draft.start(); + } + return; + case "long-press-release": this.draft.release(); return; + case "double-click": this.draft.cancel(); shell.yieldFocusToSidebar(); return; + } + } + menuItems(): MenuItem[] { + const record = this.conversations.current(); + const busy = () => this.draft.active || Boolean(record.session?.isTurnActive()); + const external = assistantBackendSetting.get() === "external"; + const submenu = (ctx: LayerContext, title: string, items: MenuItem[]) => ctx.stack.push(new WindowMenuLayer(title, items, true)); + return [ + ...(external ? [{ label: "Sessions and model managed by bridge", disabled: true, onSelect: () => {} }] : []), + { label: "New session", disabled: () => external || busy(), onSelect: (ctx) => { + if (this.conversations.create()) ctx.stack.clearToBase(); + } }, + { label: "Switch session", disabled: () => external || busy(), onSelect: (ctx) => submenu(ctx, "Sessions", + [...this.conversations.list()].reverse().map((item) => ({ + label: `${item.id === record.id ? "✓ " : ""}${this.conversations.title(item)}`, + onSelect: (ctx) => { if (this.conversations.select(item.id)) ctx.stack.clearToBase(); }, + }))) }, + { label: `Model: ${assistantModelLabel(record.model)}`, disabled: () => external || busy(), onSelect: (ctx) => submenu(ctx, "Model", + ASSISTANT_MODEL_VALUES.map((model) => ({ + label: `${model === record.model ? "✓ " : ""}${assistantModelLabel(model)}`, + disabled: () => !this.conversations.available(model, record.reasoning), + onSelect: (ctx) => { if (this.conversations.configure(model, record.reasoning)) ctx.stack.clearToBase(); }, + }))) }, + { label: `Reasoning: ${record.reasoning}`, disabled: () => { + const llm = resolveAssistantModel(record.model, { anthropic: anthropicApiKeySetting.get(), openai: openAiApiKeySetting.get() }); + return external || busy() || !llm?.effort; + }, onSelect: (ctx) => submenu(ctx, "Reasoning", (["default", "low", "medium", "high"] as ReasoningLevel[]).map((reasoning) => ({ + label: `${reasoning === record.reasoning ? "✓ " : ""}${reasoning === "default" ? "Model default" : reasoning}`, + onSelect: (ctx) => { if (this.conversations.configure(record.model, reasoning)) ctx.stack.clearToBase(); }, + }))) }, + ...(record.session?.isTurnActive() ? [{ label: "Cancel response", onSelect: (ctx: LayerContext) => { + record.session?.cancel(); ctx.stack.clearToBase(); + } }] : []), + ]; + } +} + +export function createAiChatWindow(options: InProcessAppOptions): InProcessWindow { + const layer = new AiChatLayer(shell.getAssistantConversations(), options); + let unsubscribe = () => {}; + const app = createInProcessWindow({ + ...options, + appId: "ai-chat", windowId: "ai-chat", title: "AI Chat", iconLetter: "AI", icon: "message-circle", closeable: true, + baseLayer: layer, holdToTalk: true, + isVoiceCapturing: () => layer.draft.active, + onSystemMenuOpened: () => layer.draft.cancel(), + onAppMenuOpened: () => layer.draft.cancel(), + setScreenOn: (on) => { if (!on) layer.draft.cancel(); }, + setSurfaceVisible: (visible) => { if (!visible) layer.draft.cancel(); options.setSurfaceVisible(visible); }, + menuItems: () => layer.menuItems(), + receiveTextInput: (text) => { if (!layer.draft.active) layer.send(text); }, + onClosed: () => { unsubscribe(); layer.draft.cancel(); options.onClosed(); }, + }); + unsubscribe = layer.start(app.requestRender); + return app; +} diff --git a/app/apps/ai-chat/index.ts b/app/apps/ai-chat/index.ts new file mode 100644 index 00000000..0ac4210a --- /dev/null +++ b/app/apps/ai-chat/index.ts @@ -0,0 +1,10 @@ +import type { AppDefinition } from "../app-definition"; +import { createAiChatWindow } from "./ai-chat-app"; + +const aiChatApp: AppDefinition = { + appId: "ai-chat", + title: "AI Chat", + icon: "message-circle", + launch: (ctx) => ctx.launchInProcessApp("ai-chat", "window:ai-chat", createAiChatWindow), +}; +export default aiChatApp; diff --git a/app/apps/ai-chat/voice-draft.ts b/app/apps/ai-chat/voice-draft.ts new file mode 100644 index 00000000..f91093fc --- /dev/null +++ b/app/apps/ai-chat/voice-draft.ts @@ -0,0 +1,136 @@ +import { voiceControlBridge } from "../../native/voice-control"; +import { voiceActivity } from "../../ui/shell/voice-activity"; +import type { LayerActions } from "../../ui/layers"; + +/** One hold/release cycle. Async startup and trailing cloud finals belong to this cycle only. */ +export class VoiceDraft { + phase: "idle" | "preparing" | "listening" | "finishing" = "idle"; + text = ""; + status = ""; + private committed = ""; + private live = ""; + private generation = 0; + private started = false; + private ownsVoiceActivity = false; + private starting = false; + private unsubscribe: (() => void)[] = []; + private timer: ReturnType | null = null; + + constructor( + private readonly actions: Pick, + private readonly prepare: () => Promise, + private readonly changed: () => void, + private readonly send: (text: string) => void, + ) {} + + get active(): boolean { return this.phase !== "idle" || this.starting; } + + async start(): Promise { + if (this.active) return; + const generation = ++this.generation; + this.text = this.committed = this.live = ""; + this.phase = "preparing"; + this.status = "Preparing microphone..."; + this.changed(); + try { + const ready = await this.prepare(); + if (generation !== this.generation) return; + if (!ready) { this.cancel("Microphone unavailable"); return; } + this.phase = "listening"; + this.status = "Listening... release to send"; + this.ownsVoiceActivity = true; + voiceActivity.setActive(true); + this.unsubscribe.push(voiceControlBridge.onTranscript((event) => { + if (!this.active || generation !== this.generation) return; + if (event.isFinal) { + const text = event.text.trim(); + if (text) this.committed = [this.committed, text].filter(Boolean).join(" "); + this.live = ""; + } else this.live = event.text.trim(); + this.text = [this.committed, this.live].filter(Boolean).join(" "); + if (event.isFinal && this.phase === "finishing") this.finish(); + else this.changed(); + })); + // onStatus immediately replays the previous capture's status. + let subscribed = false; + this.unsubscribe.push(voiceControlBridge.onStatus(({ status }) => { + if (!subscribed) return; + if (generation !== this.generation || !this.active) return; + if (/ignored|failed|error|denied/i.test(status)) this.cancel(status); + })); + subscribed = true; + if (generation !== this.generation) return; + this.starting = true; + this.changed(); + await this.actions.startVoiceCapture(); + this.starting = false; + if (generation !== this.generation) { + await this.actions.stopVoiceCapture(); + this.changed(); + return; + } + this.started = true; + if (this.isFinishing()) this.stopAndFinalize(); + } catch (error) { + this.starting = false; + if (generation === this.generation) this.cancel(`Microphone: ${String(error)}`); + } + } + + private isFinishing(): boolean { return this.phase === "finishing"; } + + release(): void { + if (this.phase === "preparing") { this.cancel(); return; } + if (this.phase !== "listening") return; + this.phase = "finishing"; + this.status = "Finishing transcription..."; + this.changed(); + if (!this.starting) this.stopAndFinalize(); + } + + private stopAndFinalize(): void { + const generation = this.generation; + const afterStop = () => { + if (generation !== this.generation || !this.isFinishing()) return; + this.timer = setTimeout(() => this.finish(), 1500); + }; + if (this.started) { + this.started = false; + // Native recognition can take longer than the synchronous stop join. + // Its final callback may finish the draft before this promise resolves. + const stopped = this.actions.stopVoiceCapture(); + if (!stopped) { afterStop(); return; } + void stopped.then(afterStop, (error) => { + if (generation === this.generation) this.cancel(String(error)); + }); + } else { + afterStop(); + } + } + + private finish(): void { + if (this.phase !== "finishing") return; + const text = this.text.trim(); + this.cancel(text ? "" : "No speech detected"); + if (text) this.send(text); + } + + cancel(status = ""): void { + ++this.generation; + this.phase = "idle"; + this.status = status; + this.text = this.live = this.committed = ""; + if (this.timer !== null) clearTimeout(this.timer); + this.timer = null; + for (const unsubscribe of this.unsubscribe.splice(0)) unsubscribe(); + if (this.started) { + this.started = false; + void Promise.resolve(this.actions.stopVoiceCapture()).catch(() => {}); + } + if (this.ownsVoiceActivity) { + this.ownsVoiceActivity = false; + voiceActivity.setActive(false); + } + this.changed(); + } +} diff --git a/app/apps/all-apps.ts b/app/apps/all-apps.ts index 6dbb80c1..864b8536 100644 --- a/app/apps/all-apps.ts +++ b/app/apps/all-apps.ts @@ -1,4 +1,5 @@ import { type AppDefinition } from "./app-definition"; +import aiChatApp from "./ai-chat"; import launcherApp from "./launcher"; import timerApp from "./timer"; import calculatorApp from "./calculator"; @@ -19,8 +20,10 @@ import blocksApp from "./blocks"; import minesweeperApp from "./minesweeper"; import freecellApp from "./freecell"; import pinballApp from "./pinball"; +import flappyApp from "./flappy"; import developerApp from "./developer"; import evenhubApp from "./evenhub"; +import glanceboardApp from "./glanceboard"; import settingsApp from "./settings"; /** @@ -30,6 +33,7 @@ import settingsApp from "./settings"; */ export const ALL_APPS: readonly AppDefinition[] = [ launcherApp, + aiChatApp, timerApp, calculatorApp, terminalApp, @@ -49,7 +53,9 @@ export const ALL_APPS: readonly AppDefinition[] = [ minesweeperApp, freecellApp, pinballApp, + flappyApp, developerApp, evenhubApp, + glanceboardApp, settingsApp, ]; diff --git a/app/apps/app-definition.ts b/app/apps/app-definition.ts index f5872232..0f73ad9d 100644 --- a/app/apps/app-definition.ts +++ b/app/apps/app-definition.ts @@ -32,6 +32,39 @@ export type AppDefinition = { showInLauncher?: boolean; /** Present on the app that handles text shared via the Android share intent. */ openSharedText?: (ctx: AppContext, title: string, text: string) => void; + /** + * Present on the app that supplies the Glanceboard: the sleep-time display + * the controller shows on a tap or hold while the shell is asleep (see + * app/g2/glance-host.ts). At most one app provides it. + */ + glanceboard?: GlanceboardProvider; +}; + +/** A board the glance host can show while the shell sleeps. */ +export type GlanceboardProvider = { + /** Board pixel size; the host centres it in the standard 576x288 band. */ + size: { width: number; height: number }; + /** Whether sleep-time gestures should show the board at all (user setting). */ + isEnabled: () => boolean; + /** Whether a single tap shows the board (for tapTimeoutMs). */ + showOnTap: () => boolean; + /** How long a tap or head-tilt keeps the board up. */ + tapTimeoutMs: () => number; + /** Whether a long-press holds the board up until released. */ + showOnLongPress: () => boolean; + /** Whether the head-tilt wake goes to the board rather than the regular UI. */ + showOnHeadTilt: () => boolean; + /** A fresh board; requestRender asks the host to repaint it. */ + createBoard: (requestRender: () => void) => GlanceBoardInstance; +}; + +export type GlanceBoardInstance = { + /** The board is about to show: start widgets (subscriptions, hardware). */ + start: () => void; + /** The board was hidden: stop everything start began. */ + stop: () => void; + /** Paint the board at its size. */ + paint: () => GrayImage; }; export type AppLaunchParams = { diff --git a/app/apps/blocks/blocks-app.worker.ts b/app/apps/blocks/blocks-app.worker.ts index 4a5ec5f1..850eedc9 100644 --- a/app/apps/blocks/blocks-app.worker.ts +++ b/app/apps/blocks/blocks-app.worker.ts @@ -1,7 +1,9 @@ /** * Blocks app worker: a falling-blocks game. One singleton window holds the * whole game; a gravity interval drives piece descent while the window is - * foreground and the screen is on (losing either auto-pauses). + * foreground, the screen is on, and the window holds input focus (losing any + * of them auto-pauses: backgrounding, screen-off, the system menu or a + * notification modal opening over the game, focus going to the sidebar). * * Controls (in play): scroll moves the piece, click rotates, long-press hard * drops, double-click pauses. Watch swipes are spatial: left/right move, @@ -17,6 +19,7 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import * as frameTimings from "../../native/frame-timings"; import { getActiveDisplay } from "../../native/active-display"; import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects"; +import { loadSoundEnabled, saveSoundEnabled } from "../../ui/sound-setting"; import { type MenuItem } from "../../ui/menu"; import { WindowMenu } from "../../ui/window-menu"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; @@ -43,11 +46,16 @@ const BOARD_X = 60; const BOARD_Y = 10; const PANEL_X = 230; -/** Gravity starts here and speeds up with score (see dropIntervalMs). */ -const BASE_DROP_MS = 1200; -const MIN_DROP_MS = 200; -/** Every this many points, gravity gets one 12% step faster. */ -const SPEED_STEP_SCORE = 300; +/** + * Gravity starts here and speeds up with score (see dropIntervalMs). Slow + * by desktop standards: the glasses round trip is ~250 ms, so a piece must + * hang around long enough to be steered through it. + */ +const BASE_DROP_MS = 1500; +const MIN_DROP_MS = 350; +/** Every this many points, gravity gets one SPEED_STEP_FACTOR step faster. */ +const SPEED_STEP_SCORE = 500; +const SPEED_STEP_FACTOR = 0.92; /** Points per cleared-line count (index = simultaneous lines), times level. */ const LINE_SCORES = [0, 100, 300, 500, 800]; const HARD_DROP_POINTS_PER_ROW = 2; @@ -201,7 +209,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { lines: 0, tickTimer: null, tickIntervalMs: BASE_DROP_MS, - soundOn: true, + soundOn: loadSoundEnabled("blocks"), lastSubmittedFingerprint: "", }; windows.set(message.windowId, window); @@ -248,6 +256,20 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { if (window.foreground) renderAndSubmit(window, 0); break; } + case "input-focus": { + const window = windows.get(message.windowId); + if (!window) break; + // Anything that takes input away from the game (the system menu, a + // notification modal, the voice dialog, focus back to the sidebar) + // pauses it: the player can't steer a piece they aren't in control of. + if (!message.focused && window.phase === "playing") { + window.phase = "paused"; + updateTickTimer(window); + // Still on screen under a shell overlay, so show the pause. + if (window.foreground) renderAndSubmit(window, 0); + } + break; + } case "screen": screenOn = message.on; for (const window of windows.values()) { @@ -296,6 +318,7 @@ function windowMenuItems(window: BlocksWindow): MenuItem[] { onSelect: (ctx) => { ctx.stack.pop(); window.soundOn = !window.soundOn; + saveSoundEnabled("blocks", window.soundOn); if (window.soundOn) playSfx(window, SFX_RESUME); }, }, @@ -547,7 +570,7 @@ function level(window: BlocksWindow): number { function dropIntervalMs(window: BlocksWindow): number { const steps = Math.floor(window.score / SPEED_STEP_SCORE); - return Math.max(MIN_DROP_MS, Math.round(BASE_DROP_MS * Math.pow(0.88, steps))); + return Math.max(MIN_DROP_MS, Math.round(BASE_DROP_MS * Math.pow(SPEED_STEP_FACTOR, steps))); } /** Keep the gravity interval running exactly when the game is live and visible. */ diff --git a/app/apps/calendar/calendar.ts b/app/apps/calendar/calendar.ts index 86907634..d2cc8629 100644 --- a/app/apps/calendar/calendar.ts +++ b/app/apps/calendar/calendar.ts @@ -178,7 +178,7 @@ function dayKeyOf(timestampMs: number): string { return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`; } -function dayHeaderLabel(timestampMs: number): string { +export function dayHeaderLabel(timestampMs: number): string { const date = new Date(timestampMs); const now = new Date(); const midnight = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime(); @@ -189,7 +189,7 @@ function dayHeaderLabel(timestampMs: number): string { return base; } -function formatEventTime(timestampMs: number): string { +export function formatEventTime(timestampMs: number): string { const date = new Date(timestampMs); const minutes = String(date.getMinutes()).padStart(2, "0"); const hour24 = date.getHours(); diff --git a/app/apps/compass/compass-app.ts b/app/apps/compass/compass-app.ts index a0f75e18..85e0f287 100644 --- a/app/apps/compass/compass-app.ts +++ b/app/apps/compass/compass-app.ts @@ -23,6 +23,7 @@ import { import { shell } from "../../ui/shell/shell"; import { ensureLocationPermission, hasLocationPermission } from "../../g2/android-permissions"; import { isCompassCalibrated, normalizeHeading } from "./calibration"; +import { cardinalDirection, createCompassBackground, drawCompassRose, layoutCompassRose, TICK_HEIGHT } from "./compass-rose"; import { CompassCalibrationLayer } from "./calibration-layer"; import { getDeclinationAvailability, onDeclinationChanged, refreshDeclination } from "./declination"; import { getNorthReference, resolveHeading, setNorthReference, type NorthReference } from "./heading"; @@ -41,59 +42,6 @@ const EDGE_PAD = 8; /** Cap on the rose's radius, so a tall window doesn't get a comical one. */ const MAX_ROSE_RADIUS = 98; -/** - * The rose is drawn as a flat disc lying in front of the wearer, tilted away - * from vertical: `TILT_SQUASH` is how much that tilt shortens the depth axis, - * and `TILT_PERSPECTIVE` how much nearer parts of the disc are magnified - * relative to farther ones. Together they turn the ring into an egg-shaped - * oval — wider and taller at the bottom — and give the rose's points their - * foreshortening for free. - */ -const TILT_SQUASH = 0.42; -const TILT_PERSPECTIVE = 0.22; -/** Screen height of the projected ring, per unit of radius. */ -const RING_HEIGHT_PER_RADIUS = - TILT_SQUASH * (1 / (1 + TILT_PERSPECTIVE) + 1 / (1 - TILT_PERSPECTIVE)); -/** Screen half-width of the projected ring, per unit of radius. */ -const RING_HALF_WIDTH_PER_RADIUS = 1 / Math.sqrt(1 - TILT_PERSPECTIVE * TILT_PERSPECTIVE); - -/** Tip radii of the rose's long and short points, as a fraction of the ring. */ -const CARDINAL_TIP = 0.9; -const INTERCARDINAL_TIP = 0.54; -/** Radius the point bases sit on: how fat the rose is at its waist. */ -const POINT_BASE_RADIUS = 0.17; -/** Half-angle of a point's base. 22.5° makes neighbouring bases just meet. */ -const POINT_BASE_HALF_ANGLE = 22.5; -/** - * A polar grid lying in the same plane as the disc, to give it somewhere to - * sit and to fill the empty flanks either side of it. Rings are multiples of - * the disc's radius; spokes are offset by half a step so none runs up the - * middle into the heading tick. - */ -const PLANE_RINGS = [1.35, 1.8, 2.5, 3.6, 5.6]; -const PLANE_SPOKE_STEP = 30; -/** Grid brightness at the disc's rim, and how fast it falls off with distance. */ -const PLANE_NEAR_VALUE = 78; -const PLANE_FALLOFF = 0.55; -/** Dimmer than this is left unpainted, so the grid ends by vanishing. */ -const PLANE_CUTOFF = 22; -/** Height over which the grid fades out as it approaches the readout. */ -const PLANE_FADE_SPAN = 45; - -/** Size of the fixed tick that marks the direction the wearer is facing. */ -const TICK_HEIGHT = 7; -const TICK_HALF_WIDTH = 4; -/** Depth of the disc's side wall, as a fraction of the ring's radius. */ -const DISC_DEPTH = 0.1; -/** - * Rim angle at which the silhouette turns vertical. Between this and its - * mirror the wall faces the wearer; outside it the rim curves back away, so a - * wall drawn there would hook inward instead of ending on the vertical edge. - */ -const WALL_START_ANGLE = (Math.acos(-TILT_PERSPECTIVE) * 180) / Math.PI; -/** Side-wall shading, from the edges of the silhouette to the nearest point. */ -const WALL_DARK = 20; -const WALL_LIT = 62; class CompassLayer implements Layer { private rawHeading: number | null = null; @@ -233,21 +181,15 @@ class CompassLayer implements Layer { // The rose is sized and placed first — it hangs off the bottom edge — and // the readout then floats in whatever room is left above it. const textHeight = readoutHeight + 4 + statusLines.length * smallStep; - const radius = Math.max( - 24, - Math.min( - MAX_ROSE_RADIUS, - Math.floor( - (height - BOTTOM_PAD - TOP_PAD - textHeight - STACK_GAP - TICK_HEIGHT) - / (RING_HEIGHT_PER_RADIUS + DISC_DEPTH), - ), - Math.floor((Math.min(cx, width - cx) - EDGE_PAD) / RING_HALF_WIDTH_PER_RADIUS), - ), - ); - // The wall hangs below the rim, so the near rim sits a wall's depth up - // from the bottom padding rather than on it. - const cy = height - BOTTOM_PAD - discDepth(radius) - (radius * TILT_SQUASH) / (1 - TILT_PERSPECTIVE); - const ringTop = cy - (radius * TILT_SQUASH) / (1 + TILT_PERSPECTIVE); + const { cy, radius, ringTop } = layoutCompassRose({ + width, + height, + cx, + topClearance: TOP_PAD + textHeight + STACK_GAP, + bottomPad: BOTTOM_PAD, + edgePad: EDGE_PAD, + maxRadius: MAX_ROSE_RADIUS, + }); let y = Math.max(TOP_PAD, Math.round((ringTop - TICK_HEIGHT - textHeight) / 2)); const fade = heading === null ? 0.45 : 1; @@ -356,257 +298,3 @@ function frameStatusText(): string { return "Magnetic heading - waiting for location"; } } - -function cardinalDirection(heading: number): string { - const names = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]; - return names[Math.round(normalizeHeading(heading) / 45) % names.length]!; -} - -interface Point { - x: number; - y: number; -} - -/** - * Project a point of the rose's plane onto the screen. `angle` is degrees - * clockwise from the far side of the disc — the direction the wearer faces — - * and `radius` is a fraction of the rose's outer ring. - */ -function projectRose(cx: number, cy: number, scale: number, radius: number, angle: number): Point { - const radians = (angle * Math.PI) / 180; - const across = radius * Math.sin(radians); - const away = radius * Math.cos(radians); - const depth = 1 + TILT_PERSPECTIVE * away; - return { - x: cx + (across * scale) / depth, - y: cy - (away * scale * TILT_SQUASH) / depth, - }; -} - -/** - * Bounds of every orientation of the rotating points. The longest tip sweeps - * a circle in the disc's plane; perspective projects it to an offset ellipse. - * Round outward so all rasterized triangle pixels fit inside the rectangle. - */ -function rotatingRoseBounds(cx: number, cy: number, radius: number): { - x: number; y: number; width: number; height: number; -} { - const perspective = TILT_PERSPECTIVE * CARDINAL_TIP; - const halfWidth = radius * CARDINAL_TIP / Math.sqrt(1 - perspective * perspective); - const depth = radius * CARDINAL_TIP * TILT_SQUASH; - const x = Math.floor(cx - halfWidth); - const y = Math.floor(cy - depth / (1 + perspective)); - return { - x, - y, - width: Math.ceil(cx + halfWidth) - x, - height: Math.ceil(cy + depth / (1 - perspective)) - y, - }; -} - -/** - * Keep the fixed pixels inside the rotating rose's dirty rectangle as one - * immutable texture. The wire planner can omit them from each raster delta - * and restore them with a cached image draw. Outside that rectangle the - * background stays raster, since heading updates do not change it. - * - * The texture uses transparent zero for the empty disc interior, so it can - * overlay the rotating points. Its only ink over the points is the fixed - * heading tick, which belongs on top of them. - */ -function createCompassBackground( - width: number, height: number, cx: number, cy: number, radius: number, clipY: number, fade: number, -): GrayImage { - const image = new GrayImage(width, height, 0); - drawPlaneGrid(image, cx, cy, radius, clipY); - drawDiscWall(image, cx, cy, radius, fade); - drawTiltedRing(image, cx, cy, radius, 105 * fade); - drawHeadingTick(image, cx, cy, radius, 255 * fade); - - const bounds = rotatingRoseBounds(cx, cy, radius); - const left = Math.max(0, bounds.x); - const top = Math.max(0, bounds.y); - const right = Math.min(width, bounds.x + bounds.width); - const bottom = Math.min(height, bounds.y + bounds.height); - if (right > left && bottom > top) { - const texture = new GrayImage(right - left, bottom - top, 0); - texture.bitBlt(image, 0, 0, { sx: left, sy: top, width: texture.width, height: texture.height }); - image.fillRect(left, top, texture.width, texture.height, 0); - image.drawImage(texture, left, top); - } - return image; -} - -/** Draw only the rotating points, with the brightest one aimed at north. */ -function drawCompassRose(image: GrayImage, cx: number, cy: number, radius: number, heading: number | null): void { - // Without a reading there is nothing to aim, so show the rose in its resting - // orientation, dimmed, rather than an empty ring. - const fade = heading === null ? 0.45 : 1; - const bearing = heading ?? 0; - // Short points first, so the long ones sit on top of them at the waist. Only - // north is drawn at full brightness: the other seven are there to make the - // rose read as a rose, and competing with north would defeat the point. - for (const degrees of [45, 135, 225, 315]) { - drawRosePoint(image, cx, cy, radius, degrees - bearing, INTERCARDINAL_TIP, 85 * fade, 40 * fade); - } - for (const degrees of [90, 180, 270]) { - drawRosePoint(image, cx, cy, radius, degrees - bearing, CARDINAL_TIP, 120 * fade, 55 * fade); - } - drawRosePoint(image, cx, cy, radius, -bearing, CARDINAL_TIP, 255 * fade, 140 * fade); -} - -/** - * One point of the rose: a tapered spike split down its axis into a lit and a - * shaded facet, which is what keeps the eight points readable once perspective - * has squashed the ones lying across the wearer's line of sight. - */ -function drawRosePoint( - image: GrayImage, - cx: number, - cy: number, - radius: number, - angle: number, - tipRadius: number, - litValue: number, - shadedValue: number, -): void { - const centre = { x: cx, y: cy }; - const tip = projectRose(cx, cy, radius, tipRadius, angle); - const clockwise = projectRose(cx, cy, radius, POINT_BASE_RADIUS, angle + POINT_BASE_HALF_ANGLE); - const anticlockwise = projectRose(cx, cy, radius, POINT_BASE_RADIUS, angle - POINT_BASE_HALF_ANGLE); - fillTriangle(image, tip, centre, clockwise, litValue); - fillTriangle(image, tip, centre, anticlockwise, shadedValue); -} - -/** - * The side wall below the wearer-facing arc of the rim, which turns the tilted - * disc into a shallow cylinder. The arc runs between the two points where the - * silhouette turns vertical, so the wall ends flush with that vertical edge, - * and it is shaded from dark there to lit where it faces the wearer head-on. - */ -function drawDiscWall(image: GrayImage, cx: number, cy: number, radius: number, fade: number): void { - const depth = discDepth(radius); - const segments = 48; - const sweep = 360 - WALL_START_ANGLE * 2; - const rimValue = 105 * fade; - let previous = projectRose(cx, cy, radius, 1, WALL_START_ANGLE); - image.drawLine(previous.x, previous.y, previous.x, previous.y + depth, rimValue); - for (let i = 1; i <= segments; i++) { - const angle = WALL_START_ANGLE + (i * sweep) / segments; - const point = projectRose(cx, cy, radius, 1, angle); - // Quads rather than per-column lines, so no gap opens up where the rim - // runs nearly horizontal across the bottom of the oval. - const value = (WALL_DARK + (WALL_LIT - WALL_DARK) * wallFacing(angle)) * fade; - const top = { x: previous.x, y: previous.y }; - const next = { x: point.x, y: point.y }; - fillTriangle(image, top, next, { x: next.x, y: next.y + depth }, value); - fillTriangle(image, top, { x: top.x, y: top.y + depth }, { x: next.x, y: next.y + depth }, value); - image.drawLine(top.x, top.y + depth, next.x, next.y + depth, rimValue); - previous = point; - } - image.drawLine(previous.x, previous.y, previous.x, previous.y + depth, rimValue); -} - -/** 1 where the wall faces the wearer head-on, 0 at the silhouette's edges. */ -function wallFacing(angle: number): number { - const towardWearer = -Math.cos((angle * Math.PI) / 180); - return (towardWearer - TILT_PERSPECTIVE) / (1 - TILT_PERSPECTIVE); -} - -/** - * The grid the disc sits on, drawn before the disc so the disc occludes it. - * Brightness falls off with distance and fades to nothing as the plane climbs - * towards `clipY`, so the grid dissolves into the black under the readout - * rather than stopping at a hard edge. - */ -function drawPlaneGrid(image: GrayImage, cx: number, cy: number, radius: number, clipY: number): void { - const shade = (point: Point, ringRadius: number): number => { - if (point.y > image.height || Math.abs(point.x - cx) > image.width) return 0; - const fade = Math.max(0, Math.min(1, (point.y - clipY) / PLANE_FADE_SPAN)); - const value = (PLANE_NEAR_VALUE / (1 + PLANE_FALLOFF * (ringRadius - 1))) * fade; - return value >= PLANE_CUTOFF ? value : 0; - }; - const trace = ( - steps: number, - at: (step: number) => { point: Point; ringRadius: number }, - ): void => { - let previous: Point | null = null; - let previousValue = 0; - for (let i = 0; i <= steps; i++) { - const { point, ringRadius } = at(i); - const value = shade(point, ringRadius); - if (previous !== null && previousValue > 0 && value > 0) { - image.drawLine(previous.x, previous.y, point.x, point.y, (previousValue + value) / 2); - } - previous = point; - previousValue = value; - } - }; - - for (const ringRadius of PLANE_RINGS) { - trace(96, (step) => ({ point: projectRose(cx, cy, radius, ringRadius, (step * 360) / 96), ringRadius })); - } - // Spokes run from just outside the disc to the outermost ring, so the grid - // closes on itself instead of trailing off into loose ends. - const outer = PLANE_RINGS[PLANE_RINGS.length - 1]!; - for (let angle = PLANE_SPOKE_STEP / 2; angle < 360; angle += PLANE_SPOKE_STEP) { - trace(24, (step) => { - const ringRadius = 1.05 + (step * (outer - 1.05)) / 24; - return { point: projectRose(cx, cy, radius, ringRadius, angle), ringRadius }; - }); - } -} - -/** Screen depth of the disc's side wall at the given ring radius. */ -function discDepth(radius: number): number { - return Math.max(3, Math.round(radius * DISC_DEPTH)); -} - -/** The ring bounding the rose: the tilted disc's rim, drawn as a polygon. */ -function drawTiltedRing(image: GrayImage, cx: number, cy: number, radius: number, value: number): void { - const segments = 72; - let previous = projectRose(cx, cy, radius, 1, 0); - for (let i = 1; i <= segments; i++) { - const point = projectRose(cx, cy, radius, 1, (i * 360) / segments); - image.drawLine(previous.x, previous.y, point.x, point.y, value); - previous = point; - } -} - -/** A fixed mark just inside the top rim: the heading the wearer is facing. */ -function drawHeadingTick(image: GrayImage, cx: number, cy: number, radius: number, value: number): void { - const top = projectRose(cx, cy, radius, 1, 0); - const tickTop = top.y + 1; - fillTriangle( - image, - { x: cx, y: tickTop + TICK_HEIGHT - 1 }, - { x: cx - TICK_HALF_WIDTH, y: tickTop }, - { x: cx + TICK_HALF_WIDTH, y: tickTop }, - value, - ); -} - -function fillTriangle(image: GrayImage, a: Point, b: Point, c: Point, value: number): void { - const left = Math.max(0, Math.floor(Math.min(a.x, b.x, c.x))); - const right = Math.min(image.width - 1, Math.ceil(Math.max(a.x, b.x, c.x))); - const top = Math.max(0, Math.floor(Math.min(a.y, b.y, c.y))); - const bottom = Math.min(image.height - 1, Math.ceil(Math.max(a.y, b.y, c.y))); - const shade = Math.round(value); - for (let y = top; y <= bottom; y++) { - for (let x = left; x <= right; x++) { - const point = { x: x + 0.5, y: y + 0.5 }; - const ab = edge(a, b, point); - const bc = edge(b, c, point); - const ca = edge(c, a, point); - // Accept either winding, so callers don't have to order their vertices. - if ((ab >= 0 && bc >= 0 && ca >= 0) || (ab <= 0 && bc <= 0 && ca <= 0)) { - image.setPixel(x, y, shade); - } - } - } -} - -/** Twice the signed area of the triangle a-b-p; its sign is p's side of a-b. */ -function edge(a: Point, b: Point, p: Point): number { - return (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x); -} diff --git a/app/apps/compass/compass-rose.ts b/app/apps/compass/compass-rose.ts new file mode 100644 index 00000000..e8410c1a --- /dev/null +++ b/app/apps/compass/compass-rose.ts @@ -0,0 +1,352 @@ +/** + * The compass rose renderer: a tilted disc with eight rotating points, drawn + * from a heading into any GrayImage. Pure drawing code shared by the Compass + * app's full-window view and the Glanceboard's compass widget; the callers + * own the magnetometer lifecycle and the readout text around it. + */ +import { GrayImage } from "../../graphics/image"; +import { normalizeHeading } from "./calibration"; + +/** + * The rose is drawn as a flat disc lying in front of the wearer, tilted away + * from vertical: `TILT_SQUASH` is how much that tilt shortens the depth axis, + * and `TILT_PERSPECTIVE` how much nearer parts of the disc are magnified + * relative to farther ones. Together they turn the ring into an egg-shaped + * oval — wider and taller at the bottom — and give the rose's points their + * foreshortening for free. + */ +const TILT_SQUASH = 0.42; +const TILT_PERSPECTIVE = 0.22; +/** Screen height of the projected ring, per unit of radius. */ +const RING_HEIGHT_PER_RADIUS = + TILT_SQUASH * (1 / (1 + TILT_PERSPECTIVE) + 1 / (1 - TILT_PERSPECTIVE)); +/** Screen half-width of the projected ring, per unit of radius. */ +const RING_HALF_WIDTH_PER_RADIUS = 1 / Math.sqrt(1 - TILT_PERSPECTIVE * TILT_PERSPECTIVE); + +/** Tip radii of the rose's long and short points, as a fraction of the ring. */ +const CARDINAL_TIP = 0.9; +const INTERCARDINAL_TIP = 0.54; +/** Radius the point bases sit on: how fat the rose is at its waist. */ +const POINT_BASE_RADIUS = 0.17; +/** Half-angle of a point's base. 22.5° makes neighbouring bases just meet. */ +const POINT_BASE_HALF_ANGLE = 22.5; +/** + * A polar grid lying in the same plane as the disc, to give it somewhere to + * sit and to fill the empty flanks either side of it. Rings are multiples of + * the disc's radius; spokes are offset by half a step so none runs up the + * middle into the heading tick. + */ +const PLANE_RINGS = [1.35, 1.8, 2.5, 3.6, 5.6]; +const PLANE_SPOKE_STEP = 30; +/** Grid brightness at the disc's rim, and how fast it falls off with distance. */ +const PLANE_NEAR_VALUE = 78; +const PLANE_FALLOFF = 0.55; +/** Dimmer than this is left unpainted, so the grid ends by vanishing. */ +const PLANE_CUTOFF = 22; +/** Height over which the grid fades out as it approaches the readout. */ +const PLANE_FADE_SPAN = 45; + +/** Size of the fixed tick that marks the direction the wearer is facing. */ +const TICK_HEIGHT = 7; +const TICK_HALF_WIDTH = 4; +/** Depth of the disc's side wall, as a fraction of the ring's radius. */ +const DISC_DEPTH = 0.1; +/** + * Rim angle at which the silhouette turns vertical. Between this and its + * mirror the wall faces the wearer; outside it the rim curves back away, so a + * wall drawn there would hook inward instead of ending on the vertical edge. + */ +const WALL_START_ANGLE = (Math.acos(-TILT_PERSPECTIVE) * 180) / Math.PI; +/** Side-wall shading, from the edges of the silhouette to the nearest point. */ +const WALL_DARK = 20; +const WALL_LIT = 62; + +/** Size of the fixed tick that marks the direction the wearer is facing. */ +export { TICK_HEIGHT }; + +/** + * Fit a rose into a box: the largest radius whose projected ring plus disc + * wall fits between `topClearance` (the bottom of whatever text sits above) + * and the box's bottom padding, and whose width clears the side padding + * around `cx`. Returns the centre and radius to hand to drawCompassRose. + */ +export function layoutCompassRose(options: { + width: number; + height: number; + cx: number; + /** Lowest y already used above the rose (readout text, its gap). */ + topClearance: number; + bottomPad: number; + edgePad: number; + maxRadius: number; + minRadius?: number; +}): { cx: number; cy: number; radius: number; ringTop: number } { + const { width, height, cx } = options; + const radius = Math.max( + options.minRadius ?? 24, + Math.min( + options.maxRadius, + Math.floor((height - options.bottomPad - options.topClearance - TICK_HEIGHT) / (RING_HEIGHT_PER_RADIUS + DISC_DEPTH)), + Math.floor((Math.min(cx, width - cx) - options.edgePad) / RING_HALF_WIDTH_PER_RADIUS), + ), + ); + // The wall hangs below the rim, so the near rim sits a wall's depth up + // from the bottom padding rather than on it. + const cy = height - options.bottomPad - discDepth(radius) - (radius * TILT_SQUASH) / (1 - TILT_PERSPECTIVE); + const ringTop = cy - (radius * TILT_SQUASH) / (1 + TILT_PERSPECTIVE); + return { cx, cy, radius, ringTop }; +} + +export function cardinalDirection(heading: number): string { + const names = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]; + return names[Math.round(normalizeHeading(heading) / 45) % names.length]!; +} + +interface Point { + x: number; + y: number; +} + +/** + * Project a point of the rose's plane onto the screen. `angle` is degrees + * clockwise from the far side of the disc — the direction the wearer faces — + * and `radius` is a fraction of the rose's outer ring. + */ +function projectRose(cx: number, cy: number, scale: number, radius: number, angle: number): Point { + const radians = (angle * Math.PI) / 180; + const across = radius * Math.sin(radians); + const away = radius * Math.cos(radians); + const depth = 1 + TILT_PERSPECTIVE * away; + return { + x: cx + (across * scale) / depth, + y: cy - (away * scale * TILT_SQUASH) / depth, + }; +} + +/** + * Bounds of every orientation of the rotating points. The longest tip sweeps + * a circle in the disc's plane; perspective projects it to an offset ellipse. + * Round outward so all rasterized triangle pixels fit inside the rectangle. + */ +function rotatingRoseBounds(cx: number, cy: number, radius: number): { + x: number; y: number; width: number; height: number; +} { + const perspective = TILT_PERSPECTIVE * CARDINAL_TIP; + const halfWidth = radius * CARDINAL_TIP / Math.sqrt(1 - perspective * perspective); + const depth = radius * CARDINAL_TIP * TILT_SQUASH; + const x = Math.floor(cx - halfWidth); + const y = Math.floor(cy - depth / (1 + perspective)); + return { + x, + y, + width: Math.ceil(cx + halfWidth) - x, + height: Math.ceil(cy + depth / (1 - perspective)) - y, + }; +} + +/** + * Keep the fixed pixels inside the rotating rose's dirty rectangle as one + * immutable texture. The wire planner can omit them from each raster delta + * and restore them with a cached image draw. Outside that rectangle the + * background stays raster, since heading updates do not change it. + * + * The texture uses transparent zero for the empty disc interior, so it can + * overlay the rotating points. Its only ink over the points is the fixed + * heading tick, which belongs on top of them. + */ +export function createCompassBackground( + width: number, height: number, cx: number, cy: number, radius: number, clipY: number, fade: number, +): GrayImage { + const image = new GrayImage(width, height, 0); + drawPlaneGrid(image, cx, cy, radius, clipY); + drawDiscWall(image, cx, cy, radius, fade); + drawTiltedRing(image, cx, cy, radius, 105 * fade); + drawHeadingTick(image, cx, cy, radius, 255 * fade); + + const bounds = rotatingRoseBounds(cx, cy, radius); + const left = Math.max(0, bounds.x); + const top = Math.max(0, bounds.y); + const right = Math.min(width, bounds.x + bounds.width); + const bottom = Math.min(height, bounds.y + bounds.height); + if (right > left && bottom > top) { + const texture = new GrayImage(right - left, bottom - top, 0); + texture.bitBlt(image, 0, 0, { sx: left, sy: top, width: texture.width, height: texture.height }); + image.fillRect(left, top, texture.width, texture.height, 0); + image.drawImage(texture, left, top); + } + return image; +} + +/** Draw only the rotating points, with the brightest one aimed at north. */ +export function drawCompassRose(image: GrayImage, cx: number, cy: number, radius: number, heading: number | null): void { + // Without a reading there is nothing to aim, so show the rose in its resting + // orientation, dimmed, rather than an empty ring. + const fade = heading === null ? 0.45 : 1; + const bearing = heading ?? 0; + // Short points first, so the long ones sit on top of them at the waist. Only + // north is drawn at full brightness: the other seven are there to make the + // rose read as a rose, and competing with north would defeat the point. + for (const degrees of [45, 135, 225, 315]) { + drawRosePoint(image, cx, cy, radius, degrees - bearing, INTERCARDINAL_TIP, 85 * fade, 40 * fade); + } + for (const degrees of [90, 180, 270]) { + drawRosePoint(image, cx, cy, radius, degrees - bearing, CARDINAL_TIP, 120 * fade, 55 * fade); + } + drawRosePoint(image, cx, cy, radius, -bearing, CARDINAL_TIP, 255 * fade, 140 * fade); +} + +/** + * One point of the rose: a tapered spike split down its axis into a lit and a + * shaded facet, which is what keeps the eight points readable once perspective + * has squashed the ones lying across the wearer's line of sight. + */ +function drawRosePoint( + image: GrayImage, + cx: number, + cy: number, + radius: number, + angle: number, + tipRadius: number, + litValue: number, + shadedValue: number, +): void { + const centre = { x: cx, y: cy }; + const tip = projectRose(cx, cy, radius, tipRadius, angle); + const clockwise = projectRose(cx, cy, radius, POINT_BASE_RADIUS, angle + POINT_BASE_HALF_ANGLE); + const anticlockwise = projectRose(cx, cy, radius, POINT_BASE_RADIUS, angle - POINT_BASE_HALF_ANGLE); + fillTriangle(image, tip, centre, clockwise, litValue); + fillTriangle(image, tip, centre, anticlockwise, shadedValue); +} + +/** + * The side wall below the wearer-facing arc of the rim, which turns the tilted + * disc into a shallow cylinder. The arc runs between the two points where the + * silhouette turns vertical, so the wall ends flush with that vertical edge, + * and it is shaded from dark there to lit where it faces the wearer head-on. + */ +function drawDiscWall(image: GrayImage, cx: number, cy: number, radius: number, fade: number): void { + const depth = discDepth(radius); + const segments = 48; + const sweep = 360 - WALL_START_ANGLE * 2; + const rimValue = 105 * fade; + let previous = projectRose(cx, cy, radius, 1, WALL_START_ANGLE); + image.drawLine(previous.x, previous.y, previous.x, previous.y + depth, rimValue); + for (let i = 1; i <= segments; i++) { + const angle = WALL_START_ANGLE + (i * sweep) / segments; + const point = projectRose(cx, cy, radius, 1, angle); + // Quads rather than per-column lines, so no gap opens up where the rim + // runs nearly horizontal across the bottom of the oval. + const value = (WALL_DARK + (WALL_LIT - WALL_DARK) * wallFacing(angle)) * fade; + const top = { x: previous.x, y: previous.y }; + const next = { x: point.x, y: point.y }; + fillTriangle(image, top, next, { x: next.x, y: next.y + depth }, value); + fillTriangle(image, top, { x: top.x, y: top.y + depth }, { x: next.x, y: next.y + depth }, value); + image.drawLine(top.x, top.y + depth, next.x, next.y + depth, rimValue); + previous = point; + } + image.drawLine(previous.x, previous.y, previous.x, previous.y + depth, rimValue); +} + +/** 1 where the wall faces the wearer head-on, 0 at the silhouette's edges. */ +function wallFacing(angle: number): number { + const towardWearer = -Math.cos((angle * Math.PI) / 180); + return (towardWearer - TILT_PERSPECTIVE) / (1 - TILT_PERSPECTIVE); +} + +/** + * The grid the disc sits on, drawn before the disc so the disc occludes it. + * Brightness falls off with distance and fades to nothing as the plane climbs + * towards `clipY`, so the grid dissolves into the black under the readout + * rather than stopping at a hard edge. + */ +function drawPlaneGrid(image: GrayImage, cx: number, cy: number, radius: number, clipY: number): void { + const shade = (point: Point, ringRadius: number): number => { + if (point.y > image.height || Math.abs(point.x - cx) > image.width) return 0; + const fade = Math.max(0, Math.min(1, (point.y - clipY) / PLANE_FADE_SPAN)); + const value = (PLANE_NEAR_VALUE / (1 + PLANE_FALLOFF * (ringRadius - 1))) * fade; + return value >= PLANE_CUTOFF ? value : 0; + }; + const trace = ( + steps: number, + at: (step: number) => { point: Point; ringRadius: number }, + ): void => { + let previous: Point | null = null; + let previousValue = 0; + for (let i = 0; i <= steps; i++) { + const { point, ringRadius } = at(i); + const value = shade(point, ringRadius); + if (previous !== null && previousValue > 0 && value > 0) { + image.drawLine(previous.x, previous.y, point.x, point.y, (previousValue + value) / 2); + } + previous = point; + previousValue = value; + } + }; + + for (const ringRadius of PLANE_RINGS) { + trace(96, (step) => ({ point: projectRose(cx, cy, radius, ringRadius, (step * 360) / 96), ringRadius })); + } + // Spokes run from just outside the disc to the outermost ring, so the grid + // closes on itself instead of trailing off into loose ends. + const outer = PLANE_RINGS[PLANE_RINGS.length - 1]!; + for (let angle = PLANE_SPOKE_STEP / 2; angle < 360; angle += PLANE_SPOKE_STEP) { + trace(24, (step) => { + const ringRadius = 1.05 + (step * (outer - 1.05)) / 24; + return { point: projectRose(cx, cy, radius, ringRadius, angle), ringRadius }; + }); + } +} + +/** Screen depth of the disc's side wall at the given ring radius. */ +function discDepth(radius: number): number { + return Math.max(3, Math.round(radius * DISC_DEPTH)); +} + +/** The ring bounding the rose: the tilted disc's rim, drawn as a polygon. */ +function drawTiltedRing(image: GrayImage, cx: number, cy: number, radius: number, value: number): void { + const segments = 72; + let previous = projectRose(cx, cy, radius, 1, 0); + for (let i = 1; i <= segments; i++) { + const point = projectRose(cx, cy, radius, 1, (i * 360) / segments); + image.drawLine(previous.x, previous.y, point.x, point.y, value); + previous = point; + } +} + +/** A fixed mark just inside the top rim: the heading the wearer is facing. */ +function drawHeadingTick(image: GrayImage, cx: number, cy: number, radius: number, value: number): void { + const top = projectRose(cx, cy, radius, 1, 0); + const tickTop = top.y + 1; + fillTriangle( + image, + { x: cx, y: tickTop + TICK_HEIGHT - 1 }, + { x: cx - TICK_HALF_WIDTH, y: tickTop }, + { x: cx + TICK_HALF_WIDTH, y: tickTop }, + value, + ); +} + +function fillTriangle(image: GrayImage, a: Point, b: Point, c: Point, value: number): void { + const left = Math.max(0, Math.floor(Math.min(a.x, b.x, c.x))); + const right = Math.min(image.width - 1, Math.ceil(Math.max(a.x, b.x, c.x))); + const top = Math.max(0, Math.floor(Math.min(a.y, b.y, c.y))); + const bottom = Math.min(image.height - 1, Math.ceil(Math.max(a.y, b.y, c.y))); + const shade = Math.round(value); + for (let y = top; y <= bottom; y++) { + for (let x = left; x <= right; x++) { + const point = { x: x + 0.5, y: y + 0.5 }; + const ab = edge(a, b, point); + const bc = edge(b, c, point); + const ca = edge(c, a, point); + // Accept either winding, so callers don't have to order their vertices. + if ((ab >= 0 && bc >= 0 && ca >= 0) || (ab <= 0 && bc <= 0 && ca <= 0)) { + image.setPixel(x, y, shade); + } + } + } +} + +/** Twice the signed area of the triangle a-b-p; its sign is p's side of a-b. */ +function edge(a: Point, b: Point, p: Point): number { + return (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x); +} diff --git a/app/apps/developer/bandwidth-benchmark.ts b/app/apps/developer/bandwidth-benchmark.ts new file mode 100644 index 00000000..8af80ceb --- /dev/null +++ b/app/apps/developer/bandwidth-benchmark.ts @@ -0,0 +1,212 @@ +import { getDefaultSmallFont } from "../../graphics/ui-fonts"; +import { GrayImage } from "../../graphics/image"; +import { Layer, type LayerContext } from "../../ui/layers"; +import { type InputEvent } from "../../ui/gestures"; +import { drawSelectionHighlight } from "../../ui/menu"; +import { tightRowHeight } from "../../ui/metrics"; +import { + cancelBandwidthBenchmark, + getBandwidthBenchmarkStatus, + startBandwidthBenchmark, + type BandwidthBenchmarkStatus, +} from "../../native/bandwidth-benchmark"; + +const MESSAGE_SIZES = [250, 500, 1000, 2000, 3800]; +const WINDOW_SIZES = [1, 2, 3, 4, 6]; +const LINK_MODES = ["Current", "Request HIGH", "Request 2M", "HIGH + 2M"]; +const DURATION_MS = 15_000; +// After painting the "running" screen, wait for that frame to reach the +// glasses before the benchmark blocks normal image sends — otherwise the +// status frame would sit queued behind the whole 15-second run. +const ARM_DELAY_MS = 800; +const POLL_INTERVAL_MS = 500; +// Give up polling if the run somehow never reports done (duration + ack +// timeout drain + slack). +const POLL_DEADLINE_MS = DURATION_MS + 15_000; + +const HEADER_HEIGHT = 30; +const LIST_X = 20; +const VALUE_X = 150; + +type Phase = "config" | "arming" | "running" | "done"; + +/** + * BLE bandwidth benchmark: pick a message size and pipeline window, stream + * no-op image payloads for 15 seconds, and report throughput. The glasses + * screen is intentionally static while the run is active — the benchmark + * stream is the only image traffic, so the numbers are clean. + */ +export class BandwidthBenchmarkLayer implements Layer { + private phase: Phase = "config"; + private selectedRow = 0; // size, window, link preference, start + private sizeIndex = 2; + private windowIndex = 2; + private linkModeIndex = 0; + private result: BandwidthBenchmarkStatus | null = null; + private error: string | null = null; + private armTimer: ReturnType | null = null; + private pollTimer: ReturnType | null = null; + private pollStartedAtMs = 0; + + constructor(private readonly requestRender: () => void) {} + + onRemoved(): void { + this.clearTimers(); + if (this.phase === "arming" || this.phase === "running") { + cancelBandwidthBenchmark(); + } + } + + private clearTimers(): void { + if (this.armTimer !== null) { + clearTimeout(this.armTimer); + this.armTimer = null; + } + if (this.pollTimer !== null) { + clearInterval(this.pollTimer); + this.pollTimer = null; + } + } + + private startRun(): void { + this.result = null; + this.error = null; + this.phase = "arming"; + this.requestRender(); + this.armTimer = setTimeout(() => { + this.armTimer = null; + const started = startBandwidthBenchmark( + MESSAGE_SIZES[this.sizeIndex]!, + WINDOW_SIZES[this.windowIndex]!, + DURATION_MS, + this.linkModeIndex, + ); + if (!started) { + this.phase = "config"; + this.error = "Could not start (not connected?)"; + this.requestRender(); + return; + } + this.phase = "running"; + this.pollStartedAtMs = Date.now(); + // No renders while polling: a repaint would queue an image update that + // stays blocked behind the benchmark anyway. Render once on completion. + this.pollTimer = setInterval(() => this.poll(), POLL_INTERVAL_MS); + }, ARM_DELAY_MS); + } + + private poll(): void { + const status = getBandwidthBenchmarkStatus(); + if (status && (status.state === "starting" || status.state === "running")) { + if (Date.now() - this.pollStartedAtMs < POLL_DEADLINE_MS) return; + cancelBandwidthBenchmark(); + return; // next poll picks up the cancelled run's "done" + } + this.clearTimers(); + if (status && status.state === "done") { + this.result = status; + this.phase = "done"; + } else { + this.phase = "config"; + this.error = "Benchmark lost (disconnected?)"; + } + this.requestRender(); + } + + paint(ctx: LayerContext): GrayImage { + const font = getDefaultSmallFont(); + const { width, height } = ctx.stack.getBaseSize(); + const image = new GrayImage(width, height, 0); + + image.drawText(font, 20, 8, "BLE bandwidth", 220); + + if (this.phase === "arming" || this.phase === "running") { + image.drawText(font, LIST_X, HEADER_HEIGHT + 8, "Running: streaming no-op packets for 15 s...", 200); + image.drawText( + font, + LIST_X, + HEADER_HEIGHT + 30, + `${MESSAGE_SIZES[this.sizeIndex]} B, window ${WINDOW_SIZES[this.windowIndex]}, ${LINK_MODES[this.linkModeIndex]}`, + 150, + ); + image.drawText(font, LIST_X, HEADER_HEIGHT + 52, "Display updates pause until the run finishes.", 110); + return image; + } + + const rowH = tightRowHeight(font) + 4; + const rows: Array<[string, string]> = [ + ["Message size", `${MESSAGE_SIZES[this.sizeIndex]} B`], + ["Window size", `${WINDOW_SIZES[this.windowIndex]}`], + ["Link request", LINK_MODES[this.linkModeIndex]!], + [this.phase === "done" ? "Run again" : "Start", ""], + ]; + for (let index = 0; index < rows.length; index++) { + const [label, value] = rows[index]!; + const y = HEADER_HEIGHT + index * rowH; + const selected = index === this.selectedRow; + if (selected) { + drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, rowH - 1, ctx.stack.isFocused(), 4); + } + image.drawText(font, LIST_X, y + 2, label, selected ? 255 : 200); + if (value) { + image.drawText(font, VALUE_X, y + 2, value, selected ? 235 : 160); + } + } + + let y = HEADER_HEIGHT + rows.length * rowH + 10; + if (this.error) { + image.drawText(font, LIST_X, y, this.error, 180); + } else if (this.result) { + const r = this.result; + const seconds = r.elapsedMs / 1000; + const payloadRate = seconds > 0 ? r.payloadBytesAcked / seconds : 0; + const wireRate = seconds > 0 ? r.wireBytesAcked / seconds : 0; + const lines = [ + `Throughput: ${(payloadRate / 1024).toFixed(2)} KB/s payload (${(wireRate / 1024).toFixed(2)} KB/s wire)`, + `Messages: ${r.messagesAcked}/${r.messagesSent} acked, ${r.timeouts} timeouts`, + `Elapsed: ${seconds.toFixed(1)} s` + (r.aborted ? " (aborted early)" : ""), + `Link request: ${LINK_MODES[r.linkMode] ?? "Current"}`, + ]; + for (const line of lines) { + image.drawText(font, LIST_X, y, line, 190); + y += 20; + } + } + + return image; + } + + async handleInput(event: InputEvent, ctx: LayerContext): Promise { + if (this.phase === "arming" || this.phase === "running") { + // A static screen during the run: only allow bailing out. + if (event.type === "double-click") { + ctx.stack.pop(); + } + return; + } + switch (event.type) { + case "scroll-up": + this.selectedRow = Math.max(0, this.selectedRow - 1); + return; + case "scroll-down": + this.selectedRow = Math.min(3, this.selectedRow + 1); + return; + case "click": + if (this.selectedRow === 0) { + this.sizeIndex = (this.sizeIndex + 1) % MESSAGE_SIZES.length; + } else if (this.selectedRow === 1) { + this.windowIndex = (this.windowIndex + 1) % WINDOW_SIZES.length; + } else if (this.selectedRow === 2) { + this.linkModeIndex = (this.linkModeIndex + 1) % LINK_MODES.length; + } else { + this.startRun(); + } + return; + case "double-click": + ctx.stack.pop(); + return; + default: + return; + } + } +} diff --git a/app/apps/developer/developer-app.ts b/app/apps/developer/developer-app.ts index eead6675..5abcf821 100644 --- a/app/apps/developer/developer-app.ts +++ b/app/apps/developer/developer-app.ts @@ -2,6 +2,7 @@ import { MenuLayer, drawSubmenuIndicator, type MenuItem } from "../../ui/menu"; import { ScreenTestLayer } from "./screen-test"; import { BuzzerDemoLayer } from "./buzzer-demo"; import { AccelerometerDemoLayer } from "./accelerometer-demo"; +import { BandwidthBenchmarkLayer } from "./bandwidth-benchmark"; import { LightSensorDemoLayer } from "./light-sensor-demo"; import { ResourceUsageLayer } from "./resource-usage"; import { LoadAppFromQrLayer, LoadAppFromUrlLayer } from "./load-app"; @@ -80,6 +81,12 @@ function debugTestsMenu(): MenuLayer { ctx.stack.push(new LightSensorDemoLayer(DEVELOPER_WINDOW_ID, ctx.actions.requestRender)); }, }, + { + label: "BLE bandwidth", + onSelect: (ctx) => { + ctx.stack.push(new BandwidthBenchmarkLayer(ctx.actions.requestRender)); + }, + }, ], MENU_LAYOUT, ); diff --git a/app/apps/developer/light-sensor-demo.ts b/app/apps/developer/light-sensor-demo.ts index 4a5a2748..8f713f8d 100644 --- a/app/apps/developer/light-sensor-demo.ts +++ b/app/apps/developer/light-sensor-demo.ts @@ -113,8 +113,7 @@ export class LightSensorDemoLayer implements Layer { if (!report) { const message = this.enabled ? "Waiting for a report…" : "Paused (page not visible)."; image.drawText(small, 22, 44, message, 190); - image.drawText(small, 22, 66, "Needs custom firmware with the als16", 120); - image.drawText(small, 22, 82, "extension (EVENCFW/18 or newer).", 120); + image.drawText(small, 22, 66, "Needs Faceclaw's custom firmware.", 120); image.drawText(small, 20, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110); return image; } diff --git a/app/apps/flappy/flappy-app.worker.ts b/app/apps/flappy/flappy-app.worker.ts new file mode 100644 index 00000000..b0b998db --- /dev/null +++ b/app/apps/flappy/flappy-app.worker.ts @@ -0,0 +1,777 @@ +/** + * Flappy app worker: a Flappy Bird-style side scroller. One singleton + * window; the bird sits a third of the way across, pipes scroll in from the + * right, a flap counters gravity, and the score is one point per pipe pair + * cleared. + * + * The BLE pipeline runs ~250 ms input-to-pixels and a handful of fps, so the + * game is tuned latency-tolerant: slow scroll, gentle gravity, a wide gap, + * and a forgiving hitbox. Physics runs at a 60 Hz fixed step inside a ~12 fps + * render tick. + * + * Bandwidth: everything that moves is a sprite placed with drawImage, so the + * wire pipeline can ship it as an on-glasses cached-image draw (a 9-byte + * record) rather than pixels. The bird is pre-rendered at a few tilt angles + * and wing positions; pipes are a cap plus vertically uniform body tiles; + * the ground is one tile repeated. Sprites hanging off the top or left edge + * fall back to raster (the planner needs a non-negative origin), which is + * small and rare. + * + * Controls (a watch swipe in either direction is the primary flap): + * swipe-up, swipe-down, click, or scroll-up flaps; double-click pauses; + * tap-then-hold opens the window menu. Ready / paused / game over: click or + * a swipe starts or resumes, double-click yields focus. Losing input focus + * mid-flight (a shell overlay such as the system menu or a notification, + * focus to the sidebar) pauses, as does backgrounding or screen-off. + */ +import "@nativescript/core/globals"; +import { GrayImage } from "../../graphics/image"; +import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane"; +import { prepareFrameDraws } from "../../graphics/glyph-wire"; +import { getFont } from "../../graphics/bdffont"; +import { getDefaultSmallFont } from "../../graphics/ui-fonts"; +import * as frameTimings from "../../native/frame-timings"; +import { getActiveDisplay } from "../../native/active-display"; +import { getStringSetting, setStringSetting } from "../../native/settings-store"; +import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects"; +import { loadSoundEnabled, saveSoundEnabled } from "../../ui/sound-setting"; +import { type MenuItem } from "../../ui/menu"; +import { WindowMenu } from "../../ui/window-menu"; +import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; +import { + directionalFallback, + GESTURE_CLICK, + GESTURE_DOUBLE_CLICK, + type InputEvent, +} from "../../ui/gestures"; +import { clamp } from "../../util/numeric-util"; +import { + BIRD_ANGLES, + BIRD_SPRITE_H, + BIRD_SPRITE_W, + BIRD_WING_FRAMES, + createBirdSprite, + createGroundTile, + createPipeBodyTile, + createPipeCap, + GROUND_H, + GROUND_TILE_W, + PIPE_BODY_TILE_H, + PIPE_CAP_H, + PIPE_CAP_OVERHANG, + PIPE_CAP_W, + PIPE_W, +} from "./flappy-sprites"; + +declare const global: any; +declare const com: any; + +const largeFont = getFont("terminus32"); +const mediumFont = getFont("terminus24"); +const smallFont = getDefaultSmallFont(); + +const HIGH_SCORE_KEY = "flappy.highScore"; + +// --- Tuning (pixels, seconds) ------------------------------------------------ +/** Bird center x; fixed, the world scrolls past it. */ +const BIRD_X = 150; +/** Gentle on purpose: a flap-to-flap cycle is well over the glasses round trip. */ +const GRAVITY = 520; +const FLAP_VY = -215; +const MAX_FALL_SPEED = 330; +const SCROLL_SPEED = 76; +const GAP_H = 104; +const PIPE_SPACING = 236; +/** Least body height either pipe of a pair keeps, so gaps never hug an edge. */ +const MIN_PIPE_BODY = 30; +/** Forgiving hitbox half-extents around the bird center. */ +const HITBOX_HALF_W = 9; +const HITBOX_HALF_H = 7; +const PHYSICS_DT = 1 / 60; +const RENDER_TICK_MS = 30; +/** Physics steps per wing frame while flying. */ +const WING_STEPS_PER_FRAME = 6; + +const SFX_FLAP: Step[] = [{ freq: 880, duty: 40, ms: 20 }, { freq: 1175, duty: 40, ms: 25 }]; +const SFX_SCORE: Step[] = [{ freq: 1568, duty: 40, ms: 40 }, { freq: 2093, duty: 40, ms: 60 }]; +const SFX_HIT: Step[] = [{ freq: 220, duty: 55, ms: 80 }, { freq: 165, duty: 55, ms: 120 }]; +const SFX_GAME_OVER: Step[] = [ + { freq: 494, duty: 45, ms: 150 }, + { freq: 440, duty: 45, ms: 150 }, + { freq: 392, duty: 45, ms: 150 }, + { freq: 294, duty: 50, ms: 320 }, +]; +const SFX_PAUSE: Step[] = [ + { freq: 1319, duty: 40, ms: 60 }, + { freq: 880, duty: 40, ms: 110 }, +]; +const SFX_RESUME: Step[] = [ + { freq: 880, duty: 40, ms: 60 }, + { freq: 1319, duty: 40, ms: 110 }, +]; +const MINOR_SFX_MIN_GAP_MS = 120; + +/** + * ready: bird hovering, waiting for the first flap. playing: scrolling. + * dying: hit something, bird tumbling to the ground with the world frozen. + * game-over / paused: static screens with a dialog. + */ +type GamePhase = "ready" | "playing" | "dying" | "game-over" | "paused"; + +type Pipe = { + /** Body left edge in viewport coordinates. */ + x: number; + /** Bottom of the top pipe's cap; the gap runs from here to gapTop + GAP_H. */ + gapTop: number; + scored: boolean; +}; + +type FlappyWindow = { + windowId: string; + surfaceId: string; + title: string; + viewportWidth: number; + viewportHeight: number; + foreground: boolean; + /** Whether this window is the shell's input target (pushed with each message). */ + focused: boolean; + /** Tap-then-hold window menu; created on first open. */ + menu: WindowMenu | null; + phase: GamePhase; + birdY: number; + birdVy: number; + /** Physics steps since the game started; drives the wing animation. */ + stepCount: number; + /** World scroll distance so far, for the ground tiling phase. */ + scrollX: number; + pipes: Pipe[]; + score: number; + highScore: number; + tickTimer: ReturnType | null; + lastTickAtMs: number; + lastMinorSfxAtMs: number; + soundOn: boolean; + lastSubmittedFingerprint: string; +}; + +const windows = new Map(); +let screenOn = true; + +// --- Sprites (immutable, built once per worker) ----------------------------- + +const pipeBodyTile = createPipeBodyTile(); +const pipeCap = createPipeCap(); +const groundTile = createGroundTile(); +/** [angleIndex][wingFrame] */ +const birdSprites: GrayImage[][] = BIRD_ANGLES.map((angle) => + Array.from({ length: BIRD_WING_FRAMES }, (_, frame) => createBirdSprite(angle, frame)), +); + +function post(message: WorkerAppReply): void { + global.postMessage(message); +} + +// The host queues messages until this arrives: posts to a worker whose bundle +// is still evaluating can be silently dropped (see WorkerAppHost). Top-level +// evaluation is synchronous, so the handler below is installed before any +// queued message can be delivered. +post({ type: "worker-ready" }); + +global.onmessage = (event: { data: WorkerAppMessage }) => { + const message = event.data; + switch (message.type) { + case "open-window": { + const window: FlappyWindow = { + windowId: message.windowId, + surfaceId: message.surfaceId, + title: message.title, + viewportWidth: message.viewport.width, + viewportHeight: message.viewport.height, + foreground: false, + focused: false, + menu: null, + phase: "ready", + birdY: 0, + birdVy: 0, + stepCount: 0, + scrollX: 0, + pipes: [], + score: 0, + highScore: loadHighScore(), + tickTimer: null, + lastTickAtMs: 0, + lastMinorSfxAtMs: 0, + soundOn: loadSoundEnabled("flappy"), + lastSubmittedFingerprint: "", + }; + resetGame(window); + windows.set(message.windowId, window); + break; + } + case "resize-window": { + const window = windows.get(message.windowId); + if (!window) break; + window.viewportWidth = message.viewport.width; + window.viewportHeight = message.viewport.height; + window.menu?.resize({ width: window.viewportWidth, height: window.viewportHeight }); + if (window.foreground) renderAndSubmit(window, 0); + break; + } + case "close-window": { + const window = windows.get(message.windowId); + if (window?.tickTimer) clearInterval(window.tickTimer); + windows.delete(message.windowId); + break; + } + case "input": { + const window = windows.get(message.windowId); + if (!window) { + frameTimings.finishFrame(message.frameId, "discarded: unknown flappy window"); + break; + } + window.focused = message.focused; + inferForeground(window, message.focused); + frameTimings.logFrame(message.frameId, `input received in ${message.windowId} worker`); + handleInput(window, message.event as InputEvent, message.frameId); + break; + } + case "render": { + const window = windows.get(message.windowId); + if (!window) break; + window.focused = message.focused; + inferForeground(window, message.focused); + renderAndSubmit(window, 0); + break; + } + case "foreground": { + const window = windows.get(message.windowId); + if (!window) break; + window.foreground = message.foreground; + window.focused = message.focused; + // The player can't see the bird while backgrounded, so don't let it + // keep falling. + if (!window.foreground && window.phase === "playing") window.phase = "paused"; + syncTickTimer(window); + if (window.foreground) renderAndSubmit(window, 0); + break; + } + case "input-focus": { + const window = windows.get(message.windowId); + if (!window) break; + // Anything that takes input away (the system menu, a notification + // modal, the voice dialog, focus back to the sidebar) pauses the + // flight; a death tumble is allowed to finish. + if (!message.focused && window.phase === "playing") { + window.phase = "paused"; + syncTickTimer(window); + if (window.foreground) renderAndSubmit(window, 0); + } + break; + } + case "screen": + screenOn = message.on; + for (const window of windows.values()) { + if (!screenOn && window.phase === "playing") window.phase = "paused"; + syncTickTimer(window); + } + break; + } +}; + +/** + * Input and render messages only ever target the shell's foreground window, + * so a focused message proves this window is foreground. This backstops the + * "foreground" message itself, which can be lost while a freshly spawned + * worker is still evaluating its bundle (see the Blocks worker). + */ +function inferForeground(window: FlappyWindow, focused: boolean): void { + if (!focused || window.foreground) return; + window.foreground = true; + syncTickTimer(window); +} + +function loadHighScore(): number { + try { + const parsed = parseInt(getStringSetting(HIGH_SCORE_KEY, "0"), 10); + return Number.isFinite(parsed) && parsed > 0 ? parsed : 0; + } catch { + return 0; + } +} + +function saveHighScore(window: FlappyWindow): void { + if (window.score <= window.highScore) return; + window.highScore = window.score; + try { + setStringSetting(HIGH_SCORE_KEY, String(window.highScore)); + } catch (error) { + console.warn(`flappy high-score save failed: ${error}`); + } +} + +/** + * Fire a buzzer effect. Non-blocking: the firmware's sequencer plays the + * steps on its own timer, and the Java call is safe from the worker thread. + * Minor (frequent) effects are dropped when they'd arrive within the + * rate-limit gap; newsworthy ones always play. + */ +function playSfx(window: FlappyWindow, steps: Step[], minor = false): void { + if (!window.soundOn || steps.length === 0) return; + const now = Date.now(); + if (minor && now - window.lastMinorSfxAtMs < MINOR_SFX_MIN_GAP_MS) return; + if (minor) window.lastMinorSfxAtMs = now; + try { + const communicator = com.faceclaw.app.FaceclawBleCommunicator.getActive(); + if (!communicator) return; + communicator.playBuzzerSequence(buildSoundSequencePayload(steps).buffer); + } catch (error) { + console.warn(`flappy sfx failed: ${error}`); + } +} + +function windowMenuItems(window: FlappyWindow): MenuItem[] { + return [ + { + label: "New game", + onSelect: (ctx) => { + ctx.stack.pop(); + resetGame(window); + playSfx(window, SFX_RESUME); + }, + }, + { + label: window.soundOn ? "Sound: on" : "Sound: off", + onSelect: (ctx) => { + ctx.stack.pop(); + window.soundOn = !window.soundOn; + saveSoundEnabled("flappy", window.soundOn); + if (window.soundOn) playSfx(window, SFX_RESUME); + }, + }, + ]; +} + +function windowMenu(window: FlappyWindow): WindowMenu { + if (!window.menu) { + window.menu = new WindowMenu({ + windowId: window.windowId, + post, + title: () => window.title, + items: () => windowMenuItems(window), + size: { width: window.viewportWidth, height: window.viewportHeight }, + paintBase: () => paintContent(window), + isFocused: () => window.focused, + }); + } + return window.menu; +} + +// --- Input ------------------------------------------------------------------ + +function handleInput(window: FlappyWindow, event: InputEvent, frameId: number): void { + // An open window menu owns all input (it closes itself via pop); menus are + // list UIs, so watch swipes take their standard fallback meanings there. + if (window.menu?.isOpen()) { + window.menu + .handleInput(directionalFallback(event)) + .catch((error) => console.error(`flappy menu input failed: ${error}`)) + .then(() => renderAndSubmit(window, frameId)); + return; + } + + // Opening the menu mid-flight would leave the bird falling under it. + if (event.type === "short-then-long-press") { + if (window.phase === "playing") { + window.phase = "paused"; + syncTickTimer(window); + } + windowMenu(window).open(); + renderAndSubmit(window, frameId); + return; + } + + switch (window.phase) { + case "ready": + case "playing": + handleFlightInput(window, event, frameId); + break; + case "dying": + // Let the tumble finish; a flap mashed during it must not restart. + frameTimings.finishFrame(frameId, "discarded: flappy ignored input while dying"); + break; + default: + handleIdleInput(window, event, frameId); + break; + } +} + +/** Input while ready or flying: the flap gestures, plus pause. */ +function handleFlightInput(window: FlappyWindow, event: InputEvent, frameId: number): void { + switch (event.type) { + // Either swipe direction flaps: on the watch the flap is a reflex, and + // which way the thumb went shouldn't matter. + case "swipe-up": + case "swipe-down": + case "click": + case "scroll-up": + flap(window); + break; + case "double-click": + if (window.phase === "playing") { + window.phase = "paused"; + playSfx(window, SFX_PAUSE); + } else { + frameTimings.finishFrame(frameId, "discarded: flappy yielded focus"); + post({ type: "yield-focus", windowId: window.windowId }); + return; + } + break; + default: + frameTimings.finishFrame(frameId, "discarded: flappy ignored input"); + return; + } + syncTickTimer(window); + renderAndSubmit(window, frameId); +} + +/** Input while paused or game over. Swipes take their standard fallback meanings. */ +function handleIdleInput(window: FlappyWindow, event: InputEvent, frameId: number): void { + switch (directionalFallback(event).type) { + case "click": + if (window.phase === "game-over") { + resetGame(window); + } else { + window.phase = "playing"; + } + syncTickTimer(window); + playSfx(window, SFX_RESUME); + break; + case "double-click": + frameTimings.finishFrame(frameId, "discarded: flappy yielded focus"); + post({ type: "yield-focus", windowId: window.windowId }); + return; + default: + frameTimings.finishFrame(frameId, "discarded: flappy ignored input"); + return; + } + renderAndSubmit(window, frameId); +} + +function groundTop(window: FlappyWindow): number { + return window.viewportHeight - GROUND_H; +} + +function resetGame(window: FlappyWindow): void { + window.phase = "ready"; + window.birdY = Math.round(groundTop(window) * 0.42); + window.birdVy = 0; + window.stepCount = 0; + window.scrollX = 0; + window.pipes = []; + window.score = 0; + syncTickTimer(window); +} + +function flap(window: FlappyWindow): void { + if (window.phase === "ready") { + window.phase = "playing"; + window.lastTickAtMs = Date.now(); + } + window.birdVy = FLAP_VY; + playSfx(window, SFX_FLAP, true); +} + +// --- Simulation ------------------------------------------------------------- + +function isAnimating(window: FlappyWindow): boolean { + return window.phase === "playing" || window.phase === "dying"; +} + +/** Keep the render tick running exactly while something is visibly moving. */ +function syncTickTimer(window: FlappyWindow): void { + const shouldRun = window.foreground && screenOn && isAnimating(window); + if (!shouldRun && window.tickTimer !== null) { + clearInterval(window.tickTimer); + window.tickTimer = null; + } + if (shouldRun && window.tickTimer === null) { + window.lastTickAtMs = Date.now(); + window.tickTimer = setInterval(() => tick(window), RENDER_TICK_MS); + } +} + +/** One render tick: catch the fixed-step physics up to real time, repaint. */ +function tick(window: FlappyWindow): void { + if (!isAnimating(window)) { + syncTickTimer(window); + return; + } + const now = Date.now(); + const elapsedMs = Math.min(now - window.lastTickAtMs, 300); + window.lastTickAtMs = now; + const steps = clamp(Math.round(elapsedMs / (PHYSICS_DT * 1000)), 1, 20); + for (let i = 0; i < steps && isAnimating(window); i++) { + stepPhysics(window); + } + renderAndSubmit(window, 0); + syncTickTimer(window); +} + +function stepPhysics(window: FlappyWindow): void { + const dt = PHYSICS_DT; + window.stepCount++; + window.birdVy = Math.min(window.birdVy + GRAVITY * dt, MAX_FALL_SPEED); + window.birdY += window.birdVy * dt; + const floor = groundTop(window) - HITBOX_HALF_H; + + if (window.phase === "dying") { + if (window.birdY >= floor) { + window.birdY = floor; + finishGame(window); + } + return; + } + + // Ceiling: stop rather than die, like the original. + if (window.birdY < HITBOX_HALF_H) { + window.birdY = HITBOX_HALF_H; + window.birdVy = Math.max(0, window.birdVy); + } + + const advance = SCROLL_SPEED * dt; + window.scrollX += advance; + for (const pipe of window.pipes) pipe.x -= advance; + if (window.pipes.length && window.pipes[0]!.x + PIPE_W + PIPE_CAP_OVERHANG < 0) { + window.pipes.shift(); + } + const last = window.pipes[window.pipes.length - 1]; + if (!last || last.x <= window.viewportWidth - PIPE_SPACING) { + spawnPipe(window, last ? last.x + PIPE_SPACING : window.viewportWidth + 40); + } + + for (const pipe of window.pipes) { + if (!pipe.scored && pipe.x + PIPE_W < BIRD_X - HITBOX_HALF_W) { + pipe.scored = true; + window.score++; + playSfx(window, SFX_SCORE); + } + } + + if (window.birdY >= floor) { + window.birdY = floor; + playSfx(window, SFX_HIT); + finishGame(window); + return; + } + if (window.pipes.some((pipe) => hitsPipe(window, pipe))) { + window.phase = "dying"; + window.birdVy = Math.max(window.birdVy, 40); + playSfx(window, SFX_HIT); + } +} + +function spawnPipe(window: FlappyWindow, x: number): void { + const minGapTop = PIPE_CAP_H + MIN_PIPE_BODY; + const maxGapTop = groundTop(window) - GAP_H - PIPE_CAP_H - MIN_PIPE_BODY; + const gapTop = Math.round(minGapTop + Math.random() * Math.max(0, maxGapTop - minGapTop)); + window.pipes.push({ x, gapTop, scored: false }); +} + +function hitsPipe(window: FlappyWindow, pipe: Pipe): boolean { + const left = BIRD_X - HITBOX_HALF_W; + const right = BIRD_X + HITBOX_HALF_W; + const top = window.birdY - HITBOX_HALF_H; + const bottom = window.birdY + HITBOX_HALF_H; + const capLeft = pipe.x - PIPE_CAP_OVERHANG; + const capRight = capLeft + PIPE_CAP_W; + const gapBottom = pipe.gapTop + GAP_H; + // The cap is wider than the body, so test the whole pipe at cap width for + // the cap rows and at body width elsewhere. + const withinBody = right > pipe.x && left < pipe.x + PIPE_W; + const withinCap = right > capLeft && left < capRight; + if (withinCap) { + if (bottom > pipe.gapTop - PIPE_CAP_H && top < pipe.gapTop) return true; + if (bottom > gapBottom && top < gapBottom + PIPE_CAP_H) return true; + } + if (withinBody) { + if (top < pipe.gapTop - PIPE_CAP_H) return true; + if (bottom > gapBottom + PIPE_CAP_H) return true; + } + return false; +} + +function finishGame(window: FlappyWindow): void { + window.phase = "game-over"; + saveHighScore(window); + playSfx(window, SFX_GAME_OVER); + syncTickTimer(window); +} + +// --- Painting --------------------------------------------------------------- + +/** + * Place a sprite. A whole sprite with a non-negative origin goes through the + * deferred-image path (texture cacheable); anything hanging off the top or + * left edge, or vertically clipped, falls back to a raster blit, since + * cached draws are whole-image only with an unsigned origin. + */ +function stamp(image: GrayImage, sprite: GrayImage, x: number, y: number, clipHeight?: number): void { + const ix = Math.round(x); + const iy = Math.round(y); + if (ix >= 0 && iy >= 0 && (clipHeight === undefined || clipHeight >= sprite.height)) { + image.drawImage(sprite, ix, iy); + } else { + image.bitBlt(sprite, ix, iy, { height: clipHeight, transparentZero: true }); + } +} + +function paint(window: FlappyWindow): Plane[] { + return windowMenu(window).paint(); +} + +function paintContent(window: FlappyWindow): GrayImage { + const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0); + const ground = groundTop(window); + + for (const pipe of window.pipes) paintPipe(image, pipe, ground); + + // Ground: tiles phased by the scroll distance so the hatching moves. + const groundPhase = -(Math.round(window.scrollX) % GROUND_TILE_W); + for (let x = groundPhase; x < window.viewportWidth; x += GROUND_TILE_W) { + stamp(image, groundTile, x, ground); + } + + // Bird last, so it sits over the pipes when they meet. + const sprite = birdSprites[birdAngleIndex(window)]![birdWingFrame(window)]!; + stamp(image, sprite, BIRD_X - BIRD_SPRITE_W / 2, window.birdY - BIRD_SPRITE_H / 2); + + paintHud(image, window); + return image; +} + +function paintPipe(image: GrayImage, pipe: Pipe, ground: number): void { + const capX = pipe.x - PIPE_CAP_OVERHANG; + // Top pipe: cap just above the gap, body tiles stacked upward from it. The + // tile that would start above the top edge is clipped to raster. + const topBodyBottom = pipe.gapTop - PIPE_CAP_H; + for (let y = topBodyBottom - PIPE_BODY_TILE_H; y > -PIPE_BODY_TILE_H; y -= PIPE_BODY_TILE_H) { + stamp(image, pipeBodyTile, pipe.x, y); + } + stamp(image, pipeCap, capX, topBodyBottom); + + // Bottom pipe: cap just below the gap, body tiles stacked down to the + // ground; the final partial tile is clipped to raster. + const gapBottom = pipe.gapTop + GAP_H; + stamp(image, pipeCap, capX, gapBottom); + for (let y = gapBottom + PIPE_CAP_H; y < ground; y += PIPE_BODY_TILE_H) { + stamp(image, pipeBodyTile, pipe.x, y, Math.min(PIPE_BODY_TILE_H, ground - y)); + } +} + +/** Nose-up while rising, nose-down the faster the fall; steepest during the death tumble. */ +function birdAngleIndex(window: FlappyWindow): number { + if (window.phase === "ready") return 1; + if (window.phase === "dying") return BIRD_ANGLES.length - 1; + const target = window.birdVy < 0 ? -25 : (window.birdVy / MAX_FALL_SPEED) * 55; + let best = 0; + for (let i = 1; i < BIRD_ANGLES.length - 1; i++) { + if (Math.abs(BIRD_ANGLES[i]! - target) < Math.abs(BIRD_ANGLES[best]! - target)) best = i; + } + return best; +} + +function birdWingFrame(window: FlappyWindow): number { + if (window.phase !== "playing") return 1; + // Up, mid, down, mid, ... so the wing beats rather than snaps. + const cycle = [0, 1, 2, 1]; + return cycle[Math.floor(window.stepCount / WING_STEPS_PER_FRAME) % cycle.length]!; +} + +function paintHud(image: GrayImage, window: FlappyWindow): void { + const width = window.viewportWidth; + if (window.phase !== "ready") { + drawCenteredIn(image, largeFont, 0, width, 10, String(window.score), 245); + } + switch (window.phase) { + case "ready": + drawCenteredIn(image, mediumFont, 0, width, 14, "FLAPPY", 245); + if (window.highScore > 0) { + drawCenteredIn(image, smallFont, 0, width, 44, `best ${window.highScore}`, 150); + } + drawCenteredIn(image, smallFont, 0, width, groundTop(window) - 26, `swipe / ${GESTURE_CLICK} flap`, 150); + break; + case "paused": + paintDialog(image, window, "PAUSED", [`${GESTURE_CLICK} resume`, `${GESTURE_DOUBLE_CLICK} leave`]); + break; + case "game-over": + paintDialog(image, window, "GAME OVER", [ + `score ${window.score} best ${window.highScore}`, + `${GESTURE_CLICK} new game ${GESTURE_DOUBLE_CLICK} leave`, + ]); + break; + } +} + +function paintDialog(image: GrayImage, window: FlappyWindow, title: string, lines: string[]): void { + const width = 260; + const height = 46 + lines.length * 20; + const x = Math.round((window.viewportWidth - width) / 2); + const y = Math.round((groundTop(window) - height) / 2); + image.fillRect(x, y, width, height, 0); + image.drawRect(x + 3, y + 3, width - 6, height - 6, 150); + drawCenteredIn(image, mediumFont, x, width, y + 12, title, 245); + lines.forEach((line, i) => { + drawCenteredIn(image, smallFont, x, width, y + 40 + i * 20, line, 150); + }); +} + +function drawCenteredIn( + image: GrayImage, + font: typeof smallFont, + x: number, + width: number, + y: number, + text: string, + value: number, +): void { + image.drawText(font, Math.round(x + (width - font.measureText(text)) / 2), y, text, value); +} + +function renderAndSubmit(window: FlappyWindow, inputFrameId: number): void { + const frameId = inputFrameId > 0 ? inputFrameId : frameTimings.startFrame(`render:${window.windowId}`); + try { + const paintStartedAtMs = Date.now(); + const planes = frameTimings.span(frameId, "paint", () => + frameTimings.runWithFrame(frameId, () => paint(window)), + ); + const paintMs = Date.now() - paintStartedAtMs; + const fingerprint = planesFingerprint(planes); + if (fingerprint === window.lastSubmittedFingerprint) { + frameTimings.finishFrame(frameId, "discarded: flappy content unchanged"); + return; + } + const communicator = getActiveDisplay(); + if (!communicator) { + frameTimings.finishFrame(frameId, "discarded: no active display"); + return; + } + const { image, draws } = frameTimings.span(frameId, "flatten", () => flattenPlanesWithDraws(planes)); + const buffer = frameTimings.span(frameId, "to8bpp", () => image.to8bppBuffer()); + communicator.submitSurfaceFrame( + buffer.buffer, + window.surfaceId, + 0, + 0, + image.width, + image.height, + fingerprint, + paintMs, + frameId, + frameTimings.span(frameId, "prepareFrameDraws", () => prepareFrameDraws(draws)), + ); + window.lastSubmittedFingerprint = fingerprint; + } catch (error) { + frameTimings.finishFrame(frameId, "discarded: flappy render failed"); + console.error(`flappy worker render failed: ${error}`); + } +} diff --git a/app/apps/flappy/flappy-sprites.ts b/app/apps/flappy/flappy-sprites.ts new file mode 100644 index 00000000..6ce5b92f --- /dev/null +++ b/app/apps/flappy/flappy-sprites.ts @@ -0,0 +1,135 @@ +/** + * Sprite assets for the Flappy game, built once per worker and never mutated + * afterwards, so every frame can place them with GrayImage.drawImage and the + * wire pipeline can ship them as on-glasses cached-image draws (see + * graphics/glyph-wire.ts). A frame then costs a handful of 9-byte draw + * records plus whatever raster is left, instead of re-sending the sprite + * pixels every tick. + * + * Constraints the pipeline puts on the art (kept here so the worker doesn't + * have to know): + * - a cached image is at most 255x255, so pipes are built from short body + * tiles under a cap rather than one tall image; + * - the body tile is vertically uniform (stripes only), so overlapping two + * tiles at any vertical offset writes identical pixels and both still + * match the composite the planner checks against; + * - value 0 is transparent (color key), so sprites use 1 for opaque black. + */ +import { GrayImage } from "../../graphics/image"; + +export const PIPE_W = 44; +export const PIPE_CAP_W = 52; +export const PIPE_CAP_H = 16; +/** How far the cap overhangs the body on each side. */ +export const PIPE_CAP_OVERHANG = (PIPE_CAP_W - PIPE_W) / 2; +export const PIPE_BODY_TILE_H = 32; + +export const GROUND_TILE_W = 96; +export const GROUND_H = 18; + +export const BIRD_SPRITE_W = 30; +export const BIRD_SPRITE_H = 26; +/** Bird rotation angles the sprites are pre-rendered at, in degrees (positive = nose down). */ +export const BIRD_ANGLES = [-25, 0, 25, 50, 80] as const; +export const BIRD_WING_FRAMES = 3; + +const OPAQUE_BLACK = 1; + +/** Vertical stripe shading across the pipe body: highlight left, shadow right. */ +function pipeColumnShade(col: number, width: number): number { + if (col === 0) return 90; + if (col <= 3) return 210; + if (col >= width - 1) return 60; + if (col >= width - 4) return 95; + return 150; +} + +export function createPipeBodyTile(): GrayImage { + const image = new GrayImage(PIPE_W, PIPE_BODY_TILE_H, 0); + for (let col = 0; col < PIPE_W; col++) { + image.fillRect(col, 0, 1, PIPE_BODY_TILE_H, pipeColumnShade(col, PIPE_W)); + } + return image; +} + +/** Vertically symmetric, so one tile serves as both the top and the bottom pipe's cap. */ +export function createPipeCap(): GrayImage { + const image = new GrayImage(PIPE_CAP_W, PIPE_CAP_H, 0); + for (let col = 0; col < PIPE_CAP_W; col++) { + image.fillRect(col, 0, 1, PIPE_CAP_H, pipeColumnShade(col, PIPE_CAP_W)); + } + image.fillRect(0, 0, PIPE_CAP_W, 2, 220); + image.fillRect(0, PIPE_CAP_H - 2, PIPE_CAP_W, 2, 220); + return image; +} + +/** Ground strip: a bright surface line over diagonal hatching that tiles at GROUND_TILE_W. */ +export function createGroundTile(): GrayImage { + const image = new GrayImage(GROUND_TILE_W, GROUND_H, 0); + image.fillRect(0, 0, GROUND_TILE_W, 2, 200); + const period = 24; // divides GROUND_TILE_W, so the hatching wraps seamlessly + for (let y = 3; y < GROUND_H; y++) { + for (let x = 0; x < GROUND_TILE_W; x++) { + const phase = ((x + y) % period + period) % period; + image.setPixel(x, y, phase < 10 ? 110 : 45); + } + } + return image; +} + +/** + * The bird, rendered by sampling shapes in bird-local space so any rotation + * and wing position comes out of the same geometry. Local x points along the + * beak, y down; the sprite is centered on the body center. + */ +export function createBirdSprite(angleDeg: number, wingFrame: number): GrayImage { + const image = new GrayImage(BIRD_SPRITE_W, BIRD_SPRITE_H, 0); + const angle = (angleDeg * Math.PI) / 180; + const cos = Math.cos(angle); + const sin = Math.sin(angle); + const cx = BIRD_SPRITE_W / 2; + const cy = BIRD_SPRITE_H / 2; + // Wing pivot sits behind the body center; the tip swings up/mid/down. + const wingTipY = [-5, 0, 4][wingFrame % BIRD_WING_FRAMES]!; + for (let py = 0; py < BIRD_SPRITE_H; py++) { + for (let px = 0; px < BIRD_SPRITE_W; px++) { + const sx = px + 0.5 - cx; + const sy = py + 0.5 - cy; + // Sprite space -> bird-local space (inverse rotation). + const x = sx * cos + sy * sin; + const y = -sx * sin + sy * cos; + const value = birdShade(x, y, wingTipY); + if (value > 0) image.setPixel(px, py, value); + } + } + return image; +} + +/** Gray value of the bird at a bird-local point, or 0 outside it. */ +function birdShade(x: number, y: number, wingTipY: number): number { + // Eye: white with a pupil, drawn first so it sits on top of the body. + const eyeX = 4.5; + const eyeY = -2.5; + if (inEllipse(x - eyeX - 1.1, y - eyeY, 1.3, 1.3)) return OPAQUE_BLACK; + if (inEllipse(x - eyeX, y - eyeY, 3.2, 3.0)) return 255; + // Beak: a wedge off the front of the body. + if (x >= 7 && x <= 14 && Math.abs(y - 1.5) <= 2.6 * (1 - (x - 7) / 8.5)) { + return y < 1.5 ? 235 : 190; + } + // Wing: an angled lobe behind the center, swinging with the frame. + const wx = x + 3; + const wy = y - wingTipY * 0.5 - wingTipY * 0.35 * (wx / 6); + if (inEllipse(wx, wy, 6.5, 3.2)) { + return inEllipse(wx, wy, 5.0, 2.0) ? 120 : 175; + } + // Body: lighter belly, darker back, dark outline ring. + if (inEllipse(x, y, 11, 8.5)) { + if (!inEllipse(x, y, 10, 7.5)) return 110; + return y > 2 ? 255 : 205; + } + return 0; +} + +function inEllipse(x: number, y: number, rx: number, ry: number): boolean { + return (x * x) / (rx * rx) + (y * y) / (ry * ry) <= 1; +} diff --git a/app/apps/flappy/index.ts b/app/apps/flappy/index.ts new file mode 100644 index 00000000..6c51b959 --- /dev/null +++ b/app/apps/flappy/index.ts @@ -0,0 +1,18 @@ +import { launchWorkerAppWindow, type AppDefinition } from "../app-definition"; + +const flappyApp: AppDefinition = { + appId: "flappy", + title: "Flappy", + icon: "bird", + launch: (ctx) => + launchWorkerAppWindow(ctx, { + createWorker: () => new Worker("./flappy-app.worker"), + windowId: "flappy:main", + title: "Flappy", + iconLetter: "B", + icon: "bird", + acceptsDirectional: true, + }), +}; + +export default flappyApp; diff --git a/app/apps/freecell/freecell-app.worker.ts b/app/apps/freecell/freecell-app.worker.ts index 27132a55..070f90ae 100644 --- a/app/apps/freecell/freecell-app.worker.ts +++ b/app/apps/freecell/freecell-app.worker.ts @@ -1,7 +1,7 @@ /** * Freecell solitaire app worker. One singleton window holds a standard * 52-card Freecell game: 8 cascades, 4 free cells, 4 foundations. Red suits - * render dim and black suits bright, since the display has no color. + * have a bright marker beside their label, since the display has no color. * * Controls: scroll moves a cursor through the 16 locations (free cells, * foundations, then cascades, wrapping). Click selects a source, then click @@ -11,6 +11,10 @@ * selection. Tap-then-hold opens the window menu (undo, new game, restart). * Watch swipes move the cursor spatially: left/right within the row, up/down * between the top row (cells + foundations) and the cascades. + * The cursor skips locations that can't take part in the move being built: + * with nothing selected, empty spots and the foundations (never a source); + * with a source selected, filled free cells and foundations that can't + * accept the card (see isCursorEligible). * Safe cards auto-play to the foundations after every move. */ import "@nativescript/core/globals"; @@ -18,10 +22,12 @@ import { GrayImage } from "../../graphics/image"; import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane"; import { prepareFrameDraws } from "../../graphics/glyph-wire"; import { getFont } from "../../graphics/bdffont"; -import { getDefaultSmallFont } from "../../graphics/ui-fonts"; +import { ensurePreinstalledFonts, installedFontPath } from "../../graphics/installed-fonts"; +import { TtfFont } from "../../graphics/ttf-font"; import * as frameTimings from "../../native/frame-timings"; import { getActiveDisplay } from "../../native/active-display"; import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects"; +import { loadSoundEnabled, saveSoundEnabled } from "../../ui/sound-setting"; import { WindowMenu } from "../../ui/window-menu"; import type { MenuItem } from "../../ui/menu"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; @@ -30,10 +36,13 @@ import { directionalFallback, GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_LONG_ declare const global: any; declare const com: any; -const largeFont = getFont("terminus32"); -const mediumFont = getFont("terminus24"); -const labelFont = getFont("terminus16"); -const smallFont = getDefaultSmallFont(); +ensurePreinstalledFonts(); +const fontPath = installedFontPath("Roboto-Regular.ttf"); +const largeFont = TtfFont.load(fontPath, 28) ?? getFont("terminus32"); +const mediumFont = TtfFont.load(fontPath, 18) ?? getFont("terminus24"); +const labelFont = TtfFont.load(fontPath, 14) ?? getFont("terminus16"); +const suitFont = TtfFont.load(fontPath, 10) ?? getFont("terminus16"); +const smallFont = TtfFont.load(fontPath, 12) ?? getFont("terminus12"); /** Cards are 0..51: suit = card % 4 (♠♥♣♦, alternating colors), rank 1..13. */ const SUIT_CHARS = ["♠", "♥", "♣", "♦"] as const; @@ -52,10 +61,6 @@ function cardLabel(card: number): string { return RANK_CHARS[rankOf(card)]! + SUIT_CHARS[suitOf(card)]!; } -/** Red suits render dimmer than black so card color survives grayscale. */ -const BLACK_SHADE = 255; -const RED_SHADE = 150; - const CARD_W = 60; const CARD_H = 36; const TOP_Y = 4; @@ -158,7 +163,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { moves: 0, cursor: LOC_CASCADE0, selected: null, - soundOn: true, + soundOn: loadSoundEnabled("freecell"), lastSubmittedFingerprint: "", }; newGame(window, false); @@ -248,6 +253,7 @@ function windowMenuItems(window: FreecellWindow): MenuItem[] { onSelect: (ctx) => { ctx.stack.pop(); window.soundOn = !window.soundOn; + saveSoundEnabled("freecell", window.soundOn); if (window.soundOn) playSfx(window, SFX_NEW_GAME); }, }, @@ -291,25 +297,25 @@ function handleInput(window: FreecellWindow, event: InputEvent, frameId: number) function handlePlayingInput(window: FreecellWindow, event: InputEvent, frameId: number): void { switch (event.type) { case "scroll-up": - window.cursor = (window.cursor + LOC_COUNT - 1) % LOC_COUNT; + moveCursor(window, -1); break; case "scroll-down": - window.cursor = (window.cursor + 1) % LOC_COUNT; + moveCursor(window, 1); break; // Watch swipes are spatial over the two rows of eight columns: up/down // switch between the top row (free cells + foundations) and the cascades - // keeping the column, left/right move within the row. + // landing on the nearest usable column, left/right move within the row. case "swipe-up": - if (window.cursor >= LOC_CASCADE0) window.cursor -= LOC_CASCADE0; + if (window.cursor >= LOC_CASCADE0) moveCursorToRow(window, LOC_CELL0); break; case "swipe-down": - if (window.cursor < LOC_CASCADE0) window.cursor += LOC_CASCADE0; + if (window.cursor < LOC_CASCADE0) moveCursorToRow(window, LOC_CASCADE0); break; case "swipe-left": - if (window.cursor % LOC_CASCADE0 > 0) window.cursor--; + moveCursorInRow(window, -1); break; case "swipe-right": - if (window.cursor % LOC_CASCADE0 < LOC_CASCADE0 - 1) window.cursor++; + moveCursorInRow(window, 1); break; case "click": if (window.selected === null) { @@ -410,6 +416,72 @@ function locationHasCard(window: FreecellWindow, location: number): boolean { return window.cascades[location - LOC_CASCADE0]!.length > 0; } +function isFoundation(location: number): boolean { + return location >= LOC_FOUNDATION0 && location < LOC_CASCADE0; +} + +/** + * Whether the cursor should stop at a location, given the move being built. + * Picking a source: it must hold a card, and foundations are never a source. + * Picking a destination: an empty free cell, a foundation that accepts the + * selected card, any cascade (a full legality check would hide the + * cascades the player wants to compare), or the source itself (clicking it + * again cancels the selection). + */ +function isCursorEligible(window: FreecellWindow, location: number): boolean { + if (window.selected === null) { + return !isFoundation(location) && locationHasCard(window, location); + } + if (location === window.selected) return true; + if (location < LOC_FOUNDATION0) return window.cells[location] === null; + if (isFoundation(location)) { + const card = topCardAt(window, window.selected); + return card !== null && foundationCanAccept(window.foundations[location - LOC_FOUNDATION0]!, card); + } + return true; +} + +/** Step the cursor through the location list (wrapping), skipping ineligible spots. */ +function moveCursor(window: FreecellWindow, step: 1 | -1): void { + let location = window.cursor; + for (let i = 0; i < LOC_COUNT; i++) { + location = (location + step + LOC_COUNT) % LOC_COUNT; + if (isCursorEligible(window, location)) { + window.cursor = location; + return; + } + } +} + +/** Step the cursor within its row (no wrapping), skipping ineligible spots. */ +function moveCursorInRow(window: FreecellWindow, step: 1 | -1): void { + const rowStart = window.cursor < LOC_CASCADE0 ? LOC_CELL0 : LOC_CASCADE0; + for (let location = window.cursor + step; location >= rowStart && location < rowStart + 8; location += step) { + if (isCursorEligible(window, location)) { + window.cursor = location; + return; + } + } +} + +/** + * Jump to the other row, keeping the column when it is eligible and + * otherwise taking the nearest eligible column; stays put when the row has + * none. + */ +function moveCursorToRow(window: FreecellWindow, rowStart: number): void { + const column = window.cursor % 8; + for (let distance = 0; distance < 8; distance++) { + for (const candidate of [column - distance, column + distance]) { + if (candidate < 0 || candidate >= 8) continue; + if (isCursorEligible(window, rowStart + candidate)) { + window.cursor = rowStart + candidate; + return; + } + } + } +} + /** True if `card` can go on `onto` in a cascade (descending, alternating color). */ function canStack(card: number, onto: number): boolean { return rankOf(onto) === rankOf(card) + 1 && isRed(onto) !== isRed(card); @@ -710,13 +782,27 @@ function paintCard( selected: boolean, fullyVisible: boolean, ): void { - const shade = isRed(card) ? RED_SHADE : BLACK_SHADE; - image.fillRoundedRect(x, y, CARD_W, CARD_H, selected ? 60 : 25, 4); + image.fillRoundedRect(x, y, CARD_W, CARD_H, 0, 4); image.drawRoundedRect(x, y, CARD_W, CARD_H, selected ? 255 : 160, 4); if (selected) image.drawRoundedRect(x + 1, y + 1, CARD_W - 2, CARD_H - 2, 255, 3); - image.drawText(labelFont, x + 5, y + 2, cardLabel(card), shade); + const rankText: string = RANK_CHARS[rankOf(card)]! + const suitText: string = SUIT_CHARS[suitOf(card)]!; + const labelText = rankText + suitText; + image.drawText(labelFont, x + 5, y, rankText, 255); + image.drawText(suitFont, x + 5 + labelFont.measureText(rankText), y + 3, suitText, 150); + if (isRed(card)) { + // Keep the marker within the top strip, clear of even a two-digit rank. + const markerX = x + 28; + image.fillRect(markerX, y + 1, Math.max(0, x + CARD_W - 4 - markerX), 13, 10); + } if (fullyVisible) { - image.drawText(mediumFont, x + CARD_W - 18, y + CARD_H - 29, SUIT_CHARS[suitOf(card)]!, shade); + image.drawText( + mediumFont, + x + CARD_W - 4 - Math.ceil(mediumFont.measureText(suitText)), + y + CARD_H - mediumFont.lineHeight - 2, + suitText, + 100, + ); } } diff --git a/app/apps/glanceboard/board.ts b/app/apps/glanceboard/board.ts new file mode 100644 index 00000000..6fe473bb --- /dev/null +++ b/app/apps/glanceboard/board.ts @@ -0,0 +1,127 @@ +import { GrayImage } from "../../graphics/image"; +import { onAnySettingChanged } from "../../ui/dashboard-settings"; +import { glanceLayout, glanceShowLinesSetting, glanceSlotSettings } from "./glanceboard-settings"; +import { resolveGlanceRegions, slotDividers, type GlanceLayout, type GlanceRegion } from "./layout"; +import { type GlanceWidget } from "./widget"; +import { findGlanceWidget, glanceWidgetSpans } from "./widgets"; + +/** Brightness of the hairlines between regions: the dimmest shade that survives 4bpp quantization. */ +const DIVIDER_VALUE = 20; + +type LiveRegion = { region: GlanceRegion; key: string; widget: GlanceWidget | null }; + +/** Identity of a region for diffing: which widget, in which slots. */ +function regionKey(region: GlanceRegion): string { + return `${region.choice}@${region.slots.join(",")}`; +} + +/** + * A board: the layout's slots filled with the widgets the settings choose, + * painted as one image. A widget chosen for two vertically adjacent slots + * (when it supports that) gets one double-height region with no divider + * between the slots. Widgets are created and started when the board starts + * and stopped when it stops; a settings change meanwhile restarts only the + * regions that changed. + */ +export class GlanceBoard { + private regions: LiveRegion[] = []; + private started = false; + private unsubscribeSettings: (() => void) | null = null; + private currentLayout: GlanceLayout; + + constructor( + private readonly requestRender: () => void, + private readonly fixedLayout?: GlanceLayout, + ) { + this.currentLayout = fixedLayout ?? glanceLayout(); + } + + get layout(): GlanceLayout { + return this.currentLayout; + } + + get width(): number { + return this.layout.width; + } + + get height(): number { + return this.layout.height; + } + + start(): void { + if (this.started) return; + this.started = true; + this.applySlotSettings(); + this.unsubscribeSettings = onAnySettingChanged(() => this.applySlotSettings()); + } + + stop(): void { + if (!this.started) return; + this.started = false; + this.unsubscribeSettings?.(); + this.unsubscribeSettings = null; + for (const live of this.regions) live.widget?.stop(); + this.regions = []; + } + + private currentRegions(): GlanceRegion[] { + const choices = glanceSlotSettings(this.layout).map((setting) => setting.get()); + return resolveGlanceRegions(this.layout, choices, glanceWidgetSpans); + } + + /** Rebuild the live regions from the settings, keeping widgets whose region is unchanged. */ + private applySlotSettings(): void { + if (!this.started) return; + const layout = this.fixedLayout ?? glanceLayout(); + const layoutChanged = layout !== this.currentLayout; + this.currentLayout = layout; + const previous = new Map(this.regions.map((live) => [live.key, live])); + const next: LiveRegion[] = []; + let changed = layoutChanged; + for (const region of this.currentRegions()) { + const key = regionKey(region); + const kept = previous.get(key); + if (kept) { + previous.delete(key); + next.push(kept); + continue; + } + const widget = findGlanceWidget(region.choice)?.create() ?? null; + widget?.start(this.requestRender); + next.push({ region, key, widget }); + changed = true; + } + for (const removed of previous.values()) { + removed.widget?.stop(); + changed = true; + } + this.regions = next; + if (changed) this.requestRender(); + } + + /** Paint the whole board (layout-sized). Widgets each get a fresh canvas of their region's size. */ + paint(): GrayImage { + const image = new GrayImage(this.layout.width, this.layout.height, 0); + for (const live of this.regions) { + if (!live.widget) continue; + const { rect } = live.region; + const canvas = new GrayImage(rect.width, rect.height, 0); + try { + live.widget.paint(canvas); + } catch (error) { + console.warn(`glanceboard widget ${live.region.choice} paint failed`, error); + } + canvas.composeInto(image, rect.x, rect.y); + } + if (glanceShowLinesSetting.get()) { + drawDividers(image, this.layout, this.regions.map((live) => live.region)); + } + return image; + } +} + +function drawDividers(image: GrayImage, layout: GlanceLayout, regions: readonly GlanceRegion[]): void { + for (const line of slotDividers(layout, regions)) { + image.drawLine(line.x0, line.y0, line.x1, line.y1, DIVIDER_VALUE); + } +} diff --git a/app/apps/glanceboard/glanceboard-app.ts b/app/apps/glanceboard/glanceboard-app.ts new file mode 100644 index 00000000..a0e2b236 --- /dev/null +++ b/app/apps/glanceboard/glanceboard-app.ts @@ -0,0 +1,358 @@ +import { GrayImage } from "../../graphics/image"; +import { truncateText, wrapText } from "../../graphics/textwrap"; +import { getDefaultSmallFont } from "../../graphics/ui-fonts"; +import { enumSettingMenuItem, onAnySettingChanged, toggleSettingMenuItem } from "../../ui/dashboard-settings"; +import { type InputEvent } from "../../ui/gestures"; +import { type Layer, type LayerContext, type PaintBelow } from "../../ui/layers"; +import { drawSelectionHighlight, MenuLayer, openModalMenu, type MenuItem } from "../../ui/menu"; +import { LIST_ROW_TEXT_INSET, lineStep } from "../../ui/metrics"; +import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window"; +import { shell } from "../../ui/shell/shell"; +import { GlanceBoard } from "./board"; +import { + clearConflictingSlots, + glanceboardEnabledSetting, + glanceLayout, + glanceLayoutSetting, + glanceShowLinesSetting, + glanceShowOnHeadTiltSetting, + glanceShowOnLongPressSetting, + glanceSlotChoiceLabel, + glanceSlotSettings, + glanceTapDurationSetting, + type GlanceSlotChoice, +} from "./glanceboard-settings"; +import { resolveGlanceRegions, slotDividers } from "./layout"; +import { glanceWidgetSpans } from "./widgets"; + +export const GLANCEBOARD_WINDOW_ID = "glanceboard"; +export const GLANCEBOARD_SURFACE_ID = "window:glanceboard"; + +const TITLE_X = 18; +const TITLE_Y = 10; +const PARAGRAPH_X = 24; +/** The entry page splits at the middle: menu left, slot preview right. */ +const PREVIEW_MARGIN = 8; +const PREVIEW_MIN_LINE_VALUE = 20; +const PREVIEW_LINE_VALUE = 100; + +const INTRO = + "Your Glanceboard is a display for things you want to look at quickly. Starting " + + "from the screen being off, you can show the glanceboard with a tap or " + + "long-press-and-hold. It will close automatically."; + +/** Full-page list layout shared by the sub-screens. */ +function pageMenuLayout(width: number) { + return { x: 8, y: 8, width: width - 16, opaque: true, showBorder: false } as const; +} + +/** + * The Glanceboard app's entry page. Left half: title, a short description + * and the menu (enable toggle, live preview, slot contents, settings). Right + * half: a scaled preview of the board's slots with their dividers and the + * name of the widget in each. "Select Contents" moves focus into that + * preview, where scroll picks a slot and a tap opens the picker for it; + * a double-tap returns focus to the menu. + */ +class GlanceboardHomeLayer implements Layer { + private menu: MenuLayer | null = null; + private menuTop = 0; + private menuHeight = 0; + private focus: "menu" | "preview" = "menu"; + private selectedSlot = 0; + + constructor(private readonly setPreviewVisible: (visible: boolean) => void) {} + + private currentMenu(ctx: LayerContext, menuTop: number): MenuLayer { + const { width, height } = ctx.stack.getBaseSize(); + if (!this.menu || this.menuTop !== menuTop || this.menuHeight !== height) { + const half = (width / 2) | 0; + const items: MenuItem[] = [ + toggleSettingMenuItem(glanceboardEnabledSetting), + { + label: "Preview", + onSelect: (menuCtx) => { + menuCtx.stack.push(new GlancePreviewLayer( + () => menuCtx.actions.requestRender(), + () => this.setPreviewVisible(false), + )); + this.setPreviewVisible(true); + }, + }, + { + label: "Select Contents", + onSelect: () => { + this.focus = "preview"; + }, + }, + { + label: "Settings", + onSelect: (menuCtx) => menuCtx.stack.push(new GlanceSettingsLayer()), + }, + ]; + this.menuTop = menuTop; + this.menuHeight = height; + this.menu = new MenuLayer(null, items, { + x: 8, y: menuTop, width: half - 16, + showBorder: false, minHeight: 0, maxHeight: height - menuTop, + }); + } + return this.menu; + } + + /** Where the scaled board sits: the right half, board aspect, vertically centred. */ + private previewRect(width: number, height: number): { x: number; y: number; width: number; height: number } { + const half = (width / 2) | 0; + const availableWidth = width - half - 2 * PREVIEW_MARGIN; + const layout = glanceLayout(); + const scale = Math.min(availableWidth / layout.width, (height - 2 * PREVIEW_MARGIN) / layout.height); + const previewWidth = Math.round(layout.width * scale); + const previewHeight = Math.round(layout.height * scale); + return { + x: half + PREVIEW_MARGIN + (((availableWidth - previewWidth) / 2) | 0), + y: ((height - previewHeight) / 2) | 0, + width: previewWidth, + height: previewHeight, + }; + } + + paint(ctx: LayerContext): GrayImage { + const font = getDefaultSmallFont(); + const { width, height } = ctx.stack.getBaseSize(); + const image = new GrayImage(width, height, 0); + const half = (width / 2) | 0; + image.drawText(font, TITLE_X, TITLE_Y, "Glanceboard", 220); + const step = lineStep(font); + let y = TITLE_Y + step + 6; + for (const line of wrapText(font, INTRO, half - PARAGRAPH_X - 12)) { + image.drawText(font, PARAGRAPH_X, y, line, 160); + y += step; + } + // The menu paints onto this page below the paragraph (its fill is raster, + // so the deferred paragraph glyphs above stay untouched either way). + // While the preview has focus the menu keeps its outline-only selection. + const menu = this.currentMenu(ctx, y + 4); + const menuFocused = ctx.stack.isFocused() && this.focus === "menu"; + const menuCtx: LayerContext = { ...ctx, stack: Object.assign(Object.create(ctx.stack), { isFocused: () => menuFocused }) }; + menu.paint(menuCtx, () => image); + + this.selectedSlot = Math.min(this.selectedSlot, glanceLayout().slots.length - 1); + const preview = this.previewRect(width, height); + drawSlotPreview(image, preview, { + selectedSlot: this.selectedSlot, + selectionFocused: ctx.stack.isFocused() && this.focus === "preview", + }); + return image; + } + + async handleInput(event: InputEvent, ctx: LayerContext): Promise { + if (this.focus === "preview") { + const slotCount = glanceLayout().slots.length; + this.selectedSlot = Math.min(this.selectedSlot, slotCount - 1); + switch (event.type) { + case "scroll-up": + this.selectedSlot = (this.selectedSlot + slotCount - 1) % slotCount; + return; + case "scroll-down": + this.selectedSlot = (this.selectedSlot + 1) % slotCount; + return; + case "click": + openSlotPicker(ctx, this.selectedSlot); + return; + case "double-click": + // Back from the preview is back to the menu, not out of the app; + // this layer is the window's root and handles the yield itself + // (see createGlanceboardAppWindow), so the gesture arrives here. + this.focus = "menu"; + return; + default: + return; + } + } + if (event.type === "double-click") { + shell.yieldFocusToSidebar(); + return; + } + await this.currentMenu(ctx, this.menuTop).handleInput(event, ctx); + } +} + +/** + * The board's slots scaled into `rect`: dividers (full brightness, or the + * dimmest dotted line when "Show lines" is off), the widget name centred in + * each region (a merged double-height region has one name and no line + * across it), and the selected slot highlighted. + */ +function drawSlotPreview( + image: GrayImage, + rect: { x: number; y: number; width: number; height: number }, + options: { selectedSlot: number; selectionFocused: boolean }, +): void { + const font = getDefaultSmallFont(); + const layout = glanceLayout(); + const settings = glanceSlotSettings(layout); + const choices = settings.map((setting) => setting.get()); + const regions = resolveGlanceRegions(layout, choices, glanceWidgetSpans); + const sx = rect.width / layout.width; + const sy = rect.height / layout.height; + const scaled = (r: { x: number; y: number; width: number; height: number }) => ({ + x: rect.x + Math.round(r.x * sx), + y: rect.y + Math.round(r.y * sy), + width: Math.round(r.width * sx), + height: Math.round(r.height * sy), + }); + + image.drawRect(rect.x - 1, rect.y - 1, rect.width + 2, rect.height + 2, 72); + const selected = scaled(layout.slots[options.selectedSlot]!.rect); + drawSelectionHighlight(image, selected.x + 1, selected.y + 1, selected.width - 2, selected.height - 2, options.selectionFocused, 4); + + const showLines = glanceShowLinesSetting.get(); + for (const line of slotDividers(layout, regions)) { + const x0 = rect.x + Math.round(line.x0 * sx); + const y0 = rect.y + Math.round(line.y0 * sy); + const x1 = rect.x + Math.round(line.x1 * sx); + const y1 = rect.y + Math.round(line.y1 * sy); + if (showLines) { + image.drawLine(x0, y0, x1, y1, PREVIEW_LINE_VALUE); + } else { + // Every other pixel at the dimmest visible shade: the line is there to + // read the layout by, but says "off". + drawDottedLine(image, x0, y0, x1, y1, PREVIEW_MIN_LINE_VALUE); + } + } + + // Names: one per region, "Empty" in slots no region covers. + const covered = new Set(); + const label = (r: { x: number; y: number; width: number; height: number }, text: string, value: number) => { + const clipped = truncateText(font, text, Math.max(0, r.width - 8)); + image.drawText(font, r.x + (((r.width - font.measureText(clipped)) / 2) | 0), r.y + (((r.height - font.lineHeight) / 2) | 0), clipped, value); + }; + for (const region of regions) { + for (const index of region.slots) covered.add(index); + label(scaled(region.rect), glanceSlotChoiceLabel(region.choice as GlanceSlotChoice), 210); + } + layout.slots.forEach((slot, index) => { + if (!covered.has(index)) label(scaled(slot.rect), "Empty", 90); + }); +} + +/** A horizontal or vertical line lit on every other pixel. */ +function drawDottedLine(image: GrayImage, x0: number, y0: number, x1: number, y1: number, value: number): void { + if (y0 === y1) { + for (let x = Math.min(x0, x1); x <= Math.max(x0, x1); x += 2) image.setPixel(x, y0, value); + } else { + for (let y = Math.min(y0, y1); y <= Math.max(y0, y1); y += 2) image.setPixel(x0, y, value); + } +} + +/** The picker for one slot: every widget, the current one marked; choosing applies the one-per-board rule. */ +function openSlotPicker(ctx: LayerContext, slotIndex: number): void { + const layout = glanceLayout(); + const setting = glanceSlotSettings(layout)[slotIndex]; + if (!setting) return; + const current = setting.get(); + const items: MenuItem[] = setting.values.map((value) => ({ + label: setting.displayValue(value), + onSelect: (menuCtx) => { + setting.set(value); + clearConflictingSlots(layout, slotIndex, value); + menuCtx.stack.pop(); + }, + render: ({ image, x, y }) => { + image.drawText(getDefaultSmallFont(), x, y + LIST_ROW_TEXT_INSET, `${setting.displayValue(value)}${setting.get() === value ? " *" : ""}`, 200); + }, + })); + openModalMenu(ctx, setting.label, items, Math.max(0, setting.values.indexOf(current))); +} + +/** Settings: layout, sleep gestures, duration, and slot lines. */ +class GlanceSettingsLayer implements Layer { + private menu: MenuLayer | null = null; + + private currentMenu(ctx: LayerContext): MenuLayer { + if (!this.menu) { + const { width } = ctx.stack.getBaseSize(); + const items: MenuItem[] = [ + enumSettingMenuItem(glanceLayoutSetting), + enumSettingMenuItem(glanceTapDurationSetting), + toggleSettingMenuItem(glanceShowOnLongPressSetting), + toggleSettingMenuItem(glanceShowOnHeadTiltSetting), + toggleSettingMenuItem(glanceShowLinesSetting), + ]; + this.menu = new MenuLayer("Glanceboard settings", items, pageMenuLayout(width)); + } + return this.menu; + } + + paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage { + return this.currentMenu(ctx).paint(ctx, paintBelow); + } + + async handleInput(event: InputEvent, ctx: LayerContext): Promise { + await this.currentMenu(ctx).handleInput(event, ctx); + } +} + +/** The live board in the window; any click or double-click returns to the list. */ +class GlancePreviewLayer implements Layer { + private readonly board: GlanceBoard; + + constructor(requestRender: () => void, private readonly onClose: () => void) { + this.board = new GlanceBoard(requestRender); + this.board.start(); + } + + paint(ctx: LayerContext): GrayImage { + const { width, height } = ctx.stack.getBaseSize(); + const board = this.board.paint(); + if (board.width === width && board.height === height) return board; + // A viewport of another size (a per-app display override) shows the board + // top-left, cropped or padded, rather than scaled. + const image = new GrayImage(width, height, 0); + board.composeInto(image, 0, 0); + return image; + } + + handleInput(event: InputEvent, ctx: LayerContext): void { + if (event.type === "click" || event.type === "double-click") ctx.stack.pop(); + } + + onRemoved(): void { + this.board.stop(); + this.onClose(); + } +} + +export function createGlanceboardAppWindow(options: InProcessAppOptions): InProcessWindow { + let previewVisible = false; + const heightMode = () => previewVisible && glanceLayoutSetting.get() === "2x3" ? "max" as const : "medium" as const; + let unsubscribeSettings: (() => void) | undefined; + const app = createInProcessWindow({ + appId: "glanceboard", + windowId: GLANCEBOARD_WINDOW_ID, + title: "Glanceboard", + iconLetter: "Gb", + icon: "eye", + closeable: true, + // Settings and the contents picker stay in the default 576x288 viewport; + // only the live six-slot preview needs the taller window. + heightMode: heightMode(), + actions: options.actions, + // Not wrapped in YieldAtRootLayer: the home page routes double-click + // itself (preview focus -> menu focus, menu focus -> sidebar). + baseLayer: new GlanceboardHomeLayer((visible) => { + previewVisible = visible; + app.setHeightMode(heightMode()); + }), + submitFrame: options.submitFrame, + setSurfaceVisible: options.setSurfaceVisible, + removeSurface: options.removeSurface, + reconfigureSurface: options.reconfigureSurface, + onClosed: () => { + unsubscribeSettings?.(); + options.onClosed(); + }, + }); + unsubscribeSettings = onAnySettingChanged(() => app.setHeightMode(heightMode())); + return app; +} diff --git a/app/apps/glanceboard/glanceboard-settings.ts b/app/apps/glanceboard/glanceboard-settings.ts new file mode 100644 index 00000000..bcb13948 --- /dev/null +++ b/app/apps/glanceboard/glanceboard-settings.ts @@ -0,0 +1,158 @@ +import { ConfigSettingBoolean, ConfigSettingEnum } from "../../ui/dashboard-settings"; +import { QUADRANT_LAYOUT, SIX_SLOT_LAYOUT, slotsVerticallyAdjacent, type GlanceLayout } from "./layout"; +import { type GlanceWidgetId } from "./widget"; +import { glanceWidgetSpans } from "./widgets"; + +export type GlanceSlotChoice = GlanceWidgetId | "none"; + +const SLOT_CHOICES: readonly GlanceSlotChoice[] = ["none", "system-card", "calendar", "terminal", "nightscout", "compass", "music"]; + +const SLOT_CHOICE_LABELS: Record = { + none: "Empty", + "system-card": "System card", + calendar: "Calendar", + terminal: "Terminal", + nightscout: "Nightscout", + compass: "Compass", + music: "Music", +}; + +export function glanceSlotChoiceLabel(choice: GlanceSlotChoice): string { + return SLOT_CHOICE_LABELS[choice] ?? choice; +} + +/** + * Slot order follows QUADRANT_LAYOUT: top left, top right, bottom left, bottom + * right. Calendar in both right slots merges into one double-height region. + */ +const DEFAULT_QUADRANT_CHOICES: readonly GlanceSlotChoice[] = ["system-card", "calendar", "music", "calendar"]; + +export const glanceLayoutSetting = new ConfigSettingEnum<"2x2" | "2x3">({ + id: "glanceboard-layout", + label: "Layout", + storageKey: "glanceboard.layout", + defaultValue: "2x2", + values: ["2x2", "2x3"], + description: "Choose two columns with two or three rows of widgets.", +}); + +export function glanceLayout(): GlanceLayout { + return glanceLayoutSetting.get() === "2x3" ? SIX_SLOT_LAYOUT : QUADRANT_LAYOUT; +} + +/** + * Whether sleep-time gestures show the board at all. Off restores the plain + * behaviour: a tap, hold or head-tilt while asleep does nothing (a head-tilt + * wakes the regular UI), double-tap wakes. + */ +export const glanceboardEnabledSetting = new ConfigSettingBoolean({ + id: "glanceboard-enabled", + label: "Enable Glanceboard", + storageKey: "glanceboard.enabled", + defaultValue: false, + description: + "While the display is asleep, a tap, a long-press or a head-tilt shows the Glanceboard instead of the regular UI. Double-tap still wakes the regular UI.", +}); + +export type GlanceTapDuration = "off" | "3s" | "5s" | "7s" | "10s"; + +const DEFAULT_TAP_DURATION: GlanceTapDuration = "5s"; + +/** + * How long a tap (or head-tilt) keeps the board up; each further tap restarts + * it. "off" means a single tap does not show the board at all; a head-tilt + * then uses the default duration. + */ +export const glanceTapDurationSetting = new ConfigSettingEnum({ + id: "glanceboard-tap-duration", + label: "Show on tap", + storageKey: "glanceboard.tapDuration", + defaultValue: DEFAULT_TAP_DURATION, + values: ["off", "3s", "5s", "7s", "10s"], + formatValue: (value) => (value === "off" ? "Disabled" : value.replace("s", " s")), + description: + "How long a single tap (or a head-tilt) keeps the Glanceboard on screen. Disabled: a single tap does not show the Glanceboard.", +}); + +/** Whether a single tap while asleep shows the board. */ +export function glanceShowOnTap(): boolean { + return glanceTapDurationSetting.get() !== "off"; +} + +export function glanceTapTimeoutMs(): number { + const duration = glanceTapDurationSetting.get(); + const seconds = duration === "off" ? DEFAULT_TAP_DURATION : duration; + return Number.parseInt(seconds, 10) * 1000; +} + +/** A long-press holds the board up until the press is released. */ +export const glanceShowOnLongPressSetting = new ConfigSettingBoolean({ + id: "glanceboard-show-on-long-press", + label: "Show on long press", + storageKey: "glanceboard.showOnLongPress", + defaultValue: true, + description: "A long-press or short-then-long-press while asleep shows the Glanceboard until the press is released.", +}); + +/** The head-tilt wake shows the board (for the tap duration) instead of the regular UI. */ +export const glanceShowOnHeadTiltSetting = new ConfigSettingBoolean({ + id: "glanceboard-show-on-head-tilt", + label: "Show on head tilt", + storageKey: "glanceboard.showOnHeadTilt", + defaultValue: true, + description: "Tilting your head up while asleep shows the Glanceboard instead of waking the regular UI.", +}); + +/** Hairlines between the board's slots. */ +export const glanceShowLinesSetting = new ConfigSettingBoolean({ + id: "glanceboard-show-lines", + label: "Show lines", + storageKey: "glanceboard.showLines", + defaultValue: true, + description: "Draw the separator lines between the Glanceboard's slots.", +}); + +/** + * Both grid sizes share the original storage keys so changing row count + * preserves the first four choices and remembers the hidden bottom row. + */ +export function glanceSlotSettings(layout: GlanceLayout = glanceLayout()): ConfigSettingEnum[] { + const grid = layout === QUADRANT_LAYOUT || layout === SIX_SLOT_LAYOUT; + const storageId = grid ? QUADRANT_LAYOUT.id : layout.id; + return layout.slots.map( + (slot, index) => + new ConfigSettingEnum({ + id: `glanceboard-${layout.id}-slot-${index}`, + label: slot.label, + storageKey: `glanceboard.${storageId}.slot.${index}`, + defaultValue: (grid ? DEFAULT_QUADRANT_CHOICES[index] : undefined) ?? "none", + values: SLOT_CHOICES, + formatValue: glanceSlotChoiceLabel, + description: `Which widget fills the ${slot.label.toLowerCase()} slot of the Glanceboard.`, + }), + ); +} + +/** + * A slot was just set to `choice`: each widget appears on the board once, so + * clear every other slot holding the same choice, except a vertically + * adjacent one when the widget can span two slots (it then renders at + * double height). Returns the indices cleared. + */ +export function clearConflictingSlots(layout: GlanceLayout, changedIndex: number, choice: GlanceSlotChoice): number[] { + if (choice === "none") return []; + const settings = glanceSlotSettings(layout); + const spans = glanceWidgetSpans(choice); + const cleared: number[] = []; + let keptPartner = false; + settings.forEach((setting, index) => { + if (index === changedIndex || setting.get() !== choice) return; + if (spans && !keptPartner && slotsVerticallyAdjacent(layout, changedIndex, index)) { + keptPartner = true; + return; + } + setting.set("none"); + cleared.push(index); + }); + return cleared; +} diff --git a/app/apps/glanceboard/index.ts b/app/apps/glanceboard/index.ts new file mode 100644 index 00000000..354bef25 --- /dev/null +++ b/app/apps/glanceboard/index.ts @@ -0,0 +1,32 @@ +import { type AppDefinition } from "../app-definition"; +import { GlanceBoard } from "./board"; +import { createGlanceboardAppWindow, GLANCEBOARD_SURFACE_ID, GLANCEBOARD_WINDOW_ID } from "./glanceboard-app"; +import { + glanceboardEnabledSetting, + glanceLayout, + glanceShowOnHeadTiltSetting, + glanceShowOnLongPressSetting, + glanceShowOnTap, + glanceTapTimeoutMs, +} from "./glanceboard-settings"; + +const glanceboardApp: AppDefinition = { + appId: "glanceboard", + title: "Glanceboard", + icon: "eye", + launch: (ctx) => ctx.launchInProcessApp(GLANCEBOARD_WINDOW_ID, GLANCEBOARD_SURFACE_ID, createGlanceboardAppWindow), + glanceboard: { + get size() { + const layout = glanceLayout(); + return { width: layout.width, height: layout.height }; + }, + isEnabled: () => glanceboardEnabledSetting.get(), + showOnTap: glanceShowOnTap, + tapTimeoutMs: glanceTapTimeoutMs, + showOnLongPress: () => glanceShowOnLongPressSetting.get(), + showOnHeadTilt: () => glanceShowOnHeadTiltSetting.get(), + createBoard: (requestRender) => new GlanceBoard(requestRender), + }, +}; + +export default glanceboardApp; diff --git a/app/apps/glanceboard/layout.ts b/app/apps/glanceboard/layout.ts new file mode 100644 index 00000000..69d2fb2b --- /dev/null +++ b/app/apps/glanceboard/layout.ts @@ -0,0 +1,122 @@ +/** + * Board geometry. A layout names its slots and places them on the board; + * the Glanceboard app's slot pickers and the board renderer are both driven + * by it, so a replacement layout (different slot count, sizes, positions) is + * a matter of swapping this object out and reusing the same widgets. + */ +export const GLANCEBOARD_WIDTH = 576; +export const GLANCEBOARD_HEIGHT = 288; + +export type GlanceSlotRect = { x: number; y: number; width: number; height: number }; + +export type GlanceLayout = { + id: string; + width: number; + height: number; + slots: readonly { label: string; rect: GlanceSlotRect }[]; +}; + +/** The first layout: four equal quadrants, each 288x144. */ +export const QUADRANT_LAYOUT: GlanceLayout = { + id: "quadrants", + width: GLANCEBOARD_WIDTH, + height: GLANCEBOARD_HEIGHT, + slots: [ + { label: "Top left", rect: { x: 0, y: 0, width: 288, height: 144 } }, + { label: "Top right", rect: { x: 288, y: 0, width: 288, height: 144 } }, + { label: "Bottom left", rect: { x: 0, y: 144, width: 288, height: 144 } }, + { label: "Bottom right", rect: { x: 288, y: 144, width: 288, height: 144 } }, + ], +}; + +/** Six 288x144 slots: the same first two rows, plus a third at the bottom. */ +export const SIX_SLOT_LAYOUT: GlanceLayout = { + id: "six-slots", + width: GLANCEBOARD_WIDTH, + height: 432, + slots: [ + ...QUADRANT_LAYOUT.slots.slice(0, 2), + { label: "Middle left", rect: { x: 0, y: 144, width: 288, height: 144 } }, + { label: "Middle right", rect: { x: 288, y: 144, width: 288, height: 144 } }, + { label: "Bottom left", rect: { x: 0, y: 288, width: 288, height: 144 } }, + { label: "Bottom right", rect: { x: 288, y: 288, width: 288, height: 144 } }, + ], +}; + +/** Whether two slots stack vertically with matching width (one region if merged). */ +export function slotsVerticallyAdjacent(layout: GlanceLayout, a: number, b: number): boolean { + const first = layout.slots[a]?.rect; + const second = layout.slots[b]?.rect; + if (!first || !second || a === b) return false; + if (first.x !== second.x || first.width !== second.width) return false; + return first.y + first.height === second.y || second.y + second.height === first.y; +} + +/** A painted area of the board: one slot, or two vertically adjacent slots merged. */ +export type GlanceRegion = { + /** The slot choice (widget id) filling the region. */ + choice: string; + rect: GlanceSlotRect; + /** Indices into layout.slots, ascending. */ + slots: number[]; +}; + +/** + * Turn per-slot choices into regions. A widget chosen for two vertically + * adjacent slots, when `canSpan` says it supports it, becomes one + * double-height region; every other non-empty slot is a region of its own + * (a duplicate that cannot merge simply paints twice). Regions come out in + * slot order. + */ +export function resolveGlanceRegions( + layout: GlanceLayout, + choices: readonly string[], + canSpan: (choice: string) => boolean, +): GlanceRegion[] { + const regions: GlanceRegion[] = []; + const consumed = new Set(); + layout.slots.forEach((slot, index) => { + if (consumed.has(index)) return; + const choice = choices[index] ?? "none"; + if (choice === "none") return; + consumed.add(index); + let rect = { ...slot.rect }; + const slots = [index]; + if (canSpan(choice)) { + const partner = layout.slots.findIndex( + (_, other) => !consumed.has(other) && choices[other] === choice && slotsVerticallyAdjacent(layout, index, other), + ); + if (partner >= 0) { + consumed.add(partner); + slots.push(partner); + const other = layout.slots[partner]!.rect; + const top = Math.min(rect.y, other.y); + rect = { x: rect.x, y: top, width: rect.width, height: Math.max(rect.y + rect.height, other.y + other.height) - top }; + } + } + regions.push({ choice, rect, slots }); + }); + return regions; +} + +/** A divider line between slots, in board coordinates (inclusive endpoints). */ +export type GlanceDivider = { x0: number; y0: number; x1: number; y1: number }; + +/** + * The hairlines between slots: every slot's left edge (when not at the + * board's left) and top edge (when not at the top), except the top edge of + * the lower slot of a merged double-height region, which is that region's + * interior. Shared by the board painter and the config app's preview. + */ +export function slotDividers(layout: GlanceLayout, regions: readonly GlanceRegion[]): GlanceDivider[] { + const dividers: GlanceDivider[] = []; + layout.slots.forEach(({ rect }, index) => { + if (rect.x > 0) dividers.push({ x0: rect.x, y0: rect.y, x1: rect.x, y1: rect.y + rect.height - 1 }); + if (rect.y === 0) return; + const interior = regions.some( + (region) => region.slots.length > 1 && region.slots.includes(index) && region.rect.y < rect.y, + ); + if (!interior) dividers.push({ x0: rect.x, y0: rect.y, x1: rect.x + rect.width - 1, y1: rect.y }); + }); + return dividers; +} diff --git a/app/apps/glanceboard/widget.ts b/app/apps/glanceboard/widget.ts new file mode 100644 index 00000000..0f5c2d78 --- /dev/null +++ b/app/apps/glanceboard/widget.ts @@ -0,0 +1,43 @@ +import { type GrayImage } from "../../graphics/image"; + +/** + * A Glanceboard widget: a small self-contained view that paints into a slot + * of the board. Widgets are sized by the layout (the first layout is four + * 288x144 quadrants) and own their data subscriptions and any hardware they + * need between start and stop, so a board that is not showing costs nothing. + * + * Layouts are expected to be swapped out and iterated on; widgets are the + * stable part, so keep them independent of any particular board geometry + * beyond the slot size they are handed. + */ +export interface GlanceWidget { + /** + * The board became visible (or this widget was added to a visible board): + * subscribe to data, start timers, enable hardware. `requestRender` asks + * the board to repaint when something changed. + */ + start(requestRender: () => void): void; + /** Undo start. Called once for every start; must be safe to call twice. */ + stop(): void; + /** + * Paint the widget into `image`, a fresh 0-filled canvas of the slot's + * size. Deferred draws (text, drawImage) are welcome and keep the cheap + * texture-cache wire path. + */ + paint(image: GrayImage): void; +} + +export type GlanceWidgetId = "system-card" | "nightscout" | "compass" | "music" | "calendar" | "terminal"; + +export type GlanceWidgetDefinition = { + id: GlanceWidgetId; + /** Picker label in the Glanceboard app. */ + label: string; + /** + * The widget can fill two vertically adjacent slots as one double-height + * region (chosen for both left or both right quadrants). Its paint then + * gets the taller canvas; the divider between the slots is not drawn. + */ + tall?: boolean; + create: () => GlanceWidget; +}; diff --git a/app/apps/glanceboard/widgets/calendar-widget.ts b/app/apps/glanceboard/widgets/calendar-widget.ts new file mode 100644 index 00000000..85f74ff4 --- /dev/null +++ b/app/apps/glanceboard/widgets/calendar-widget.ts @@ -0,0 +1,137 @@ +import { type GrayImage, type UiFont } from "../../../graphics/image"; +import { truncateText } from "../../../graphics/textwrap"; +import { getDefaultMediumFont, getDefaultSmallFont } from "../../../graphics/ui-fonts"; +import { hasCalendarPermission } from "../../../g2/android-permissions"; +import { readUpcomingEvents, type CalendarEvent } from "../../../native/calendar"; +import { lineStep } from "../../../ui/metrics"; +import { dayHeaderLabel, formatEventTime } from "../../calendar/calendar"; +import { type GlanceWidget } from "../widget"; + +const PAD = 8; +/** A row fits while its glyph line clears this margin above the bottom edge. */ +const BOTTOM_MARGIN = 2; +const MINUTE_MS = 60_000; +const HOUR_MS = 60 * MINUTE_MS; + +/** + * What is next on the calendar: the current or next event large, with how + * far off it is (or when it ends), then the following events grouped under + * day headers, as many as fit. Reads the same cached provider query as the + * Calendar app; a minute tick keeps the countdown honest and lets the + * 30-second cache refresh on its own. + */ +export class CalendarWidget implements GlanceWidget { + private tick: ReturnType | null = null; + + start(requestRender: () => void): void { + this.tick = setInterval(requestRender, MINUTE_MS); + } + + stop(): void { + if (this.tick !== null) clearInterval(this.tick); + this.tick = null; + } + + paint(image: GrayImage): void { + const small = getDefaultSmallFont(); + const medium = getDefaultMediumFont(); + const step = lineStep(small); + const textWidth = image.width - 2 * PAD; + + if (!hasCalendarPermission()) { + image.drawText(small, PAD, PAD, "Calendar", 150); + image.drawText(small, PAD, PAD + step + 4, "Calendar permission needed", 140); + image.drawText(small, PAD, PAD + 2 * step + 4, "Open the Calendar app to grant it", 100); + return; + } + const nowMs = Date.now(); + // Events still in progress count; the provider's window starts at "now", + // so the list can include an event that began earlier and is still on. + const events = readUpcomingEvents().filter((event) => event.endMs > nowMs); + if (!events.length) { + image.drawText(small, PAD, PAD, "Calendar", 150); + image.drawText(small, PAD, PAD + step + 4, "No upcoming events", 140); + return; + } + + // Headline: the current or next event, with its day when it is not today. + const next = events[0]!; + let y = PAD; + const headline = truncateText(medium, next.title || "(untitled)", textWidth); + image.drawText(medium, PAD, y, headline, 230); + y += medium.lineHeight + 2; + image.drawText(small, PAD, y, truncateText(small, headlineDetail(next, nowMs), textWidth), 170); + y += step + 6; + + // The rest, grouped by day. A day header only where the day changes from + // the previous listed event (the headline's day included). + let previousDayKey = dayKeyOf(next.startMs); + for (let index = 1; index < events.length; index++) { + const event = events[index]!; + const dayKey = dayKeyOf(event.startMs); + const needsHeader = dayKey !== previousDayKey; + // The header and its row are placed a step apart; the row only needs + // its line height to fit above the bottom margin. + if (y + (needsHeader ? step : 0) + small.lineHeight > image.height - BOTTOM_MARGIN) break; + if (needsHeader) { + image.drawText(small, PAD, y, truncateText(small, dayHeaderLabel(event.startMs), textWidth), 120); + y += step; + previousDayKey = dayKey; + } + drawEventLine(image, small, PAD, y, textWidth, event, 190); + y += step; + } + } +} + +/** "Now, ends 14:30", "In 25 min", "Tomorrow 09:00", "All day"... for the headline. */ +function headlineDetail(event: CalendarEvent, nowMs: number): string { + const dayDelta = dayDeltaFromToday(event.startMs); + const when = event.allDay + ? "All day" + : `${formatEventTime(event.startMs)} - ${formatEventTime(event.endMs)}`; + if (event.startMs <= nowMs) { + if (event.allDay) return dayDelta === 0 ? "All day today" : `All day, ${dayHeaderLabel(event.startMs)}`; + return `Now, ends ${formatEventTime(event.endMs)}`; + } + const untilMs = event.startMs - nowMs; + if (dayDelta === 0 && untilMs < 12 * HOUR_MS) { + return `In ${formatDuration(untilMs)}, ${when}`; + } + const day = dayDelta === 0 ? "Today" : dayDelta === 1 ? "Tomorrow" : dayHeaderLabel(event.startMs); + return `${day}, ${when}`; +} + +function drawEventLine( + image: GrayImage, + font: UiFont, + x: number, + y: number, + width: number, + event: CalendarEvent, + value: number, +): void { + const time = event.allDay ? "All day" : formatEventTime(event.startMs); + const timeWidth = font.measureText(time); + image.drawText(font, x, y, time, value - 50); + const titleX = x + timeWidth + 8; + image.drawText(font, titleX, y, truncateText(font, event.title || "(untitled)", Math.max(0, x + width - titleX)), value); +} + +function formatDuration(ms: number): string { + const minutes = Math.max(1, Math.round(ms / MINUTE_MS)); + if (minutes < 60) return `${minutes} min`; + const hours = Math.floor(minutes / 60); + const rest = minutes % 60; + return rest ? `${hours} h ${rest} min` : `${hours} h`; +} + +function dayKeyOf(timestampMs: number): string { + const date = new Date(timestampMs); + return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`; +} + +function dayDeltaFromToday(timestampMs: number): number { + const midnight = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime(); + return Math.round((midnight(new Date(timestampMs)) - midnight(new Date())) / (24 * HOUR_MS)); +} diff --git a/app/apps/glanceboard/widgets/compass-widget.ts b/app/apps/glanceboard/widgets/compass-widget.ts new file mode 100644 index 00000000..0a3a6d1d --- /dev/null +++ b/app/apps/glanceboard/widgets/compass-widget.ts @@ -0,0 +1,100 @@ +import { type GrayImage } from "../../../graphics/image"; +import { getDefaultMediumFont, getDefaultSmallFont } from "../../../graphics/ui-fonts"; +import { hasLocationPermission } from "../../../g2/android-permissions"; +import { addCompassListener, COMPASS_CHANGED, setCompassEnabled } from "../../../native/compass"; +import { isCompassCalibrated, normalizeHeading } from "../../compass/calibration"; +import { cardinalDirection, createCompassBackground, drawCompassRose, layoutCompassRose, TICK_HEIGHT } from "../../compass/compass-rose"; +import { getDeclinationAvailability, onDeclinationChanged, refreshDeclination } from "../../compass/declination"; +import { getNorthReference, resolveHeading } from "../../compass/heading"; +import { type GlanceWidget } from "../widget"; + +/** Owner token for the refcounted magnetometer, distinct from the Compass app's. */ +const COMPASS_OWNER = "glanceboard"; +const TOP_PAD = 4; +const BOTTOM_PAD = 4; +const EDGE_PAD = 8; +const MAX_ROSE_RADIUS = 60; + +/** + * The Compass app's rose at card size: heading readout above, tilted rose + * below. Turns the magnetometer on for as long as the board shows it (the + * Compass app keeps its own hold, so the two never switch each other off). + * Never prompts for location: true north is used when a declination is + * already known, otherwise the readout says it is magnetic. + */ +export class CompassWidget implements GlanceWidget { + private rawHeading: number | null = null; + private unsubscribe: (() => void) | null = null; + private unsubscribeDeclination: (() => void) | null = null; + private enabled = false; + private background: { key: string; image: GrayImage } | null = null; + + start(requestRender: () => void): void { + this.unsubscribe = addCompassListener((event) => { + if (event.command === COMPASS_CHANGED && event.headingDegrees >= 0) { + this.rawHeading = normalizeHeading(event.headingDegrees); + requestRender(); + } + }); + this.unsubscribeDeclination = onDeclinationChanged(requestRender); + if (!this.enabled) { + this.enabled = true; + setCompassEnabled(true, COMPASS_OWNER); + } + if (getNorthReference() === "true" && hasLocationPermission()) refreshDeclination(); + } + + stop(): void { + this.unsubscribe?.(); + this.unsubscribe = null; + this.unsubscribeDeclination?.(); + this.unsubscribeDeclination = null; + if (this.enabled) { + this.enabled = false; + setCompassEnabled(false, COMPASS_OWNER); + } + } + + private statusText(): string | null { + if (this.rawHeading === null) return "Waiting for compass"; + if (!isCompassCalibrated()) return "Uncalibrated"; + if (getNorthReference() === "true" && getDeclinationAvailability() !== "available") return "Magnetic"; + return null; + } + + paint(image: GrayImage): void { + const medium = getDefaultMediumFont(); + const small = getDefaultSmallFont(); + const { width, height } = image; + const heading = this.rawHeading === null ? null : resolveHeading(this.rawHeading).displayDegrees; + const headingText = heading === null ? "--°" : `${Math.round(heading)}° ${cardinalDirection(heading)}`; + const status = this.statusText(); + const textHeight = medium.lineHeight + (status ? small.lineHeight + 2 : 0); + const cx = width / 2; + const { cy, radius, ringTop } = layoutCompassRose({ + width, + height, + cx, + topClearance: TOP_PAD + textHeight + 4, + bottomPad: BOTTOM_PAD, + edgePad: EDGE_PAD, + maxRadius: MAX_ROSE_RADIUS, + minRadius: 16, + }); + const fade = heading === null ? 0.45 : 1; + const y = Math.max(TOP_PAD, Math.round((ringTop - TICK_HEIGHT - textHeight) / 2)); + const clipY = y + textHeight + 4; + const key = [width, height, cx, cy, radius, clipY, fade].join(","); + if (this.background?.key !== key) { + this.background = { key, image: createCompassBackground(width, height, cx, cy, radius, clipY, fade) }; + } + // composeInto keeps the background's cached interior texture as a + // deferred image draw, so the wire planner can restore it from cache. + this.background.image.composeInto(image, 0, 0); + drawCompassRose(image, cx, cy, radius, heading); + image.drawText(medium, Math.round(cx - medium.measureText(headingText) / 2), y, headingText, heading === null ? 150 : 255); + if (status) { + image.drawText(small, Math.round(cx - small.measureText(status) / 2), y + medium.lineHeight + 2, status, 125); + } + } +} diff --git a/app/apps/glanceboard/widgets/index.ts b/app/apps/glanceboard/widgets/index.ts new file mode 100644 index 00000000..2efd48ab --- /dev/null +++ b/app/apps/glanceboard/widgets/index.ts @@ -0,0 +1,26 @@ +import { type GlanceWidgetDefinition, type GlanceWidgetId } from "../widget"; +import { CalendarWidget } from "./calendar-widget"; +import { CompassWidget } from "./compass-widget"; +import { MusicWidget } from "./music-widget"; +import { NightscoutWidget } from "./nightscout-widget"; +import { SystemCardWidget } from "./system-card"; +import { TerminalWidget } from "./terminal-widget"; + +/** Every widget a board slot can hold. */ +export const GLANCE_WIDGETS: readonly GlanceWidgetDefinition[] = [ + { id: "system-card", label: "System card", create: () => new SystemCardWidget() }, + { id: "calendar", label: "Calendar", tall: true, create: () => new CalendarWidget() }, + { id: "terminal", label: "Terminal", tall: true, create: () => new TerminalWidget() }, + { id: "nightscout", label: "Nightscout", create: () => new NightscoutWidget() }, + { id: "compass", label: "Compass", create: () => new CompassWidget() }, + { id: "music", label: "Music", create: () => new MusicWidget() }, +]; + +export function findGlanceWidget(id: GlanceWidgetId | string): GlanceWidgetDefinition | null { + return GLANCE_WIDGETS.find((widget) => widget.id === id) ?? null; +} + +/** Whether a slot choice may span two vertically adjacent slots (see GlanceWidgetDefinition.tall). */ +export function glanceWidgetSpans(choice: string): boolean { + return Boolean(findGlanceWidget(choice)?.tall); +} diff --git a/app/apps/glanceboard/widgets/music-widget.ts b/app/apps/glanceboard/widgets/music-widget.ts new file mode 100644 index 00000000..b142f28f --- /dev/null +++ b/app/apps/glanceboard/widgets/music-widget.ts @@ -0,0 +1,161 @@ +import { GrayImage } from "../../../graphics/image"; +import { renderIcon } from "../../../graphics/icons"; +import { getDefaultMediumFont, getDefaultSmallFont } from "../../../graphics/ui-fonts"; +import { truncateText } from "../../../graphics/textwrap"; +import { mediaControllerBridge, type MediaControllerState } from "../../../native/media-controller"; +import { clamp } from "../../../util/numeric-util"; +import { type GlanceWidget } from "../widget"; + +const PAD = 8; +const ART_SIZE = 96; +/** The idle note: the Music app's icon, at this size and the dimmest shade. */ +const IDLE_NOTE_SIZE = 64; +const IDLE_NOTE_VALUE = 20; +let idleNote: GrayImage | null | undefined; + +/** + * The music icon reduced to a single dim shade: every pixel the renderer + * lit at least half becomes IDLE_NOTE_VALUE, the rest stay transparent + * (scaling the antialiased original down would quantize its edges away). + * Built once and kept, so drawImage's content-addressed cache holds. + */ +function idleNoteImage(): GrayImage | null { + if (idleNote !== undefined) return idleNote; + const icon = renderIcon("music", IDLE_NOTE_SIZE); + if (!icon) { + idleNote = null; + return null; + } + const note = new GrayImage(icon.width, icon.height, 0); + for (let y = 0; y < icon.height; y++) { + for (let x = 0; x < icon.width; x++) { + if (icon.getPixel(x, y) >= 128) note.setPixel(x, y, IDLE_NOTE_VALUE); + } + } + idleNote = note; + return note; +} +const ART_X = PAD; +const PROGRESS_BAR_HEIGHT = 5; + +/** + * Now playing: album art, title/artist/album and a progress bar for the + * active Android media session, the Music app's header at card size. The + * media bridge runs for the whole session; the widget subscribes and ticks + * once a second only while something is playing. + */ +export class MusicWidget implements GlanceWidget { + private media: MediaControllerState = mediaControllerBridge.snapshot(); + private unsubscribe: (() => void) | null = null; + private progressTimer: ReturnType | null = null; + private art: GrayImage | null = null; + private artKey = ""; + + start(requestRender: () => void): void { + this.unsubscribe = mediaControllerBridge.onStateChange((state) => { + this.media = state; + if (state.playbackState === "playing" && state.durationMs > 0 && state.positionMs >= 0) { + this.progressTimer ??= setInterval(requestRender, 1_000); + } else { + this.stopProgressTimer(); + } + requestRender(); + }); + } + + stop(): void { + this.unsubscribe?.(); + this.unsubscribe = null; + this.stopProgressTimer(); + } + + private stopProgressTimer(): void { + if (this.progressTimer !== null) clearInterval(this.progressTimer); + this.progressTimer = null; + } + + paint(image: GrayImage): void { + const medium = getDefaultMediumFont(); + const small = getDefaultSmallFont(); + const media = mediaControllerBridge.snapshot(); + this.media = media; + if (!media.available || (!media.title && !media.artist)) { + if (!media.accessEnabled) { + // Actionable, so it stays as text. + image.drawText(small, PAD, PAD, "Music", 150); + image.drawText(small, PAD, PAD + small.lineHeight + 6, "Notification access needed", 140); + return; + } + // Nothing playing: a dim note, centred, and nothing else. + const note = idleNoteImage(); + if (note) image.drawImage(note, ((image.width - note.width) / 2) | 0, ((image.height - note.height) / 2) | 0); + return; + } + + const artY = Math.max(PAD, ((image.height - ART_SIZE) / 2) | 0); + this.drawArt(image, media, artY); + + const textX = ART_X + ART_SIZE + 12; + const textWidth = image.width - textX - PAD; + let y = artY; + image.drawText(medium, textX, y, truncateText(medium, media.title || "Unknown title", textWidth), 230); + y += medium.lineHeight + 2; + if (media.artist) { + image.drawText(small, textX, y, truncateText(small, media.artist, textWidth), 170); + y += small.lineHeight + 2; + } + if (media.album) { + image.drawText(small, textX, y, truncateText(small, media.album, textWidth), 120); + } + + // Progress pinned to the art's bottom edge; the state label sits beside it. + const barY = artY + ART_SIZE - PROGRESS_BAR_HEIGHT; + const timeY = barY - small.lineHeight - 3; + const stateLabel = media.playbackState === "playing" ? "" : media.playbackState === "paused" ? "Paused" : media.playbackState; + if (media.durationMs > 0 && media.positionMs >= 0) { + const elapsed = formatMediaTime(media.positionMs); + const duration = formatMediaTime(media.durationMs); + image.drawText(small, textX, timeY, elapsed, 140); + image.drawText(small, textX + textWidth - small.measureText(duration), timeY, duration, 140); + if (stateLabel) { + image.drawText(small, textX + (((textWidth - small.measureText(stateLabel)) / 2) | 0), timeY, stateLabel, 140); + } + image.drawRect(textX, barY, textWidth, PROGRESS_BAR_HEIGHT, 55); + const progress = clamp(media.positionMs / media.durationMs, 0, 1); + image.fillRect(textX + 1, barY + 1, Math.round((textWidth - 2) * progress), PROGRESS_BAR_HEIGHT - 2, 170); + } else if (stateLabel) { + image.drawText(small, textX, timeY, stateLabel, 140); + } + } + + private drawArt(image: GrayImage, media: MediaControllerState, artY: number): void { + const key = `${media.packageName}|${media.title}|${media.album}`; + // Retry while null: players often publish metadata before the bitmap. + if (key !== this.artKey || this.art === null) { + this.artKey = key; + this.art = mediaControllerBridge.getAlbumArt(ART_SIZE); + } + if (this.art) { + const dx = ART_X + Math.max(0, ((ART_SIZE - this.art.width) / 2) | 0); + const dy = artY + Math.max(0, ((ART_SIZE - this.art.height) / 2) | 0); + image.bitBlt(this.art, dx, dy); + image.drawRect(dx - 1, dy - 1, this.art.width + 2, this.art.height + 2, 60); + } else { + image.drawRect(ART_X, artY, ART_SIZE, ART_SIZE, 60); + const font = getDefaultSmallFont(); + image.drawText(font, ART_X + Math.round((ART_SIZE - font.measureText("no art")) / 2), + artY + Math.round((ART_SIZE - font.lineHeight) / 2), "no art", 90); + } + } +} + +function formatMediaTime(milliseconds: number): string { + const totalSeconds = Math.max(0, Math.floor(milliseconds / 1_000)); + const seconds = totalSeconds % 60; + const totalMinutes = Math.floor(totalSeconds / 60); + const minutes = totalMinutes % 60; + const hours = Math.floor(totalMinutes / 60); + return hours > 0 + ? `${hours}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}` + : `${minutes}:${String(seconds).padStart(2, "0")}`; +} diff --git a/app/apps/glanceboard/widgets/nightscout-widget.ts b/app/apps/glanceboard/widgets/nightscout-widget.ts new file mode 100644 index 00000000..d9425d84 --- /dev/null +++ b/app/apps/glanceboard/widgets/nightscout-widget.ts @@ -0,0 +1,119 @@ +import { type GrayImage } from "../../../graphics/image"; +import { getDefaultLargeFont, getDefaultSmallFont } from "../../../graphics/ui-fonts"; +import { truncateText } from "../../../graphics/textwrap"; +import { nightscoutBridge, type NightscoutState } from "../../../native/nightscout-bridge"; +import { isNightscoutSettingsConfigured, loadNightscoutThresholds } from "../../../ui/dashboard-settings"; +import { lineStep } from "../../../ui/metrics"; +import { formatAgeShortFromTimestamp } from "~/util/date-util"; +import { evaluateNightscoutAlerts } from "../../nightscout/nightscout-alerts"; +import { + drawDirectionIndicator, + drawNightscoutGraph, + drawNightscoutValueStrikeThrough, + formatDelta, + isNightscoutPointStale, +} from "../../nightscout/nightscout"; +import { type GlanceWidget } from "../widget"; + +const PAD = 8; +/** Width of the readout column left of the graph. */ +const READOUT_WIDTH = 96; + +/** + * Current glucose (struck through once older than the app's staleness + * limit) with delta, trend, age and IOB beside the Nightscout app's 2-hour + * graph, plus any of cannula age, reservoir, pump battery and loop age that + * breach the limits in Nightscout settings, inverted as the app shows them. The bridge polls on its own for the whole session, so the + * widget only subscribes; a minute tick keeps the age and staleness moving + * during a stalled fetch. + */ +export class NightscoutWidget implements GlanceWidget { + private state: NightscoutState = nightscoutBridge.snapshot(); + private unsubscribe: (() => void) | null = null; + private tick: ReturnType | null = null; + + start(requestRender: () => void): void { + this.unsubscribe = nightscoutBridge.onStateChange((state) => { + this.state = state; + requestRender(); + }); + this.tick = setInterval(requestRender, 60_000); + } + + stop(): void { + this.unsubscribe?.(); + this.unsubscribe = null; + if (this.tick !== null) clearInterval(this.tick); + this.tick = null; + } + + paint(image: GrayImage): void { + const small = getDefaultSmallFont(); + const large = getDefaultLargeFont(); + const state = this.state; + const nowMs = Date.now(); + const step = lineStep(small); + image.drawText(small, PAD, PAD, "Nightscout", 150); + + if (!isNightscoutSettingsConfigured() || state.configurationMissing) { + image.drawText(small, PAD, PAD + step + 4, "Not configured", 140); + image.drawText(small, PAD, PAD + 2 * step + 4, "Set the site URL in the Nightscout app", 100); + return; + } + const latest = state.latest; + if (!state.available || !latest) { + image.drawText(small, PAD, PAD + step + 4, "No data", 140); + image.drawText(small, PAD, PAD + 2 * step + 4, truncateText(small, state.status, image.width - 2 * PAD), 100); + return; + } + + // Readout column: big value, units, then delta + trend, age and IOB. + const glucoseText = `${latest.sgv}`; + const glucoseY = PAD + step; + const glucoseWidth = large.measureText(glucoseText); + image.drawText(large, PAD, glucoseY, glucoseText, 230); + if (isNightscoutPointStale(latest, nowMs)) { + // Same rule as the app: older than NIGHTSCOUT_STALE_MS (15 min) gets a + // line through the digits at mid-height. + drawNightscoutValueStrikeThrough(image, PAD, glucoseY + (large.lineHeight >> 1), glucoseWidth); + } + const unitsX = PAD + glucoseWidth + 4; + if (unitsX + small.measureText(state.units) <= PAD + READOUT_WIDTH) { + image.drawText(small, unitsX, glucoseY + large.lineHeight - small.lineHeight, state.units, 140); + } + let y = glucoseY + large.lineHeight + 2; + const deltaText = `${formatDelta(state.delta)} `; + image.drawText(small, PAD, y, deltaText, 180); + drawDirectionIndicator(image, small, PAD + small.measureText(deltaText), y, state.direction, 180); + y += step; + image.drawText(small, PAD, y, `${formatAgeShortFromTimestamp(latest.timestampMs, nowMs)} ago`, 130); + y += step; + image.drawText(small, PAD, y, `IOB ${state.iob === null ? "--" : state.iob.toFixed(2)}`, 160); + y += step; + + // Breached limits only, one per line while they fit, inverted like the + // app's warning fields. Nothing here means nothing is out of range. + const alerts = evaluateNightscoutAlerts(state, loadNightscoutThresholds(), nowMs); + const warnings: string[] = []; + if (alerts.cannula) warnings.push(`CAGE ${formatAgeShortFromTimestamp(state.cageTimestampMs, nowMs)}`); + if (alerts.cartridge) warnings.push(`Reservoir ${state.reservoirUnits === null ? "--" : Math.round(state.reservoirUnits)}U`); + if (alerts.battery) warnings.push(`Battery ${state.batteryVoltage === null ? "--" : state.batteryVoltage.toFixed(2)}V`); + if (alerts.loop) warnings.push(`Loop ${formatAgeShortFromTimestamp(state.loopTimestampMs, nowMs)}`); + for (const warning of warnings) { + if (y + small.lineHeight > image.height - 2) break; + const text = truncateText(small, warning, READOUT_WIDTH - 4); + image.fillRect(PAD - 2, y - 1, small.measureText(text) + 4, small.lineHeight + 2, 230); + image.drawText(small, PAD, y, text, 1); + y += step; + } + + const graphX = PAD + READOUT_WIDTH + PAD; + drawNightscoutGraph( + image, + { x: graphX, y: PAD, width: image.width - graphX - PAD, height: image.height - 2 * PAD }, + state, + nowMs, + small, + ); + } +} diff --git a/app/apps/glanceboard/widgets/system-card.ts b/app/apps/glanceboard/widgets/system-card.ts new file mode 100644 index 00000000..c9b2c601 --- /dev/null +++ b/app/apps/glanceboard/widgets/system-card.ts @@ -0,0 +1,233 @@ +import { BATTERY_ICON_WIDTH, drawBattery } from "../../../graphics/battery"; +import { type GrayImage, type UiFont } from "../../../graphics/image"; +import { getDefaultLargeFont, getDefaultMediumFont, getDefaultSmallFont } from "../../../graphics/ui-fonts"; +import { onAndroidNotificationPosted, readActiveNotificationIcons } from "../../../native/notification-icons"; +import { readPhoneBatteryState } from "../../../native/phone-battery"; +import { formatClockDate, formatClockTime } from "../../../ui/clock-format"; +import { + batteryDisplayModeSetting, + batteryIndicatorVisible, + glassesBatteryVisibilitySetting, + onAnySettingChanged, + phoneBatteryVisibilitySetting, + ringBatteryVisibilitySetting, + watchBatteryVisibilitySetting, + type BatteryIndicatorVisibility, +} from "../../../ui/dashboard-settings"; +import { shell } from "../../../ui/shell/shell"; +import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../../util/render-freshness"; +import { truncateText } from "../../../graphics/textwrap"; +import { timerEngine } from "../../timer/timer-engine"; +import { formatCountdown, sortTimers, timerDisplayName, timerPhase, timerRemainingMs } from "../../timer/timer-model"; +import { lineStep } from "../../../ui/metrics"; +import { type GlanceWidget } from "../widget"; + +const PAD = 8; +const NOTIFICATION_ICON_SIZE = 24; +const NOTIFICATION_ICON_GAP = 4; +const BATTERY_ITEM_GAP = 12; +const BATTERY_LABEL_VALUE = 150; + +type BatteryItem = { label: string; percent: number; charging: boolean }; + +/** + * Date and time, the phone's notification icons, the phone/watch/G2/R1 + * battery indicators (the Wear OS watch's only while one is reachable), and + * the Timers app's countdowns: the top bar's contents plus timers, laid out + * for a card. Battery style and per-device visibility + * follow Settings > Display > Battery indicators, so the card agrees with + * the bar. Countdowns tick once a second only while one is running. + */ +export class SystemCardWidget implements GlanceWidget { + private requestRender: (() => void) | null = null; + private minuteTimer: ReturnType | null = null; + private secondTimer: ReturnType | null = null; + private unsubscribeNotifications: (() => void) | null = null; + private unsubscribeSettings: (() => void) | null = null; + private unsubscribeTimers: (() => void) | null = null; + + start(requestRender: () => void): void { + this.requestRender = requestRender; + this.scheduleMinuteTick(); + this.unsubscribeNotifications = onAndroidNotificationPosted(() => this.requestRender?.()); + this.unsubscribeSettings = onAnySettingChanged(() => this.requestRender?.()); + this.unsubscribeTimers = timerEngine.onChange(() => { + this.syncSecondTick(); + this.requestRender?.(); + }); + this.syncSecondTick(); + } + + stop(): void { + this.requestRender = null; + if (this.minuteTimer !== null) clearTimeout(this.minuteTimer); + this.minuteTimer = null; + if (this.secondTimer !== null) clearInterval(this.secondTimer); + this.secondTimer = null; + this.unsubscribeNotifications?.(); + this.unsubscribeNotifications = null; + this.unsubscribeSettings?.(); + this.unsubscribeSettings = null; + this.unsubscribeTimers?.(); + this.unsubscribeTimers = null; + } + + /** Countdowns change every second; run that clock only while one is running. */ + private syncSecondTick(): void { + const running = timerEngine.timers().some((timer) => timerPhase(timer) === "running"); + if (running && this.secondTimer === null) { + this.secondTimer = setInterval(() => this.requestRender?.(), 1_000); + } else if (!running && this.secondTimer !== null) { + clearInterval(this.secondTimer); + this.secondTimer = null; + } + } + + /** Repaint on the minute boundary, so the clock never shows a stale minute. */ + private scheduleMinuteTick(): void { + if (this.minuteTimer !== null) clearTimeout(this.minuteTimer); + const now = Date.now(); + const untilNextMinute = 60_000 - (now % 60_000) + 50; + this.minuteTimer = setTimeout(() => { + this.minuteTimer = null; + if (!this.requestRender) return; + this.requestRender(); + this.scheduleMinuteTick(); + }, untilNextMinute); + } + + paint(image: GrayImage): void { + const large = getDefaultLargeFont(); + const medium = getDefaultMediumFont(); + const small = getDefaultSmallFont(); + const now = new Date(); + + // Clock and date down the left; batteries take the right edge. + const batteryLeft = drawBatteryBlock(image, small, image.width - PAD, PAD); + const textWidth = Math.max(0, batteryLeft - BATTERY_ITEM_GAP - PAD); + const timeText = formatClockTime(now); + const timeFont = large.measureText(timeText) <= textWidth ? large : medium; + let y = PAD; + image.drawText(timeFont, PAD, y, timeText, 230); + y += timeFont.lineHeight + 2; + image.drawText(medium, PAD, y, formatClockDate(now), 170); + y += medium.lineHeight + 4; + + // Notification icons along the bottom, as many as fit; the Timers app's + // countdowns take the band between the date and the icons. + const iconY = image.height - PAD - NOTIFICATION_ICON_SIZE; + drawTimers(image, small, PAD, y, textWidth, iconY - 4, now.getTime()); + const maxIcons = Math.max(0, ((image.width - 2 * PAD + NOTIFICATION_ICON_GAP) / (NOTIFICATION_ICON_SIZE + NOTIFICATION_ICON_GAP)) | 0); + if (maxIcons > 0) { + const { icons, stale } = readActiveNotificationIcons(maxIcons, renderPassAllowsStaleData()); + if (stale) noteStaleDataUsed(); + for (let index = 0; index < icons.length; index++) { + image.drawImage(icons[index]!, PAD + index * (NOTIFICATION_ICON_SIZE + NOTIFICATION_ICON_GAP), iconY); + } + } + } +} + +function collectBatteryItems(): BatteryItem[] { + const items: BatteryItem[] = []; + const push = (visibility: BatteryIndicatorVisibility, label: string, percent: number | null, charging: boolean | null) => { + if (percent === null || !Number.isFinite(percent)) return; + const clamped = Math.max(0, Math.min(100, Math.round(percent))); + if (!batteryIndicatorVisible(visibility, clamped)) return; + items.push({ label, percent: clamped, charging: Boolean(charging) }); + }; + const phone = readPhoneBatteryState(); + push(phoneBatteryVisibilitySetting.get(), "Phone", phone.battery, phone.charging); + const levels = shell.getBatteryLevels(); + push(watchBatteryVisibilitySetting.get(), "Watch", levels.watch, levels.watchCharging); + push(glassesBatteryVisibilitySetting.get(), "G2", levels.headset, levels.headsetCharging); + if (levels.ring !== null && Number.isInteger(levels.ring) && levels.ring >= 0 && levels.ring <= 100) { + push(ringBatteryVisibilitySetting.get(), "R1", levels.ring, levels.ringCharging); + } + return items; +} + +/** + * The battery indicators right-aligned at `right`, in the configured style. + * Side-by-side styles put the label beside the gauge (or percentage) on one + * line; stacked styles centre the label above it. Returns the block's left + * edge (or `right` when nothing is shown). + */ +function drawBatteryBlock(image: GrayImage, font: UiFont, right: number, top: number): number { + const items = collectBatteryItems(); + if (!items.length) return right; + const mode = batteryDisplayModeSetting.get(); + const percentage = mode === "percentage" || mode === "stacked-percentage"; + const stacked = mode === "stacked" || mode === "stacked-percentage"; + const gaugeHeight = drawBattery(0, false).height; + let x = right; + for (let index = items.length - 1; index >= 0; index--) { + const item = items[index]!; + const percentText = `${item.percent}%`; + const labelWidth = font.measureText(item.label); + const valueWidth = percentage ? font.measureText(percentText) : BATTERY_ICON_WIDTH; + if (stacked) { + const itemWidth = Math.max(labelWidth, valueWidth); + x -= itemWidth; + image.drawText(font, x + (((itemWidth - labelWidth) / 2) | 0), top, item.label, BATTERY_LABEL_VALUE); + drawBatteryValue(image, font, x + (((itemWidth - valueWidth) / 2) | 0), top + font.lineHeight + 2, item, percentage, gaugeHeight); + } else { + x -= labelWidth + 5 + valueWidth; + image.drawText(font, x, top, item.label, BATTERY_LABEL_VALUE); + drawBatteryValue(image, font, x + labelWidth + 5, top, item, percentage, gaugeHeight); + } + x -= BATTERY_ITEM_GAP; + } + return x + BATTERY_ITEM_GAP; +} + +function drawBatteryValue( + image: GrayImage, + font: UiFont, + x: number, + lineTop: number, + item: BatteryItem, + percentage: boolean, + gaugeHeight: number, +): void { + if (percentage) { + const percentText = `${item.percent}%`; + if (item.charging) { + // Inverted text marks charging, as in the top bar. + image.fillRect(x - 2, lineTop - 1, font.measureText(percentText) + 4, font.lineHeight + 2, 255); + image.drawText(font, x, lineTop, percentText, 1); + } else { + image.drawText(font, x, lineTop, percentText, 200); + } + return; + } + const icon = drawBattery(item.percent, item.charging); + image.bitBlt(icon, x, lineTop + Math.max(0, ((font.lineHeight - gaugeHeight) / 2) | 0), { transparentZero: true }); +} + +/** + * The Timers app's countdowns, soonest first: remaining time (or "Done" once + * rung, inverted so it is noticed; "paused" for a paused one) and the + * timer's name, one per line while they fit between `top` and `bottom`. + */ +function drawTimers(image: GrayImage, font: UiFont, x: number, top: number, width: number, bottom: number, nowMs: number): void { + const timers = sortTimers(timerEngine.timers(), nowMs); + const step = lineStep(font); + let y = top; + for (const timer of timers) { + if (y + font.lineHeight > bottom) break; + const phase = timerPhase(timer); + const clock = phase === "rung" ? "Done" : formatCountdown(timerRemainingMs(timer, nowMs)); + const clockWidth = font.measureText(clock); + if (phase === "rung") { + image.fillRect(x - 2, y - 1, clockWidth + 4, font.lineHeight + 2, 230); + image.drawText(font, x, y, clock, 1); + } else { + image.drawText(font, x, y, clock, phase === "paused" ? 120 : 200); + } + const nameX = x + clockWidth + 8; + const name = phase === "paused" ? `${timerDisplayName(timer)} (paused)` : timerDisplayName(timer); + image.drawText(font, nameX, y, truncateText(font, name, Math.max(0, x + width - nameX)), 160); + y += step; + } +} diff --git a/app/apps/glanceboard/widgets/terminal-widget.ts b/app/apps/glanceboard/widgets/terminal-widget.ts new file mode 100644 index 00000000..b48b8543 --- /dev/null +++ b/app/apps/glanceboard/widgets/terminal-widget.ts @@ -0,0 +1,126 @@ +import { type GrayImage } from "../../../graphics/image"; +import { truncateText } from "../../../graphics/textwrap"; +import { getDefaultSmallFont } from "../../../graphics/ui-fonts"; +import { lineStep } from "../../../ui/metrics"; +import { onWorkerStateChanged, readWorkerState } from "../../../ui/shell/worker-state"; +import { + drawSessionRow, + isSessionRowActive, + SESSION_ACTIVITY_STEP_MS, + TERMINAL_SESSIONS_STATE_KEY, + type TerminalSessionsSnapshot, +} from "../../terminal/session-list"; +import { type GlanceWidget } from "../widget"; + +const PAD = 8; +const GUTTER_X = PAD; +/** A row fits while its glyph line clears this margin above the bottom edge. */ +const BOTTOM_MARGIN = 2; + +/** + * The Terminal app's session list at card size: the same hosts, sessions, + * activity indicators and open-window numbers as the hub window, painted + * with the same row painter from the snapshot the Terminal worker publishes. + * The indicator animates on the hub's cadence while any session is active; + * each row carries its own activity deadline, so nothing needs the worker + * once the snapshot is in. + */ +export class TerminalWidget implements GlanceWidget { + private snapshot: TerminalSessionsSnapshot | undefined = readWorkerState(TERMINAL_SESSIONS_STATE_KEY); + private unsubscribe: (() => void) | null = null; + private requestRender: (() => void) | null = null; + private phase = 0; + private animationTimer: ReturnType | null = null; + + start(requestRender: () => void): void { + this.requestRender = requestRender; + this.snapshot = readWorkerState(TERMINAL_SESSIONS_STATE_KEY); + this.unsubscribe = onWorkerStateChanged(TERMINAL_SESSIONS_STATE_KEY, (snapshot) => { + this.snapshot = snapshot; + this.syncAnimation(); + requestRender(); + }); + this.syncAnimation(); + } + + stop(): void { + this.requestRender = null; + this.unsubscribe?.(); + this.unsubscribe = null; + if (this.animationTimer !== null) clearInterval(this.animationTimer); + this.animationTimer = null; + } + + private anyActive(nowMs = Date.now()): boolean { + return Boolean(this.snapshot?.hosts.some((host) => host.sessions.some((row) => isSessionRowActive(row, nowMs)))); + } + + /** Run the indicator clock only while something is active; the last tick clears expired ones. */ + private syncAnimation(): void { + const shouldRun = this.anyActive(); + if (shouldRun && this.animationTimer === null) { + this.phase = 0; + this.animationTimer = setInterval(() => { + this.phase = (this.phase + 1) % 2; + this.requestRender?.(); + if (!this.anyActive()) this.syncAnimation(); + }, SESSION_ACTIVITY_STEP_MS); + } else if (!shouldRun && this.animationTimer !== null) { + clearInterval(this.animationTimer); + this.animationTimer = null; + } + } + + paint(image: GrayImage): void { + const font = getDefaultSmallFont(); + const step = lineStep(font); + const textWidth = image.width - 2 * PAD; + const snapshot = this.snapshot; + const nowMs = Date.now(); + let y = PAD; + image.drawText(font, PAD, y, "Terminal", 150); + y += step; + + if (!snapshot) { + image.drawText(font, PAD, y, "Open the Terminal app to connect", 120); + return; + } + const hosts = snapshot.hosts; + const sessionCount = hosts.reduce((sum, host) => sum + host.sessions.length, 0); + if (!hosts.length || !sessionCount) { + const text = !snapshot.configured + ? "No connections configured" + : !hosts.length + ? snapshot.status + : "No live sessions"; + image.drawText(font, PAD, y, truncateText(font, text, textWidth), 120); + return; + } + + // Rows are placed a line step apart but only need their line height to + // fit, so the last one may sit right against the bottom margin. + const fits = (top: number) => top + font.lineHeight <= image.height - BOTTOM_MARGIN; + const multiHost = hosts.length > 1; + for (const host of hosts) { + if (multiHost) { + if (!fits(y)) return; + image.drawText(font, PAD, y, truncateText(font, host.name, textWidth), 110); + y += step; + } + for (const row of host.sessions) { + if (!fits(y)) return; + drawSessionRow(image, font, { + x: GUTTER_X, + y, + width: image.width - GUTTER_X - PAD, + label: row.label, + openGlyph: row.openGlyph, + active: isSessionRowActive(row, nowMs), + phase: this.phase, + value: 200, + }); + y += step; + } + } + } +} diff --git a/app/apps/launcher/launcher-folders.ts b/app/apps/launcher/launcher-folders.ts index 69eb486c..b9f0e990 100644 --- a/app/apps/launcher/launcher-folders.ts +++ b/app/apps/launcher/launcher-folders.ts @@ -16,6 +16,7 @@ const DEFAULT_ASSIGNMENTS: Record = { freecell: "Games", minesweeper: "Games", pinball: "Games", + flappy: "Games", calculator: "Prototypes", microphones: "Prototypes", nightscout: "Prototypes", diff --git a/app/apps/microphones/mic-control.ts b/app/apps/microphones/mic-control.ts index 31924493..49b46251 100644 --- a/app/apps/microphones/mic-control.ts +++ b/app/apps/microphones/mic-control.ts @@ -20,8 +20,9 @@ declare const com: any; * Host-side controller for the CFW mic_control array: sends the same config * to both temples (each temple is its own endpoint and its own 2-mic array), * tracks per-temple field-104 status, and keeps the 90 s streaming lease - * renewed while capture is armed. Degrades cleanly on firmware without the - * feature: micControlSupported() is false and apply() refuses to arm. + * renewed while capture is armed. The feature is part of the required + * firmware revision, so the only gate is the developer setting: + * micControlSupported() is false and apply() refuses to arm when it is off. */ const CONFIG_SETTING_KEY = "microphones.array-config"; @@ -38,26 +39,13 @@ function activeCommunicator(): any { } } -/** True when the connected glasses advertise the CFW mic_control feature. */ -export function micControlAdvertised(): boolean { - const communicator = activeCommunicator(); - if (!communicator) return false; - try { - const caps = String(communicator.getFirmwareCapabilities() ?? ""); - return caps.trim().split(/\s+/).includes("micctl"); - } catch { - return false; - } -} - /** - * True when the connected glasses advertise the CFW mic_control feature AND - * the "Use microphone control" developer setting is on. With the setting off - * (the default), Faceclaw behaves exactly as it would on firmware without the - * micctl caps token. + * True when the "Use microphone control" developer setting is on. With the + * setting off, Faceclaw behaves exactly as it would on firmware without the + * mic-control channel (one mixed stream). */ export function micControlSupported(): boolean { - return useMicControlSetting.get() && micControlAdvertised(); + return useMicControlSetting.get(); } export function loadMicConfig(): MicConfig { diff --git a/app/apps/microphones/mic-protocol.ts b/app/apps/microphones/mic-protocol.ts index 9bf435b8..02cd9788 100644 --- a/app/apps/microphones/mic-protocol.ts +++ b/app/apps/microphones/mic-protocol.ts @@ -1,7 +1,6 @@ /** - * Wire codec for the CFW mic_control feature (g2flash `microphone-configurations` - * branch, EVENCFW/16, caps tokens micctl/micmc/micraw). Mirrors the contract - * header in g2flash patches/mic_control.c: + * Wire codec for the CFW mic_control feature. Mirrors the contract header in + * g2flash patches/mic_control.c: * * field 103 (write) ['M','C', ver, op, <9 config bytes for CONFIGURE>] * field 104 (read) 21-byte ['M','C', ver, active, src, chanMask, codec, diff --git a/app/apps/microphones/mic-session.ts b/app/apps/microphones/mic-session.ts index e2d9cf5b..5f019ab8 100644 --- a/app/apps/microphones/mic-session.ts +++ b/app/apps/microphones/mic-session.ts @@ -730,7 +730,10 @@ class MicSession { }, }); engine.setListener(this.captionListenerProxy); - engine.setAsrModelDir(isAsrModelReady() ? moonshineModelDir() : null); + // Live captions are a separate sherpa-onnx pipeline (FaceclawCaptionEngine) + // that only ever uses Moonshine; unaffected by the two-model on-device + // Whisper addition in native/voice-control.ts's push-to-talk path. + engine.setAsrModelDir(isAsrModelReady("moonshine") ? moonshineModelDir() : null); engine.setSpeakerModelPath(micModelPath("speaker-embedding")); engine.start(); this.captionEngine = engine; diff --git a/app/apps/microphones/microphones-app.ts b/app/apps/microphones/microphones-app.ts index febafe6d..ef0d491e 100644 --- a/app/apps/microphones/microphones-app.ts +++ b/app/apps/microphones/microphones-app.ts @@ -23,7 +23,7 @@ import { isAsrModelReady, startAsrModelDownload, asrModelState } from "../../nat import { CaptionsLayer } from "./captions-layer"; import { LevelsLayer } from "./levels-layer"; import { RadarLayer } from "./radar-layer"; -import { loadMicConfig, micArrayController, micControlAdvertised, micControlSupported, saveMicConfig } from "./mic-control"; +import { loadMicConfig, micArrayController, micControlSupported, saveMicConfig } from "./mic-control"; import { isMicModelReady, micModelState, startMicModelDownload } from "./mic-models"; import { micChannelLabel, type MicChannelKey, type MicConfig } from "./mic-protocol"; import { micSession } from "./mic-session"; @@ -166,7 +166,7 @@ function micSetupMenu(): MenuLayer { { label: "Array status", description: - "Per-temple mic-control status. Requires the mic-control custom firmware (caps token micctl) and the Use microphone control developer setting.", + "Per-temple mic-control status. Requires the Use microphone control developer setting.", onSelect: (ctx) => { micArrayController.query(); const { left, right } = micArrayController.getStatuses(); @@ -186,9 +186,7 @@ function micSetupMenu(): MenuLayer { "Array status", micControlSupported() ? `${describe("Left", left)}\n${describe("Right", right)}\n${consistency}` - : micControlAdvertised() - ? "Mic-control is available but disabled. Turn on Settings > Developer > Use microphone control to control the four mics individually." - : "The connected firmware does not advertise mic-control. Flash the microphone-configurations CFW build to control the four mics individually; on stock firmware the glasses stream one mixed channel with a firmware-computed direction of arrival.", + : "Mic-control is disabled. Turn on Settings > Developer > Use microphone control to control the four mics individually; while it is off the glasses stream one mixed channel with a firmware-computed direction of arrival.", ), ); }, @@ -330,17 +328,20 @@ function voiceSpeakersMenu(): MenuLayer { () => startMicModelDownload("speaker-embedding"), ), modelItem( + // Live captions always use Moonshine (see the matching note in + // mic-session.ts); the second on-device model (Whisper) is a + // push-to-talk dictation option only, managed in Settings > Voice. "Caption ASR model", - isAsrModelReady, + () => isAsrModelReady("moonshine"), () => { - const state = asrModelState(); + const state = asrModelState("moonshine"); if (state.status === "ready") return "ready"; if (state.status === "downloading") { return `${Math.round((state.bytesDownloaded / state.totalBytes) * 100)}%`; } return "download (141 MB)"; }, - startAsrModelDownload, + () => startAsrModelDownload("moonshine"), ), modelItem( "Re-diarization model", diff --git a/app/apps/minesweeper/minesweeper-app.worker.ts b/app/apps/minesweeper/minesweeper-app.worker.ts index 1f1b958a..2e0b5c5f 100644 --- a/app/apps/minesweeper/minesweeper-app.worker.ts +++ b/app/apps/minesweeper/minesweeper-app.worker.ts @@ -9,9 +9,13 @@ * scroll moves along the row, click reveals (or chords a satisfied number), * long-press toggles a flag, double-click returns to row-select. * Watch swipes skip the two-layer scheme and move the cell cursor in four - * directions; a watch double-click pauses directly. + * directions; a watch double-click pauses directly. Tap-then-hold opens the + * window menu in any phase, pausing a live game first. * Paused/won/lost: click resumes or starts a new game, double-click yields - * focus, long-press opens the window menu. + * focus. Losing input focus mid-game (a shell overlay such as the system + * menu or a notification, focus to the sidebar) pauses, as does + * backgrounding or screen-off. The difficulty setting persists across + * launches. */ import "@nativescript/core/globals"; import { GrayImage } from "../../graphics/image"; @@ -19,9 +23,11 @@ import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../gra import { prepareFrameDraws } from "../../graphics/glyph-wire"; import { getFont } from "../../graphics/bdffont"; import { getDefaultSmallFont } from "../../graphics/ui-fonts"; +import { getStringSetting, setStringSetting } from "../../native/settings-store"; import * as frameTimings from "../../native/frame-timings"; import { getActiveDisplay } from "../../native/active-display"; import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects"; +import { loadSoundEnabled, saveSoundEnabled } from "../../ui/sound-setting"; import { type MenuItem } from "../../ui/menu"; import { WindowMenu } from "../../ui/window-menu"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; @@ -55,6 +61,8 @@ const DIFFICULTIES = [ { name: "Medium", mines: 20 }, { name: "Hard", mines: 26 }, ] as const; +/** Persisted difficulty, stored by name so a reordering can't misfile it. */ +const DIFFICULTY_KEY = "minesweeper.difficulty"; /** Number glyph shades by adjacent-mine count; higher counts read brighter. */ const COUNT_SHADES = [0, 140, 170, 200, 220, 235, 245, 250, 250]; @@ -155,7 +163,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { focused: false, menu: null, phase: "playing", - difficultyIndex: 0, + difficultyIndex: loadDifficultyIndex(), mines: new Uint8Array(COLS * ROWS), counts: new Uint8Array(COLS * ROWS), cellState: new Uint8Array(COLS * ROWS), @@ -169,7 +177,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { elapsedMs: 0, runningSinceMs: null, tickTimer: null, - soundOn: true, + soundOn: loadSoundEnabled("minesweeper"), lastSubmittedFingerprint: "", }; windows.set(message.windowId, window); @@ -215,6 +223,19 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { if (window.foreground) renderAndSubmit(window, 0); break; } + case "input-focus": { + const window = windows.get(message.windowId); + if (!window) break; + // Anything that takes input away (the system menu, a notification + // modal, the voice dialog, focus back to the sidebar) pauses, so the + // clock stops and the board is hidden while the player can't act. + if (!message.focused && window.phase === "playing") { + window.phase = "paused"; + syncClock(window); + if (window.foreground) renderAndSubmit(window, 0); + } + break; + } case "screen": screenOn = message.on; for (const window of windows.values()) { @@ -237,6 +258,24 @@ function inferForeground(window: MinesweeperWindow, focused: boolean): void { syncClock(window); } +function loadDifficultyIndex(): number { + try { + const name = getStringSetting(DIFFICULTY_KEY, ""); + const index = DIFFICULTIES.findIndex((difficulty) => difficulty.name === name); + return index >= 0 ? index : 0; + } catch { + return 0; + } +} + +function saveDifficultyIndex(window: MinesweeperWindow): void { + try { + setStringSetting(DIFFICULTY_KEY, DIFFICULTIES[window.difficultyIndex]!.name); + } catch (error) { + console.warn(`minesweeper difficulty save failed: ${error}`); + } +} + /** * Fire a buzzer effect. Non-blocking: the firmware's sequencer plays the * steps on its own timer, and the Java call is safe from the worker thread. @@ -252,7 +291,7 @@ function playSfx(window: MinesweeperWindow, steps: Step[]): void { } } -/** The window's context menu (game actions), offered while paused or over; playing keeps long-press for flagging. */ +/** The window's context menu (game actions). Tap-then-hold reaches it in any phase; playing keeps long-press for flagging. */ function windowMenuItems(window: MinesweeperWindow): MenuItem[] { const nextDifficulty = DIFFICULTIES[(window.difficultyIndex + 1) % DIFFICULTIES.length]!; return [ @@ -269,6 +308,7 @@ function windowMenuItems(window: MinesweeperWindow): MenuItem[] { onSelect: (ctx) => { ctx.stack.pop(); window.difficultyIndex = (window.difficultyIndex + 1) % DIFFICULTIES.length; + saveDifficultyIndex(window); resetGame(window); playSfx(window, SFX_RESUME); }, @@ -278,6 +318,7 @@ function windowMenuItems(window: MinesweeperWindow): MenuItem[] { onSelect: (ctx) => { ctx.stack.pop(); window.soundOn = !window.soundOn; + saveSoundEnabled("minesweeper", window.soundOn); if (window.soundOn) playSfx(window, SFX_RESUME); }, }, @@ -290,7 +331,7 @@ function windowMenu(window: MinesweeperWindow): WindowMenu { windowId: window.windowId, post, title: () => window.title, - items: () => (window.phase === "playing" ? [] : windowMenuItems(window)), + items: () => windowMenuItems(window), claimsLongPress: () => window.phase === "playing", size: { width: window.viewportWidth, height: window.viewportHeight }, paintBase: () => paintContent(window), @@ -367,7 +408,11 @@ function handlePlayingInput(window: MinesweeperWindow, event: InputEvent, frameI toggleFlag(window); break; case "short-then-long-press": - // No context menu mid-game, so this opens the system menu instead. + // The menu's actions (new game, difficulty) all discard the board, and + // the clock must not run under it, so pause first; the board is hidden + // while paused, so the menu can't be used to study it off the clock. + window.phase = "paused"; + syncClock(window); windowMenu(window).open(); break; case "double-click": diff --git a/app/apps/music/music-app.ts b/app/apps/music/music-app.ts index c1895007..40eb5600 100644 --- a/app/apps/music/music-app.ts +++ b/app/apps/music/music-app.ts @@ -68,7 +68,7 @@ class MusicAppLayer implements Layer { if (!media.accessEnabled) { const lines = wrapText( font, - "Notification access is required before Android exposes media sessions. Click to open settings.", + "Notification access is required to control Android media sessions. Tap to open settings.", width - 48, ); for (let index = 0; index < lines.length; index++) { diff --git a/app/apps/navigate/navigate-app.worker.ts b/app/apps/navigate/navigate-app.worker.ts index e8855384..3eff4595 100644 --- a/app/apps/navigate/navigate-app.worker.ts +++ b/app/apps/navigate/navigate-app.worker.ts @@ -28,12 +28,14 @@ import { WindowMenu, WindowMenuLayer } from "../../ui/window-menu"; import type { LayerContext } from "../../ui/layers"; import { truncateText, wrapText } from "../../graphics/textwrap"; import { onSettingsStoreChanged } from "../../native/settings-store"; +import { openUrlOnPhone } from "../../native/open-url"; import { navigateDestinationAddressDraftSetting, navigateDestinationNameDraftSetting, navigateRememberRecentSetting, navigateDisplayModeSetting, navigateVerticalPositionSetting, + mapboxApiKeySetting, enumSettingMenuItem, type ConfigSettingString, } from "../../ui/dashboard-settings"; @@ -68,6 +70,7 @@ import { fetchStaticMapGray, geocodeForward, isMapboxConfigured, + MAPBOX_TOKEN_SETTING_KEY, type GeocodeCandidate, type Route, type RouteProfile, @@ -190,10 +193,14 @@ type NavTarget = | { kind: "query"; query: string; label?: string } | { kind: "place"; name: string; place: string; longitude: number; latitude: number }; -/** An entry on the idle page's destination list. */ +/** + * An entry on the idle page's list: a destination, or (while no Mapbox + * token is set) one of the setup actions offered in its place. + */ type IdleEntry = | { kind: "saved"; destination: SavedDestination } - | { kind: "recent"; destination: RecentDestination }; + | { kind: "recent"; destination: RecentDestination } + | { kind: "action"; label: string; detail: string; run: () => void }; /** Idle-page list selection (index into idleEntries()). */ let idleSelection = 0; @@ -208,6 +215,8 @@ type DestinationEdit = { setting: ConfigSettingString; title: string; onDone: (value: string) => void; + /** Runs on double-click (cancel); edits of a live setting restore it here. */ + onCancel?: () => void; }; let editing: DestinationEdit | null = null; @@ -251,7 +260,9 @@ function post(message: WorkerAppReply): void { // Destinations edited on the phone (the text editor, or the Settings app's // Home/Work rows) repaint the idle list / the edit screen live. onSettingsStoreChanged((key) => { - if (key.startsWith("navigate.")) render(); + // The token key repaints too: the phone editor writes it live during + // Edit token, and the idle page changes shape once one is set. + if (key.startsWith("navigate.") || key === MAPBOX_TOKEN_SETTING_KEY) render(); }); // The host queues messages until this arrives: posts to a worker whose bundle @@ -374,7 +385,7 @@ function startNavigation(query: string, requestedProfile: RouteProfile): Promise async function startNavigationTo(target: NavTarget, requestedProfile: RouteProfile): Promise { const query = target.kind === "query" ? target.query : target.name; if (!isMapboxConfigured()) { - statusMessage = "Set a Mapbox token in Settings > API Keys."; + statusMessage = "Navigation needs a Mapbox token. This is free (up to a usage limit); open Mapbox in a browser on your phone or pick Edit token below."; phase = "idle"; render(); throw new Error(statusMessage); @@ -1036,8 +1047,13 @@ function closeMenusAnd(ctx: LayerContext, action: () => void): void { * Open the phone text editor on a staging setting. The editor writes the * draft live (repainted via the settings listener); click here confirms. */ -function beginEdit(setting: ConfigSettingString, title: string, onDone: (value: string) => void): void { - editing = { setting, title, onDone }; +function beginEdit( + setting: ConfigSettingString, + title: string, + onDone: (value: string) => void, + onCancel?: () => void, +): void { + editing = { setting, title, onDone, onCancel }; post({ type: "start-text-setting-edit", settingId: setting.id }); render(); } @@ -1047,6 +1063,7 @@ function finishEdit(confirmed: boolean): void { editing = null; post({ type: "end-text-setting-edit" }); if (current && confirmed) current.onDone(current.setting.get()); + else if (current) current.onCancel?.(); // onDone may have started the next step; only fully leave when it didn't. if (!editing) { navigateDestinationNameDraftSetting.set(""); @@ -1075,10 +1092,52 @@ function beginAddDestination(): void { }); } +/** + * Edit the Mapbox token in place: the phone editor writes the real setting + * live, so cancelling puts back whatever was there before. + */ +function beginTokenEdit(): void { + const previous = mapboxApiKeySetting.get(); + beginEdit( + mapboxApiKeySetting, + mapboxApiKeySetting.glassesEditTitle, + () => { + statusMessage = ""; + }, + () => mapboxApiKeySetting.set(previous), + ); +} + // --------------------------------------------------------------------------- // Idle page destination list +/** Where a user gets a token: Mapbox's access-tokens page (sign-up/login first when needed). */ +const MAPBOX_TOKENS_URL = "https://account.mapbox.com/access-tokens/"; + +/** Offered in place of the destination list until a Mapbox token is set. */ +function tokenSetupEntries(): IdleEntry[] { + return [ + { + kind: "action", + label: "Open mapbox.com", + detail: "Get a free token in the phone browser", + run: () => { + statusMessage = openUrlOnPhone(MAPBOX_TOKENS_URL) + ? "Opened mapbox.com on your phone. Copy your public token (pk...) and pick Edit token." + : "Could not open a browser on the phone. Visit account.mapbox.com/access-tokens to get a token."; + }, + }, + { + kind: "action", + label: "Edit token", + detail: "Type or paste it in the phone app", + run: () => beginTokenEdit(), + }, + ]; +} + function idleEntries(): IdleEntry[] { + if (!isMapboxConfigured()) return tokenSetupEntries(); const entries: IdleEntry[] = loadSavedDestinations() .filter((destination) => destination.address) .map((destination): IdleEntry => ({ kind: "saved", destination })); @@ -1094,6 +1153,10 @@ function clampIdleSelection(): void { } function navigateToIdleEntry(entry: IdleEntry): void { + if (entry.kind === "action") { + entry.run(); + return; + } const target: NavTarget = entry.kind === "saved" ? { kind: "query", query: entry.destination.address, label: entry.destination.name } @@ -1233,8 +1296,9 @@ function paintIdle(image: GrayImage, win: NavWindow): void { image.drawText(mediumFont, 24, 16, "Navigate", 245); const busy = phase !== "idle"; const entries = busy ? [] : idleEntries(); - const hint = !isMapboxConfigured() - ? "Set a Mapbox token in Settings > API Keys to enable navigation." + const configured = isMapboxConfigured(); + const hint = !configured + ? "Navigation needs a Mapbox public token (free at mapbox.com). Get one, then enter it here or in Settings > API Keys." : entries.length ? "Pick a destination below, or say one via Voice input (system menu, long-press)." : "Ask the voice assistant to navigate somewhere, or pick Voice input from the system menu (long-press) to say a destination. Save Home, Work and other places from the app menu."; @@ -1255,7 +1319,7 @@ function paintIdle(image: GrayImage, win: NavWindow): void { paintIdleList(image, win, entries, y); drawFooter( image, - `${GESTURE_SCROLL} select ${GESTURE_CLICK} go ${GESTURE_SHORT_THEN_LONG_PRESS} app menu ${GESTURE_DOUBLE_CLICK} back`, + `${GESTURE_SCROLL} select ${GESTURE_CLICK} ${configured ? "go" : "choose"} ${GESTURE_SHORT_THEN_LONG_PRESS} app menu ${GESTURE_DOUBLE_CLICK} back`, ); } else { drawFooter(image, `${GESTURE_SHORT_THEN_LONG_PRESS} app menu ${GESTURE_DOUBLE_CLICK} back`); @@ -1281,7 +1345,18 @@ function paintIdleList(image: GrayImage, win: NavWindow, entries: IdleEntry[], t if (selected) drawSelectionHighlight(image, rowX, y, rowWidth, rowHeight - 2, win.focused); const textX = rowX + 6; const textY = y + LIST_ROW_TEXT_INSET; - if (entry.kind === "saved") { + if (entry.kind === "action") { + const label = truncateText(smallFont, entry.label, labelWidth); + image.drawText(smallFont, textX, textY, label, selected ? 245 : 210); + const detailX = textX + labelWidth + 8; + image.drawText( + smallFont, + detailX, + textY, + truncateText(smallFont, entry.detail, rowX + rowWidth - 6 - detailX), + selected ? 170 : 130, + ); + } else if (entry.kind === "saved") { const label = truncateText(smallFont, entry.destination.name, labelWidth); image.drawText(smallFont, textX, textY, label, selected ? 245 : 210); const detailX = textX + labelWidth + 8; diff --git a/app/apps/nightscout/nightscout.ts b/app/apps/nightscout/nightscout.ts index 380f0595..8a0878da 100644 --- a/app/apps/nightscout/nightscout.ts +++ b/app/apps/nightscout/nightscout.ts @@ -24,11 +24,11 @@ import { openSettingsSubMenu } from "../../ui/dashboard/settings-panel"; import { lineStep } from "../../ui/metrics"; const nightscoutLargeFont = getDefaultLargeFont(); -const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000; +export const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000; const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000; const NIGHTSCOUT_GRAPH_TIME_QUANTUM_MS = 60 * 1000; -function drawDirectionIndicator( +export function drawDirectionIndicator( image: GrayImage, font: UiFont, x: number, @@ -85,7 +85,7 @@ function truncateLine(text: string, maxChars: number): string { return `${text.slice(0, Math.max(0, maxChars - 3))}...`; } -function formatDelta(delta: number | null): string { +export function formatDelta(delta: number | null): string { if (delta === null) return "--"; return `${delta >= 0 ? "+" : ""}${Math.round(delta)}`; } @@ -98,7 +98,7 @@ function formatBolusLabel(value: number): string { return Number.isInteger(value) ? `${value}` : value.toFixed(1); } -function drawNightscoutGraph( +export function drawNightscoutGraph( image: GrayImage, bounds: { x: number; y: number; width: number; height: number }, nightscout: NightscoutState, @@ -431,10 +431,10 @@ export function nightscoutMenuItems(): MenuItem[] { ]; } -function isNightscoutPointStale(point: NightscoutState["latest"], nowMs: number): boolean { +export function isNightscoutPointStale(point: NightscoutState["latest"], nowMs: number): boolean { return point !== null && nowMs - point.timestampMs > NIGHTSCOUT_STALE_MS; } -function drawNightscoutValueStrikeThrough(image: GrayImage, x: number, y: number, width: number): void { +export function drawNightscoutValueStrikeThrough(image: GrayImage, x: number, y: number, width: number): void { image.drawLine(x, y, x + width, y, 180); } diff --git a/app/apps/pinball/pinball-app.worker.ts b/app/apps/pinball/pinball-app.worker.ts index b38b40ea..e9b375a5 100644 --- a/app/apps/pinball/pinball-app.worker.ts +++ b/app/apps/pinball/pinball-app.worker.ts @@ -13,11 +13,12 @@ * * Controls (ball ready): scroll sets launch power, click launches. In play: * click flips both flippers, scroll-up/down flips left/right individually, - * long-press nudges the table (three quick nudges tilt), double-click pauses. - * Watch swipes: left/right work the matching flipper, up nudges (or raises - * launch power at the plunger), down lowers launch power. + * double-click pauses. Watch swipes: left/right work the matching flipper, + * up/down raise and lower launch power at the plunger. * Paused/game over: click resumes or starts a new game, double-click yields - * focus, long-press opens the window menu. + * focus, long-press opens the window menu. Losing input focus mid-game (a + * shell overlay such as the system menu or a notification, focus to the + * sidebar) pauses, as does backgrounding or screen-off. */ import "@nativescript/core/globals"; import { GrayImage } from "../../graphics/image"; @@ -29,6 +30,7 @@ import * as frameTimings from "../../native/frame-timings"; import { getActiveDisplay } from "../../native/active-display"; import { getStringSetting, setStringSetting } from "../../native/settings-store"; import { buildSoundSequencePayload, type Step } from "../../ui/sound-effects"; +import { loadSoundEnabled, saveSoundEnabled } from "../../ui/sound-setting"; import { type MenuItem } from "../../ui/menu"; import { WindowMenu } from "../../ui/window-menu"; import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window"; @@ -36,7 +38,6 @@ import { directionalFallback, GESTURE_CLICK, GESTURE_DOUBLE_CLICK, - GESTURE_LONG_PRESS, GESTURE_SCROLL, type InputEvent, } from "../../ui/gestures"; @@ -77,11 +78,6 @@ const RENDER_TICK_MS = 50; const LAUNCH_SPEEDS = [320, 380, 440, 500, 560] as const; const BUMPER_KICK = 340; const SLING_KICK = 300; -const NUDGE_KICK_UP = 70; -const NUDGE_KICK_SIDE = 45; -/** Nudges add 1 heat each and decay slowly; reaching 3 tilts the ball away. */ -const TILT_LIMIT = 3; -const TILT_HEAT_DECAY_PER_S = 0.4; const SCORE_BUMPER = 100; const SCORE_SLING = 25; @@ -208,7 +204,6 @@ const SFX_DRAIN: Step[] = [ { freq: 370, duty: 45, ms: 100 }, { freq: 247, duty: 50, ms: 200 }, ]; -const SFX_TILT: Step[] = [{ freq: 110, duty: 60, ms: 300 }]; const SFX_GAME_OVER: Step[] = [ { freq: 494, duty: 45, ms: 150 }, { freq: 440, duty: 45, ms: 150 }, @@ -269,10 +264,6 @@ type PinballWindow = { /** Debounce: a sensor re-arms only after the ball leaves its zone. */ rolloverInside: boolean[]; bumperFlashUntilMs: number[]; - tiltHeat: number; - tilted: boolean; - /** Alternates nudge direction so mashing doesn't push one way forever. */ - nudgeSign: 1 | -1; /** Transient center-table message ("BALL LOST", "+500", ...). */ toast: string; toastUntilMs: number; @@ -331,15 +322,12 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { rolloverLit: ROLLOVERS.map(() => false), rolloverInside: ROLLOVERS.map(() => false), bumperFlashUntilMs: BUMPERS.map(() => 0), - tiltHeat: 0, - tilted: false, - nudgeSign: 1, toast: "", toastUntilMs: 0, tickTimer: null, lastTickAtMs: 0, lastMinorSfxAtMs: 0, - soundOn: true, + soundOn: loadSoundEnabled("pinball"), lastSubmittedFingerprint: "", }; windows.set(message.windowId, window); @@ -385,6 +373,19 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { if (window.foreground) renderAndSubmit(window, 0); break; } + case "input-focus": { + const window = windows.get(message.windowId); + if (!window) break; + // Anything that takes input away (the system menu, a notification + // modal, the voice dialog, focus back to the sidebar) pauses: the + // ball must not drain under a menu the player can't flip through. + if (!message.focused && window.phase === "playing") { + window.phase = "paused"; + syncTickTimer(window); + if (window.foreground) renderAndSubmit(window, 0); + } + break; + } case "screen": screenOn = message.on; for (const window of windows.values()) { @@ -446,7 +447,7 @@ function playSfx(window: PinballWindow, steps: Step[], minor = false): void { } } -/** The window's context menu (game actions), offered while paused or over; playing keeps long-press for the nudge. */ +/** The window's context menu (game actions), offered while paused or over. */ function windowMenuItems(window: PinballWindow): MenuItem[] { return [ { @@ -462,6 +463,7 @@ function windowMenuItems(window: PinballWindow): MenuItem[] { onSelect: (ctx) => { ctx.stack.pop(); window.soundOn = !window.soundOn; + saveSoundEnabled("pinball", window.soundOn); if (window.soundOn) playSfx(window, SFX_RESUME); }, }, @@ -475,7 +477,6 @@ function windowMenu(window: PinballWindow): WindowMenu { post, title: () => window.title, items: () => (window.phase === "playing" ? [] : windowMenuItems(window)), - claimsLongPress: () => window.phase === "playing", size: { width: window.viewportWidth, height: window.viewportHeight }, paintBase: () => paintContent(window), isFocused: () => window.focused, @@ -519,8 +520,8 @@ function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: n flip(window, window.flippers[1]!); } break; - // Watch swipes: left/right work the matching flipper; up nudges the - // table (or raises launch power at the plunger), down lowers it. + // Watch swipes: left/right work the matching flipper; up/down set the + // launch power at the plunger. case "swipe-left": if (!ready) flip(window, window.flippers[0]!); break; @@ -530,8 +531,6 @@ function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: n case "swipe-up": if (ready) { window.launchPower = clamp(window.launchPower + 1, 1, LAUNCH_SPEEDS.length); - } else { - nudge(window); } break; case "swipe-down": @@ -547,13 +546,6 @@ function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: n flip(window, window.flippers[1]!); } break; - case "long-press": - if (ready) { - frameTimings.finishFrame(frameId, "discarded: pinball ignored input"); - return; - } - nudge(window); - break; case "short-then-long-press": // No context menu mid-game, so this opens the system menu instead. windowMenu(window).open(); @@ -606,8 +598,6 @@ function resetGame(window: PinballWindow): void { window.score = 0; window.rolloverLit = ROLLOVERS.map(() => false); window.rolloverInside = ROLLOVERS.map(() => false); - window.tiltHeat = 0; - window.tilted = false; window.toast = ""; window.toastUntilMs = 0; for (const flipper of window.flippers) { @@ -628,7 +618,6 @@ function launchBall(window: PinballWindow): void { } function flip(window: PinballWindow, flipper: Flipper): void { - if (window.tilted) return; if (flipper.state === "hold") { flipper.holdUntilMs = Date.now() + FLIPPER_HOLD_MS; return; @@ -637,25 +626,8 @@ function flip(window: PinballWindow, flipper: Flipper): void { playSfx(window, SFX_FLIPPER, true); } -function nudge(window: PinballWindow): void { - if (window.tilted) return; - window.ballVy -= NUDGE_KICK_UP; - window.ballVx += window.nudgeSign * NUDGE_KICK_SIDE; - window.nudgeSign = window.nudgeSign === 1 ? -1 : 1; - window.tiltHeat += 1; - if (window.tiltHeat >= TILT_LIMIT) { - window.tilted = true; - showToast(window, "TILT"); - // A tilt drops the flippers dead until the ball drains. - for (const flipper of window.flippers) { - if (flipper.state !== "rest") flipper.state = "falling"; - } - playSfx(window, SFX_TILT); - } -} - function addScore(window: PinballWindow, points: number): void { - if (!window.tilted) window.score += points; + window.score += points; } function showToast(window: PinballWindow, text: string, ms = 1100): void { @@ -710,7 +682,6 @@ function tick(window: PinballWindow): void { function stepPhysics(window: PinballWindow): void { const dt = PHYSICS_DT; stepFlippers(window, dt); - window.tiltHeat = Math.max(0, window.tiltHeat - TILT_HEAT_DECAY_PER_S * dt); if (window.ballState !== "live") return; window.ballVy += GRAVITY * dt; @@ -894,8 +865,6 @@ function ballDrained(window: PinballWindow): void { window.ballVx = 0; window.ballVy = 0; window.trail = []; - window.tilted = false; - window.tiltHeat = 0; window.ballsLeft--; if (window.ballsLeft <= 0) { window.phase = "game-over"; @@ -1007,9 +976,6 @@ function paintContent(window: PinballWindow): GrayImage { if (window.toastUntilMs > now && window.toast) { drawCenteredIn(image, mediumFont, LEFT, LANE_X - LEFT, 150, window.toast, 245); } - if (window.tilted) { - drawCenteredIn(image, mediumFont, LEFT, LANE_X - LEFT, 60, "TILT", 245); - } if (window.phase === "paused") { paintDialog(image, "PAUSED", [`${GESTURE_CLICK} resume`, `${GESTURE_DOUBLE_CLICK} leave`]); } else if (window.phase === "game-over") { @@ -1050,7 +1016,7 @@ function paintPanel(image: GrayImage, window: PinballWindow): void { image.drawText(smallFont, PANEL_X, 236, `${GESTURE_DOUBLE_CLICK} pause`, 115); } else { image.drawText(smallFont, PANEL_X, 216, `${GESTURE_CLICK} flip ${GESTURE_SCROLL} L/R flip`, 115); - image.drawText(smallFont, PANEL_X, 236, `${GESTURE_LONG_PRESS} nudge ${GESTURE_DOUBLE_CLICK} pause`, 115); + image.drawText(smallFont, PANEL_X, 236, `${GESTURE_DOUBLE_CLICK} pause`, 115); } } diff --git a/app/apps/terminal/session-list.ts b/app/apps/terminal/session-list.ts new file mode 100644 index 00000000..fec37741 --- /dev/null +++ b/app/apps/terminal/session-list.ts @@ -0,0 +1,100 @@ +/** + * The terminal session list as it is drawn in two places: the Terminal app's + * hub window (in the worker) and the Glanceboard's Terminal widget (on the + * main thread). The worker publishes a snapshot of the list through the + * host's worker-state channel; both painters use drawSessionRow so a row + * looks the same in each. + * + * No NativeScript imports: this module is bundled into the worker as well. + */ +import { type GrayImage, type UiFont } from "../../graphics/image"; +import { truncateText } from "../../graphics/textwrap"; + +/** Worker-state key the Terminal worker publishes its snapshot under. */ +export const TERMINAL_SESSIONS_STATE_KEY = "terminal:sessions"; + +/** Alternation period of the activity indicator, shared by hub rows, the widget and sidebar cursors. */ +export const SESSION_ACTIVITY_STEP_MS = 800; + +export type TerminalSessionRow = { + /** Connection-scoped identity (connection id + socket). */ + key: string; + label: string; + /** Local-clock time (Date.now() domain) until which the session counts as active; 0 = idle. */ + activeUntilMs: number; + /** Sidebar glyph ("1", "2", ...) of the view window showing this session, or null when none is open. */ + openGlyph: string | null; +}; + +export type TerminalHostGroup = { + /** Host name, shown as a heading when more than one host is connected. */ + name: string; + sessions: TerminalSessionRow[]; +}; + +export type TerminalSessionsSnapshot = { + /** Connected hosts, each with its live sessions most-recently-updated first. */ + hosts: TerminalHostGroup[]; + /** The hub's status line ("Connecting...", "No connections configured.", ...). */ + status: string; + /** Whether any g2mirror connection is configured at all. */ + configured: boolean; +}; + +/** Whether a row's activity indicator should show right now. */ +export function isSessionRowActive(row: TerminalSessionRow, nowMs = Date.now()): boolean { + return row.activeUntilMs > nowMs; +} + +/** Width of the window-number column (one glyph plus breathing room). */ +export function sessionGlyphColumnWidth(font: UiFont): number { + return font.measureText("W") + 6; +} + +/** Left edge of the label in a row whose activity gutter starts at `x`. */ +export function sessionLabelX(font: UiFont, x: number): number { + return x + SESSION_INDICATOR_SIZE + 4 + sessionGlyphColumnWidth(font); +} + +const SESSION_INDICATOR_SIZE = 6; + +/** + * One session row: the activity indicator in the gutter at `x` (a small + * square, filled on even animation phases and outlined on odd ones, drawn as + * shapes rather than a font glyph so both states read in every UI font), + * then the open view window's glyph in its own column, then the label, + * truncated (never wrapped) to fit `width`. + */ +export function drawSessionRow( + image: GrayImage, + font: UiFont, + options: { + x: number; + /** Top of the text line. */ + y: number; + /** Horizontal room from `x`, label included. */ + width: number; + label: string; + openGlyph: string | null; + active: boolean; + /** Animation phase (0 = filled indicator). */ + phase: number; + /** Text brightness for the label (the glyph draws a little dimmer). */ + value: number; + }, +): void { + const { x, y, width, label, openGlyph, active, phase, value } = options; + if (active) { + const iy = y + Math.max(0, ((font.lineHeight - SESSION_INDICATOR_SIZE) / 2) | 0); + if (phase % 2 === 0) { + image.fillRect(x, iy, SESSION_INDICATOR_SIZE, SESSION_INDICATOR_SIZE, value); + } else { + image.drawRect(x, iy, SESSION_INDICATOR_SIZE, SESSION_INDICATOR_SIZE, value); + } + } + if (openGlyph) { + image.drawText(font, x + SESSION_INDICATOR_SIZE + 4, y, openGlyph, Math.max(0, value - 60)); + } + const labelX = sessionLabelX(font, x); + image.drawText(font, labelX, y, truncateText(font, label, Math.max(0, x + width - labelX)), value); +} diff --git a/app/apps/terminal/terminal-app.worker.ts b/app/apps/terminal/terminal-app.worker.ts index 8d60bdad..ac1c57ba 100644 --- a/app/apps/terminal/terminal-app.worker.ts +++ b/app/apps/terminal/terminal-app.worker.ts @@ -38,6 +38,11 @@ import { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fo import { layoutHubHeader } from "./hub-header"; import { truncateText } from "../../graphics/textwrap"; import { TERMINAL_ICON_GLYPHS, type IconActivity } from "../../graphics/icons"; +import { + drawSessionRow, + TERMINAL_SESSIONS_STATE_KEY, + type TerminalSessionsSnapshot, +} from "./session-list"; import * as frameTimings from "../../native/frame-timings"; import { getActiveDisplay } from "../../native/active-display"; import { GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures"; @@ -723,6 +728,48 @@ function renderHubWindows(): void { for (const window of windows.values()) { if (window.kind === "hub") scheduleRender(window); } + // Every change the hub repaints for is one the published list may reflect. + publishSessionsSnapshot(); +} + +let lastPublishedSnapshot = ""; + +/** + * Publish the session list for main-thread consumers (the Glanceboard's + * Terminal widget): connected hosts with their sessions most-recently-updated + * first, each with its activity deadline (local clock, so the consumer can + * expire and animate it itself) and the glyph of its open view window. Posted + * only when the JSON actually changed. + */ +function publishSessionsSnapshot(): void { + const connected = connectedControls(); + const snapshot: TerminalSessionsSnapshot = { + hosts: connected.map((control) => { + const connectionId = control.config.id; + const sessions = (control.state?.sessions ?? []) + .slice() + .sort( + (a, b) => + (sessionRecency.get(recencyKey(connectionId, b.socket)) ?? 0) - + (sessionRecency.get(recencyKey(connectionId, a.socket)) ?? 0), + ); + return { + name: connectionDisplayName(control.config), + sessions: sessions.map((session) => ({ + key: recencyKey(connectionId, session.socket), + label: sessionLabel(session), + activeUntilMs: (sessionActivity.get(recencyKey(connectionId, session.socket)) ?? -ACTIVITY_ACTIVE_MS) + ACTIVITY_ACTIVE_MS, + openGlyph: viewGlyphForSocket(connectionId, session.socket), + })), + }; + }), + status: sessionsStatusLine(), + configured: controls.size > 0, + }; + const encoded = JSON.stringify(snapshot); + if (encoded === lastPublishedSnapshot) return; + lastPublishedSnapshot = encoded; + post({ type: "publish-state", key: TERMINAL_SESSIONS_STATE_KEY, state: snapshot }); } // One animation clock for foreground hub rows and every terminal sidebar icon. @@ -1118,6 +1165,8 @@ type HubItem = { heading?: boolean; /** Session with recent output: an animated indicator marks the row. */ active?: boolean; + /** Glyph of the view window showing this session (the number column). */ + openGlyph?: string | null; onSelect?: () => void; }; @@ -1183,10 +1232,10 @@ function hubSessionItems(window: HubWindow): HubItem[] { } const sessions = orderedSessions(window, control); for (const session of sessions) { - const openWindowId = viewWindowIdForSocket(control.config.id, session.socket); items.push({ - label: openWindowId ? `${sessionLabel(session)} [open]` : sessionLabel(session), + label: sessionLabel(session), active: isSessionActive(control.config.id, session.socket), + openGlyph: viewGlyphForSocket(control.config.id, session.socket), onSelect: () => { const windowId = viewWindowIdForSocket(control.config.id, session.socket); if (windowId) { @@ -1421,6 +1470,19 @@ function handleHubInput(window: HubWindow, event: InputEvent, frameId: number): * Includes views that were requested but whose surface hasn't opened yet, so * a quick double-select can't spawn two windows for one session. */ +/** Sidebar glyph of the (open or opening) view window on a session, or null. */ +function viewGlyphForSocket(connectionId: string, socket: string): string | null { + for (const window of windows.values()) { + if (window.kind === "view" && window.connectionId === connectionId && window.socket === socket) { + return window.glyph || null; + } + } + for (const pending of pendingViews.values()) { + if (pending.connectionId === connectionId && pending.socket === socket) return pending.glyph || null; + } + return null; +} + function viewWindowIdForSocket(connectionId: string, socket: string): string | null { for (const window of windows.values()) { if (window.kind === "view" && window.connectionId === connectionId && window.socket === socket) { @@ -1539,20 +1601,18 @@ function paintHub(window: HubWindow): GrayImage { // an outline-only selection signals the sidebar owns input. drawSelectionHighlight(image, 20, y - 2, window.viewportWidth - 40, hubRowH - 1, window.focused, 8); } - image.drawText(chromeFont(), 32, y + 2, item.label, selected ? 255 : 200); - if (item.active) { - // Activity indicator in the gutter left of the label, alternating - // filled/outline each animation step (drawn shapes, not a font glyph, - // so the two states render distinctly in every UI font). - const size = 6; - const iy = y + 2 + Math.max(0, ((font.lineHeight - size) / 2) | 0); - const value = selected ? 255 : 200; - if (hubAnimationPhase === 0) { - image.fillRect(22, iy, size, size, value); - } else { - image.drawRect(22, iy, size, size, value); - } - } + // Activity gutter, open-window number column, then the label, truncated + // to the row (shared with the Glanceboard's Terminal widget). + drawSessionRow(image, chromeFont(), { + x: 22, + y: y + 2, + width: window.viewportWidth - 22 - 26, + label: item.label, + openGlyph: item.openGlyph ?? null, + active: Boolean(item.active), + phase: hubAnimationPhase, + value: selected ? 255 : 200, + }); } if (items.length > visibleRowCount) { drawListScrollbar( @@ -1595,6 +1655,11 @@ function hubStatusLine(window: HubWindow): string { if (window.mode === "connections") { return "Select a connection to connect, disconnect, or remove."; } + return sessionsStatusLine(); +} + +/** The sessions view's status line (also published with the session snapshot). */ +function sessionsStatusLine(): string { if (controls.size === 0) { return "No connections configured."; } @@ -1830,7 +1895,8 @@ function toolListSessions(): ToolResult { lines.push(`${connectionDisplayName(control.config)}:`); } for (const session of sessions) { - const open = viewWindowIdForSocket(control.config.id, session.socket) ? " [open]" : ""; + const glyph = viewGlyphForSocket(control.config.id, session.socket); + const open = glyph ? ` [open in window ${glyph}]` : viewWindowIdForSocket(control.config.id, session.socket) ? " [open]" : ""; lines.push(`- ${sessionLabel(session)}${open}`); } if (!sessions.length && multiHost) { diff --git a/app/apps/timer/timer-engine.ts b/app/apps/timer/timer-engine.ts index 61efa9c7..57bb5e88 100644 --- a/app/apps/timer/timer-engine.ts +++ b/app/apps/timer/timer-engine.ts @@ -266,6 +266,11 @@ export class TimerEngine { ); } + /** Every countdown timer (running, paused or rung), unsorted. */ + timers(): readonly CountdownTimer[] { + return this.state.timers; + } + ringingItems(): RingingItem[] { const items: RingingItem[] = []; for (const timer of this.state.timers) { diff --git a/app/apps/transcribe/transcribe.ts b/app/apps/transcribe/transcribe.ts index 8c056c52..4fa5952a 100644 --- a/app/apps/transcribe/transcribe.ts +++ b/app/apps/transcribe/transcribe.ts @@ -13,7 +13,9 @@ import { TranscriptModel, TranscriptScroll, wrapTranscribeText } from "./transcr * it, and saves it to Downloads from the app menu. */ export class TranscribeLayer implements Layer { - private status = "Listening..."; + private status = "Starting microphone..."; + private listening = false; + private detail = ""; private readonly transcript = new TranscriptModel(); private readonly scroll = new TranscriptScroll(); private saveNotice = ""; @@ -29,6 +31,8 @@ export class TranscribeLayer implements Layer { this.unsubscribePause = voiceControlBridge.onSpeechPause(() => this.transcript.pause()); this.unsubscribeStatus = voiceControlBridge.onStatus((state) => { this.status = state.status; + this.listening = state.listening; + this.detail = state.detail; this.saveNotice = ""; requestRender(); }); @@ -38,7 +42,7 @@ export class TranscribeLayer implements Layer { const font = getDefaultSmallFont(); const { width, height } = ctx.stack.getBaseSize(); const image = new GrayImage(width, height, 0); - const text = this.transcript.text || "Listening..."; + const text = this.transcript.text || (this.listening ? "Listening..." : this.detail); const wrapped = wrapTranscribeText((text) => font.measureText(text), text, width - 64); image.drawText(font, 24, 20, "Transcribe", 200); diff --git a/app/assistant/conversations.ts b/app/assistant/conversations.ts new file mode 100644 index 00000000..7e5df8f8 --- /dev/null +++ b/app/assistant/conversations.ts @@ -0,0 +1,95 @@ +import { AssistantSession, type AssistantBackendConfig, type AssistantSessionHistory } from "./session"; +import { ASSISTANT_MODEL_VALUES, type AssistantModel } from "./models"; + +export type ReasoningLevel = "default" | "low" | "medium" | "high"; +export type Conversation = { + id: string; + model: AssistantModel; + reasoning: ReasoningLevel; + session: AssistantSession | null; + history?: AssistantSessionHistory; +}; +type SavedConversation = Omit; +type SavedConversations = { selectedId: string; conversations: SavedConversation[] }; + +/** Shared selection and history for every assistant entry point. No credentials are saved. */ +export class AssistantConversations { + private records: Conversation[] = []; + private selectedId = ""; + private readonly listeners = new Set<() => void>(); + + constructor( + private readonly resolve: (model: AssistantModel, reasoning: ReasoningLevel) => AssistantBackendConfig | null, + private readonly defaultModel: () => AssistantModel, + private readonly persist: (value: string) => void, + saved = "", + ) { + try { + const data: SavedConversations = JSON.parse(saved); + if (Array.isArray(data.conversations)) { + this.records = data.conversations.filter((record) => + typeof record.id === "string" && ASSISTANT_MODEL_VALUES.includes(record.model) && + ["default", "low", "medium", "high"].includes(record.reasoning) && + Array.isArray(record.history?.messages) && Array.isArray(record.history?.transcript), + ).map((record) => ({ ...record, session: null })); + this.selectedId = data.selectedId; + } + } catch { /* First launch or invalid saved state. */ } + if (!this.records.length) this.records.push(this.makeConversation()); + if (!this.records.some((record) => record.id === this.selectedId)) this.selectedId = this.records[0]!.id; + } + + current(): Conversation { return this.records.find((record) => record.id === this.selectedId)!; } + list(): readonly Conversation[] { return this.records; } + title(record = this.current()): string { + const transcript = record.session?.transcript ?? record.history?.transcript ?? []; + return transcript.find((entry) => entry.role === "user")?.text.replace(/\s+/g, " ").slice(0, 60) || "New session"; + } + onChanged(listener: () => void): () => void { + this.listeners.add(listener); + return () => this.listeners.delete(listener); + } + private changed(save = true): void { + if (save) this.persist(JSON.stringify({ selectedId: this.selectedId, conversations: this.records.map( + ({ session, ...record }) => ({ ...record, history: session?.history() ?? record.history ?? { messages: [], transcript: [] } }), + ) })); + for (const listener of this.listeners) listener(); + } + private makeConversation(): Conversation { + return { id: `${Date.now()}-${Math.random().toString(36).slice(2)}`, model: this.defaultModel(), reasoning: "default", session: null }; + } + create(): boolean { + if (this.current().session?.isTurnActive()) return false; + const record = this.makeConversation(); + this.records.push(record); + this.selectedId = record.id; + this.changed(); + return true; + } + select(id: string): boolean { + if (this.current().session?.isTurnActive() || !this.records.some((record) => record.id === id)) return false; + this.selectedId = id; + this.changed(); + return true; + } + configure(model: AssistantModel, reasoning: ReasoningLevel): boolean { + const record = this.current(); + if (record.session?.isTurnActive() || !this.resolve(model, reasoning)) return false; + record.model = model; + record.reasoning = reasoning; + this.ensureSession(); + this.changed(); + return true; + } + available(model: AssistantModel, reasoning: ReasoningLevel): boolean { return this.resolve(model, reasoning) !== null; } + ensureSession(): AssistantSession | null { + const record = this.current(); + const config = this.resolve(record.model, record.reasoning); + if (!config) return null; + if (!record.session) { + record.session = new AssistantSession(config, undefined, record.history); + record.session.onChanged(() => this.changed(!record.session!.isTurnActive())); + } else record.session.configure(config); + return record.session; + } +} diff --git a/app/assistant/direct-backend.ts b/app/assistant/direct-backend.ts index 12e5cbbc..451abdf6 100644 --- a/app/assistant/direct-backend.ts +++ b/app/assistant/direct-backend.ts @@ -50,6 +50,7 @@ export class DirectAssistantBackend { const startMs = Date.now(); let cancelled = false; let streamHandle: LlmStreamHandle | null = null; + let priorText = ""; const finishError = (message: string) => { if (cancelled) return; @@ -78,7 +79,7 @@ export class DirectAssistantBackend { tools: options.buildTools(), onTextDelta: (delta, textSoFar) => { if (cancelled) return; - options.callbacks.onTextDelta(delta, textSoFar); + options.callbacks.onTextDelta(delta, priorText + textSoFar); }, onDone: (result) => { streamHandle = null; @@ -87,6 +88,9 @@ export class DirectAssistantBackend { finishError("The assistant declined this request"); return; } + const fullText = priorText + result.text; + options.callbacks.onTextDelta("", fullText); + priorText = fullText ? `${fullText}\n\n` : ""; // Record what the model produced this iteration. const assistantContent: LlmContentBlock[] = result.content.length ? result.content diff --git a/app/assistant/session.ts b/app/assistant/session.ts index 604095a9..69a915fc 100644 --- a/app/assistant/session.ts +++ b/app/assistant/session.ts @@ -15,26 +15,20 @@ import type { AssistantTurnHandle, } from "./types"; -/** - * One assistant conversation. Owns the message history and turn state and - * drives either the on-phone provider loop (direct) or the external agent - * bridge. The UI talks only to this surface, so AssistantLayer is - * backend-agnostic. - * - * Sessions are cheap and idle-expire (see isExpired): the shell starts a fresh - * one for a new wakeword and reuses the current one for a follow-up. In - * external mode the conversation history lives on the agent's machine (one - * long-lived session there), so expiry here only affects the overlay UI. - */ +/** One shared conversation, independent of the voice overlay or chat window. */ +export type AssistantTranscriptEntry = { role: "user" | "assistant"; text: string }; +export type AssistantSessionHistory = { + messages: LlmMessage[]; + transcript: AssistantTranscriptEntry[]; + /** Model identity for safe replay after Auto resolves differently on restart. */ + engine?: string; +}; /** Which engine answers utterances, plus what it needs to do so. */ export type AssistantBackendConfig = | { kind: "direct"; llm: ResolvedAssistantModel } | { kind: "external"; bridge: AssistantBridgeConfig }; -/** A new PTT after this much idle starts a fresh conversation. */ -const SESSION_IDLE_MS = 10 * 60 * 1000; - /** Trim history from the head once it grows past this many messages. */ const MAX_HISTORY_MESSAGES = 40; @@ -42,38 +36,61 @@ export class AssistantSession { private readonly directBackend = new DirectAssistantBackend(); private readonly messages: LlmMessage[] = []; private turnHandle: AssistantTurnHandle | null = null; - private lastActivityMs = Date.now(); + readonly transcript: AssistantTranscriptEntry[] = []; + status = ""; + private readonly listeners = new Set<() => void>(); + private turnGeneration = 0; // API-safe tool name -> canonical registry name. Provider APIs restrict tool // names, so dotted registry names are sanitized and mapped back on calls. private readonly toolNameMap = new Map(); constructor( - private readonly config: AssistantBackendConfig, + private config: AssistantBackendConfig, private readonly registry: ToolRegistry = toolRegistry, - ) {} - - matchesConfiguration(config: AssistantBackendConfig): boolean { - if (this.config.kind !== config.kind) return false; - if (this.config.kind === "direct" && config.kind === "direct") { - return ( - this.config.llm.provider === config.llm.provider && - this.config.llm.model === config.llm.model && - this.config.llm.apiKey === config.llm.apiKey - ); + history?: AssistantSessionHistory, + ) { + if (history) { + this.messages.push(...history.messages); + this.transcript.push(...history.transcript); + if (history.engine !== this.engine()) this.rebuildTextHistory(); } - if (this.config.kind === "external" && config.kind === "external") { - return ( - this.config.bridge.host === config.bridge.host && - this.config.bridge.port === config.bridge.port && - this.config.bridge.token === config.bridge.token - ); - } - return false; } - /** Whether this session has been idle long enough to retire. */ - isExpired(nowMs = Date.now()): boolean { - return nowMs - this.lastActivityMs > SESSION_IDLE_MS; + onChanged(listener: () => void): () => void { + this.listeners.add(listener); + return () => this.listeners.delete(listener); + } + + private changed(): void { + for (const listener of this.listeners) { + try { listener(); } catch (error) { console.warn("assistant history listener failed", error); } + } + } + + history(): AssistantSessionHistory { + return { messages: this.messages, transcript: this.transcript, engine: this.engine() }; + } + + configure(config: AssistantBackendConfig): void { + if (this.isTurnActive()) return; + // Opaque reasoning/tool provider items are only replayable on their + // original model. Preserve visible conversation when switching engines. + if (this.config.kind !== config.kind || + (this.config.kind === "direct" && config.kind === "direct" && + (this.config.llm.model !== config.llm.model || this.config.llm.provider !== config.llm.provider))) { + this.rebuildTextHistory(); + } + this.config = config; + } + + private engine(): string { + return this.config.kind === "direct" ? `${this.config.llm.provider}:${this.config.llm.model}` : "external"; + } + + private rebuildTextHistory(): void { + this.messages.splice(0, this.messages.length, ...this.transcript + .filter((entry) => entry.text.trim()) + .map((entry) => ({ role: entry.role, content: entry.text }))); } isTurnActive(): boolean { @@ -86,20 +103,44 @@ export class AssistantSession { callbacks.onError("The assistant is still working on the previous request"); return; } - this.lastActivityMs = Date.now(); + text = text.trim(); + if (!text) return; + const generation = ++this.turnGeneration; + const reply: AssistantTranscriptEntry = { role: "assistant", text: "" }; + this.transcript.push({ role: "user", text }, reply); + this.status = "Thinking..."; + // Install a sentinel before calling providers: some failures are synchronous. + this.turnHandle = { cancel: () => {} }; + this.changed(); const finish = () => { + ++this.turnGeneration; this.turnHandle = null; - this.lastActivityMs = Date.now(); + this.changed(); }; const wrappedCallbacks: AssistantTurnCallbacks = { - onTextDelta: callbacks.onTextDelta, - onToolActivity: callbacks.onToolActivity, + onTextDelta: (delta, full) => { + if (generation !== this.turnGeneration) return; + reply.text = full; + this.status = "Thinking..."; + this.changed(); + callbacks.onTextDelta(delta, full); + }, + onToolActivity: (label) => { + if (generation !== this.turnGeneration) return; + this.status = `→ ${label}`; + this.changed(); + callbacks.onToolActivity(label); + }, onTurnDone: (result) => { + if (generation !== this.turnGeneration) return; + this.status = ""; finish(); callbacks.onTurnDone(result); }, onError: (message) => { + if (generation !== this.turnGeneration) return; + this.status = message; finish(); callbacks.onError(message); }, @@ -108,7 +149,8 @@ export class AssistantSession { if (this.config.kind === "external") { // History and the agent loop live on the agent's machine; the phone just // streams this turn. The overlay keeps its own display state. - this.turnHandle = assistantBridge.sendUtterance(text, ctx, wrappedCallbacks); + const handle = assistantBridge.sendUtterance(text, ctx, wrappedCallbacks); + if (generation === this.turnGeneration && this.turnHandle) this.turnHandle = handle; return; } @@ -123,24 +165,48 @@ export class AssistantSession { content: isLocal ? `${text}\n\n(${describeAssistantContext(ctx)})` : text, }); this.trimHistory(); - this.turnHandle = this.directBackend.runTurn({ + // Work on a turn-local array: cancelled tools may finish later, and must + // never append orphan results into a subsequent turn's context. + const turnMessages = this.messages.slice(); + const handle = this.directBackend.runTurn({ provider: llm.provider, apiKey: llm.apiKey, model: llm.model, effort: llm.effort, system: isLocal ? ASSISTANT_SYSTEM_PROMPT_BASE : buildAssistantSystemPrompt(ctx), - messages: this.messages, + messages: turnMessages, buildTools: () => this.buildToolDefinitions(), registry: this.registry, resolveToolName: (apiName) => this.toolNameMap.get(apiName) ?? apiName, - callbacks: wrappedCallbacks, + callbacks: { + ...wrappedCallbacks, + onTurnDone: (result) => { + if (generation !== this.turnGeneration) return; + this.messages.splice(0, this.messages.length, ...turnMessages); + wrappedCallbacks.onTurnDone(result); + }, + onError: (message) => { + if (generation !== this.turnGeneration) return; + // Retain the visible partial answer, without incomplete tool pairs. + if (reply.text) this.messages.push({ role: "assistant", content: reply.text }); + wrappedCallbacks.onError(message); + }, + }, }); + if (generation === this.turnGeneration && this.turnHandle) this.turnHandle = handle; } cancel(): void { - this.turnHandle?.cancel(); + if (!this.turnHandle) return; + ++this.turnGeneration; + this.turnHandle.cancel(); this.turnHandle = null; - this.lastActivityMs = Date.now(); + const reply = this.transcript[this.transcript.length - 1]; + if (reply?.role === "assistant" && reply.text) { + this.messages.push({ role: "assistant", content: reply.text }); + } + this.status = "Cancelled"; + this.changed(); } private buildToolDefinitions(): LlmToolDefinition[] { diff --git a/app/g2/ble-image-optimizer.ts b/app/g2/ble-image-optimizer.ts index 46948a67..b874b53a 100644 --- a/app/g2/ble-image-optimizer.ts +++ b/app/g2/ble-image-optimizer.ts @@ -2,10 +2,10 @@ import { concat, rle4 } from './ble-protocol' /** Android BleImageOptimizer's mode-3 changed rectangle. Coordinates are in * units of 4 columns / 2 rows; pixels are top-down packed 4bpp, high nibble first. - * null means identical, incomparable, or a full-screen box: use dedup/mode 6. + * null means identical, incomparable, or a full-screen box: use dedup/mode 6. Compression belongs to the CFW transport. */ export function buildBoundingBoxPayload(previous: Uint8Array | null, next: Uint8Array, - width: number, height: number, frameId: number, deflate: (data: Uint8Array) => Uint8Array): Uint8Array | null { + width: number, height: number, frameId: number): Uint8Array | null { if (!Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0 || width % 4 || height % 2 || width / 4 > 255 || height / 2 > 255 || !previous || previous.length !== width * height / 2 || next.length !== previous.length) return null @@ -30,5 +30,20 @@ export function buildBoundingBoxPayload(previous: Uint8Array | null, next: Uint8 region.set(next.subarray(start, start + regionStride), y * regionStride) } return concat(new Uint8Array([3, left / 4, top / 2, boxWidth / 4, boxHeight / 2, - frameId & 255, (frameId >>> 8) & 255]), deflate(rle4(region))) + frameId & 255, (frameId >>> 8) & 255]), rle4(region)) +} + +/** Full repaint as independent 64-row mode-3 bands when RLE exceeds uint16. */ +export function buildFullFrameBands(packed: Uint8Array, width: number, height: number, firstId: number): Uint8Array[] { + if (width <= 0 || width > 640 || width % 4 || height <= 0 || height > 480 || height % 2 || packed.length !== width * height / 2) + throw new Error('Invalid framebuffer dimensions') + const bands: Uint8Array[] = [] + let id = firstId + for (let top = 0; top < height; top += 64) { + const rows = Math.min(64, height - top) + bands.push(concat(new Uint8Array([3, 0, top / 2, width / 4, rows / 2, id & 255, id >>> 8]), + rle4(packed.subarray(top * width / 2, (top + rows) * width / 2)))) + id = id >= 0xfffe ? 1 : id + 1 + } + return bands } diff --git a/app/g2/ble-protocol.ts b/app/g2/ble-protocol.ts index 4465ea9e..201ca280 100644 --- a/app/g2/ble-protocol.ts +++ b/app/g2/ble-protocol.ts @@ -3,7 +3,7 @@ export const G2_WRITE = '00002760-08c2-11e1-9073-0e8ac72e5401' export const G2_NOTIFY = '00002760-08c2-11e1-9073-0e8ac72e5402' export const G2_RENDER_NOTIFY = '00002760-08c2-11e1-9073-0e8ac72e6402' export const RING_NOTIFY = ['bae80011-4f05-4503-8e65-3af1f7329d1f', 'bae80013-4f05-4503-8e65-3af1f7329d1f'] -export const SID = { auth: 0x80, launch: 1, hub: 0xe0, settings: 9 } as const +export const SID = { auth: 0x80, launch: 1, hub: 0xe0, settings: 9, cfw: 0xf0 } as const export function concat(...parts: Uint8Array[]): Uint8Array { const output = new Uint8Array(parts.reduce((n, p) => n + p.length, 0)) let offset = 0; for (const part of parts) { output.set(part, offset); offset += part.length }; return output @@ -28,13 +28,7 @@ export const framebufferLease = (acquire: boolean) => concat(integer(1, 1), inte export function createLayout(magic: number): Uint8Array { const geometry = concat(integer(1, 0), integer(2, 0), integer(3, 576), integer(4, 288)) const text = concat(geometry, integer(9, 1), string(10, 'dashboard'), integer(11, 1), string(12, ' ')) - const image = concat(geometry, integer(5, 10), string(6, 'img00')) - return wrap(0, magic, 3, concat(integer(1, 2), bytes(3, text), bytes(4, image), integer(5, 10000))) -} -export function imageFragment(magic: number, payload: Uint8Array, offset: number, size = 3800): Uint8Array { - const fragment = payload.subarray(offset, offset + size) - return wrap(3, magic, 5, concat(integer(1, 10), string(2, 'img00'), integer(3, 10), integer(4, payload.length), - integer(5, 0), integer(6, Math.floor(offset / size)), integer(7, fragment.length), bytes(8, fragment))) + return wrap(0, magic, 3, concat(integer(1, 1), bytes(3, text), integer(5, 10000))) } export function crc16(data: Uint8Array): number { let crc = 0xffff @@ -55,7 +49,7 @@ export function frameMessage(payload: Uint8Array, sid: number, flag: number, seq return concat(new Uint8Array([0xaa, 0x21, sequence & 255, chunk.length, count, i + 1, sid, flag]), chunk) }) } -export type ProtocolMessage = { sid: number; flag: number; payload: Uint8Array; command: number; magic: number } +export type ProtocolMessage = { sid: number; flag: number; payload: Uint8Array; command: number; magic: number; packet?: Uint8Array } /** Handles split/coalesced envelopes and reassembles each link/sequence separately. */ export class MessageReceiver { private streams = new Map() @@ -70,7 +64,12 @@ export class MessageReceiver { const length = stream[3], count = stream[4], index = stream[5] if (stream.length < length + 8) break const sid = stream[6], flag = stream[7], key = `${link}:${stream[2]}:${sid}:${flag}` + const packet = stream.slice(0, length + 8) const chunk = stream.slice(8, 8 + length); stream = stream.subarray(length + 8) + if (sid === SID.cfw) { + output.push({ sid, flag, payload: chunk, command: -1, magic: -1, packet }) + continue + } if (!count || !index || index > count) { this.messages.delete(key); continue } if (index === 1) this.messages.set(key, { chunks: [], total: count, seen: now, size: 0 }) const message = this.messages.get(key) diff --git a/app/g2/cfw-transport.ts b/app/g2/cfw-transport.ts new file mode 100644 index 00000000..922e0c20 --- /dev/null +++ b/app/g2/cfw-transport.ts @@ -0,0 +1,56 @@ +import { concat, crc16, SID } from './ble-protocol' + +declare const require: (name: string) => any +export const CFW_MAX_MESSAGE = 65535 +export type CfwAck = { nack: boolean; streamId: number; messageId: number; lens: number; size: number; checksum: number } +const u16 = (data: Uint8Array, offset: number) => data[offset] | (data[offset + 1] << 8) + +/** Matches Android CfwTransport. maxWrite is the ATT value limit (MTU - 3). */ +export class CfwTransport { + private compressor: any + private resetPending = true + private lenses = 0 + reset(): void { this.compressor = null; this.resetPending = true; this.lenses = 0 } + encode(message: Uint8Array, streamId: number, lenses: number, maxWrite: number): Uint8Array[] { + if (message.length > CFW_MAX_MESSAGE || !Number.isInteger(streamId) || streamId < 0 || streamId > 255 || + ![1, 2, 3].includes(lenses) || !Number.isInteger(maxWrite) || maxWrite < 20 || maxWrite > 514) + throw new Error('Invalid CFW stream parameters') + if (this.lenses !== lenses) this.reset() + if (!this.compressor) this.compressor = new (require('pako').Deflate)() + const chunks: Uint8Array[] = [] + // SYNC_FLUSH emits this record while retaining history for the next one. + this.compressor.onData = (chunk: Uint8Array) => chunks.push(chunk.slice()) + if (!this.compressor.push(message, 2)) throw new Error(this.compressor.msg || 'CFW compression failed') + let body = concat(...chunks), flags = lenses | 4 | (this.resetPending ? 8 : 0) + if (!body.length) flags &= ~4 + if (body.length > CFW_MAX_MESSAGE) { + this.reset(); body = message; flags = lenses | 8 + } else { this.resetPending = false; this.lenses = lenses } + const checksum = crc16(message) + const record = concat(new Uint8Array([flags, body.length & 255, body.length >>> 8, checksum & 255, checksum >>> 8]), body) + const capacity = Math.min(252, maxWrite - 11), packets: Uint8Array[] = [] + for (let offset = 0, index = 0; offset < record.length; offset += capacity, index++) { + const body = concat(new Uint8Array([lenses | (offset === 0 ? 0x80 : 0) | + (offset + capacity >= record.length ? 0x40 : 0)]), record.subarray(offset, offset + capacity)) + const crc = crc16(body) + packets.push(concat(new Uint8Array([0xaa, 0x21, (streamId + index) & 255, body.length + 2, 1, 1, SID.cfw, 0]), + body, new Uint8Array([crc & 255, crc >>> 8]))) + } + return packets + } +} + +/** Validate the entire primary + redundant-ACK packet before applying any ACK. */ +export function parseCfwAcks(packet: Uint8Array): CfwAck[] | null { + const n = packet.length + if (n < 19 || n > 40 || (n - 19) % 7 || packet[0] !== 0xaa || packet[1] !== 0x12 || + packet[3] !== n - 8 || packet[4] !== 1 || packet[5] !== 1 || packet[6] !== SID.cfw || packet[7] !== 0 || + ![1, 3].includes(packet[8]) || ![1, 2].includes(packet[12]) || (packet[8] === 3 && n !== 19) || + crc16(packet.subarray(8, -2)) !== u16(packet, n - 2)) return null + const acks = [{ nack: packet[8] === 3, streamId: packet[9], messageId: u16(packet, 10), + lens: packet[12], size: u16(packet, 13), checksum: u16(packet, 15) }] + for (let offset = 17; offset < n - 2; offset += 7) + acks.push({ nack: false, streamId: packet[offset], messageId: u16(packet, offset + 1), lens: packet[12], + size: u16(packet, offset + 3), checksum: u16(packet, offset + 5) }) + return acks +} diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index adb0c7ca..a70a7c55 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -16,7 +16,7 @@ import { ALL_NOTIFICATIONS, onAndroidNotificationPosted, readActiveNotifications import { shouldShowNotificationOnGlasses } from "../native/notification-sources"; import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict"; import { grayImageToPreviewSource } from "../native/gray-image-preview"; -import { firmwareIncompatibilityMessage } from "./firmware-compat"; +import { firmwareIncompatibilityMessage, hasCompatibleFirmware } from "./firmware-compat"; import { hasExtractedEvenHubFonts } from "./firmware-builder"; import { resumeAutoReconnect, suppressAutoReconnect } from "./reconnect-policy"; import { WearRemote, type WearRemoteInputKind } from "./wear-remote"; @@ -43,6 +43,8 @@ const MIRROR_TOUCH_GESTURES: Record, WearRemoteI "swipe-right": "swipe-right", }; import { findSoundEffect, playSoundEffect } from "../ui/sound-effects"; +import { GlanceHost } from "./glance-host"; +import { type GlanceEvent } from "./glance-state"; import { isWelcomeSoundPending, setWelcomeSoundPending } from "../phone-ui/onboarding-state"; import { beginRenderPass, endRenderPass } from "../util/render-freshness"; import { voiceControlBridge } from "../native/voice-control"; @@ -52,6 +54,7 @@ import { prepareFrameDraws } from "../graphics/glyph-wire"; import { getDefaultMediumFont } from "../graphics/ui-fonts"; import { wrapText } from "../graphics/textwrap"; import { rawInputEventToInputEvent, shell, type ShellInputOutcome } from "../ui/shell/shell"; +import { type InputEvent } from "../ui/gestures"; import { registerSystemTools } from "../assistant/system-tools"; import { updateGlassesPresence } from "./glasses-presence"; import { timerEngine } from "../apps/timer/timer-engine"; @@ -252,10 +255,30 @@ class DashboardController { private screenTimeoutTimer: ReturnType | null = null; private evenHubSuspendTimer: ReturnType | null = null; private evenHubSessionSuspended = false; + /** + * The Glanceboard: the alternate sleep-time display, on its own surface + * above the shell. Fed sleep-time input from handleInputEvent; it uses the + * same wake barrier as the shell and hands the compositor back to the + * screen-off path when it hides. + */ + private readonly glance = new GlanceHost({ + getDisplay: () => this.display, + getProvider: () => ALL_APPS.find((app) => app.glanceboard)?.glanceboard ?? null, + canShow: () => (this.phase === "connected" || this.isPreviewDisplayActive()) && !this.glassesLocked, + ensureSessionActive: (frameId) => this.ensureEvenHubSessionActive(frameId), + onHiddenWhileAsleep: () => { + if (!shell.isScreenOn()) this.handleScreenStateChanged(false); + }, + onVisibilityChanged: () => { + this.schedulePreviewUpdate(); + this.emit(); + }, + appendLog: (message) => this.appendLog(message), + }); private evenHubResumePromise: Promise | null = null; - private faceclawWakeLeaseSupported = false; + /** Faceclaw's firmware at the required revision reported in; its extensions can be used. */ + private customFirmwareConfirmed = false; private faceclawWakeLeaseState: boolean | null = null; - private wearNotifySupported = false; private glassesWorn: boolean | null = null; private phoneLocked = false; private glassesLocked = false; @@ -319,7 +342,7 @@ class DashboardController { toggle?: TextSettingsEditToggle, ) => this.startTextSettingsEdit(settings, title, onFinish, toggle), endTextSettingEdit: () => this.endTextSettingEdit(), - startVoiceCapture: () => this.startVoiceCapture(), + startVoiceCapture: (endpointing = false) => this.startVoiceCapture(endpointing), stopVoiceCapture: () => this.stopVoiceCapture(), startContinuousVoiceCapture: () => this.startContinuousVoiceCapture(), stopContinuousVoiceCapture: () => this.stopContinuousVoiceCapture(), @@ -359,6 +382,8 @@ class DashboardController { this.emit(); }, onScreenStateChanged: (on) => { + // Any wake of the regular UI replaces a showing Glanceboard. + if (on) this.glance.dismiss(); this.handleScreenStateChanged(on); if (on) this.requestShellRender(); this.emit(); @@ -631,7 +656,7 @@ class DashboardController { const communicator = this.communicator; if ( !lockScreenEnabledSetting.get() || - !this.wearNotifySupported || + !this.customFirmwareConfirmed || this.phase !== "connected" || !communicator ) { @@ -736,7 +761,7 @@ class DashboardController { // foreground app when Faceclaw handles the glasses wakeword. Without the // latter, Even AI displaces EvenHub before our first wake frame can ACK. return ( - this.faceclawWakeLeaseSupported && + this.customFirmwareConfirmed && (suspendEvenHubWhenScreenOffSetting.get() || wakeWordActionSetting.get() !== "off") ); } @@ -788,6 +813,7 @@ class DashboardController { if ( !suspendEvenHubWhenScreenOffSetting.get() || shell.isScreenOn() || + this.glance.isVisible() || this.phase !== "connected" || !this.communicator || this.evenHubSessionSuspended @@ -801,9 +827,11 @@ class DashboardController { if ( !suspendEvenHubWhenScreenOffSetting.get() || shell.isScreenOn() || + this.glance.isVisible() || this.phase !== "connected" || this.communicator !== communicator ) { + // A showing Glanceboard re-arms this when it hides. return; } @@ -816,7 +844,7 @@ class DashboardController { } void (async () => { - if (this.faceclawWakeLeaseSupported) { + if (this.customFirmwareConfirmed) { // Refresh immediately before teardown so the first suspended wake // cannot race an old lease's expiry. const leaseReady = await this.syncFaceclawWakeLease(communicator, true); @@ -829,6 +857,7 @@ class DashboardController { if ( !suspendEvenHubWhenScreenOffSetting.get() || shell.isScreenOn() || + this.glance.isVisible() || this.phase !== "connected" || this.communicator !== communicator ) { @@ -1250,6 +1279,7 @@ class DashboardController { const target = this.previewTarget; if (!target) return; this.previewTarget = null; + this.glance.reset(); target.release(); this.clearDashboardTimer(); this.appendLog("Preview-only display released."); @@ -1291,10 +1321,10 @@ class DashboardController { ); let communicator: FaceclawCommunicatorBridge | null = null; - this.faceclawWakeLeaseSupported = false; + this.customFirmwareConfirmed = false; this.faceclawWakeLeaseState = null; - this.wearNotifySupported = false; this.lockSurfaceConfigured = false; + this.glance.reset(); this.evenHubResumePromise = null; this.connectRunning = true; @@ -1390,9 +1420,14 @@ class DashboardController { // especially while the glasses remain reachable in their case. const hasBatteryLevel = Number.isInteger(state.battery) && state.battery >= 0 && state.battery <= 100; if (hasBatteryLevel) this.lastHeadsetBattery = state.battery; + const ringBattery = state.ringBattery; + const hasRingBattery = typeof ringBattery === "number" && Number.isInteger(ringBattery) + && ringBattery >= 0 && ringBattery <= 100; shell.setBatteryLevels({ headset: hasBatteryLevel ? state.battery : this.lastHeadsetBattery, headsetCharging: state.chargingStatus > 0, + ring: hasRingBattery ? ringBattery : null, + ringCharging: hasRingBattery ? state.ringChargingStatus === 1 : null, }); updateGlassesPresence({ charging: state.chargingStatus > 0 || this.phase === "charging" }); if ((this.phase === "connected" || this.phase === "charging") && this.communicator) { @@ -1436,26 +1471,18 @@ class DashboardController { this.offFirmwareInfo = communicator.onFirmwareInfo((info) => { this.appendLog( `firmware: L=${info.leftVersion || "?"} R=${info.rightVersion || "?"}` + - (info.capabilities ? ` caps="${info.capabilities}"` : " (no CFW capability string)"), + (info.extension ? ` ext="${info.extension}"` : " (no firmware extension string)"), ); const warning = firmwareIncompatibilityMessage(info) ?? ""; - const wakeLeaseSupported = info.capabilities - .trim() - .split(/\s+/) - .includes("wakelease"); - const wearNotifySupported = info.capabilities - .trim() - .split(/\s+/) - .includes("wearnotify"); - if (wakeLeaseSupported !== this.faceclawWakeLeaseSupported) { - this.faceclawWakeLeaseSupported = wakeLeaseSupported; + // The firmware contract is all-or-nothing: a compatible revision has + // every extension (wake lease, wear notifications, ...) we use. + const customFirmwareConfirmed = !warning && hasCompatibleFirmware(info); + if (customFirmwareConfirmed !== this.customFirmwareConfirmed) { + this.customFirmwareConfirmed = customFirmwareConfirmed; this.faceclawWakeLeaseState = null; void this.syncFaceclawWakeLease().catch((error) => { this.appendLog(`wake takeover lease sync failed: ${this.formatError(error)}`); }); - } - if (wearNotifySupported !== this.wearNotifySupported) { - this.wearNotifySupported = wearNotifySupported; this.ensureWearStateTracking(); } if (warning !== this.firmwareWarningMessage) { @@ -1553,8 +1580,8 @@ class DashboardController { } this.communicator = null; this.lockSurfaceConfigured = false; - this.wearNotifySupported = false; - this.faceclawWakeLeaseSupported = false; + this.glance.reset(); + this.customFirmwareConfirmed = false; this.faceclawWakeLeaseState = null; this.evenHubResumePromise = null; this.clearDashboardTimer(); @@ -1688,6 +1715,7 @@ class DashboardController { const communicator = this.communicator; this.communicator = null; this.lockSurfaceConfigured = false; + this.glance.reset(); this.evenHubSessionSuspended = false; this.evenHubResumePromise = null; @@ -1746,9 +1774,8 @@ class DashboardController { await communicator?.close().catch(() => {}); } finally { stopForegroundNotification(); - this.faceclawWakeLeaseSupported = false; + this.customFirmwareConfirmed = false; this.faceclawWakeLeaseState = null; - this.wearNotifySupported = false; this.setPhase("disconnected"); this.setStatus("Disconnected."); this.appendLog("Disconnected from the glasses."); @@ -1762,14 +1789,14 @@ class DashboardController { * finger-down/finger-up (the watch) hold for as long as the user does. */ async injectSyntheticRingInput(kind: WearRemoteInputKind, origin: SyntheticInputOrigin = "ring"): Promise { - // Match the ring while the display is dark: only a double-click wakes it, - // and that wake is handled by Shell.receiveInput. This check also protects - // against a watch acting on a stale state snapshot. + // Match the ring while the display is dark: a double-click wakes it + // (handled by Shell.receiveInput) and a tap or hold shows the + // Glanceboard; scrolls and the menu gesture mean nothing. This check also + // protects against a watch acting on a stale state snapshot. if ( origin === "watch" && !shell.isScreenOn() && - kind !== "double-click" && - kind !== "long-press-release" + (kind === "scroll-up" || kind === "scroll-down" || kind === "short-then-long-press") ) { this.appendLog(`${kind} (watch scheme) ignored while display is off`); return; @@ -1800,7 +1827,12 @@ class DashboardController { return; } if (!shell.isScreenOn()) { + // Asleep, the mirror offers the sleep gestures: double-tap wakes, a + // tap shows the Glanceboard for its timeout. The mirror's hold has no + // real release (the synthetic long-press releases at once, which would + // only flash the board), so it counts as a tap here too. if (kind === "double-tap") await this.injectSyntheticRingInput("double-click", "watch"); + else if (kind === "tap" || kind === "long-press") await this.injectSyntheticRingInput("click", "watch"); return; } if (kind !== "tap") { @@ -1874,12 +1906,15 @@ class DashboardController { * push-to-talk and the Transcribe app. Android mic permission is the consent * gate even though the audio source is the G2 mic over BLE. */ - private startVoiceCapture(endpointing = false): void { - this.beginVoiceCapture("ptt", endpointing); + private pttCaptureGeneration = 0; + + private startVoiceCapture(endpointing = false): Promise { + return this.beginVoiceCapture("ptt", endpointing); } - private stopVoiceCapture(): void { - voiceControlBridge.stopPushToTalk(); + private stopVoiceCapture(): Promise | void { + ++this.pttCaptureGeneration; + return voiceControlBridge.stopPushToTalk(); } private startContinuousVoiceCapture(): void { @@ -1944,7 +1979,8 @@ class DashboardController { return granted; } - private beginVoiceCapture(kind: "ptt" | "continuous", endpointing = false): void { + private async beginVoiceCapture(kind: "ptt" | "continuous", endpointing = false): Promise { + const pttGeneration = kind === "ptt" ? ++this.pttCaptureGeneration : 0; // Preview mode captures from the phone mic (voiceCaptureOptions with a // null communicator); otherwise a live glasses session must be the source. const previewCapture = this.isPreviewDisplayActive(); @@ -1952,8 +1988,12 @@ class DashboardController { return; } const communicator = this.communicator; - void ensureVoicePermissions() + // The system prompt appears on the phone; tell the glasses dialog so it + // sends the user there rather than claiming to listen. + if (!hasMicrophonePermission()) voiceControlBridge.reportPermissionPrompt(); + await ensureVoicePermissions() .then(() => { + if (kind === "ptt" && pttGeneration !== this.pttCaptureGeneration) return; if (previewCapture) { if (!this.isPreviewDisplayActive()) return; } else if (this.phase !== "connected" || this.communicator !== communicator) { @@ -1968,6 +2008,7 @@ class DashboardController { }) .catch((error) => { this.appendLog(`voice permission failed: ${this.formatError(error)}`); + if (!hasMicrophonePermission()) voiceControlBridge.reportPermissionDenied(); }); } @@ -2057,6 +2098,20 @@ class DashboardController { } return; } + if (!shell.isScreenOn()) { + // Sleep-time gestures belong to the Glanceboard: a tap or a hold + // shows it (the shell would ignore them), and a double-tap while it + // is up dismisses it and falls through to the normal wake below. + const glanceEvent = this.glanceEventFor(inputEvent, event); + if (glanceEvent?.type === "dismiss") { + this.glance.dismiss(); + } else if (glanceEvent) { + frameTimings.annotateFrame(frameId, `glanceboard ${glanceEvent.type}`); + await this.glance.handleEvent(glanceEvent, frameId); + frameOwned = true; + return; + } + } const wakewordShouldWake = event.kind === "even-ai" && event.eventType === EvenAIStatus.EVEN_AI_WAKE_UP && @@ -2130,6 +2185,19 @@ class DashboardController { } } + /** + * The Glanceboard event a sleep-time input means, or null when the shell + * should see the input as usual. A display-wake carries the head-tilt + * gesture (HEAD_UP_EVENT) as a press; the double-tap display-wake stays the + * regular UI's wake. + */ + private glanceEventFor(inputEvent: InputEvent, event: RawInputEvent): GlanceEvent | null { + if (inputEvent.type === "display-wake") { + return event.eventType === OsEventTypeList.HEAD_UP_EVENT ? this.glance.eventForGesture("head-tilt") : null; + } + return this.glance.eventForGesture(inputEvent.type); + } + /** Launch or focus an in-process singleton app (notifications, debug tests). */ private async launchInProcessApp( windowId: string, @@ -2527,6 +2595,9 @@ class DashboardController { private setPhase(phase: ConnectionPhase): void { if (this.phase === phase) return; this.phase = phase; + if (phase !== "connected" && phase !== "charging") { + shell.setBatteryLevels({ ring: null, ringCharging: null }); + } // "charging" is a live BLE link with the glasses in their case. updateGlassesPresence({ connected: phase === "connected" || phase === "charging", diff --git a/app/g2/events.ts b/app/g2/events.ts index 877dd901..8e6a7ee2 100644 --- a/app/g2/events.ts +++ b/app/g2/events.ts @@ -71,6 +71,12 @@ export const OsEventTypeList = { RING_LONG_PRESS_RELEASE_EVENT: 10, /** CFW extension: the 2.2.9 tap-then-hold Menu gesture. */ SHORT_THEN_LONG_PRESS_EVENT: 11, + /** + * CFW extension (head-tilt wake branch): the IMU head-up gesture, forwarded + * while the display sleeps. Reaches the phone as a display-wake carrying + * this eventType; the glance host treats it as a press. + */ + HEAD_UP_EVENT: 12, } as const; export const OsEventTypeName: Record = { @@ -86,4 +92,5 @@ export const OsEventTypeName: Record = { 9: "RING_LONG_PRESS_EVENT", 10: "RING_LONG_PRESS_RELEASE_EVENT", 11: "SHORT_THEN_LONG_PRESS_EVENT", + 12: "HEAD_UP_EVENT", }; diff --git a/app/g2/firmware-compat.ts b/app/g2/firmware-compat.ts index 07904bd5..7a85eb00 100644 --- a/app/g2/firmware-compat.ts +++ b/app/g2/firmware-compat.ts @@ -1,20 +1,79 @@ /** - * Compatibility check for the glasses firmware. Faceclaw requires the custom - * firmware: version >= 2.2.4.34 with the required direct-framebuffer and wear - * notification tokens in the CFW capability string. Stock firmware sends no - * capability string at all. + * Compatibility check for the glasses firmware. Faceclaw requires its own + * custom firmware at a specific revision. + * + * The firmware identifies itself through one extra string in the sid-0x09 + * settings READ response (protobuf field 100, the "firmware extension" slot): + * + * "Faceclaw/" -- Faceclaw's custom firmware, revision . The revision + * goes up whenever the firmware contract changes and is + * not kept in sync with Faceclaw app versions. + * "EVENCFW/..." -- older Faceclaw firmware, from before revisions existed + * (it advertised feature tokens instead). Always outdated. + * (empty) -- stock firmware; it never sends the field. + * anything else -- custom firmware from a different source. + * + * Because an exact revision is required, nothing else in the app gates on the + * extension string: once the firmware is compatible, every feature it provides + * is assumed present. */ -import { type FirmwareInfo } from "../native/faceclaw-communicator"; +export type FirmwareInfo = { + leftVersion: string; + rightVersion: string; + /** Raw contents of the firmware-extension slot ("" on stock firmware). */ + extension: string; +}; -const MIN_FIRMWARE_VERSION = [2, 2, 4, 34]; -const REQUIRED_FIRMWARE_EXTENSIONS = ["img640", "fbguard", "wearnotify"] as const; +/** The Faceclaw firmware revision this build of the app needs. */ +export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 13; + +const FACECLAW_PREFIX = "Faceclaw/"; +const LEGACY_PREFIX = "EVENCFW"; // The stock firmware release Faceclaw's custom image is built from. Stock at or // below this can be flashed with our patched image; a newer stock version is // unrecognized (its layout may differ from what our patch set targets). -export const FLASHABLE_STOCK_VERSION = [2, 2, 9, 22]; -export const FLASHABLE_STOCK_VERSION_TEXT = FLASHABLE_STOCK_VERSION.join("."); +export const BASE_STOCK_VERSION = [2, 2, 9, 22]; +export const BASE_STOCK_VERSION_TEXT = BASE_STOCK_VERSION.join("."); +export const VALIDATED_STOCK_VERSION = [2, 2, 10, 10]; +export const VALIDATED_STOCK_VERSION_TEXT = VALIDATED_STOCK_VERSION.join("."); + +export type FirmwareExtension = + /** Nothing in the slot: stock firmware. */ + | { kind: "none" } + /** Faceclaw's firmware at the given revision. */ + | { kind: "faceclaw"; version: number } + /** Pre-revision Faceclaw firmware ("EVENCFW/ "). */ + | { kind: "legacy-faceclaw"; text: string } + /** Custom firmware from some other project. */ + | { kind: "other"; text: string }; + +export function parseFirmwareExtension(extension: string): FirmwareExtension { + const text = extension.trim(); + if (!text) return { kind: "none" }; + if (text.startsWith(FACECLAW_PREFIX)) { + const version = parseInt(text.slice(FACECLAW_PREFIX.length), 10); + if (Number.isFinite(version) && version >= 0) return { kind: "faceclaw", version }; + return { kind: "other", text }; + } + if (text.startsWith(LEGACY_PREFIX)) return { kind: "legacy-faceclaw", text }; + return { kind: "other", text }; +} + +/** Short user-facing description of what the extension slot reported. */ +export function describeFirmwareExtension(extension: FirmwareExtension): string { + switch (extension.kind) { + case "faceclaw": + return `Faceclaw firmware revision ${extension.version}`; + case "legacy-faceclaw": + return `an older Faceclaw firmware (reported "${extension.text}")`; + case "other": + return `custom firmware from a different source (reported "${extension.text}")`; + default: + return "stock firmware"; + } +} function parseDottedVersion(version: string): number[] { return version @@ -36,66 +95,53 @@ function compareVersions(a: number[], b: number[]): number { return 0; } +/** + * True when the glasses run Faceclaw's firmware at the required revision or + * newer. (A newer revision is accepted: revisions only add to the contract.) + */ +export function hasCompatibleFirmware(info: FirmwareInfo): boolean { + const extension = parseFirmwareExtension(info.extension); + return extension.kind === "faceclaw" && extension.version >= REQUIRED_FACECLAW_FIRMWARE_VERSION; +} + /** * Human-readable explanation of why this firmware cannot run Faceclaw, or - * null if it is compatible. Returns null when no version was reported at all + * null if it is compatible. Returns null when nothing was reported at all * (no data is not evidence of incompatibility). */ export function firmwareIncompatibilityMessage(info: FirmwareInfo): string | null { const reportedVersions = [info.leftVersion, info.rightVersion].filter((v) => v.trim().length > 0); - if (reportedVersions.length === 0) return null; + const extension = parseFirmwareExtension(info.extension); + if (reportedVersions.length === 0 && extension.kind === "none") return null; - const minVersionText = MIN_FIRMWARE_VERSION.join("."); const versionsText = `L=${info.leftVersion || "unknown"} R=${info.rightVersion || "unknown"}`; + const required = `Faceclaw firmware revision ${REQUIRED_FACECLAW_FIRMWARE_VERSION}`; - if (reportedVersions.some((v) => compareVersions(parseDottedVersion(v), MIN_FIRMWARE_VERSION) < 0)) { - return ( - `The glasses report firmware ${versionsText}, but Faceclaw requires the modified firmware, ` + - `version ${minVersionText} or newer. Displaying images will not work until the glasses firmware is updated.` - ); + switch (extension.kind) { + case "faceclaw": + if (extension.version >= REQUIRED_FACECLAW_FIRMWARE_VERSION) return null; + return ( + `The glasses run Faceclaw firmware revision ${extension.version} (base ${versionsText}), ` + + `but this version of Faceclaw requires revision ${REQUIRED_FACECLAW_FIRMWARE_VERSION}. ` + + "Install the updated custom firmware to continue." + ); + case "legacy-faceclaw": + return ( + `The glasses run an older version of Faceclaw's custom firmware (reported "${extension.text}", ` + + `base ${versionsText}). This version of Faceclaw requires ${required}. ` + + "Install the updated custom firmware to continue." + ); + case "other": + return ( + `The glasses run custom firmware from a different source (reported "${extension.text}", ` + + `base ${versionsText}). Faceclaw requires ${required}; installing it will replace the current firmware.` + ); + default: + return ( + `The glasses report stock firmware ${versionsText}. Faceclaw requires ${required}. ` + + "Displaying images will not work until the custom firmware is installed." + ); } - - const tokens = info.capabilities.trim().split(/\s+/); - const missingExtensions = REQUIRED_FIRMWARE_EXTENSIONS.filter( - (extension) => !tokens.includes(extension), - ); - if (missingExtensions.length) { - return ( - `The glasses firmware (${versionsText}) does not advertise the required ` + - `${missingExtensions.map((extension) => `"${extension}"`).join(" and ")} extension` + - `${missingExtensions.length === 1 ? "" : "s"}` + - `${info.capabilities.trim() ? ` (reported: ${info.capabilities.trim()})` : ", which suggests stock firmware"}. ` + - `Faceclaw requires the modified firmware with the guarded 640x480 direct-framebuffer path and wear notifications.` - ); - } - - return null; -} - -/** True when the glasses advertise every custom-firmware extension Faceclaw needs. */ -export function hasCustomFirmware(info: FirmwareInfo): boolean { - const tokens = info.capabilities.trim().split(/\s+/); - return REQUIRED_FIRMWARE_EXTENSIONS.every((extension) => tokens.includes(extension)); -} - -/** - * True when the firmware advertises the optional mic-control extension: the - * private field-103/104 channel for per-temple multi-microphone capture that - * the Microphones app's 4-mic array mode and beamforming need. Absent on the - * stock single-mono-stream path, which still works (firmware-computed - * direction of arrival, one mixed channel). - */ -export function hasMicControl(info: FirmwareInfo): boolean { - return info.capabilities.trim().split(/\s+/).includes("micctl"); -} - -/** - * True when the firmware advertises the optional ambient-light extension: - * image-handler mode 16 (query / passive polling of the OPT3001 light sensor) - * with field-105 reports, used to drive a phone-side brightness policy. - */ -export function hasAmbientLightSensor(info: FirmwareInfo): boolean { - return info.capabilities.trim().split(/\s+/).includes("als16"); } /** The higher of the two arms' reported versions, or "" if none reported. */ @@ -109,24 +155,56 @@ export function reportedFirmwareVersion(info: FirmwareInfo): string { /** * How the pre-flash firmware check should treat the connected glasses: - * - "custom": Faceclaw's firmware is already installed — nothing to flash. + * - "custom": Faceclaw's firmware at the required revision (or newer) is + * already installed — nothing to flash. + * - "older-faceclaw": Faceclaw's firmware at an older revision (including + * the pre-revision "EVENCFW" builds) — flash to update it. + * - "other-custom": custom firmware from a different source — flash to + * replace it. * - "flashable-stock": stock firmware at or below the version we build from. - * - "newer-stock": stock firmware newer than we recognize — flash only on override. + * - "newer-stock-validated": stock firmware newer than the version we build + * from, on which the downgrade has been tested successfully + * - "newer-stock-unvalidated": stock firmware newer than we recognize — flash only on override. * - "unknown": no version could be read (treated as a probe/connection failure). */ -export type OnboardingFirmwareKind = "custom" | "flashable-stock" | "newer-stock" | "unknown"; +export type OnboardingFirmwareKind = + | "custom" + | "older-faceclaw" + | "other-custom" + | "flashable-stock" + | "newer-stock-validated" + | "newer-stock-unvalidated" + | "unknown"; export function classifyOnboardingFirmware(info: FirmwareInfo): { kind: OnboardingFirmwareKind; version: string; + extension: FirmwareExtension; } { - if (hasCustomFirmware(info)) { - return { kind: "custom", version: reportedFirmwareVersion(info) }; - } + const extension = parseFirmwareExtension(info.extension); const version = reportedFirmwareVersion(info); + switch (extension.kind) { + case "faceclaw": + return { + kind: extension.version >= REQUIRED_FACECLAW_FIRMWARE_VERSION ? "custom" : "older-faceclaw", + version, + extension, + }; + case "legacy-faceclaw": + return { kind: "older-faceclaw", version, extension }; + case "other": + return { kind: "other-custom", version, extension }; + default: + break; + } if (!version) { - return { kind: "unknown", version: "" }; + return { kind: "unknown", version: "", extension }; + } + if (compareVersions(parseDottedVersion(version), BASE_STOCK_VERSION) <= 0) { + return { kind: "flashable-stock", version, extension }; + } else if (compareVersions(parseDottedVersion(version), VALIDATED_STOCK_VERSION) <= 0) { + return { kind: "newer-stock-validated", version, extension }; + } else { + return { kind: "newer-stock-unvalidated", version, extension }; } - const comparison = compareVersions(parseDottedVersion(version), FLASHABLE_STOCK_VERSION); - return { kind: comparison <= 0 ? "flashable-stock" : "newer-stock", version }; } diff --git a/app/g2/firmware/cfw-patches.ts b/app/g2/firmware/cfw-patches.ts index 5e1f169a..445e4551 100644 --- a/app/g2/firmware/cfw-patches.ts +++ b/app/g2/firmware/cfw-patches.ts @@ -19,168 +19,192 @@ export type FirmwarePatchSet = { export const CFW_PATCH_SET: FirmwarePatchSet = { "base": "g2_2.2.9.22.bin", "baseSha256": "a03fbea9f68a9de6bc271daabb9f3a41c59053d1086622c76a4e990f829cc561", - "outputSha256": "920f5e45129453c155d7fb004b93049985594744be973e793cf41e8b6e07005a", + "outputSha256": "32cea69474252a2b2f9c0fdc5f89bf0d5d6f745b4eec10aea8e9c34e3f106b3f", "patches": [ + { + "offset": 935280, + "old": "fff717f8", + "new": "64f395fb", + "desc": "bl cfw_message_bridge_received (ordered private bridge delivery before worker pool)" + }, + { + "offset": 935628, + "old": "fef769ff", + "new": "64f3e7fa", + "desc": "bl cfw_message_bridge_received (ordered private bridge delivery before worker pool)" + }, + { + "offset": 943818, + "old": "fcf76aff", + "new": "62f3e8fa", + "desc": "bl cfw_message_bridge_received (ordered private bridge delivery before worker pool)" + }, + { + "offset": 1415004, + "old": "fcf745f8", + "new": "eef23dfb", + "desc": "bl cfw_receive_packet (private SID-f0 probe before TPL reassembly)" + }, + { + "offset": 1363762, + "old": "7c20", + "new": "7d20", + "desc": "Set Local Feature: enable LE 2M bit 8" + }, + { + "offset": 4410298, + "old": "0c001800", + "new": "06000600", + "desc": "fast connection interval min=max=7.5 ms; latency remains 0" + }, + { + "offset": 1053266, + "old": "0500", + "new": "a325", + "desc": "_connectParamReq_impl: force requested mode to fast (0xa3); disables idle slow requests" + }, { "offset": 1124178, "old": "5ff43432", "new": "5ff43332", "desc": "reserve final 1 KiB of primary TLSF arena for CFW context anchor" }, - { - "offset": 1524180, - "old": "bdf82c10", - "new": "40f24120", - "desc": "container width <= 576" - }, - { - "offset": 1524380, - "old": "bdf82e00", - "new": "40f22111", - "desc": "container height movw #0x121" - }, - { - "offset": 1524384, - "old": "9128", - "new": "8842", - "desc": "container height cmp r0,r1" - }, - { - "offset": 1516784, - "old": "70f775ff", - "new": "d6f295fa", - "desc": "bl snapshot_side @ 0x4ec0ee (shared image-complete helper)" - }, - { - "offset": 1516816, - "old": "30d0", - "new": "1cd0", - "desc": "image-complete success -> immediate ACK (pipelining-safe)" - }, - { - "offset": 1222660, - "old": "49f0daff", - "new": "1ef30ff9", - "desc": "bl image_deferred (deferred consumer -> FIFO restore + worker, both lenses)" - }, { "offset": 1242342, "old": "d4f790fb", - "new": "1af3faf9", + "new": "1af33cfc", "desc": "bl settings_send_wrapper (append caps field 100)" }, { "offset": 1240038, "old": "f5f710f9", - "new": "1af3bafb", + "new": "1af3dafd", "desc": "bl settings_decode_wrapper (Faceclaw lease field 101)" }, { "offset": 939336, "old": "0bf02af9", - "new": "63f325fe", - "desc": "bl faceclaw_display_start @ 0x45f146 (fail-open double-tap takeover)" + "new": "64f351f8", + "desc": "bl faceclaw_display_start @ 0x45f146 (fail-open wake takeover)" }, { "offset": 939528, "old": "0bf0caf8", - "new": "63f3c5fd", - "desc": "bl faceclaw_display_start @ 0x45f206 (fail-open double-tap takeover)" + "new": "64f3bff8", + "desc": "bl faceclaw_display_start_headup @ 0x45f206 (fail-open wake takeover)" + }, + { + "offset": 939016, + "old": "10f096f8", + "new": "65f397fd", + "desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)" + }, + { + "offset": 939036, + "old": "fff765fb", + "new": "63f3ddff", + "desc": "bl faceclaw_idle_input_gate (idle tap/long/release -> field-102 events 2/3/4)" }, { "offset": 831036, "old": "1df057fc", - "new": "7ff3b3fd", + "new": "7ff373ff", "desc": "bl gesture_press (Faceclaw lease gates event 9 vs stock UI event 8)" }, { "offset": 831042, "old": "24f023f9", - "new": "7ff354fe", + "new": "80f314f8", "desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)" }, { "offset": 831800, "old": "1df0d9fa", - "new": "7ff339fc", + "new": "7ff3f9fd", "desc": "bl gesture_release (source-qualified event 10 vs stock UI event 0x4a)" }, { "offset": 1553752, "old": "7fb50600", - "new": "cef2afb9", + "new": "cef2f1bb", "desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline" }, { "offset": 1047796, "old": "f6f7edff", - "new": "45f37df9", + "new": "45f32ffd", "desc": "bl display_copy_hook @ 0x4798f2 (640x480 direct framebuffer)" }, { "offset": 1048112, "old": "f6f74fff", - "new": "45f3dff8", + "new": "45f391fc", "desc": "bl display_copy_hook @ 0x479a2e (640x480 direct framebuffer)" }, { "offset": 1255404, "old": "d9f758ff", - "new": "16f3fbfb", + "new": "16f3f9fd", "desc": "bl faceclaw_send_wear_event @ 0x4ac3ea (outside onboarding)" }, { "offset": 1255504, "old": "d9f726ff", - "new": "16f3c9fb", + "new": "16f3c7fd", "desc": "bl faceclaw_send_wear_event @ 0x4ac44e (outside onboarding)" }, { - "offset": 831998, - "old": "1df076fa", - "new": "79f3b8fe", - "desc": "bl compass_event_forward (global IMU heading -> stock nav BLE notifier)" + "offset": 1297700, + "old": "65f0affd", + "new": "0cf351f8", + "desc": "bl compass_decode_capture (sample-matched GAF diagnostics)" + }, + { + "offset": 1296176, + "old": "fff759fc", + "new": "0cf3c7fb", + "desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)" }, { "offset": 4476518, "old": "", - "new": "02fb01f000e000bfb0b54ff2ac44c2f229040146206846f23f52c5f28802b2eb500f40f258304cf2e9124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304cf20732c2f20000c0f24802104770b500284ed001684ef66962ccf2ff02914218bf70bd90f8081190f8095146f6756c8d42c0f2510c2ad205eb8501014491f80d2191f80e4191f80ae191f80b3191f80c1142ea0424012c4ff0010298bf14466e1c054680f80961b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f80811bde870406047e047d5f8040138b142f64d42c0f244022146bde87040104770bd00bf70b542f2ed23c0f2460314460d4698474ff2a841c2f229010e6831466ff39601b1f1005f0ad131684ef66962ccf2ff02914218bf0026412d03d070bd0026412dfbd1002cf9d04cf6dd71c0f2450105468847002e01462846efd00129edd196f807120029e9d02168002948bf70bd4ff27d42c0f2590208469047284670bd00bf2de9f04f9db04ff2a84ac2f2290adaf800b058466ff39600b0f1005f40f07d81dbf800004ef66967ccf2ff07b84240f074819bf82802002800f05d81dbf82442002c00f0588140f6b400c2f20000d0f8008004a802f0aaffb8f1000f00f0f881032045f24075cff68070a4f1600108f160026ff0bf03c0f2020500bf0e6ed41826664e6ec03366668e6eab42a666ce6ee6660e6f26674e6f66678e6fa667ce6fe667d1f88060c4f88060d1f88460c4f88460d1f88860c4f88860d1f88c60c4f88c60d1f89060c4f89060d1f89460c4f89460d1f89860c4f89860d1f89c60c4f89c60d1f8a060c4f8a060d1f8a460c4f8a460d1f8a860c4f8a860d1f8ac60c4f8ac60d1f8b060c4f8b060d1f8b460c4f8b460d1f8b860c4f8b860d1f8bc60c4f8bc6051f8c06fc4f8c0604e68c4f8c4608e68c4f8c860ce68c4f8cc600e69c4f8d0604e69c4f8d4608e69c4f8d860ce69c4f8dc600e6ac4f8e0604e6ac4f8e4608e6ac4f8e860ce6ac4f8ec600e6bc4f8f0604e6bc4f8f4608e6bc4f8f860ce6bc4f8fc600e6cc4f800614e6cc4f804618e6cc4f80861ce6cc4f80c610e6dc4f810614e6dc4f814618e6dc4f81861ce6dc4f81c617ff462afdaf800603040b0f1005f40f0b2803068b84240f0ae8096f8ce00002840f04f8196f8dc10002000298df8140000f0c78105a90a5c002a00f09a810a185378002b00f058819378002b00f05681d378002b00f054811379002b00f052815379002b00f050819379002b00f04e81d379002b00f04c81137a002b00f04a81537a002b00f04881937a002b00f04681d37a002b00f04481137b002b00f04281537b002b00f04081937b002b00f03e81d37b002b00f03c81137c002b00f03a81537c002b00f03881937c002b00f03681d37c002b00f03481137d002b00f03281537d002b00f03081937d002b00f02e81d37d002b00f02c81137e002b00f02a81537e002b00f02881937e002b00f02681d37e002b00f02481137f002b00f02281537f002b00f02081937f002b00f01e81d27f002a00f01c81203060287ff47baf3be19bf82a0270b1dbf82c0240b146f68051c2f207010968401a002800f3c98000208bf82a0240f6d100c0f247001db0bde8f04f00474ff4217004f071fd002800f09c804ff67c51cff6ff71002200bf43182e3183f8842283f8852283f8862283f8872283f8882283f8892283f88a2283f88b2283f88c2283f88d2283f88e2283f88f2283f8902283f8912283f8922283f8932283f8942283f8952283f8962283f8972283f8982283f8992283f89a2283f89b2283f89c2283f89d2283f89e2283f89f2283f8a02283f8a12283f8a22283f8a32283f8a42283f8a52283f8a62283f8a72283f8a82283f8a92283f8aa2283f8ab2283f8ac2283f8ad2283f8ae2283f8af2283f8b02283f8b122a0d1012180f8ce104ff0ff310760a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe1010e000208bf82802cbf824028bf82a0201208bf8290240f6d100c0f24700804715e00020caf8000000208bf82802cbf824024ff416304cf60361069005a8c0f24701cdf81480884701208bf82a0204a802f08bfecbf8d4001db0bde8f08f01303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f2821d84ff052020a541dd0014445225e284a7018d04f225d288a7014d052225c28ca7010d044225b280a710cd045225a284a7108d0522259288a7104d020225828ca7142f0178500208df87300012096f8dd10002900f0c280002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf54e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2915d84ff05303535411d00a444b235e2953700cd049235d29937008d050235c29d37004d020235b29137140f0c28200218df87310013096f8de10002900f0be80002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f08e8000218df87310013096f8df10002900f0cd80002005a90a5c002a00f0a3800a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b53d0137c002b52d0537c002b51d0937c002b50d0d37c002b4fd0137d002b4ed0537d002b4dd0937d002b4cd0d37d002b4bd0137e002b4ad0537e002b49d0937e002b48d0d37e002b47d0137f002b46d0537f002b45d0937f002b44d0d27f002a43d0203060287ff49aaf5fe001303de002303be0033039e0043037e0053035e0063033e0073031e008302fe009302de00a302be00b3029e00c3027e00d3025e00e3023e00021117171e70f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281dd84ff053020a5419d001444e225e284a7014d041225d288a7010d050225c28ca700cd04f225b280a7108d046225a284a7104d0202259288a7142f0b38200208df873000120daf8041046f23f52c5f28802b2eb510f40f08b80c90700f08e80002005a90a5c002a00f083810a185378002b00f0f7809378002b00f0f780d378002b00f0f7801379002b00f0f7805379002b00f0f7809379002b00f0f780d379002b00f0f780137a002b00f0fa80537a002b00f0fa80937a002b00f0fa80d37a002b00f0fa80137b002b00f0fa80537b002b00f0fa80937b002b00f0fa80d37b002b00f0fa80137c002b00f0fa80537c002b00f0fa80937c002b00f0fa80d37c002b00f0fa80137d002b00f0fa80537d002b00f0fa80937d002b00f0fa80d37d002b00f0fa80137e002b00f0fa80537e002b00f0fa80937e002b00f0fa80d37e002b00f0fa80137f002b00f00b81537f002b00f00981937f002b00f00781d27f002a00f00581203060287ff47baf1be14cf67e21caf21011caf80410002840f01681002005a90a5c002a00f0d9800a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5cd09379002b5dd0d379002b5ed0137a002b5fd0537a002b60d0937a002b61d0d37a002b65d0137b002b66d0537b002b67d0937b002b68d0d37b002b69d0137c002b6ad0537c002b6bd0937c002b6cd0d37c002b6dd0137d002b6ed0537d002b6fd0937d002b70d0d37d002b71d0137e002b72d0537e002b73d0937e002b74d0d37e002b75d0137f002b76d0537f002b77d0937f002b78d0d27f002a79d0203060287ff49aafa9e0013073e0023071e003306fe004306de0013084e0053069e0023080e0063065e003307ce0073061e0043078e008305de0053074e0093059e0063070e00a3055e007306ce0002151713de50b304ee0083065e00c304ae0093061e00d3046e00a305de00e3042e00b3059e00f303ee00c3055e010303ae00d3051e0113036e00e304de0123032e00f3049e013302ee0103045e014302ae0113041e0153026e012303de0163022e0133039e017301ee0143035e018301ae0153031e0193016e016302de01a3012e0173029e01b300ee0183025e01c300ae0193021e01d3006e01a301de01e3002e01b3019e01f305f2831d84ff04f020a542dd001444b225e284a7028d020225d288a7024d00020c87024e01c3004e01d3002e01e3000e01f305f2818d84ff041020a5414d001444c225e284a700fd05d288a700cd04f225c28ca7008d043225b280a7104d020225a284a7142f0028100208df8730005a80021cdf80880804618f80100002800f0a18008eb0102507800285ed0907800285dd0d07800285cd0107900285bd0507900285ad09079002859d0d079002858d0107a002857d0507a002856d0907a002855d0d07a002854d0107b002853d0507b002852d0907b002851d0d07b002850d0107c00284fd0507c00284ed0907c00284dd0d07c00284cd0107d00284bd0507d00284ad0907d002849d0d07d002848d0107e002847d0507e002846d0907e002845d0d07e002844d0107f002843d0507f002842d0907f002841d0d07f002840d0203160297ff498af43e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d84ff0770008f8010003d100208df8730003e008eb010000214170d6f8d0704ff0000918f80900002800f0c48008eb09014878002862d08878002862d0c878002862d00879002862d04879002862d08879002862d0c879002862d0087a002862d0487a002862d0887a002862d0c87a002862d0087b002862d0487b002862d0887b002862d0c87b002862d0087c002862d0487c002862d0887c002862d0c87c002862d0087d002862d0487d002862d0887d002862d0c87d002862d0087e002862d0487e002862d0887e002862d0c87e002862d0087f002862d0487f002862d0887f002862d0c87f002862d009f12009b9f1600f7ff496af4ff060095be009f1010958e009f1020955e009f1030952e009f104094fe009f105094ce009f1060949e009f1070946e009f1080943e009f1090940e009f10a093de009f10b093ae009f10c0937e009f10d0934e009f10e0931e009f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f090a2f4ff0010103961ed364204ff47a7542f2107401eb81035b00b7fbf3f60a2e11d301fb00f3b7fbf3f60a2e0bd301fb05f3b7fbf3f60a2e05d36143b7fbf1f3092be7d800e01946cc46b9f15f0f98bf4ff05f0cccf1000e1eeb090052d0b7fbf1f34cf6cd4203f13004ccf6cc4208f809400a29a1fb025446d3451c42d003fb1173e608b3fbf6f448f21f5204f1300508eb0907c5f2eb127d706429a1fb025835d3851c36d004fb16334fea5814b3fbf4f644f6d35206f13005c1f26202bd70b1f57a7fa1fb022526d303300df1140818d006fb1430aa0941f25974b0fbf2f3cdf2b714a1fb044503f13004fc7003fb120742f2107009f1040981424fea5531aad20de0e1460be009f1010908e009f1020903e0e14601e009f103090df11408039b002108f8091018f80100002800f0a18008eb0102507800285ed0907800285dd0d07800285cd0107900285bd0507900285ad09079002859d0d079002858d0107a002857d0507a002856d0907a002855d0d07a002854d0107b002853d0507b002852d0907b002851d0d07b002850d0107c00284fd0507c00284ed0907c00284dd0d07c00284cd0107d00284bd0507d00284ad0907d002849d0d07d002848d0107e002847d0507e002846d0907e002845d0d07e002844d0107f002843d0507f002842d0907f002841d0d07f002840d0203160297ff498af52e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2913d84ff0750008f801000ed008eb010073225e29427008d020225d29827004d070225c29c27040f09e8000208df87300d3f8d4104ff0000918f80900002800f0c78008eb09035878002862d09878002862d0d878002862d01879002862d05879002862d09879002862d0d879002862d0187a002862d0587a002862d0987a002862d0d87a002862d0187b002862d0587b002862d0987b002862d0d87b002865d0187c002865d0587c002865d0987c002865d0d87c002865d0187d002865d0587d002865d0987d002865d0d87d002865d0187e002865d0587e002865d0987e002865d0d87e002865d0187f002865d0587f002865d0987f002865d0d87f002865d009f12009b9f1600f7ff496af4ff060095ee009f101095be009f1020958e009f1030955e009f1040952e009f105094fe009f106094ce009f1070949e009f1080946e009f1090943e009f10a0940e009f10b093de009f10c093ae009f10d0937e009f10e0934e00021017161e709f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a291ed364204ff47a7742f2107503eb83067600b1fbf6f40a2c11d303fb00f6b1fbf6f40a2c0bd303fb07f6b1fbf6f40a2c05d36b43b1fbf3f6092ee7d800e03346ce46b9f15f0f98bf4ff05f0ecef1000842f2107c18eb09004ed0b1fbf3f405aa04f1300502f809504cf6cd42ccf6cc420a2ba3fb025641d3451c3dd004fb1317f608b7fbf6f405a948f21f5204f130054944c5f2eb124d70642ba3fb022530d3821c29d004fb16776c09b7fbf4f6b3f57a7f06f130028a7044f6d352c1f26202a3fb022520d3033016d006fb1470aa0941f25975b0fbf2f4cdf2b715a3fb055604f13005cd7004fb120109f1040963454fea5633aed209e0f14607e009f1010904e009f1020901e009f1030900210df1140808f80910ddf8089018f80100002800f0a18008eb0102507800285ed0907800285dd0d07800285cd0107900285bd0507900285ad09079002859d0d079002858d0107a002857d0507a002856d0907a002855d0d07a002854d0107b002853d0507b002852d0907b002851d0d07b002850d0107c00284fd0507c00284ed0907c00284dd0d07c00284cd0107d00284bd0507d00284ad0907d002849d0d07d002848d0107e002847d0507e002846d0907e002845d0d07e002844d0107f002843d0507f002842d0907f002841d0d07f002840d0203160297ff498af4ae001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f290bd84ff0750008f8010006d008eb010073225e29427040f00f8100208df8730040f2403cc2f2000cdcf81c1045f2a800c2f2130042f2a0038142c2f2200328d1dcf82810b1f54d2f23d1dcf82c1081421fd145f61c540022c2f213044cf639471d1d4ff0ff3eac4213d8216831f0030000f0a683a34228bf0c290cd31e1bb04209d8c90718bf02442044013f00f10404e9d14ff0ff3e46f68050c2f20700d0f8880003f1080142f6a0038842c2f2270321d142f61c550022c2f2200546f6b974181d854217d8296831f0030700f0d980ab424ff0ff36039628bf0c290ed35e1bb7420bd8c90705eb070118bf3a44013c01f10405e5d14ff0ff300390dcf8001003f1080081422bd1dcf80c10b1f5333f26d1dcf81010814222d143f21c530021c2f2270342f6f932aaf10404aaf108004ff0ff3ca34213d81e6836f0030500f04683984228bf0c2e0cd3c71abd4209d8f7072b4418bf2944013a03f10403e9d14ff0ff3c002118f80100002800f0aa8008eb01046078002861d0a078002860d0e07800285fd0207900285ed0607900285dd0a07900285cd0e07900285bd0207a00285ad0607a002859d0a07a002858d0e07a002857d0207b002856d0607b002855d0a07b002854d0e07b002853d0207c002852d0607c002851d0a07c002856d0e07c002855d0207d002854d0607d002853d0a07d002852d0e07d002851d0207e002850d0607e00284fd0a07e00284ed0e07e00284dd0207f00284cd0607f00284bd0a07f00284ad0e07f002849d0203160297ff498af77e000218170f0e6013140e002313ee003313ce004313ae0053138e0063136e0073134e0083132e0093130e00a312ee00b312ce00c312ae00d3128e00e3126e00f3124e0103122e0113120e0854218bf4ff0ff32039236e7123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f292fd84ff0200008f801002ad008eb010366205e29587024d031205d29987020d033205c29d8701cd02f205b29187118d032205a29587114d030205929987110d02f205829d8710cd032205729187208d037205629587204d03d205529987241f0938200208df873001ef10100cdf804c000f090804fea9e214ff0000a18f80a00002800f0898108eb0a046078002800f00b81a078002800f00a81e078002800f009812079002800f008816079002800f00781a079002800f00681e079002800f00581207a002800f00481607a002800f00381a07a002800f00281e07a002800f00181207b002800f00081607b002800f0ff80a07b002800f0fe80e07b002800f0fd80207c002800f0fc80607c002800f0fb80a07c002800f0fc80e07c002800f0fd80207d002800f0fe80607d002800f0ff80a07d002800f00081e07d002800f00181207e002800f00281607e002800f00381a07e002800f00481e07e002800f00581207f002800f00681607f002800f00781a07f002800f00881e07f002800f009810af1200abaf1600f7ff477af4ff0600a01e1039b002118f80100002800f0ba8108eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04e81107c002800f04c81507c002800f04a81907c002800f04881d07c002800f04681107d002800f04481507d002800f04281907d002800f04081d07d002800f03e81107e002800f03c81507e002800f03a81907e002800f03881d07e002800f03681107f002800f03481507f002800f03281907f002800f03081d07f002800f03b81203160297ff479af3de10af1010a74e00af1020a71e00af1030a6ee00af1040a6be00af1050a68e00af1060a65e00af1070a62e00af1080a5fe00af1090a5ce00af10a0a59e00af10b0a56e00af10c0a53e00af10d0a50e00af10e0a4de00af10f0a4ae00af1100a47e00af1110a44e0013101e10af1120a3fe00231fce00af1130a3ae00331f7e00af1140a35e00431f2e00af1150a30e00531ede00af1160a2be00631e8e00af1170a26e00731e3e00af1180a21e00831dee00af1190a1ce00931d9e00af11a0a17e00a31d4e00af11b0a12e00b31cfe00af11c0a0de00c31cae00af11d0a08e00d31c5e00af11e0a03e00e31c0e00af11f0a0122bef5205f1ed364204ff47a7342f2107502eb82077f00b1fbf7f40a2c11d302fb00f7b1fbf7f40a2c0bd302fb03f7b1fbf7f40a2c05d36a43b1fbf2f7092fe7d800e03a46d146baf15f0f98bf4ff05f09c9f1000842f2107e18eb0a004ed0b1fbf2f305af03f1300407f80a404cf6cd47ccf6cc470a2aa2fb075441d3451c3dd003fb1217e308b7fbf3f405a948f21f5604f130055144c5f2eb164d70642aa2fb06c530d3861c29d004fb13736c09b3fbf4f7b2f57a7f07f130068e7044f6d356c1f26206a2fb066520d3033016d007fb1430ab0941f25976b0fbf3f7cdf2b716a2fb066507f13006ce7007fb13010af1040a72454fea5532aed209e0ca4607e00af1010a04e00af1020a01e00af1030a00200df11408dde9029308f80a003ce00f312be0103129e0113127e0123125e0133123e0143121e015311fe016311de017311be0183119e0193117e01a3115e01b3113e01c3111e01d310fe01e310de0ac4218bf4ff0ff329646fff764bca34218bf4ff0ff318c46c4e41f315f2904d84ff03f0008f8010003d100208df8730003e008eb010000214170002118f80100002800f0a18008eb0102507800285ed0907800285dd0d07800285cd0107900285bd0507900285ad09079002859d0d079002858d0107a002857d0507a002856d0907a002855d0d07a002854d0107b002853d0507b002852d0907b002851d0d07b002850d0107c00284fd0507c00284ed0907c00284dd0d07c00284cd0107d00284bd0507d00284ad0907d002849d0d07d002848d0107e002847d0507e002846d0907e002845d0d07e002844d0107f002843d0507f002842d0907f002841d0d07f002840d0203160297ff498af43e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d84ff02f0008f8010003d100208df8730003e008eb010000214170ddf804a0581c00f08f80990a4ff0000c18f80c00002800f0888108eb0c046078002800f00a81a078002800f00981e078002800f008812079002800f007816079002800f00681a079002800f00581e079002800f00481207a002800f00381607a002800f00281a07a002800f00181e07a002800f00081207b002800f0ff80607b002800f0fe80a07b002800f0fd80e07b002800f0fc80207c002800f0fb80607c002800f0fa80a07c002800f0fb80e07c002800f0fc80207d002800f0fd80607d002800f0fe80a07d002800f0ff80e07d002800f00081207e002800f00181607e002800f00281a07e002800f00381e07e002800f00481207f002800f00581607f002800f00681a07f002800f00781e07f002800f008810cf1200cbcf1600f7ff477af4ff0600c00e1002118f80100002800f0ad8108eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04e81107c002800f04c81507c002800f04a81907c002800f04881d07c002800f04681107d002800f04481507d002800f04281907d002800f04081d07d002800f03e81107e002800f03c81507e002800f03a81907e002800f03881d07e002800f03681107f002800f03481507f002800f03281907f002800f03081d07f002800f02e81203160297ff479af30e10cf1010c74e00cf1020c71e00cf1030c6ee00cf1040c6be00cf1050c68e00cf1060c65e00cf1070c62e00cf1080c5fe00cf1090c5ce00cf10a0c59e00cf10b0c56e00cf10c0c53e00cf10d0c50e00cf10e0c4de00cf10f0c4ae00cf1100c47e00cf1110c44e00131f4e00cf1120c3fe00231efe00cf1130c3ae00331eae00cf1140c35e00431e5e00cf1150c30e00531e0e00cf1160c2be00631dbe00cf1170c26e00731d6e00cf1180c21e00831d1e00cf1190c1ce00931cce00cf11a0c17e00a31c7e00cf11b0c12e00b31c2e00cf11c0c0de00c31bde00cf11d0c08e00d31b8e00cf11e0c03e00e31b3e00cf11f0c0124b3f5205f1ed364204ff47a7342f2107704eb84067600b1fbf6f50a2d11d304fb00f6b1fbf6f50a2d0bd304fb03f6b1fbf6f50a2d05d37c43b1fbf4f6092ee7d800e03446e146bcf15f0f98bf4ff05f09c9f1000842f2107e18eb0c004ed0b1fbf4f305aa03f1300702f80c704cf6cd42ccf6cc420a2ca4fb027541d3471c3dd003fb1417eb08b7fbf3f505a948f21f5205f130066144c5f2eb124e70642ca4fb022630d3821c29d005fb13737509b3fbf5f7b4f57a7f07f130028a7044f6d352c1f26202a4fb022620d3033016d007fb1530b20941f25975b0fbf2f3cdf2b715a4fb055603f13005cd7003fb12010cf1040c74454fea5634aed209e0cc4607e00cf1010c04e00cf1020c01e00cf1030c00200df11408ddf8089008f80c002fe00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d84ff03f0008f8010003d100208df8730003e008eb010000214170002118f80100002800f0a18008eb0102507800285ed0907800285dd0d07800285cd0107900285bd0507900285ad09079002859d0d079002858d0107a002857d0507a002856d0907a002855d0d07a002854d0107b002853d0507b002852d0907b002851d0d07b002850d0107c00284fd0507c00284ed0907c00284dd0d07c00284cd0107d00284bd0507d00284ad0907d002849d0d07d002848d0107e002847d0507e002846d0907e002845d0d07e002844d0107f002843d0507f002842d0907f002841d0d07f002840d0203160297ff498af43e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d84ff02f0008f8010003d100208df8730003e008eb0100002141701af1010000f090804fea9a214ff0000918f80900002800f0888108eb09046078002800f00a81a078002800f00981e078002800f008812079002800f007816079002800f00681a079002800f00581e079002800f00481207a002800f00381607a002800f00281a07a002800f00181e07a002800f00081207b002800f0ff80607b002800f0fe80a07b002800f0fd80e07b002800f0fc80207c002800f0fb80607c002800f0fa80a07c002800f0fb80e07c002800f0fc80207d002800f0fd80607d002800f0fe80a07d002800f0ff80e07d002800f00081207e002800f00181607e002800f00281a07e002800f00381e07e002800f00481207f002800f00581607f002800f00681a07f002800f00781e07f002800f0088109f12009b9f1600f7ff477af4ff0600900e1002118f80100002800f0ad8108eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04e81107c002800f04c81507c002800f04a81907c002800f04881d07c002800f04681107d002800f04481507d002800f04281907d002800f04081d07d002800f03e81107e002800f03c81507e002800f03a81907e002800f03881d07e002800f03681107f002800f03481507f002800f03281907f002800f03081d07f002800f02e81203160297ff479af30e109f1010974e009f1020971e009f103096ee009f104096be009f1050968e009f1060965e009f1070962e009f108095fe009f109095ce009f10a0959e009f10b0956e009f10c0953e009f10d0950e009f10e094de009f10f094ae009f1100947e009f1110944e00131f4e009f112093fe00231efe009f113093ae00331eae009f1140935e00431e5e009f1150930e00531e0e009f116092be00631dbe009f1170926e00731d6e009f1180921e00831d1e009f119091ce00931cce009f11a0917e00a31c7e009f11b0912e00b31c2e009f11c090de00c31bde009f11d0908e00d31b8e009f11e0903e00e31b3e009f11f090123baf5205f1ed364204ff47a7742f2107603eb83056d00b1fbf5f40a2c11d303fb00f5b1fbf5f40a2c0bd303fb07f5b1fbf5f40a2c05d37343b1fbf3f5092de7d800e02b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c18eb09004ed0b1fbf3f405aa04f1300502f809504cf6cd42ccf6cc420a2ba3fb025741d3451c3dd004fb1316ff08b6fbf7f405a948f21f5204f130054944c5f2eb124d70642ba3fb022530d3821c29d004fb17676c09b7fbf4f6b3f57a7f06f130028a7044f6d352c1f26202a3fb022520d3033016d006fb1470aa0941f25975b0fbf2f4cdf2b715a3fb055604f13005cd7004fb120109f1040963454fea5633aed209e0f14607e009f1010904e009f1020901e009f1030900200df1140808f80900ddf808902fe00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d84ff03f0008f8010003d100208df8730003e008eb010000214170002118f80100002800f0a18008eb0102507800285ed0907800285dd0d07800285cd0107900285bd0507900285ad09079002859d0d079002858d0107a002857d0507a002856d0907a002855d0d07a002854d0107b002853d0507b002852d0907b002851d0d07b002850d0107c00284fd0507c00284ed0907c00284dd0d07c00284cd0107d00284bd0507d00284ad0907d002849d0d07d002848d0107e002847d0507e002846d0907e002845d0d07e002844d0107f002843d0507f002842d0907f002841d0d07f002840d0203160297ff498af43e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d84ff06b0008f8010003d100208df8730003e008eb0100002141709df814a0baf1000f10d0022208eb020010f8013c63b118f8023063b143784bb1807804320028f1d1023a04e0002005e0013a00e0013202eb4200400040eae070821c09f5207c00f1010e02f0030822f0030709f5a0724ff0ff3504e001350d2d02f5a07269d005eb8500bef1030f0ceb801405d24ff0ff30b8f1000f2ed1ede70020164604e000bf874206f1020621d0431cdb09042b03d8337803f0f0033370831cdb09042b03d8737803f00f037370c31cdb09042b03d8737803f0f00373700430c309042bdfd84308e15c01f00f01e154d9e70138b8f1000fbfd0861cf109042908d87108635cc6076ff00f0608bf0f2633406354b8f1010fafd0c61cf109042909d87108635cc6074ff00f0608bf6ff00f0633406354b8f1020f9ed0061df10904299ad87108c007635c6ff00f0008bf0f201840605490e7baf1000f00f0ab800298022200f281280df1140e40f27d2940f27a2c08e01ef801af0632baf1000f08f1030800f09780aaf17f0010f15f0ff1d346f61a01c0f200010aeb4a00794401eb8000a0f5c0710027d409404605e000bf02370c2f00f52070dcd0cb57042c06d8b3f1ff3f03dc067846f0f0060670042cdeb206d816f0400303d0037843f00f030370b30605d54a4503d8437843f0f0034370f30606d5b2f51f7f03d8437843f00f03437033074fea920305d59e2b03d8857845f0f0058570750705d5624503d8857845f00f058570cd1995f90160042c08d8b6f1ff3f05dc90f8405145f0f00580f84051042cf6b208d816f0400505d090f8405145f00f0580f84051b50607d54a4505d890f8415145f0f00580f84151f50608d5b2f51f7f05d890f8415145f00f0580f84151350707d59e2b05d890f8423143f0f00380f8423173077ff588af62453ff685af90f8423143f00f0380f842317de7ddf80880fdf775ba0020c871fdf74cbd00208871fdf7fdbe00200872fdf7e8ba0020d872fef76cbdf0b581b041f204054cf65561cef20005ccf2ac51c5f8ac1f4ef6fc51cef200010a684ff2a84642f080720a6055f8041cc2f2290641f0010145f8041c316807460a466ff39602b2f1005f07d108684ef66962ccf2ff02904200f098804ff4217001f002ff002800f0ca8001464ff67c50cff6ff70002200bf0b182e3083f8842283f8852283f8862283f8872283f8882283f8892283f88a2283f88b2283f88c2283f88d2283f88e2283f88f2283f8902283f8912283f8922283f8932283f8942283f8952283f8962283f8972283f8982283f8992283f89a2283f89b2283f89c2283f89d2283f89e2283f89f2283f8a02283f8a12283f8a22283f8a32283f8a42283f8a52283f8a62283f8a72283f8a82283f8a92283f8aa2283f8ab2283f8ac2283f8ad2283f8ae2283f8af2283f8b02283f8b122a0d14ef66960ccf2ff000860012081f8ce004ff0ff30a1f8e000a1f8e200a1f8e400a1f8e600a1f8e800a1f8ea00a1f8ec00a1f8ee00a1f8f000a1f8f200a1f8f400a1f8f600a1f8f800a1f8fa00a1f8fc00a1f8fe003160d1f8d800b8bb46f6805245f6e464c2f20702cff6f8741368204600bf16689e420ed116689e420bd116689e4208d116689e4203d1002800f10400efd19e421ad02b6816681068b0420ed11068b0420bd11068b04208d11068b04203d1002c04f10404efd1b04206d02868c01ac1f8d80001e0002030602868386001b0f0bd00bf2de9f04141f204084ff2a847cef20008c2f229070146d8f8004038680d6801466ff39601b1f1005f07d101684ef66962ccf2ff02914200f097804ff4217001f00dfe002800f0a0804ff67c51cff6ff71002200bf43182e3183f8842283f8852283f8862283f8872283f8882283f8892283f88a2283f88b2283f88c2283f88d2283f88e2283f88f2283f8902283f8912283f8922283f8932283f8942283f8952283f8962283f8972283f8982283f8992283f89a2283f89b2283f89c2283f89d2283f89e2283f89f2283f8a02283f8a12283f8a22283f8a32283f8a42283f8a52283f8a62283f8a72283f8a82283f8a92283f8aa2283f8ab2283f8ac2283f8ad2283f8ae2283f8af2283f8b02283f8b122a0d14ef66961ccf2ff010160012180f8ce104ff0ff31a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe103860d0f8d81081b144f6d350c1f26200a1fb0001880901284ff0010088bf88094be000203860fa2047e046f6805245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f422ad0d8f80030176800bf1168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94214d0d8f8001044f6d357ca1ac1f26207a2fb0776c0f8d820b00901284ff0010088bfb009994208bffa2000e0fa20611bb1fbf0f0bde8f08100bf2de9f04f85b0044618b1a069002840f0ad804ff2a845c2f22905286801466ff39601b1f1005f07d101684ef66962ccf2ff02914200f096804ff4217001f0f8fc002800f08e804ff67c51cff6ff71002243182e3183f8842283f8852283f8862283f8872283f8882283f8892283f88a2283f88b2283f88c2283f88d2283f88e2283f88f2283f8902283f8912283f8922283f8932283f8942283f8952283f8962283f8972283f8982283f8992283f89a2283f89b2283f89c2283f89d2283f89e2283f89f2283f8a02283f8a12283f8a22283f8a32283f8a42283f8a52283f8a62283f8a72283f8a82283f8a92283f8aa2283f8ab2283f8ac2283f8ad2283f8ae2283f8af2283f8b02283f8b122a0d14ef66961ccf2ff010160012180f8ce104ff0ff31a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe102860002c18bf002807d14cf6dd70c0f2450005b0bde8f04f0047d4f80cc0bcf1000ff2d0d4f820a0baf1000fedd0d4f844e000f104094ff0ff38002700264ff0ff3106e000bf6037c02f06f1060600f0eb81c3195a68002a50d01a69013205d01a6942453cbfd3f8108031465a69002a06f1010241d01d6a013505d01d6a45453cbfd3f8208011465a6a002a06f1020233d01d6b013505d01d6b45453cbfd3f8308011465a6b002a06f1030225d01d6c013505d01d6c45453cbfd3f8408011465a6c002a06f1040217d01d6d013505d01d6d45453cbfd3f8508011465a6d002a06f1050209d01d6e0135acd01d6e45453cbfd3f860801146a5e71646002e019600f1a281f24500f29f810aeb0c0102910eeb0c0100220491cdf80c9000bf130159f80330a34224d109eb02135f68674507d30499b94204d304999e68cd1bae4208d9df68013714d00021196059609960d9600ee00299b9420bd9df68013708d00021196059609960d960012180f8df1000bf01320c2ad2d1049e04e000bfbef1000f00f0ba80b6eb0c02c0f0b880924500f2b5803546a6eb0a0b00224ff0000e02e06032c02aead000eb0208d8f80430a34217d1d8f80830a3b1d8f80c90002709eb03018b454ff0000138bf01219d4288bf01279e4238bf33460f421cbf4ff0010e1e46d8f81410a14216d1d8f818309bb1d8f81c10002719448b454ff0000138bf01219d4288bf01279e4238bf33460f421cbf4ff0010e1e46d8f82410a14216d1d8f828309bb1d8f82c10002719448b454ff0000138bf01219d4288bf01279e4238bf33460f421cbf4ff0010e1e46d8f83410a14216d1d8f838309bb1d8f83c10002719448b454ff0000138bf01219d4288bf01279e4238bf33460f421cbf4ff0010e1e46d8f84410a14216d1d8f848309bb1d8f84c10002719448b454ff0000138bf01219d4288bf01279e4238bf33460f421cbf4ff0010e1e46d8f85410a1427ff46eafd8f85830002b3ff469afd8f85c10002719448b454ff0000138bf01219d4288bf01279e4238bf33460f421cbf4ff0010e1e4653e7554562d1ddf80c904ff0ff36002200274ff0ff3505e000bf6032c02a07f1060744d083185968a14207d11969013104d01969a9423cbf1d693e465969a14207d1196a013104d0196aa9423cbf1d6a7e1c596aa14207d1196b013104d0196ba9423cbf1d6bbe1c596ba14207d1196c013104d0196ca9423cbf1d6cfe1c596ca14207d1196d013104d0196da9423cbf1d6d3e1d596da142bfd1196e0131bcd0196ea9423cbf1d6e7e1db6e700bf002e4ed409eb06113301002249f803204a608a60ca60012180f8df10ace6dc4543d21af00303524615d0aaf101021cf80210012b0bf802100dd0aaf102021cf80210022b0bf8021005d0aaf103021cf802100bf80210baf1040f5dd3abf10203acf10406b118cf789d186f708f789f54497805f8011cb15c043a05f8021cf1d14ae000290dd409eb01120b01002549f8035055609560d56001220e4680f8df2059e6012180f8df10dce535d90af0030e5fea9a024ff0000317d0a3eb82080bf101060cf101026ff003055119cf787319df700f7904351f714f795f71897908eb050704379971f0d12b1dbef1000f13d01cf80310bef1010f0bf803100cd0591c1cf80120bef1020f0bf8012004d0991c1cf801200bf80120039b019a03eb021112019c50d0f8c420c1f804b0531cc1f808a024bf01230022c0f8c430ca6091e520463146fff7d8bc2de9f047044648b1a06938b14ef2bb33c0f24e032046bde8f04718474ff2a848c2f22908d8f8005028466ff39600b0f1005f07d128684ef66963ccf2ff03984200f09b804ff421700f46164601f0c8f90546002800f028814ff67c50cff6ff70002100bf2a182e3082f8841282f8851282f8861282f8871282f8881282f8891282f88a1282f88b1282f88c1282f88d1282f88e1282f88f1282f8901282f8911282f8921282f8931282f8941282f8951282f8961282f8971282f8981282f8991282f89a1282f89b1282f89c1282f89d1282f89e1282f89f1282f8a01282f8a11282f8a21282f8a31282f8a41282f8a51282f8a61282f8a71282f8a81282f8a91282f8aa1282f8ab1282f8ac1282f8ad1282f8ae1282f8af1282f8b01282f8b112a0d14ef66960ccf2ff002860012085f8ce004ff0ff30a5f8e000a5f8e200a5f8e400a5f8e600a5f8e800a5f8ea00a5f8ec00a5f8ee00a5f8f000a5f8f200a5f8f400a5f8f600a5f8f800a5f8fa00a5f8fc00a5f8fe00c8f8005005f1040a4ff000094ff0ff38002016e000bf002948bfbde8f0870aeb01170e017968ba682046c7f80c8000f088f84af80690c7f80490c7f80890c7f80c90daf80010a14205d04ff0ff314ff0ff3205e000bf29690131f6d02a6900216b69a34204d12b6a93423cbf2a6a01216b6aa34204d12b6b93423cbf2a6b02216b6ba34204d12b6c93423cbf2a6c03216b6ca34204d12b6d93423cbf2a6d04216b6da34204d12b6e93423cbf2a6e05216b6ea34204d12b6f93423cbf2a6f06216b6fa34206d1d5f8803093423cbfd5f880200721d5f88430a34206d1d5f8903093423cbfd5f890200821d5f89430a34206d1d5f8a03093423cbfd5f8a0200921d5f8a430a34206d1d5f8b03093423cbfd5f8b0200a21d5f8b430a3427ff47bafd5f8c0309342bff476afd5f8c0000b2175e7204639463246c8f80050bde8f047ffe72de9f047a4b0804643f677504ff2a847c0f24f0091468a46c2f2290780473c68002021466ff39601b1f1005f02908df80c0007d120684ef66961ccf2ff01884200f098804ff4217001f06ef80446002800f08f804ff67c50cff6ff70002100bf22182e3082f8841282f8851282f8861282f8871282f8881282f8891282f88a1282f88b1282f88c1282f88d1282f88e1282f88f1282f8901282f8911282f8921282f8931282f8941282f8951282f8961282f8971282f8981282f8991282f89a1282f89b1282f89c1282f89d1282f89e1282f89f1282f8a01282f8a11282f8a21282f8a31282f8a41282f8a51282f8a61282f8a71282f8a81282f8a91282f8aa1282f8ab1282f8ac1282f8ad1282f8ae1282f8af1282f8b01282f8b112a0d14ef66960ccf2ff002060012084f8ce004ff0ff30a4f8e000a4f8e200a4f8e400a4f8e600a4f8e800a4f8ea00a4f8ec00a4f8ee00a4f8f000a4f8f200a4f8f400a4f8f600a4f8f800a4f8fa00a4f8fc00a4f8fe003c60baf1000f4ff0010618bfb9f1000f23d101af3846fff79af802ad404651464a460123009501f04cfe05463846fff794f9002e064608d19df80c0028b949f28340c0f247004c308047002c18bfc4f8d060284624b0bde8f0879af8001001f07f00a0f1100212f1040f09d80b2807d001f07e01082903d0032801d00628c8d13cb149f28340c0f24700804794f8280210b14ff0ff35dce70026bae700bf4ff2a840c2f22900016808466ff39600b0f1005f16d108684ef66962ccf2ff0290420fd1d1f8fc0160b146f68052c2f207021268801a0028cebf01200020c1f8fc017047002070474ff2a840c2f22900026810466ff39600b0f1005f28d110684ef66961ccf2ff01884221d1d2f82c02f0b146f68051c2f207010968401a0028c4bf01207047d2f8301200200029c2f82c0282f82a0208bf704710b5c2f8300204460846fbf790ff2046bde81040704700207047f0b101684ef66962ccf2ff02914218bf704790f8061299b110b54af29f344ff0000cc0f24604864680f806c20120002100220023aef804c2a446bde810406047704700bf70b54ff2a846c2f229063468054621466ff39601b1f1005f07d120684ef66961ccf2ff01884200f097804ff4217000f0f7fe002800f0b88004464ff67c50cff6ff70002122182e3082f8841282f8851282f8861282f8871282f8881282f8891282f88a1282f88b1282f88c1282f88d1282f88e1282f88f1282f8901282f8911282f8921282f8931282f8941282f8951282f8961282f8971282f8981282f8991282f89a1282f89b1282f89c1282f89d1282f89e1282f89f1282f8a01282f8a11282f8a21282f8a31282f8a41282f8a51282f8a61282f8a71282f8a81282f8a91282f8aa1282f8ab1282f8ac1282f8ad1282f8ae1282f8af1282f8b01282f8b112a0d14ef66960ccf2ff002060012084f8ce004ff0ff30a4f8e000a4f8e200a4f8e400a4f8e600a4f8e800a4f8ea00a4f8ec00a4f8ee00a4f8f000a4f8f200a4f8f400a4f8f600a4f8f800a4f8fa00a4f8fc00a4f8fe00346000230820032184f81b322a2384f8180284f81912102184f81c32042384f81e0201204df60f1c04f5067284f81a1284f81d3284f81f0284f82012002d18bf0125c0f2470c0a2384f82152bde8704060470020306070bd00bf2de9f0414ff2a847c2f229073f684ff000083c466ff39604b4f1005f07d13e684ef66965ccf2ff05ae4208bfb84601280fd11c4615460f460646fff78dfe2346044639462a463046002c18bfb8f1000f06d14af29f3cc0f2460cbde8f041604798f8060270b1d8f800020021002888f80612a8f804123ed042f68d41c0f24401884738e0b8f804020121013080b2012898bf0846a8f80402d8f8000242f68d44c0f2440488f8061268b94ff65350cff6ff70a4f594777844002142460023b847c8f8000240b1a047d8f80002a4f140024ff4c8719047c8b198f80602002808bfbde8f081d8f80002002188f80612a8f8041200b1a0474af29f3cc0f2460c0120002100220023bde8f04160474cf6dd70c0f245008047012830d1082088f80802032088f80902102088f80a02002088f80b02b22088f80c02062088f80d0288f80e024620b8f8041288f80f02432088f8100201200f0a4df6090c08f5027288f8110288f8120288f81312c0f2470c09210d2388f81472bde8f0416047bde8f08170b50446d0f8000242f665360d46c0f2440668b94ff66d40cff6ff707844002122460023b0470028c4f8000208bf70bd06f594718847d4f8000206f1e8022946bde87040104700bf2de9f04f81b04568002d00f09e828368002b00f09a8205eb030a4ff000080026002412e04ff2a840c2f229000099c0f8008020463246bc460ceb0903002653451d464ff0000480f08082ab461bf9013b03f07f07b740002b44ea070410d404f00703012b16dc0bb3012b40f06e82aaeb0b03082bc0f0698205f10903dee700bfd34580f06282182e06f107065d46dcd95be200bf022b3ad0052b40f05682aaeb0b03042bc0f051826b1dc7e7d34580f04c8295f90130002b05f10203bed5534580f0438295f90230b3f1ff3f05f10303b4dc534580f0398295f90330b3f1ff3f05f10403aadc534580f02f8295f90430b3f1ff3f05f10503a0dc534580f0258295f90530002b00f12082ab1d96e7d34580f01b8295f9013005f1020c002b03f07f091fd5d44580f0108295f90260eb1c06f07f07b6f1ff3f49eac71902dde3469c460fe0534580f0008295f9037005f1040c07f07f06b7f1ff3f49ea863940f31e819b46aaeb0c03994500f2ee81e308672b00f00781652b7ff45eafb9f1060ffff45aaf9cf80030462b7ff455af9bf80230432b7ff450af9bf80330012b7ff44baf4ff2a843c2f229031d682b466ff39603b3f1005f07d12b684ef66967ccf2ff07bb4200f0a28004464ff4217067460091164600f068fc00283ff423af4ff67c5300990546cff6ff7320463246bc46ec182e3384f8848284f8858284f8868284f8878284f8888284f8898284f88a8284f88b8284f88c8284f88d8284f88e8284f88f8284f8908284f8918284f8928284f8938284f8948284f8958284f8968284f8978284f8988284f8998284f89a8284f89b8284f89c8284f89d8284f89e8284f89f8284f8a08284f8a18284f8a28284f8a38284f8a48284f8a58284f8a68284f8a78284f8a88284f8a98284f8aa8284f8ab8284f8ac8284f8ad8284f8ae8284f8af8284f8b08284f8b182a0d14ef66963ccf2ff032b60012385f8ce304ff0ff33a5f8e030a5f8e230a5f8e430a5f8e630a5f8e830a5f8ea30a5f8ec30a5f8ee30a5f8f030a5f8f230a5f8f430a5f8f630a5f8f830a5f8fa30a5f8fc30a5f8fe304ff2a843c2f229031d609bf804309bf805709bf80660032b47ea062459dd052b7adc042b00f0a780052b7ff484aed5f82c323bb146f68057c2f207073f68db1b002b11dcd5f8303285f82a8263b183461846c5f8308216460c466746fbf7fbfbbc4621463246584646f68053c2f207031b6845f69077c0f201073b44c5f82c3259e6044660460d4649461646674600f0e4fbbc462946324620464ce6d44580f0d38095f904706b1d07f07f06b7f1ff3f49ea46593ff7c2ae534580f0c58095f90560002e00f1c08005f1060c49ea0679c6e6012b42d0022b00f08f80032b7ff42aae009016468b466746fff7d0fb03460098bc4659463246002b3ff41cae95f80632002b3ff417ae284641f28831a5f80442fff7d0fd55e0062b58d0072b7ff40aae83464cf23330c0f24a0015460e466446804703465f1ea44631462a465846012f3ff6f8ad981eb0fa80f04009fff71afca44631462a465846ece546f68053c2f207031b6845f69077c0f201073b44c5f8fc31dfe5009016468b466746fff786fb03460098bc4659463246002b3ff4d2ad95f80632002b3ff4cdadb5f80432a3427ff4c8add5f8003285f80682002ba5f804823ff4bfad42f68d411846c0f2440188470098bc4659463246b3e5d5f83032c5f82c82002b85f82a823ff4abad04461846c5f8308215460e466746fbf732fbbc4631462a464ee795f80632c5f8fc81002b3ff497ad0446d5f800028b461646cdf800c085f80682a5f8048220b142f68d41c0f2440188474af29f370120002100220023c0f24607b847ddf800c020463246594676e54df60923c0f2490301b0bde8f04f184700bf7fb50646002806d1fff714fb002807d19de80f00064645f25b1cc0f24f0c60477fbd00bf092940f0f9802de9f04f89b0772b48d8a22702eb030cd75406278cf8017085278cf8027001278cf8037044f6e04ec0f2000e0026fe4400bf1ef806500ceb06040eeb060725717d7897f8028097f8039097f804a0657184f8068084f8079084f808a07d7913366572bd79852ea572fd79e5723d7a25737d7a6573bd7aa573fd7ae5733d7b25747d7b6574bd7ba574fd7be5743d7c25757d7c6575bd7ca575cbd189334ff2a847c2f22907d7f8008045466ff39605b5f1005f40d1d8f800704ef66966ccf2ff06b74238d198f8347298f83962009798f835724cf6dd75029798f8377298f83a92049798f83872c0f245050797b8f83c72019605973f0a0697b8f83e7298f83b6208973f0a03971c4617468b468246a847d8f840525946cb463a4623468446504637464fea15294fea154a2e0e4ff0a008e82b19d95ae000244ff0000800264ff0000a4ff0000900254ff0000c00274ff0000b0894cde90644cde90444cde90244cde90044e82b41d802eb030e06248ef8014015248ef802404d248ef8034043248ef8044001248ef80540009c8ef810708ef80640029c00278ef80740049c8ef817708ef80840079cc2278ef80940019cd7548ef80a40059c18338ef80b40069c8ef80fb08ef80c40089c8ef811c08ef80d40039c8ef812508ef80e408ef813908ef814a08ef815608ef8168009b0bde8f04f4df6090cc0f2470c604700bf2de9f04f89b04ff2a843c2f229031d680c4629466ff39601b1f1005f38d129684ef66963ccf2ff0399424bd195f83412b5f83c82039195f8351295f83862019195f8371295f83a92079195f8391295f83b7204914fea18210891b5f83e1282460291090a05914cf6dd71c0f2450193468847d5f840525a46290c06910199be463346844650462e0a4fea156aa02734e0002100234ff0000b00274ff0000a0691002600254ff0000c4ff0000e4ff000090591029108934ff0000804910791cdf80cb01ae0002100234ff0000b4ff0000a00260027069300254ff0000c4ff0000e4ff000090593029308934ff000080493cdf81ca08a4603965e46121b28bf182a2cd3c22202552044c17107990622017204994270152282704d2281720299c270432202710122417305994271039a817306998271089a017500211834437280f80b80027380f80f9080f810e080f811c08574c67480f815a08775c175204609b0bde8f08f2de9f04f81b04ff2a840c2f22900066830466ff39600b0f1005f0dd130684ef66963ccf2ff03984206d196f8340218b1002a18bf002902d101b0bde8f08f96f83b020028f8d0d6f844020028f4d046f6805ac2f2070adaf80030c01a0128ebdb96f83502012802d14ff0010b06e096f837b2bbf1010f18bf4ff0020b96f83a520020eb078846adf80200adf8000013d0bbf1020f10d196f8390268b96b464bf2f1270df10201c0f25a07404614461a46b84796f83a5222461446b2f5c86f28bf4ff4c86404f115094846174600f078f80028b1d0b7f5c86f88bf45f08005daf80010d6f8402253230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017396f8392283734273bdf80020bdf80230c273120a02741a0a8274220a0275621e032a04f0030c4374c47414d340f2fc7104ea010308f1010700217d1815f8014c421854757c5c043194756c788b42d475ad781576f1d1bcf1000f12d018f8017000f11503bcf1010f5f540ad04f1c18f80750bcf1020fdd5503d0023118f801205a544df66d22c0f24702494605469047d6f8400248f2c7310130c6f84002c0f245012846884701b0bde8f08fb0b54ff2ac44c2f22904216846f23f52c5f28802b2eb510f48f283314cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66962ccf2ff0291421bd190f83b12c1b1d0f84412b1b146f68052c2f207021368cb1a012b0edb1268d0f84802002808bf7047891a42f64d42c0f2440208bf01211047704710b5002143f2c942c0f8441280f83b12c0f25902002044f24361904748f65354c0f25a04a04704f1bc00bde81040004700bf70b50429c0f0d080024600784d2840f0cb805078432840f0c7809078012840f0c3804ff2a844c2f22904206803466ff39603b3f1005f07d103684ef66966ccf2ff06b34200f09a804ff421700d461646fff77cff002800f0a5804ff67c51cff6ff71002243182e3183f8842283f8852283f8862283f8872283f8882283f8892283f88a2283f88b2283f88c2283f88d2283f88e2283f88f2283f8902283f8912283f8922283f8932283f8942283f8952283f8962283f8972283f8982283f8992283f89a2283f89b2283f89c2283f89d2283f89e2283f89f2283f8a02283f8a12283f8a22283f8a32283f8a42283f8a52283f8a62283f8a72283f8a82283f8a92283f8aa2283f8ab2283f8ac2283f8ad2283f8ae2283f8af2283f8b02283f8b122a0d14ef66961ccf2ff010160012180f8ce104ff0ff31a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe10324629462060d378022b06dc012b11d0022b0ed1bde87040e7e0032b73d0042b07d190f8341221b1bde87040abe00020206070bd0d2938bf70bd90f83b12b1b1002143f2c94380f83b12c0f259030446002044f243611546984748f65356c0f25a06b04706f1bc0080472a46204611790446012988bf002180f83512517901f00303012b4ff0010198bf0b4680f837329679012e88bf002680f83862d679022e88bf002680f83962167a557a46ea0526502e98bf5026b6f5f07f28bf4ff4f076a0f83c62967ad57a46ea052641f28835ae4238bf3546a0f83e52127b80f8341202f0030280f83a2203f0010202eb5302002180f83622c0f8401200f00cf8204600f041f802e0044600f0dff82046bde870406ae000bfb0b5044690f83a02800758bfb0bd94f8350248f6a3450128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f83502012801d1002004e094f83702013818bf0120a8474ff6a522cff6ff7243f271337a44c0f25903002044f243619847012084f83b02b0bd00bf70b5044646f68050c2f20700006894f83b1245f69075c0f2010500292844c4f8440208bf70bdd4f8480242f66536c0f2440658b94ff64940cff6ff707844002122460023b047c4f8480250b106f594718847d4f8480206f1e8022946bde87040104770bd70b5044600f51375082084f84c02032084f84d02102084f84e02c22084f85002062084f851024d2084f85302432084f85402012084f8550294f8340294f8351284f8560284f8571294f83902b4f83c1284f85a0284f85b12080ab4f83e1284f85c02080a84f85e0294f83a0294f8372294f8383284f85d1294f83b1284f85f024cf6dd700026c0f2450084f84f6284f8582284f8593284f860128047d4f8401284f86102080a84f86302080c84f86402080e84f86502a02084f8676215264df6090c84f8621284f86602c0f2470c012009212a461c2384f85262bde87040604770b54ff2a840c2f22900046820466ff39600b0f1005f33d120684ef66961ccf2ff01884218bf70bd94f83b020025c4f8445288b143f2c942c0f25902002044f2436184f83b52904748f65356c0f25a06b04706f1bc008047d4f8480284f8345270b142f68d45c0f24405a847d4f8480205f166018847002804bf0020c4f8480270bd00bf2de9f04182b04ff2a841c2f229010c6821466ff39601b1f1005f75d121684ef66962ccf2ff0291426ed194f86c1279b394f86e02c0070ad0d4f82c0278b346f68051c2f207010968401a002827dd46f2d835c2f2070555f8040c002854d04ff27717c0f24b0747f62938002607f5437101a8c0f24b0801968847a8b1032084f86f622860b4f87002c04702b0bde8f081d4f87812c1b302b0bde8f0410847204602b0bde8f04133e001984ef6ed56c0f24b06a861b04706f5af708047e861b847012084f86f0203202860b4f87002c047d4f88002a0b10199d4f87c22b4f87272531a38bf8b1abb420ad2b4f8741259b146f68052c2f207021268101a884203d32046022100f06ef802b0bde8f08100bfb0b590f86c42002c42d043f60852c2f2000211880829114622d0114631f8083f082b1dd0114631f8103f082b18d0114631f8183f082b13d0114631f8203f082b0ed0114631f8283f082b09d0114631f8303f082b04d032f8381f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff67363cff6ff737b449a4204d1d0f87822002a18bf4a60002180f86c1290f86d12b1b1002180f86d1244f68241c2f20701097869b946f2d431c2f20701096839b148f26111c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b004464cf6dd70c0f245000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070046f2f030c2f2070050f81c2c94f86c12002a18bf0122002944f68141c2f207014b7818bf0232002b94f86f3218bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4df609058df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1046f68051c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f87c0208680921c4f8800201201f23a84708b0b0bd00bf02293cbf4ff0ff3070472de9f0414ff2a84540f20108c2f22905cff680782c68074608f1020020400e46b0f1005f07d120684ef66961ccf2ff01884200f098804ff42170fff790fb002800f0a98004464ff67c50cff6ff70002100bf22182e3082f8841282f8851282f8861282f8871282f8881282f8891282f88a1282f88b1282f88c1282f88d1282f88e1282f88f1282f8901282f8911282f8921282f8931282f8941282f8951282f8961282f8971282f8981282f8991282f89a1282f89b1282f89c1282f89d1282f89e1282f89f1282f8a01282f8a11282f8a21282f8a31282f8a41282f8a51282f8a61282f8a71282f8a81282f8a91282f8aa1282f8ab1282f8ac1282f8ad1282f8ae1282f8af1282f8b01282f8b112a0d14ef66960ccf2ff002060012084f8ce004ff0ff30a4f8e000a4f8e200a4f8e400a4f8e600a4f8e800a4f8ea00a4f8ec00a4f8ee00a4f8f000a4f8f200a4f8f400a4f8f600a4f8f800a4f8fa00a4f8fc00a4f8fe002c604cf6dd70c0f24500804701281cbf0020bde8f081787802281bd001280ed048b9204600210024fff795fe2046bde8f081002028604ff0ff30bde8f081022e41f288300cd14ff4fa720021012341f2883721e02046fff714fe0020bde8f081b978052e10d3fa783b79072e42ea03220fd37b79bd79092e43ea0523e7d3fe793f7a46ea072707e041f288374ff4fa7201e041f288370123642a98bf6422824228bf024694f86c0284f86e12a4f87022a4f87232a4f8747278b146f2d430c2f207000068002852d020460121fff743fe0020c4f88002bde8f08143f60850c2f2000001880829014622d0014631f8082f082a1dd0014631f8102f082a18d0014631f8182f082a13d0014631f8202f082a0ed0014631f8282f082a09d0014631f8302f082a04d030f8381f0829014630d14a686ff00100b2f5870f38bfbde8f08102ea0802012a7ff478af4a684ff61b20cff6ff707844824214bfc4f87822d4f87822b2b14860012084f86c02a5e748f2ef01c0f24b010420884730b105462046fff77ffd2846bde8f081012084f86d029ae76ff00100bde8f081334600f005b800bf334600f037b800bf2de9f04182b042f2d7281e4614460d460746c0f24608fef7b3fa002e18bf002808d108f1160338462946224602b0bde8f041184746f26870c2f207000068c0470028eed00068e028ebd130784bf6d32601900027c0f24e0600200021002209230097b047012002b0bde8f0812de9f04182b042f2d7281e4614460d460746c0f24608fef77dfa002e18bf002808d108f1160338462946224602b0bde8f041184746f26870c2f207000068c0470028eed00068e028ebd130784bf6d32601900027c0f24e060020002100220a230097b047012002b0bde8f08110b582b00446fef74ffa0146002c4ff0000018bf002901d102b010bd46f26870c2f20700006842f2d721c0f24601884790b10068e0284ff00000edd121784bf6d32c0191c0f24e0c002100220b230090e047012002b010bd002002b010bd00bf08b53046fff7ccff002805d002b044f6e970c0f24400004748f68b43c0f24603984708bd2de9f04f95b0002918bf002a04d115b0bde8f04f01f014b90e78ddf878b006f07f070a2f40f361810f2f00f333820b2f00f08d830c2f40f03382b2f1010901f0c78001f1010b0023002200bfa9eb03000428c0f088870beb0306b078f7781c1d40ea0727a9eb040087424ff0ff3001f2b0801bf80330767843ea06233b44b3f5803f01f2a680002f07eb040318bf01224b45dbd3002a01f09b808846fef7c2f9002800f060874ff2a847c2f229073c6820466ff39600b0f1005f07d120684ef66961ccf2ff01884200f097804ff42170fff710f9002801f0498004464ff67c50cff6ff70002122182e3082f8841282f8851282f8861282f8871282f8881282f8891282f88a1282f88b1282f88c1282f88d1282f88e1282f88f1282f8901282f8911282f8921282f8931282f8941282f8951282f8961282f8971282f8981282f8991282f89a1282f89b1282f89c1282f89d1282f89e1282f89f1282f8a01282f8a11282f8a21282f8a31282f8a41282f8a51282f8a61282f8a71282f8a81282f8a91282f8aa1282f8ab1282f8ac1282f8ad1282f8ae1282f8af1282f8b01282f8b112a0d14ef66960ccf2ff002060012084f8ce004ff0ff30a4f8e000a4f8e200a4f8e400a4f8e600a4f8e800a4f8ea00a4f8ec00a4f8ee00a4f8f000a4f8f200a4f8f400a4f8f600a4f8f800a4f8fa00a4f8fc00a4f8fe003c60d4f8300200286fd14ff48030faf7a9f8002800f0ab8600210022831881544032b2f5803f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f830020021cdf80c8004e1052f00f06381072f00f0bf820a2f40f0d280022ac0f032864ff2a844c2f22904206803466ff39603b3f1005f07d103684ef66967ccf2ff07bb4200f09a804ff4217015460e46fef7e0ff002800f057854ff67c51cff6ff71002243182e3183f8842283f8852283f8862283f8872283f8882283f8892283f88a2283f88b2283f88c2283f88d2283f88e2283f88f2283f8902283f8912283f8922283f8932283f8942283f8952283f8962283f8972283f8982283f8992283f89a2283f89b2283f89c2283f89d2283f89e2283f89f2283f8a02283f8a12283f8a22283f8a32283f8a42283f8a52283f8a62283f8a72283f8a82283f8a92283f8aa2283f8ab2283f8ac2283f8ad2283f8ae2283f8af2283f8b02283f8b122a0d14ef66961ccf2ff010160012180f8ce104ff0ff31a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe1031462a4620604c78002c00f0c584022c00f27e8540f08886062ac0f079858a78cb780f794e7942ea032147ea062232290791089280f07286322100f074be102f00f0e681422f3ff4b7ada7f10d05022d00f2d7828568002d00f05a85b0f84060b0f842406643b6f5163fc0f0518501310e2fa2f101029846064628465b4600f041850d2f40f0418500f029ff00f03fbd07eb0a0149454ff0000080f06f860beb01039878da7801f1040a50ea0227efd012025b7802441bf80160013a1d02032a00f0030e04a8e0c001d2002223e00398a7eb0e030844a91900228618d4f830c296f805800ceb010707f80280d4f83072b5790f4417447d70d4f83072f5790f441744bd70d4f83072367a0f44174404329342fe70e1d1069fdde90465bef1000fb6d0d4f830120beb0a00835c31442944bef1010f8b54abd0d4f83032511c10f801c033442b44bef1020f03f801c09fd0911cd4f83022405c32442a44505497e74ff2a848c2f22908022a2cbf4d78ff25d8f8004020466ff39600b0f1005f07d120684ef66963ccf2ff03984200f09d804ff4217016460f46fef781fe002800f0838204464ff67c50cff6ff700021324600bf23182e3083f8841283f8851283f8861283f8871283f8881283f8891283f88a1283f88b1283f88c1283f88d1283f88e1283f88f1283f8901283f8911283f8921283f8931283f8941283f8951283f8961283f8971283f8981283f8991283f89a1283f89b1283f89c1283f89d1283f89e1283f89f1283f8a01283f8a11283f8a21283f8a31283f8a41283f8a51283f8a61283f8a71283f8a81283f8a91283f8aa1283f8ab1283f8ac1283f8ad1283f8ae1283f8af1283f8b01283f8b112a0d14ef66960ccf2ff002060012084f8ce004ff0ff303946a4f8e000a4f8e200a4f8e400a4f8e600a4f8e800a4f8ea00a4f8ec00a4f8ee00a4f8f000a4f8f200a4f8f400a4f8f600a4f8f800a4f8fa00a4f8fc00a4f8fe00c8f8004094f8080170b1d4f8040140b142f68d43c0f244030e46174698473a463146002084f808010123032a80f0e181ebe14ff2a846c2f22906346820466ff39600b0f1005f40f0358520684ef66967ccf2ff07b8424ff0000040f02c85c4f82c0284f82a0284f82802d4f83012c4f8240284f8290221b1c4f830020846f9f703fed4f8040140f2030942f68d48cff68079c0f244080021a4f8081150b1c047d4f8040108f166018847002804bf0020c4f8040146f67560c0f251008047356805ea0900b0f1005f2bd12868b84228d195f83b024ff0000ac5f844a288b143f2c942c0f25902002044f2436185f83ba2904748f6535bc0f25a0bd8470bf1bc008047d5f8480285f834a250b1c047d5f8480208f166018847002804bf0020c5f84802306800ea0901b1f1005f40f011840168b94240f00d8490f86c12002900f00284fff78df800f004bc0846114615b0bde8f04ffff78cb94ff2a844c2f22904236818466ff39600b0f1005f07d118684ef66967ccf2ff07b84200f09b804ff4217015460e46fef727fd0346002800f08e804ff67c50cff6ff7000211a182e3082f8841282f8851282f8861282f8871282f8881282f8891282f88a1282f88b1282f88c1282f88d1282f88e1282f88f1282f8901282f8911282f8921282f8931282f8941282f8951282f8961282f8971282f8981282f8991282f89a1282f89b1282f89c1282f89d1282f89e1282f89f1282f8a01282f8a11282f8a21282f8a31282f8a41282f8a51282f8a61282f8a71282f8a81282f8a91282f8aa1282f8ab1282f8ac1282f8ad1282f8ae1282f8af1282f8b01282f8b112a0d14ef66960ccf2ff001860012083f8ce004ff0ff30a3f8e000a3f8e200a3f8e400a3f8e600a3f8e800a3f8ea00a3f8ec00a3f8ee00a3f8f000a3f8f200a3f8f400a3f8f600a3f8f800a3f8fa00a3f8fc00a3f8fe0031462a462360022a2cbf4978ff21002b00f0f98302294ff0000000f0fb81012900f0f481002940f0ef834cf67e21caf21011c3f8dc0061604ff0ff31a3f8cc00c3f8c800a3f8e010a3f8e210a3f8e410a3f8e610a3f8e810a3f8ea10a3f8ec10a3f8ee10a3f8f010a3f8f210a3f8f410a3f8f610a3f8f810a3f8fa10a3f8fc10a3f8fe1083f8000115b0bde8f08f092f00f08a80082f40f012810746002b4ff0ff3000f0b1834af28973cff6fd73d61802339e42c0f0a88391f801803846b8f1000f00f075820226b71c974200f266828b198e5d5b7856ea032300f05f82de19964200f25b82cc5d04f07f0cacf1100515f1030f0ad804f07b05092d06d0bcf1030f03d0bcf1060f40f0488214460d4639441a4600230746cdf800b0fff78bfa002840f03b82b8f10108294622463846cad13de20023c8f80030002439463246032a0bd355b98878082800f25c8346f67561c0f251019631884754e3052a1ad3012d18d18d78681e06284ff0000000f24b83cb78032b00f247830a79002a00f0438346f67560c0f2510000f59a7728461946b84737e3022d40f0598146f67560c0f2510080472ee337064ff0210658bf1126b242c0f0f281002f01f101050ed54cf6dd72c0f245020f4604461e469047334601462046022918bf07f1110584462879697950ea01264ff0ff301ebfa979ea7951ea022900f00783297b6a7b41ea02218e4240f00083a97bea7b41ea0221894540f0f9822878697840ea01217018b0f5207f4ff0ff3000f2ee82aa78ec7842ea042209eb0204b4f5f07f00f2e4822c7a6f7a44ea072806eb0807b7f5207f00f2da82af7aed7a47ea052509eb0507b7f5f07f00f2d082dcf80800002800f09581bcf84070bcf842406743b7f5163fc0f08c819a4643466446cde90169009502f059f8dbf800000f280ad80bebc0010130a1f806800d814e81a1f80c90cbf80000baf1000f00f0a682204678e1fd1e18bf0125bc1f18bf0124032afff4baa925407ff4b7a900254c1ca2f1010c8df81c508df81d508df820508df824508df825508df826508df827508df828508df829508df82a508df82b508df82c508df82d508df82e508df82f508df830508df831508df832508df833508df834508df835508df836508df837508df838508df839508df83a508df83b508df848508df849508df84a508df84b508df84c508df84d508df84e508df84f508df850508df851508df852508df85350cde9074c49f20164cff6ff747c440f9449f24164cff6ff747c44032f1094119500f00d81062f40f0fc800646002000211d4602f0d5f9b168002900f0f280b6f84020b6f842005043b0f5163fc0f0e98007a84ff4a0724ff4f07302f0ebfa002800f0df80dbf800000f280dd80bebc0010022ca800a814ff420724a814ff4f07201308a81cbf80000002d304640f0d380fce1012083f8ce00f8e183f8ce0015b0bde8f08f00202060bbe0002480f807424cf6dd70c0f24500804701462046012940f0e5814df25f50c0f2550015b0bde8f04f0047072a33d3032d31d18878cb780a7940ea03204d798e7901284ff0010498bf204644f62061884228bf084646f67561c0f25101642a28bf642201f5e2731146984746f2a070c2f207000068002800f0b48145ea0621012988bf0c4642f68d41c0f24401a1f1400221469047a5e1032a4ff00000c0f0a2812f1fb7fa87f77f093b4000f09b81d01e4cf6cd42ccf6cc428b78a0fb0202b3eb920f88bf9308302b184628bf3020002b00f0ad8100eb800303f0030c03f4fe770023ce18f578e21882f80a513579043382f80b5175799f4282f80c51b67982f80d61eed1bcf1000f10d01944ca782344bcf1010f83f80a2108d00a79bcf1020f83f80b211cbf497983f80c1184f80801d4f8040142f68d45c0f24405002184f8091170b949f27740cff6ff70a5f59477784422460023b8470028c4f8040100f06c81a5f14002012190473ae100f065fd01e001f0a8f920b14ff0ff3015b0bde8f08fb8f1000f00f02c813046594601f0e6fd26e1370600f12881082aecd384464ff0070e052501268c1994f802a04ff0ff30baf1000f00f01581e778002f00f0118111f806904fea8a0808eb8906b6f5207f00f2078166787c0004eb4607b7f5f07f00f2ff8048190f46495d4078cde9033e41ea002081b20120cde9052c02f09af8002840f0ed80069988680028b3d0b1f84020b1f842105143b1f5163fabd3049b4fea4a02f91807910599c91a089106eb860100ebc11000eb490107a8234602f0a3f9002897d0dbf800000f280cd84fea890172000bebc0030130d9801a81a3f80a809c81cbf800000398002806988cd1b6e090f86d12002918bffef787fc94f80702002684f8076258b14cf6dd70c0f245008047012804d14df25f50c0f255008047d4f8000294f80652c4f8fc6184f80662a4f8046250b1c047d4f8000208f166018847002804bf0020c4f8000200200121002d6060a060e06020616061a061e06120626062a062e06220636063a063e06320646064a064e06420656065a065e06520666066a066e06620676067a067e067c4f88000c4f88400c4f88800c4f88c00c4f89000c4f89400c4f89800c4f89c00c4f8a000c4f8a400c4f8a800c4f8ac00c4f8b000c4f8b400c4f8b800c4f8bc00c4f8c000c4f8c40084f8ce1040d04af29f37c0f2460701200021002200230024b847204615b0bde8f08f00203860f9e6b1f5fa6f02d94ff4fa6107910121054680f807124cf6dd70c0f24500804701281dd14df25f56c0f25506a6f188008047022c08bf002801d058b910e048f2d31207a9c0f24b020220904740b10446b0472046002185f8071215b0bde8f08f002015b0bde8f08f0c2afff4c4aecf78ce79b7427ff4bfae814608790f46097a88427ff4b8ae4cf6dd70c0f245009846144680470526022808bf01264ff00b0e092539462246cc464346bce60020a4f8080115b0bde8f08f46f675600025c0f2510084f808518047284615b0bde8f08ff0b583b04ff2a843c2f229031f683b466ff39603b3f1005f09d13b684ef66966ccf2ff06b34204bf002387f82a32002958d0362a56d30b78422b53d14b784d2b50d10b7f4f7f43ea0723042b4ad18b7dcf7d0e7e43ea072343ea06434f7e8e7ccd7c53ea076346ea05270e7d4d7d47ea064747ea05641d4648bf5d42b0f84070002b4ff00003c8bf0123bc422ad1b0f84270bd4226d18f7ace7a91f80cc047ea06274e7b47ea0c4747ea0667974219d2621c032606eb5202866822f0030cca19cde901c30746304621462346009502f07bfa3846314622462b4602f00ffb002003b0f0bd4ef2bb33c0f24e0303b0bde8f0401847072a1cbf4ff0ff3070472de9f04f8db00f4683461d46fdf76bf8002800f039834ff2a846c2f22906306801466ff39601b1f1005f07d101684ef66962ccf2ff02914200f097804ff42170fdf7b9ff002800f01d834ff67c51cff6ff71002200bf43182e3183f8842283f8852283f8862283f8872283f8882283f8892283f88a2283f88b2283f88c2283f88d2283f88e2283f88f2283f8902283f8912283f8922283f8932283f8942283f8952283f8962283f8972283f8982283f8992283f89a2283f89b2283f89c2283f89d2283f89e2283f89f2283f8a02283f8a12283f8a22283f8a32283f8a42283f8a52283f8a62283f8a72283f8a82283f8a92283f8aa2283f8ab2283f8ac2283f8ad2283f8ae2283f8af2283f8b02283f8b122a0d14ef66961ccf2ff010160012180f8ce104ff0ff31a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe10306039787a7841ea022a4ff6ff718a454ff0ff3200f08982d0f830121046002900f0808211f80a304ff0ff30002b00f0798251444a78002a00f0748202fb03f001f1020c4ff000064ff000010195009278b34ff6fe794ff6fd7801eb0a054d4500f05e828e4661440a78140903d00125a0421ad254e2454500f052824c781cb10225a04211d24be24ff6fb72aa1a042ac0f046828a78c97852ea012400f040820425a042c0f03c8200bf001b05eb0e01d3d10691b878f9783a797d79bf7940ea0129b8060f2142ea052507f00f0201eae07000fb02f189204143c90a8df824100e2117f0200f08bf0f2608bf012102fb01f100fb01f14fead1218df825104ff00d0108bf022102fb01f100fb01f14fead1218df826104ff00c0108bf032102fb01f100fb01f14fead1218df827104ff00b0108bf042102fb01f100fb01f14fead1218df828104ff00a0108bf052102fb01f100fb01f14fead1218df829104ff0090108bf062102fb01f100fb01f14fead1218df82a104ff0080108bf072102fb01f100fb01f14fead1218df82b104ff0070108bf082102fb01f100fb01f14fead1218df82c104ff0060108bf092102fb01f100fb01f14fead1218df82d104ff0050108bf0a2102fb01f100fb01f14fead1218df82e104ff0040108bf0b2102fb01f100fb01f14fead1218df82f104ff0030108bf0c2102fb01f100fb01f14fead1218df830104ff0020108bf0d2102fb01f100fb01f14fead1218df831104ff0010108bf0e2151434143c90a8df8321006fb02f1069a48434ff0010ec00a002a8df8330000f0758107f010008eea1010002604904ff00008cdf814c008e0dde90706069a0644ddf814c0964280f061811cf806000896040901d0012113e0971b012f00f056810ceb06014c780cb1022109e0042fc0f04d818a78c97852ea012400f047810421079110f00f0109a810f801a018bf012104984fea0a1e40ea010c14f00300474600f08080b8fbf3f100224f19b7f1ff3fc8bf012202ea0c02012a1dd101fb13814944ca09042a17d87a090e2a14d807eb87020beb82124f08d65dc9076ff00f01029608bf0f210390504608bf7046029e314001430398d155012808f1010751d0b7fbf3f100264a19b2f1ff3fc8bf012606ea0c06012e1ad101fb13714944ce09042e14d856090e2e11d802eb82020beb82124e08c9070390905d6ff00f01574604bf0f2177460140039839439155022808f1020726d0b7fbf3f100224e19b6f1ff3fc8bf012202ea0c02012a18d101fb13714944ca09042a12d872090e2a0fd806eb86020beb82124e08c907905d6ff00f01574604bf0f21774601403943915508f10307611e0329a04405d244e700bf0437b8453ff440afb7fbf3f600227119b1f1ff3fc8bf012202ea0c02012a19d106fb137202eb0906f209042a12d84a090e2a0fd801eb81010beb811172088c5cf6076ff00f06504604bf0f2670463440204388547e1cb6fbf3f200205119b1f1ff3fc8bf012000ea0c00012819d102fb136000eb0906f009042812d848090e280fd801eb81000beb80107108425cf4076ff00f04564604bf0f247646224032434254be1cb6fbf3f200205119b1f1ff3fc8bf012000ea0c00012819d102fb136000eb0906f009042812d848090e280fd801eb81000beb80107108425cf4076ff00f04564604bf0f247646224032434254fe1cb6fbf3f200205119b1f1ff3fc8bf012000ea0c0001287ff47aaf02fb136000eb0906f00904283ff672af48090e283ff66eaf01eb81000beb80107108425cf4076ff00f04564604bf0f2476462240324342545ce7002030604ff0ff300db0bde8f08f10460db0bde8f08f009909eb03002944b0f5207fa8bf4ff42070b1f5f07fa8bf4ff4f071019f484588bfa94203d800200db0bde8f08f3a680f2af8d8a0eb090007ebc203491b5881501ca3f806901d8199813860ebe700bf082a3cbf4ff0ff3070472de9f04f95b015460c4680469a46fcf7f0fc002800f00482e67906f1080085424ff0ff3040f0fe812178627841ea02254ff640718d4200f2f5814ff2a849c2f22909d9f80000a77901466ff39601b1f1005f07d101684ef66962ccf2ff02914200f098804ff42170fdf72bfc002800f0d4814ff67c51cff6ff71002200bf43182e3183f8842283f8852283f8862283f8872283f8882283f8892283f88a2283f88b2283f88c2283f88d2283f88e2283f88f2283f8902283f8912283f8922283f8932283f8942283f8952283f8962283f8972283f8982283f8992283f89a2283f89b2283f89c2283f89d2283f89e2283f89f2283f8a02283f8a12283f8a22283f8a32283f8a42283f8a52283f8a62283f8a72283f8a82283f8a92283f8aa2283f8ab2283f8ac2283f8ad2283f8ae2283f8af2283f8b02283f8b122a0d14ef66961ccf2ff010160012180f8ce104ff0ff31a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe10c9f80000d0f830e2bef1000f00f04081a178ba061091e1780f230d91217903eae2720e9107f00f014a434ff0890c02fb0cf2d20a8df844200e2294f805900b9717f0200f08bf012201fb02f202fb0cf24fead2228df845204ff00d0208bf022201fb02f202fb0cf24fead2228df846204ff00c0208bf032201fb02f202fb0cf24fead2228df847204ff00b0208bf042201fb02f202fb0cf24fead2228df848204ff00a0208bf052201fb02f202fb0cf24fead2228df849204ff0090208bf062201fb02f202fb0cf24fead2228df84a204ff0080208bf072201fb02f202fb0cf24fead2228df84b204ff0070208bf082201fb02f202fb0cf24fead2228df84c204ff0060208bf092201fb02f202fb0cf24fead2228df84d204ff0050208bf0a2201fb02f202fb0cf24fead2228df84e204ff0040208bf0b2201fb02f202fb0cf24fead2228df84f204ff0030208bf0c2201fb02f202fb0cf24fead2228df850204ff0020208bf0d2201fb02f202fb0cf24fead2228df851204ff0010208bf0e2201fb02f202fb0cf24fead2228df852204ff0000208bf0f22514301fb0cf14ff0000bc90a002e0f968df8531000f09d820eeb05010c9110990d9a04f1080641ea02210d910e994ff6fd7241ea09210e914ff6ff714ff000094ff6fe7c57469246cdf8408088460a9704e00f9909f10109894552d016f809104a1e1f2af5d34ab2202a45db0c9a02eb410111f8402c11f83f1c42ea012747453ad01ef807104ff0ff3b002900f061820eeb07025378002b00f05b8202f1020b5943002200bfd319634525d00beb02052c78240903d00125a14216d21ce053451ad06c781cb10225a1420ed214e04ff6fb741b1b042b0fd3ab78ec7853ea04240ad00425a14207d300bf091b2a44dad1afe70020c9f800004ff0ff3015b0bde8f08f0a990122063101910b99002501f010014ff6ff774ff6fe7a82ea1111cde90616725d1f2a04d80d990f9c11440b3908e2d0f830124ff0ff3b002900f009820c9b03eb420212f8403c12f83f2c43ea0228b84500f0fd8111f808e0bef1000f00f0f78141444b78002b00f0f28103fb0ef7ddf834c0002fcde9023500f0ac818b1c002202eb08055545b5d09c182178090901d0012412e04ff6fd718d42abd0617809b102240ae04ff6fb71691a0429a2d3a178e47851ea04219dd004248f429ad37f1a2244ddd1002a00f0858100250027cde904230ae00b9d0999049a0d44079e059b95424ff6fe7a80f07581595d0b955fea111b01d0012215e0541b012c00f06a815a1992f801b0bbf1000f01d0022209e0042cc0f05f819478d27854ea022b00f059810422099211f00f0111aa12f8018018bf0121069a0e9e42ea010a4fea08191bf003013a4600f09280b7fbfef4cdf820b004fb1e724ff0000b6244b2f1ff3fc8bf4ff0010b0aea0b05012d1cd1a4191ad4d509042d17d865090e2d14d80b46109904eb840401eb84145508d207194614f805b06ff00f02434604bf0f224b4602ea0b021a436255ddf820b0012907f101025cd0b2fbfef4002504fb1e226244b2f1ff3fc8bf012505ea0a05012d1ed1a4191cd4d509042d19d865090e2d16d80b46109904eb840401eb841b5508d20719461bf805306ff00f02444604bf0f224c461a4022430bf80520ddf820b0022907f102022bd0b2fbfef4002504fb1e226244b2f1ff3fc8bf012505ea0a05012d1cd1a4191ad4d509042d17d865090e2d14d8109904eb840401eb841b5508d2071bf805306ff00f02444604bf0f224c461a4022430bf80520ddf820b0fa1cabf10104032c5f4405d22ce704325f4693453ff428afb2fbfef4002304fb1e25bb466544b5f1ff3fc8bf012303ea0a03012b18d1a41916d4eb09042b13d863090e2b10d8109904eb840301eb83136c08195ded076ff00f05474604bf0f254f46294039431955511cb1fbfef404fb1e1101eb0c050021b5f1ff3fc8bf012101ea0a01012918d1a41916d4e909042913d861090e2910d8109b04eb840103eb81116b08cc5ced076ff00f05474604bf0f254f462c403c43cc54911cb1fbfef404fb1e1101eb0c050021b5f1ff3fc8bf012101ea0a01012918d1a41916d4e909042913d861090e2910d8109b04eb840103eb81116b08cc5ced076ff00f05474604bf0f254f462c403c43cc54d11cb1fbfef404fb1e1101eb0c050021b5f1ff3fc8bf012101ea0a0101297ff470afa4193ff56dafe90904293ff669af61090e293ff665af109b04eb840103eb81116b08cc5ced076ff00f05474604bf0f254f462c403c43cc5452e70e9d029a0ceb0e01ab18b1f5207f0f462ceaec72a8bf4ff42077b3f5f07fa8bf4ff4f07397421ddd0f9cab421bd9ddf82880d8f800500f2d15d8ddf838e0a7eb0209019fa3eb0e0c07ebc50327f835206a1ca3f802e0a3f80490a3f806c0c8f8002000e00f9c039d4ff6ff7701354ff0000ba5420d917ff4e8ad584615b0bde8f08f062a3cbf4ff0ff3070472de9f04fadf2944d9a46154688460f90fcf7a9f8002800f0d68098f80510881d854240f0298446f6ac10c2f20700d0f800b0bbf1000f00f01f849bf80c009bf80d209bf80e309bf80f7040ea022040ea034040ea0769a9f1810010f1800f4ff0ff30c0f0b2809bf810209bf811309bf8137042ea03229bf8123042ea034242ea07620692813a12f5817f40f29e800029cdf828b000f09d8008f1060b002426aa4ff4e01c00270ae000bf05f1004042f8240001378f4204f1010480f08e801bf80750681e1e28f0d968b21f2801dd012075e0a5f1c2000beb07061d28a1eb07000fd8012800f0c88396f9010010f1410f00f3c28300f03f0365f38a1302201d465de005f0f003e02b24d10328c0f0b48396f9013013f1410f00f3ae8396f9020010f1410f00f3a883e02ddeb202d1a02ec0f0a283ed2d02d19f2e00f29d832b039bb206f03f0643ea861300f03f001d18032034e004284ff0ff3036d3a5f1f50313f1050f31d396f9013013f1410f2cdc96f9020010f1410f00f37e8396f9036016f1410f00f37883f02ddbb202d1902bc0f07283f42d02d18f2b00f26d830cea854e03f03f054eea053300f03f0043ea801006f03f0326aac518042000bf074442f8245076e74ff0ff300df2944dbde8f08f0021012007915ee0002c57d0a4f1010bcdf86090cdf810a000250df1780a5f46914608e026aaab4505f1010509f10409a7f1010739d052f825100029f3d400202b4687421dd009eb80067268b2f1ff3f18dc5a1c934514d0b268b2f1ff3f11dc9a1c93450dd0f268b2f1ff3f0adcda1c934506d032690433002a00f10400e0d400e000220a9853461aae009601f040fa002800f008831a980028c3d046f2a1415046c0f24e018847bce7ddf810a0ddf828b0ddf860900020079404e00020ddf828b00790012098f804400f21a20604f00f0501eae271694389225143c90a8df8681001260e2198f800c098f801e098f8023098f8037014f0200f08bf0e2608bf012105fb01f102fb01f14fead1218df869104ff00d0108bf022105fb01f102fb01f14fead1218df86a104ff00c0108bf032105fb01f102fb01f14fead1218df86b104ff00b0108bf042105fb01f102fb01f14fead1218df86c104ff00a0108bf052105fb01f102fb01f14fead1218df86d104ff0090108bf062105fb01f102fb01f14fead1218df86e104ff0080108bf072105fb01f102fb01f14fead1218df86f104ff0070108bf082105fb01f102fb01f14fead1218df870104ff0060108bf092105fb01f102fb01f14fead1218df871104ff0050108bf0a2105fb01f102fb01f14fead1218df872104ff0040108bf0b2105fb01f102fb01f14fead1218df873104ff0030108bf0c2105fb01f102fb01f14fead1218df874104ff0020108bf0d2105fb01f102fb01f14fead1218df8751006fb05f102fb01f14fead1218df876104ff0000108bf0f2169435143c90a00284ff000008df877107ff4cdae43ea0720079a484403904cea0e290af10600571e00260df198080190cdf810a0029718e000bf46f2a1411ea8c0f24e0188479df87c009df87d10dde90ab9029fdde9072640ea01200df1980801369642814400f0ff8158f82610b1f1ff3f1edd33469f421fd008eb83004268b2f1ff3f1adc0133bb4216d08268b2f1ff3f13dc0133bb420fd0c268b2f1ff3f0cdc0133bb4208d002690133002ae2d404e001f01f000b38d2e7002258461eab19ad009501f0fff8002800f0c781199900290d9100f0ba819df880209df881309df87e009df87f1052ea03259df8822040ea01279df8833010979df884704fea024208969df8856042ea0362069b4fea074747ea06672b4403eb2743039fcdf82c90a7eb030609eb22491aaf149500f05e810902109b014400f0030809f101004ff0010c099009f102000ceb530305900d980c934b1e0e930b9b0130121415900ceb510003eb020e9a1acde91180a1eb08001890d0074ff0000a17904feace70169013960ae014980af1010a824512981599139e0144159100f029810aeb06014b090e2befd810980028ecd00e9801eb810103280f984ff0000600eb811e80f0848011980028ded0dde90c105feac67c0afb01084fea560018f8000000f00f03c1b208bf0b09b3fa83f0400910ea141f14d106eb0901c80904280fd848081ef80020fb5c02f00f0b02f0f0021a431aafc90708bf4bea03120ef8002011980128b1d0701c400818f80000bcf1000fc1b24fea111308bf00f00f03d8b2b0fa80f0400910ea141f14d109983118c80904280fd848081ef80020fb5c02f00f0b02f0f0021a431aafc90708bf4bea03120ef80020119802283ff486afb01c400818f80000bcf1000f00f00f01c2b208bf1109b1fa81f0400910ea141f7ff474af05983318d80904283ff66eaf58081ef80020795c02f00f0602f0f0020a43db0708bf46ea01120ef800205de7ddf8548007e000bf18980436b04208f102083ff471af18f8011c0023c9b2102938bf012313ea141f09eb060c16d14feadc13042b12d84fea5c0309091ef80320795c02f00f0b02f0f0020a431aaf5feac97008bf4bea01120ef8032018f8010c00f00f01b1fa81f0400910ea141f15d10cf10103d809042810d858081ef80020795c02f00f03179d43ea011302f0f002002d08bf42ea01030ef8003098f80000c1b210294ff0000038bf012010ea141f15d10cf10203d809042810d8080959081ef80120385c02f00f0302f0f002169d0243002d08bf43ea00120ef8012098f8000000f00f01b1fa81f0400910ea141f8ad10cf10303d80904283ff685af58081ef80020795c02f00f03179d43ea011302f0f002002d08bf42ea01030ef8003072e700bf109809eb00011498b1f5207f06eb000229eae970a8bf4ff42071b2f5f07fa8bf4ff4f072ddf810a081427ff70fae26eae6739a427ff70aaedaf800700f2f3ff605ae019dd21a091a05ebc70625f83700781c7380b180f280caf80000f6e59df87c009df87d10079a40ea012001e64ff0ff300df2944dbde8f08f00200df2944dbde8f08f2de9f04182b04ff2a847c2f229073d68884629466ff39601b1f1005f064607d128684ef66961ccf2ff01884200f098804ff42170fcf7b8fb0546002800f08f804ff67c50cff6ff70002100bf2a182e3082f8841282f8851282f8861282f8871282f8881282f8891282f88a1282f88b1282f88c1282f88d1282f88e1282f88f1282f8901282f8911282f8921282f8931282f8941282f8951282f8961282f8971282f8981282f8991282f89a1282f89b1282f89c1282f89d1282f89e1282f89f1282f8a01282f8a11282f8a21282f8a31282f8a41282f8a51282f8a61282f8a71282f8a81282f8a91282f8aa1282f8ab1282f8ac1282f8ad1282f8ae1282f8af1282f8b01282f8b112a0d14ef66960ccf2ff002860012085f8ce004ff0ff30a5f8e000a5f8e200a5f8e400a5f8e600a5f8e800a5f8ea00a5f8ec00a5f8ee00a5f8f000a5f8f200a5f8f400a5f8f600a5f8f800a5f8fa00a5f8fc00a5f8fe003d60b068002818bf002d02d102b0bde8f081b6f84010b6f842205143b1f5163ff4d3c5f8240201264ff4f07085f8286201904ff4207049f683540090c0f2470400200021002200230027a04730b185f82872c5f8247202b0bde8f08188f8046002b0bde8f0812de9f04f8ab0dde914a5089243ea010242ea0a02d207864640f0c4800eeb51004ff0ff374fea5a0c0eeb53068646012207eb5a00bcf1010f88bf4fea5a02069002f003000790caf341006ff00107059007eb5a006ff00207019007eb5a00009022f00302701c544203900ef101004ff0000b09960290cdf810e004e00bf1010bab4500f0c3810898139e5f466fea0b02864288bfaf183a183744099802eb820207eb87070eeb82198b4200eb871835d9059e6246b6b10698012e19f8002008f8002002460ed00198022e19f8002008f80020024606d0009819f8002008f80020024600bf06980328c8d300bf09eb020717f8016c08eb020000f8016c17f8026c043a00f8026c17f8036c00f8036c17f8047c00f8047ce9d1b0e700bfbaf1080f02d2002223e000bf03989601ba0102440298e64600eb060a6ff0030c0aeb0c00c67802eb0c07fe7006790cf1040c3e7146797e71807904eb0c060436b871edd10cf10402dde914a5f446ddf810e0079800283ff483af079e19f80200012e08f802003ff47baf501c079e19f80070022e08f800703ff472af901c19f8002008f800206be74ff6fc7000ea0a000af0030b0990aaf1010000240490cde905be07e0079c159d0134ddf850a0ac4200f01e81089f139ee0432246be42079488bf2a18d01900eb80000eeb801c901900eb8000baf1040f0eeb80184ff00009c0f09880ddf810a0ddf850e048468b4288bf504600eb010400eb03054fea54001cf800706ff0010080ea090009f1010288bf0eeb00026ff0020089ea000609f1020088bf0eeb06006ff0030686ea090609f1030b4feac47488bf0eeb060b07f00f06002c4fea550408bf3e0918f80470ed0707f00f0507f0f007374408bf45ea061708f80470541865081cf805501a44e40705f00f064fea520408bf2e0918f80450d20705f00f0205f0f005354408bf42ea0615421808f8045054081cf804401844d20704f00f054fea500208bf250918f80240c00704f00f0004f0f0042c4408bf40ea05140beb010008f8024042081cf802200beb0304c00702f00f054fea540008bf150918f80020e40702f00f0402f0f0022a4408bf44ea051208f80020099809f104098145aaf1040a7ff46eafdde905bebbf1000f3ff444af6fea09004a468b42149f88bf3a18501845081a44c0071cf805504fea520018f8007005f00f0408bf2c0907f00f0507f0f0072744d20708bf45ea0417bbf1010f08f800703ff420af149809f10102a0eb090a8b4288bfaaf10202541865081a44e4071cf805504fea520418f8040005f00f0708bf2f0900f00f0500f0f0003844d20708bf45ea0710bbf1020f08f804003ff4faae09f102008b4288bfaaf10300421854081844d2071cf804704fea500218f8024007f00f0508bf3d0904f00f0704f0f0042c44c00708bf47ea051408f80240d9e60ab0bde8f08f00bf70b54ff2a846c2f2290632680c4611466ff39601b1f1005f054607d110684ef66961ccf2ff01884200f098804ff42170fcf7cef8002800f0db8002464ff67c50cff6ff70002100bf13182e3083f8841283f8851283f8861283f8871283f8881283f8891283f88a1283f88b1283f88c1283f88d1283f88e1283f88f1283f8901283f8911283f8921283f8931283f8941283f8951283f8961283f8971283f8981283f8991283f89a1283f89b1283f89c1283f89d1283f89e1283f89f1283f8a01283f8a11283f8a21283f8a31283f8a41283f8a51283f8a61283f8a71283f8a81283f8a91283f8aa1283f8ab1283f8ac1283f8ad1283f8ae1283f8af1283f8b01283f8b112a0d14ef66960ccf2ff001060012082f8ce004ff0ff30a2f8e000a2f8e200a2f8e400a2f8e600a2f8e800a2f8ea00a2f8ec00a2f8ee00a2f8f000a2f8f200a2f8f400a2f8f600a2f8f800a2f8fa00a2f8fc00a2f8fe0032600120002d82f8cc0047d0104630f8e01fa1423bd0b2f8e210a14237d0b2f8e410a14233d0b2f8e610a1422fd0b2f8e810a1422bd0b2f8ea10a14227d0b2f8ec10a14223d0b2f8ee10a1421fd0b2f8f010a1421bd0b2f8f210a14217d0b2f8f410a14213d0b2f8f610a1420fd0b2f8f810a1420bd0b2f8fa10a14207d0b2f8fc10a14203d0b2f8fe10a1420ad1012082f8de0070bd0020306070bd82f8cd00002070bd92f8cd1081b9b2f8c810611a0bb2b3f1ff3f06dd89b2022924bf012182f8dd1002e0012182f8dc10b2f8ca30002182f8cd109c42a2f8c84088bfa2f8ca4092f8001120f81140481c00f00f0082f80001002070bd00bf2de9f04fcdb046f22b149246c0f25d0447f2f85298460e4604f13c07c0f27b020f2138230546b84718b12846a047002423e20afb08f040000b960295059001250da94ff4807004f585724ff0000b4ff0000947464ff000080023564604930a930697cdf820a00192029ce1602061204600219047e1680daa891a07910da900f0e681ddf82ce00021002400900be000bf04940c9c002101234ff0030807980134844200f0d181002940f0e0810da80c94045db8f1020febd0b8f1010f00f09280b8f1000f40f0968004f00f000a900598210900f0a6808842c0f08880401a05900a9800eb00140001039014e01cf80b000a9a00f0f00010440cf80b000bf1010b01390125b34524bf4ff0000b09f10109002900f08c81b9454ff000084ff0000338bf012380f0028109eb8900002d0eeb801cdbd0cdf82490a946a6eb0b05b5eb510f88bf4d088db3a8080ceb0b0820d0002708f10102a7eb80006ff0030600bf02eb060e043600eb060a1af104078ef803408ef804408ef805408ef80640efd1301d069f089eddf82ce015f0030204d10ce0002015f0030208d0012a08f8004004d04044022a447018bf8470a1eb4501ab4489b1b34510d21cf80b00039a00f00f001043ddf824900cf80b00013900250029a0d12be100bf00214d46ddf8249090e700bfbcb10598a04228d201214ff0000821e0ddf810a005985aea042a16d00c9c5045cdf810a080f0938001214ff00008002342e70c9c002101234ff002083ce70c9c00214ff00108012336e7002001214ff0000804900c9c00232ee7001b05900a9800eb00110001099015e000bf1af80b200a9802f0f00202430af80b200bf1010b013c0125b34524bf4ff0000b09f10109002c00f0da80b9454ff000084ff0000338bf012350d209eb8902002d0eeb821adcd0ac46a6eb0b05b5eb540f88bf650855b3ae080aeb0b0818d0002008f10102a0eb860e6ff00306901904360eeb06070437c170017141718171f5d1069fddf82ce0321d15f0030604d10de0002215f0030609d0012e08f8021005d04244022e517018bf917000bfa4eb4504ab447cb1089eb3450ed21af80b00099a00f00f0010430af80b00013c0025002cabd184e0089e002465469de70c9c0121b4e6a0eb0a0005900a9800eb00110001099015e01cf80b000a9a00f0f00010430cf80b000bf1010baaf1010a0125b34524bf4ff0000b09f10109baf1000f65d0b9454ff000084ff0000338bf01235bd20b9a09eb8900002d02eb801cdad0ce46a946a6eb0b05b5eb5a0f88bf4fea5a0545b3a8080ceb0b0817d0002408f10102a4eb80006ff003069719043684190434f97039717971b971f6d1301d069f089e0c9c15f0030204d10ce0002015f0030208d0012a08f8001004d04044022a417018bf8170aaeb450abaf1000fab4411d0b34511d21cf80b00099a00f00f0010430cf80b00aaf1010a0025f146baf1000fa6d10be04ff0000a4d46f14697e70c9c4ff00008002131e6012102e04ff000080021ddf82ce029e600980da973b1012817d04ff0000450b90798019ab0fa80f040094ff480703ff4ffad00e00024029846f22b11c0f25d01884720464db0bde8f08f059840ea0800b0fa80f04409eee72de9f04f83b00c9e0292002e019000f08e80019823f00304471c029803f0030ac4f1000c01384ff00008009005e000bf08f10108b0450f4479d00e98c14600286fea080418bf06eb0409002bf0d0042b06d24ff0000bbaf1000f2ed1e8e700bf0d98b64609fb00f400986ff003050444607800f0f00242ea10107a19d0706078043500f00f0646ea0010107114f8020f00f0f00646ea10105071207800f00f0646ea00100ceb050604369071e0d105f1040b7646baf1000fbad002980d9a4fea5b0509fb0204019814f805e008fb01050ef00f025feacb7908bf4fea1e1242ea0212baf1010f05f80b20a1d00bf1010e4fea5e00205cb9f1000f4fea101208bf00f00f0242ea0210baf1020f05f80e008ed00bf102004208a25cb9f1000f02f00f0408bf140944ea04122a5480e703b0bde8f08f2de9f04182b003fb02f68846cde900164cf6036107466846c0f247011c461546884740f2196047f8240f788946f2c10245ea0040b86045ea044057f8204c7860c0f24a0220463946fe60c7f81080904740f69b51c0f244012046884702b0bde8f08100bf2de9f04188b046f24f461c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0814556454e4346572f313820696d6736343020696d677a20726c652077616b656c65617365206469726563746662206662677561726420776561726e6f7469667920636c65616e75703131207465786361636865313220746578696d67313320746578737472313420666f6e743135206d696363746c207461706c6f6e67313120616c7331360000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a8900000000000000000", + "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fa5b04ef66c6b4ff2a84416460d46ccf2ff0bc2f229044ff6ff7900274ff00108019006e048f2c731c0f24501bff32f8f8847d4f800a0bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0bb804ff4377005f039f8002800f0a1824ff62451cff6ff7142183d3182f8dc7282f8dd7282f8de7282f8df7282f8e07282f8e17282f8e27282f8e37282f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382d1c0f800b080f80a80a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001f51457ff436afbff35f8f44e8000121b154e8001f5145f8d02be7aa4645ea064100260127c0f8701206e048f2c731c0f24501bff32f8f88472568bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0bc804ff4377004f05eff002800f0c6814ff62451cff6ff7100bf42183d3182f8dc6282f8dd6282f8de6282f8df6282f8e06282f8e16282f8e26282f8e36282f8e46282f8e56282f8e66282f8e76282f8e86282f8e96282f8ea6282f8eb6282f8ec6282f8ed6282f8ee6282f8ef6282f8f06282f8f16282f8f26282f8f36282f8f46282f8f56282f8f66282f8f76282f8f86282f8f96282f8fa6282f8fb6282f8fc6282f8fd6282f8fe6282f8ff6282f8006382f8016382f8026382f8036382f8046382f8056382f8066382f8076382f8086382f8096382f80a6382f80b6382f80c6382f80d6382f80e6382f80f6382f8106382f8116382f8126382f8136382f8146382f8156382f8166382f8176382f8186382d1c0f800b08772a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fa9427ff437afbff35f8f00bf44e8000121b154e8001fa942f8d02be7d0f8746242f6f767c0f24407002ebff35f8f00f0eb8007f19a0230464ff0ff314ff0ff379047002840f0418143f67750c0f24f00804700274ff001080397adf8107006e048f2c731c0f24501bff32f8f88472568bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0e1804ff4377004f068fe002800f0d9804ff62451cff6ff7100bf42183d3182f8dc7282f8dd7282f8de7282f8df7282f8e07282f8e17282f8e27282f8e37282f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382d1c0f800b080f80a80a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fa9427ff436afbff35f8f44e8000149b354e8001fa942f8d02be705460020b847b0b105f51d7151e8006f4eb9bff35f8f00bf41e8000292b151e8006f002ef8d00021bff32f8fbff35f8f21b10646f9e64ff0ff3742e007f5a9718847f2e60121f1e70020019d42f6f764002d4ff0010bc0f2440418bfbaf1000f33d10df108098046484602f07df903ab28465146012205f0abfc9df8111007464846002918bf4ff0ff3702f0a3fabbf1000f044608d19df8100028b949f28340c0f247004c308047b8f1000f18bfc8f80c4042f6f764c0f2440404f5807130468847384625b0bde8f08f2a7802f07f01a1f1150313f1030f0bd802f07b030b2b07d002f07e02082a03d0032901d00629b7d140b149f28341c0f247010746884797f8641111b14ff0ff37d6e738464ff0000ba6e770b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f8455046f6756c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04f9fb04ff2a840c2f229000668bff35f8f30466ff39600b0f1005f42d130684ef66c65ccf2ff05a8423bd196f8640130b3d6f860411cb340f6b400c2f20000076804a802f0a5f8002f00f06a8140f2030a384621464ff416320296cff6807a4ff6ff760397fff752fb4ff6245b48f2c738cff6ff7b00270124c0f245081ce096f8660170b1d6f8680140b146f68051c2f207010968401a002802f37080002086f8660140f6d100c0f247001fb0bde8f04f0047bff32f8fc0474ff2a840c2f22900d0f80090bff35f8f0068bff35f8f00ea0a01b1f1005f03d10168a94200f0aa804ff4377004f050fc002802f02f80594642183d3182f8dc7282f8dd7282f8de7282f8df7282f8e07282f8e17282f8e27282f8e37282f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382d14ff2a842056084728683c683068446848684c684068546858685c685068646868686c68606874687c2f2290252e8001f49457ff449afbff35f8f42e8000121b152e8001f4945f8d03ee7817a002941f08887027e0021002a8df81c107cd04ff2a84507aac2f22905535c002b00f0b68053185f78002f74d09f78002f73d0df78002f72d01f79002f71d05f79002f70d09f79002f6fd0df79002f6ed01f7a002f6dd05f7a002f6cd09f7a002f6bd0df7a002f6ad01f7b002f69d05f7b002f68d09f7b002f67d0df7b002f66d01f7c002f65d05f7c002f64d09f7c002f63d0df7c002f62d01f7d002f61d05f7d002f60d09f7d002f5fd0df7d002f5ed01f7e002f5dd05f7e002f5cd09f7e002f5bd0df7e002f5ad01f7f002f59d05f7f002f58d09f7f002f57d0db7f002b56d0203160297ff49aaf76e0002086f86401c6f8600186f86601012086f8650140f6d100c0f24700804701f019bf4ff2a845c2f2290564e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f0d68300218df87b100121427e002a00f0c280002207ab9f5c002f00f0a0809f187e78002e5ed0be78002e5dd0fe78002e5cd03e79002e5bd07e79002e5ad0be79002e59d0fe79002e58d03e7a002e57d07e7a002e56d0be7a002e55d0fe7a002e54d03e7b002e53d07e7b002e52d0be7b002e51d0fe7b002e50d03e7c002e4fd07e7c002e4ed0be7c002e4dd0fe7c002e4cd03e7d002e4bd07e7d002e4ad0be7d002e49d0fe7d002e48d03e7e002e47d07e7e002e46d0be7e002e45d0fe7e002e44d03e7f002e43d07e7f002e42d0be7f002e41d0ff7f002f40d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff053079f5411d013444b275e2a5f700cd049275d2a9f7008d050275c2adf7004d020275b2a1f7140f0f08100228df87b200131827e002a00f0be80002107aa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df87b1001216a6846f23f53c5f28803b3eb520f40f08b80d20700f08d80002107aa535c002b00f0858153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0fc805f7a002f00f0fc809f7a002f00f0fc80df7a002f00f0fc801f7b002f00f0fc805f7b002f00f0fc809f7b002f00f0fc80df7b002f00f0fc801f7c002f00f0fc805f7c002f00f0fc809f7c002f00f0fc80df7c002f00f0fc801f7d002f00f0fc805f7d002f00f0fc809f7d002f00f0fc80df7d002f00f0fc801f7e002f00f0fc805f7e002f00f0fc809f7e002f00f0fc80df7e002f00f0fc801f7f002f00f00d815f7f002f00f00b819f7f002f00f00981db7f002b00f00781203160297ff47baf1de14cf67e22caf210126a60002940f01981002107aa535c002b00f0dc8053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f68d01f7b002f69d05f7b002f6ad09f7b002f6bd0df7b002f6cd01f7c002f6dd05f7c002f6ed09f7c002f6fd0df7c002f70d01f7d002f71d05f7d002f72d09f7d002f73d0df7d002f74d01f7e002f75d05f7e002f76d09f7e002f77d0df7e002f78d01f7f002f79d05f7f002f7ad09f7f002f7bd0db7f002b7cd0203160297ff49aaface000211171f6e6013173e0023171e003316fe004316de0013184e0053169e0023180e0063165e003317ce0073161e0043178e008315de0053174e0093159e0063170e00a3155e007316ce000225a710fe60b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f0948000218df87b1000210df11c0c1cf80120002a00f0a1800ceb01025378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff498af43e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d84ff077020cf8012003d100218df87b1002e0614400224a70c2684ff0000e1cf80e10002900f0c4800ceb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7642f2107503eb83014900b2fbf1f40a2c11d303fb07f1b2fbf1f40a2c0bd303fb06f1b2fbf1f40a2c05d36b43b2fbf3f10929e7d800e00b46f146bef15f0f98bf4ff05f09c9f1000818eb0e0b52d0b2fbf3f40a2b04f130010cf80e104cf6cd41ccf6cc41a3fb011646d31bf1010141d004fb1324f708b4fbf7fa0ceb0e020af13001517048f21f51c5f2eb11642ba3fb011634d31bf102012cd00afb17447709b4fbf7f6b3f57a7f06f13001917044f6d351c1f26201a3fb015123d31bf1030518d006fb1744890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114242f210710ef1040e8b424fea5733aad209e0ce4607e00ef1010e04e00ef1020e01e00ef1030e0022e3460cf80e201bf80210002900f0a1800beb02014b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff498af52e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a13d84ff075010bf802100ed00beb020173235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df87b1002694ff000081bf80810002900f0c7800beb08035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d008f12008b8f1600f7ff496af4ff060085ee008f101085be008f1020858e008f1030855e008f1040852e008f105084fe008f106084ce008f1070849e008f1080846e008f1090843e008f10a0840e008f10b083de008f10c083ae008f10d0837e008f10e0834e000220a7162e708f10f082ee008f110082be008f1110828e008f1120825e008f1130822e008f114081fe008f115081ce008f1160819e008f1170816e008f1180813e008f1190810e008f11a080de008f11b080ae008f11c0807e008f11d0804e008f11e0801e008f11f0801230a2a1ed364274ff47a7642f2107503eb83014900b2fbf1f40a2c11d303fb07f1b2fbf1f40a2c0bd303fb06f1b2fbf1f40a2c05d36b43b2fbf3f10929e7d800e00b46c646b8f15f0f98bf4ff05f0ecef1000a42f2107c1aeb080950d0b2fbf3f40a2b04f130010bf808104cf6cd41ccf6cc41a3fb011644d319f101013fd004fb1324f708b4fbf7f60beb080206f13001517048f21f51c5f2eb11642ba3fb015132d319f102052ad006fb17444e09b4fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb015121d319f1030516d007fb1644890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114208f1040863454fea5733acd209e0f04607e008f1010804e008f1020801e008f10308039f00220bf808201bf80210002900f0a1800beb02014b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff498af4ae001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a0bd84ff075010bf8021006d00beb020173235e2a4b7040f08780044600208df87b00384602215a4608f09ef8d4f870c272208df81c0078208df81d0020204ff000091ffa8cf28df81e008df81f901bf80900002800f0c8800beb09035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d009f12009b9f1600f7ff496af4ff060095fe004460020887078e709f1010958e009f1020955e009f1030952e009f104094fe009f105094ce009f1060949e009f1070946e009f1080943e009f1090940e009f10a093de009f10b093ae009f10c0937e009f10d0934e009f10e0931e009f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7642f2107503eb83004000b2fbf0f40a2c11d303fb07f0b2fbf0f40a2c0bd303fb06f0b2fbf0f40a2c05d36b43b2fbf3f00928e7d800e00346ca46b9f15f0f98bf4ff05f0acaf1000842f2107e18eb09054dd0b2fbf3f04cf6cd4100f13004ccf6cc410bf809400a2ba3fb016441d36e1c3dd000fb1320e408b0fbf4f748f21f5107f130060beb0902c5f2eb115670642ba3fb011630d3a91c29d007fb14007409b0fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb011620d3e91c16d007fb1400b10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb110209f1040973454fea5633afd209e0d14607e009f1010904e009f1020901e009f1030900220bf809201bf80200002800f0a1800beb0201487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff498af56e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a17d84ff020000bf8020012d00beb020163205e2a48700cd072205d2a887008d063205c2ac87004d020205b2a087140f0668100208df87b0037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df8171000f137010a2838bf00f13001ccf303508df8181000f137010a2838bf00f13001ccf303408df8191000f137010a2838bf00f1300100208df81b001f208df81a100beb000111f81f2c002a00f0818011f81e2c002a7ed011f81d2c002a7cd011f81c2c002a7ad011f81b2c002a78d011f81a2c002a76d011f8192c002a74d011f8182c002a72d011f8172c002a70d011f8162c002a6ed011f8152c002a6cd011f8142c002a6ad011f8132c002a68d011f8122c002a66d011f8112c002a64d011f8102c002a62d011f80f2c002a60d011f80e2c002a5ed011f80d2c002a5cd011f80c2c002a5ad011f80b2c002a58d011f80a2c002a56d011f8092c002a54d011f8082c002a52d011f8072c002a50d011f8062c002a4ed011f8052c002a4cd011f8042c002a4ad011f8032c002a48d011f8022c002a46d011f8011c002944d01bf80010002941d020307f287ff479af61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c584400260df11705af5d8755b7b1b34211d0af1979788419617079b1b2420ad0b978a17051b1b64505d0f978e17029b10436b445e8d100208df87b00039842f2a00845f2a80440f2403507aa0e21c2f22008c2f21304c2f2000507f047fde869ae46a0425fd1def82800b0f54d2f5ad1def82c00a04256d145f61c530020c2f213034cf6394508f1040c002763454ad81c6834f003061cd098454ff0ff3228bf0c2c42d3a8eb03018e424ff0ff313ed83946be4288bf3146e2071cbf0f4630449919013d01f10403e0d12ce00020487199e60421b7f5807f1ed300223e46b6f5007f14d3b6f5806f13d3b6f5006f12d30901b2eb163f4fea1616f0d10ce000219171fef76bbf00211172fef729bc490002e0890000e0c900634504d1494207ea0102014603e04ff0ff324ff0ff3146f68050c2f20700d0f8880008f1080342f6a00c9842c2f2270c29d142f61c574ff00008c2f2200746f6b9750cf1040b00264ff0ff394ff0ff3a5f4518d83c6834f003005cd0bc4528bf0c2c12d3aceb0703984210d8b042334688bf0346e4071cbf1e4680443844013d00f10407e4d14ff0ff394ff0ff3adef800300cf10800834240f08b80def80c30b3f5333f40f08580def81030834240f080804ff2a84043f21c53c2f229004ff0000bc2f2270342f6f934a0f1040ca0f1080e00264ff0ff3863456ad81d6835f0030730d09e454ff0ff30019028bf0c2d62d3aeeb0300874260d83046b74288bf3846ed071cbf0646bb44d819013c00f10403e1d14de073460425b6f5807f2dd34ff0000e3046b0f5007f22d3b0f5806f21d3b0f5006f20d32d01beeb103f4fea1010f0d11ae00425b6f5807f29d300273446b4f5007f1fd3b4f5806f1ed3b4f5006f1dd32d01b7eb143f4fea1414f0d117e06d0002e0ad0000e0ed005f4505d1684206ea0009c2469e4680e74ff0ff394ff0ff3a9e467ae76d0002e0ad0000e0ed00634505d16b4206ea03000190d84604e04ff0ff3001904ff0ff3866208df81c0072208df81d0065208df81e008df81f002f208df820006d204b238df8210061208df8253069238df8220078208df82630422356278df8230020208df827303a238df82b70472707ac8df824008df828308df829004c238df82c708df82e00002720468df82a308df82d308df82f7007f04efde05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f88000208df87b00204651464a4607f07afc0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df87b0007ac019a2046414607f0adfb03981a21224607f02afa029e002086f86401c6f8600103984cf6036107904ff41630089007a8c0f247018847012086f8660104a800f041f930611fb0bde8f08f0020c871d6e70021417207e700bf2de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff2a8474ff6245a48f2c738ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168b14200f0a8804ff4377002f0b2fb002800f0de80514642183d3182f8dc5282f8dd5282f8de5282f8df5282f8e05282f8e15282f8e25282f8e35282f8e45282f8e55282f8e65282f8e75282f8e85282f8e95282f8ea5282f8eb5282f8ec5282f8ed5282f8ee5282f8ef5282f8f05282f8f15282f8f25282f8f35282f8f45282f8f55282f8f65282f8f75282f8f85282f8f95282f8fa5282f8fb5282f8fc5282f8fd5282f8fe5282f8ff5282f8005382f8015382f8025382f8035382f8045382f8055382f8065382f8075382f8085382f8095382f80a5382f80b5382f80c5382f80d5382f80e5382f80f5382f8105382f8115382f8125382f8135382f8145382f8155382f8165382f8175382f8185382d1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff44fafbff35f8f00bf47e8000121b157e8001f4945f8d043e74169d1bb46f6805245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f81b041f20401cef200014ef66c674ff2a846d1f8009000684ff6245bccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108009007e000bf48f2c731c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168b94200f0a8804ff4377002f08cfa002800f0fc80594642183d3182f8dc5282f8dd5282f8de5282f8df5282f8e05282f8e15282f8e25282f8e35282f8e45282f8e55282f8e65282f8e75282f8e85282f8e95282f8ea5282f8eb5282f8ec5282f8ed5282f8ee5282f8ef5282f8f05282f8f15282f8f25282f8f35282f8f45282f8f55282f8f65282f8f75282f8f85282f8f95282f8fa5282f8fb5282f8fc5282f8fd5282f8fe5282f8ff5282f8005382f8015382f8025382f8035382f8045382f8055382f8065382f8075382f8085382f8095382f80a5382f80b5382f80c5382f80d5382f80e5382f80f5382f8105382f8115382f8125382f8135382f8145382f8155382f8165382f8175382f8185382d1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f51457ff44bafbff35f8f00bf46e8000121b156e8001f5145f8d03fe74169009d61b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ce046f6805245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f422fd041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94217d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2001e0009dfa20a9eb0501b1fbf0f001b0bde8f08f002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204606f0affd854228d14cf6dd70c0f245008047811eb1fa81f14f09012808bf0227002f00f02b81207887f00301084200f02781012039464246334600f06cfa0446002898f8080018bf06241ae14ff2e933c0f24c0318470b2400e00a244cf6dd70c0f245008047811eb1fa81f14d09012808bf0225002d00f0fd804ef66c6a4ff2a8474ff624580294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2c731c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168514500f0a9804ff4377002f0e3f8002800f0ca80414600bf42183d3182f8dc6282f8dd6282f8de6282f8df6282f8e06282f8e16282f8e26282f8e36282f8e46282f8e56282f8e66282f8e76282f8e86282f8e96282f8ea6282f8eb6282f8ec6282f8ed6282f8ee6282f8ef6282f8f06282f8f16282f8f26282f8f36282f8f46282f8f56282f8f66282f8f76282f8f86282f8f96282f8fa6282f8fb6282f8fc6282f8fd6282f8fe6282f8ff6282f8006382f8016382f8026382f8036382f8046382f8056382f8066382f8076382f8086382f8096382f80a6382f80b6382f80c6382f80d6382f80e6382f80f6382f8106382f8116382f8126382f8136382f8146382f8156382f8166382f8176382f8186382d1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff449afbff35f8f47e8000121b157e8001f4945f8d03ee705eb450100eb011090f85d1201b300f513760024304629462a460323009406f047fd706840b146f22b11c0f25d018847706806f0b7fb74603068b475002818bf06f0b0fb0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f064f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104606f034fc201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009506f0dafc606840b146f22b11c0f25d018847606806f04afb65602068a575002818bf06f043fb00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff2a8464ff624598046ccf2ff05c2f229064ff6ff77cff6ff7900244ff0010a06e048f2c731c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f0a9804ff4377001f074ff002800f0a180494642183d3182f8dc4282f8dd4282f8de4282f8df4282f8e04282f8e14282f8e24282f8e34282f8e44282f8e54282f8e64282f8e74282f8e84282f8e94282f8ea4282f8eb4282f8ec4282f8ed4282f8ee4282f8ef4282f8f04282f8f14282f8f24282f8f34282f8f44282f8f54282f8f64282f8f74282f8f84282f8f94282f8fa4282f8fb4282f8fc4282f8fd4282f8fe4282f8ff4282f8004382f8014382f8024382f8034382f8044382f8054382f8064382f8074382f8084382f8094382f80a4382f80b4382f80c4382f80d4382f80e4382f80f4382f8104382f8114382f8124382f8134382f8144382f8154382f8164382f8174382f8184382d1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff44bafbff35f8f00bf46e8000129b156e8001f5945f8d03fe7002008eb480100eb0111002818bf01f5137001b0bde8f08fb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fcf771fda81c4af28d5582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c654ff2a8464ff6245948f2c73bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450bcde90612cde9080303e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f0a8804ff4377001f06cfe002800f04484494642183d3182f8dc4282f8dd4282f8de4282f8df4282f8e04282f8e14282f8e24282f8e34282f8e44282f8e54282f8e64282f8e74282f8e84282f8e94282f8ea4282f8eb4282f8ec4282f8ed4282f8ee4282f8ef4282f8f04282f8f14282f8f24282f8f34282f8f44282f8f54282f8f64282f8f74282f8f84282f8f94282f8fa4282f8fb4282f8fc4282f8fd4282f8fe4282f8ff4282f8004382f8014382f8024382f8034382f8044382f8054382f8064382f8074382f8084382f8094382f80a4382f80b4382f80c4382f80d4382f80e4382f80f4382f8104382f8114382f8124382f8134382f8144382f8154382f8164382f8174382f8184382d1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff44fafbff35f8f00bf46e8000121b156e8001f4145f8d043e70999089d01eb410100eb011095f9081000f51376b1f1ff3f01f0030409dd374617f8110fd0bb3068002818bf06f044f92ee3307cf0b1707ce0b10799099a002730460323009706f0bdfa706840b146f22b11c0f25d018847706806f02df977603068b775002818bf06f026f900203060b06030823068002818bf06f01df900204ff480713060b0603182a978b081092006f11107f174b17434757076b07ca978884240f0da82317da14240f0d682069b411ca3f10b00727e02971e2828bf1e209042b17488bf7076981e84b200270a2c4ff00008c0f0e682092241f221090920039419e030684f46002818bf06f0e4f8b089376001303774b760b081002c18bf4ff00608039cd146ddf814a00aeb0b0082b2a24280f0c682317c80b20429824600f28880aa5c00f1010a4b1c0129337405dd022906d0032970d1f28106e021b9727503e0338943ea02223281a24580f0a98204296ed015f80a204ff0000c831c8f1c0129377406ddff290bd0032967460dd19a4652e000291cbf378947ea0222328100e072756746a34204d38ae2f281a34280f08782022936d8ea5c00f1030acb1c0129337407dd022937d0fe2907d17275a2450cd375e231b9338943ea02223281a24504d36de2f281a24580f06a8202292fd015f80a20031d41f00407fc29377408ddfd2909d0fe291cbf378947ea0222328103e079b9f28100e072756746a34280f04f8209b19a4613e0ea5c00f1050a0520307401e09a466746f189308941ea0221f18128b106f050f80028306000f0698233897089191a1ffa81fb1ffa8af1621a5a45b8bf93465fea0b4208d03268294410441ffa8bf2fcf75bfb70893389584481b2994270817ff44faf0025cdf81080d6f800808df82b50707db8f1000f06930df12b0108bf88460f2806d8317d00f00302511ab1fa81f14d09000706d4317e707e814238bf30760fe000bf706840b146f22b11c0f25d018847706805f0faff7760707e30760120f082cdf814a09db1707db57d400714d4002d4ff0000400f0888106984ff6ff7381b2002900f00d8101295ed10020d2e0707d400753d4002477e14ff4803005f0dfff002d804600f06f81b07d002800f06b81b8f1000f00f067817568002d00f0ff8030890428c0f05f8131680a1812f8043c002b40f0588112f8033c002b40f0538112f8023cff2b40f04e8112f8012cff2a40f049814ff4803429606860c5f80c802c610028019000f0668146f22b10c0f25d0000f58572284600219047002840f032812969002900f02e8168688c420c46e7d1019a0c468242e3d124e14ff4803005f08dff04461fe1069a4ff6fe701040a44642426ff0010000bf08eb0005ac78ed7883ea04231cb25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead73787ea430383ea05231fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead737023087ea430309ead5371518023587ea430395d1023000276446069ad20732d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003f0899ab282426fd14046fcf7d0fa00286ad141f2210a4ff00009012375e0382005f0cdfe00285ed00546077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f8377046f28510c0f200007844286246f28d10c0f200007844686246f22b10c0f25d0047f2f85200f13c0c28460f21c0f27b023823e04740b3284605f062fe4446706841f2210a40b146f22b11c0f25d018847706805f055fe77604ff000090323b77506980799099a089dddf8108087b23046009705f0cbff002c214604463ff456ad084605f03dfe51e5756074e6c4f58030b4f5803f444606902f60ef607ff647aecde70799099a002430460323009405f0adff706840b146f22b11c0f25d018847706805f01dfe74603068b475002818bf05f016fe0020387000203060b06030824ff00a0840460bb0bde8f08f287a4006f8d5307c08b302980078e0b10799099a002430460323009405f080ff706840b146f22b11c0f25d018847706805f0f0fd74603068b475002818bf05f0e9fd00203060b06030824ff00b083068002818bf05f0defd00203060b0603082cae702980078e0b10799099a002430460323009405f054ff706840b146f22b11c0f25d018847706805f0c4fd74603068b475002818bf05f0bdfd00203060b06030824ff00608a7e72de9f041f02846d100294ff00b0000f08880022ac0f085804cf6dd70c0f245000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a0072d07578e91ec9b2fe2938bfbde8f081307833463946022829d0012866d1ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7e1f920b306462846fff738fa21462a46fff70cfa3046bde8f0814cf6dd77c0f2450707f5e27cbde8f0416047ac4219d1a1f1210010f1160f06d36ff0480048432330c0b2242810d90b20bde8f081b07a204207d04046394622462b46bde8f041fff710bb0020bde8f0811a4612f8020f40f00207032f18d19b796340032b14d10b2904d0032804bf0b20bde8f081881e4df22d7783b2c0f247070120f021b847002818bf0620bde8f0810a20bde8f081b0b54cf28544c0f251041d46a0474ff2a841c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd45f2e823c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd47f27e32c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b045f6e532c0f24b020c46054690474ff2a841c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d04cf6dd71c0f2450107468847014638460129ecd1ff22079244f6435245f2e8210020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22fbf7e3fe04f117034df60f166a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f2010000904ef6a970c0f2470016460c46804798b147f2a620c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522fbf79ffe0834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b04cf6dd70c0f24500804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f2010004904ef6a970c0f24700804798b147f2a620c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522fbf749fe4df60f1cc0f2470c0120092122460c23e04706b010bd4ff2a840c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b146f68052c2f207021268801a0028cebf01200020c1f838017047002070474ff2a840c2f22900026810466ff39600b0f1005f2bd110684ef66c61ccf2ff01884224d1d2f8680108b346f68051c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f8660108bf704710b5c2f86c0148f2c732c0f245020446084690472046bde8104070470020704700bff0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af29f344ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bff0b581b004464ef2e960c0f245008047002c18bf012801d101b0f0bd21796279a379e77941ea022141ea034151ea076109d00e2904d00329eed10646032504e00646042501e006460225fff759ff00283046e1d04ff2a841c2f229010e6831466ff39601b1f1005fd6d131684ef66c62ccf2ff029142cfd14cf6dd71a778c0f2450104468847014620460129c4d1b221082086f86412062186f86002032086f8651286f86612462186f86102102086f86712432186f86202002086f86812012186f86b724df6090706f5187286f8630286f8691286f86c02c0f24707012009210d2386f86a52b847204601b0f0bd00bf2046fff785bf00bf2de9f04f81b04ef66c694ff2a8464ff624580446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2c731c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168494500f0a8804ff4377000f04efe002800f0cd80414642183d3182f8dc5282f8dd5282f8de5282f8df5282f8e05282f8e15282f8e25282f8e35282f8e45282f8e55282f8e65282f8e75282f8e85282f8e95282f8ea5282f8eb5282f8ec5282f8ed5282f8ee5282f8ef5282f8f05282f8f15282f8f25282f8f35282f8f45282f8f55282f8f65282f8f75282f8f85282f8f95282f8fa5282f8fb5282f8fc5282f8fd5282f8fe5282f8ff5282f8005382f8015382f8025382f8035382f8045382f8055382f8065382f8075382f8085382f8095382f80a5382f80b5382f80c5382f80d5382f80e5382f80f5382f8105382f8115382f8125382f8135382f8145382f8155382f8165382f8175382f8185382d1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff44aafbff35f8f46e8000121b156e8001f5945f8d03fe7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214df60f1c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff2a847c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff7d2fd2346044631462a463846002c18bfb9f1000f07d14af29f3cc0f2460c01b0bde8f043604799f8420188b1b8f1010f40f08580d9f83c01002189f84211a9f84011e0b342f68d41c0f24401884736e0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421168b94ff6dd30cff6ff70a4f59477784400214a460023b847c9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af29f3cc0f2460c0120002100220023a6e74cf6dd70c0f24500804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014df6090c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f850716fe701b0bde8f08300bf80b582b04ff0050ccdf800c0fff734ff02b080bd2de9f04f83b04468002c00f0c1828368002b00f0bd8204eb030b4ff000090027002614e046f68053c2f207031b6845f69077c0f201073b44c6f838310ceb0a0300275b451c464ff0000680f0a182a04618f9013b03f07f05bd40002b46ea050610d406f00703012b16dc0bb3012b40f08f82abeb0803082bc0f08a8204f10903dee700bfd84580f08382182f07f107074446dcd97ce200bf022b3ad0052b40f07782abeb0803042bc0f07282631dc7e7d84580f06d8294f90130002b04f10203bed55b4580f0648294f90230b3f1ff3f04f10303b4dc5b4580f05a8294f90330b3f1ff3f04f10403aadc5b4580f0508294f90430b3f1ff3f04f10503a0dc5b4580f0468294f90530002b00f14182a31d96e7d84580f03c8294f9013004f1020c002b03f07f0a1ed5dc4580f0318294f90270e31c07f07f05b7f1ff3f4aeac51a02dde0469c460ee05b4580f0218294f9037004f1040c07f07f05b7f1ff3f4aea853a33dd9846abeb0c039a4500f21082f308672b1dd0652b7ff460afbaf1060ffff45caf9cf80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf4ff2a844c2f229040290cde9002132e0044660460e4651461746654600f01bfcac4631463a46204637e7dc4580f0df8194f90470631d07f07f05b7f1ff3f4aea455aaddc5b4580f0d28194f90570002f00f1cd8104f1060c4aea077ab1e748f2c7313046c0f24501bff32f8f8847dde900210298ac462768bff35f8f2668bff35f8f33466ff39603b3f1005f07d133684ef66c65ccf2ff05ab4200f0bc804ff43770654600f07dfbdde9002106460298ac46002e3ff4f1ae4ff62453cff6ff7300bff4183d3384f8dc9284f8dd9284f8de9284f8df9284f8e09284f8e19284f8e29284f8e39284f8e49284f8e59284f8e69284f8e79284f8e89284f8e99284f8ea9284f8eb9284f8ec9284f8ed9284f8ee9284f8ef9284f8f09284f8f19284f8f29284f8f39284f8f49284f8f59284f8f69284f8f79284f8f89284f8f99284f8fa9284f8fb9284f8fc9284f8fd9284f8fe9284f8ff9284f8009384f8019384f8029384f8039384f8049384f8059384f8069384f8079384f8089384f8099384f80a9384f80b9384f80c9384f80d9384f80e9384f80f9384f8109384f8119384f8129384f8139384f8149384f8159384f8169384f8179384f8189382d14ef66c63ccf2ff0333600123b3724ff6ff734ff2a844b383f38333847384b384f38433857385b385f38533867386b386f38633877387c2f2290454e8003fbb427ff42fafbff35f8f00bf44e8006323b154e8003fbb42f8d023e798f8043098f8057098f80650032b47ea052433dd052b54dc042b74d0052b7ff431aed6f868313bb146f68057c2f207073f68db1b002b14dcd6f86c3186f866917bb10c4648f2c73180461846c0f24501c6f86c91174665468847ac4621463a46404646f68053c2f207031b6845f69077c0f201073b44c6f8683103e6012b3ff4f5ad022b00f08380032b7ff4fbad174688466546fff7fefa03460298ac4641463a46002b3ff4eead96f84231002b3ff4e9ad304641f28831a6f8404105f04ef847e0062b4ad0072b7ff4dcad80464cf23330c0f24a0016460f466446804703465d1ea446394632464046012d3ff6caad981eb0fa80f04009fff7c8fba446394632464046bee5174688466546fff7c2fa03460298ac4641463a46002b3ff4b2ad96f84231002b3ff4adadb6f84031a3427ff4a8add6f83c3186f84291002ba6f840913ff49fad42f68d411846c0f2440188470298ac4641463a4693e5d6f86c31c6f86891002b86f866913ff48bad0f4648f2c73104461846c0f24501c6f86c91164665468847ac463946324640e696f84231c6f83891002b3ff474ad0446d6f83c0165468846174686f84291a6f8409120b142f68d41c0f2440188474af29f360120002100220023c0f24606b04720463a464146ac4655e54df60923c0f2490303b0bde8f04f18477fb50646002806d1fff750fa002807d19de80f00064645f25b1cc0f24f0c60477fbd00bf2de9f04182b04df609061d4614460929c0f247064cd180460f46f22d10d8a22160196155062141700b21817045f64251c0f20001033079440b22fbf763f80e35204629464ff4807200f038f80546ff208df8040044f25220c0f20100009006f5bd50804798b147f2a620c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400f82d0cd8d221601961550621417005218170033069460522fbf72df808353946404622462b46b04702b0bde8f081f0b587b00c464ff2a841c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df810104cf6dd71c0f245018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522faf781ff1834204607b0f0bd00bf2de9f04f81b04ff2a840c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d046f68059c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b464bf2f1270df10201c0f25a07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246faf7d7fe4df66d22c0f24702384651469047d4f87c0148f2c7310130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2ac44c2f22904216846f23f52c5f28802b2eb510f48f283314cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b146f68052c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002143f2c942c0f8801180f87711c0f25902002044f24361904748f65354c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f0f7800c46014600784d2840f0f1804878432840f0ed808878012840f0e9804ef66c684ff2a847ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2c731c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f03d10268424500f0ac804ff43770fff766ff002800f0ba804ff624525146cff6ff7283183d3283f8dc5283f8dd5283f8de5283f8df5283f8e05283f8e15283f8e25283f8e35283f8e45283f8e55283f8e65283f8e75283f8e85283f8e95283f8ea5283f8eb5283f8ec5283f8ed5283f8ee5283f8ef5283f8f05283f8f15283f8f25283f8f35283f8f45283f8f55283f8f65283f8f75283f8f85283f8f95283f8fa5283f8fb5283f8fc5283f8fd5283f8fe5283f8ff5283f8005383f8015383f8025383f8035383f8045383f8055383f8065383f8075383f8085383f8095383f80a5383f80b5383f80c5383f80d5383f80e5383f80f5383f8105383f8115383f8125383f8135383f8145383f8155383f8165383f8175383f8185382d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a457ff445afbff35f8f47e8000222b157e8002f4a45f8d03ae7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002143f2c94280f87711c0f259020446002044f24361904748f65355c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f8710148f6a3450128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff6a122cff6ff7243f271337a44c0f25903002044f243619847012084f87701b0bd00bf70b5044646f68050c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6f930cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b014cf6dd700026c0f2450084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264df6090c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff2a840c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b143f2c942c0f25902002044f2436184f87751904748f65356c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff2a841c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b346f68051c2f207010968401a002827dd46f2d835c2f2070555f8040c002854d04ff27717c0f24b0747f62938002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e001984ef6ed56c0f24b06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b146f68052c2f207021268101a884203d32046022100f06ef802b0bde8f08100bfb0b590f8a841002c42d043f60852c2f2000211880829114622d0114631f8083f082b1dd0114631f8103f082b18d0114631f8183f082b13d0114631f8203f082b0ed0114631f8283f082b09d0114631f8303f082b04d032f8381f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff66f63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91144f68241c2f20701097869b946f2d431c2f20701096839b148f26111c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b004464cf6dd70c0f245000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070046f2f030c2f2070050f81c2c94f8a811002a18bf0122002944f68141c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4df609058df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1046f68051c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff35fee0cde901100120cff680704ef66c644ff2a8464ff6245bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2c731c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f03d10168a14200f0a7804ff43770fff74bfb0028c5d0594642183d3182f8dc8282f8dd8282f8de8282f8df8282f8e08282f8e18282f8e28282f8e38282f8e48282f8e58282f8e68282f8e78282f8e88282f8e98282f8ea8282f8eb8282f8ec8282f8ed8282f8ee8282f8ef8282f8f08282f8f18282f8f28282f8f38282f8f48282f8f58282f8f68282f8f78282f8f88282f8f98282f8fa8282f8fb8282f8fc8282f8fd8282f8fe8282f8ff8282f8008382f8018382f8028382f8038382f8048382f8058382f8068382f8078382f8088382f8098382f80a8382f80b8382f80c8382f80d8382f80e8382f80f8382f8108382f8118382f8128382f8138382f8148382f8158382f8168382f8178382f8188382d1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f51457ff44dafbff35f8f00bf46e8000121b156e8001f5145f8d041e704464cf6dd70c0f24500804701281dd1029d6978022916d00129204607d000297ff413af00210025fff76cfe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff7f2fd0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b146f2d431c2f207010968002954d001210446fff71efe0025c4f8bc51bee743f60852c2f2000211880829114622d0114631f8083f082b1dd0114631f8103f082b18d0114631f8183f082b13d0114631f8203f082b0ed0114631f8283f082b09d0114631f8303f082b04d032f8381f0829114632d14a686ff00105b2f5870ffff48daf0123cff680731a40012a7ff486af4b684ff6cd12cff6ff727a44934214bfc0f8b431d0f8b431002b3ff477af4a60012180f8a811a3e748f2ef01c0f24b010420884720b105462046fff758fd65e70121204684f8a91199e76ff001055de700bf334600f005b800bf334600f037b800bf2de9f04182b042f2d7281e4614460d460746c0f24608fef771fa002e18bf002808d108f1160338462946224602b0bde8f041184746f26870c2f207000068c0470028eed00068e028ebd130784bf6d32601900027c0f24e0600200021002209230097b047012002b0bde8f0812de9f04182b042f2d7281e4614460d460746c0f24608fef73bfa002e18bf002808d108f1160338462946224602b0bde8f041184746f26870c2f207000068c0470028eed00068e028ebd130784bf6d32601900027c0f24e060020002100220a230097b047012002b0bde8f08110b582b00446fef70dfa0146002c4ff0000018bf002901d102b010bd46f26870c2f20700006842f2d721c0f24601884790b10068e0284ff00000edd121784bf6d32c0191c0f24e0c002100220b230090e047012002b010bd002002b010bd00bf08b53046fff7ccff002805d002b044f6e970c0f24400004748f68b43c0f24603984708bd012818bf002900d170478968002908bf704710b582b00a794b798c79c97942ea032242ea044242ea0161062910d14ef22151c0f24501044688470146204639b144f6e100c0f2440080470146204619b102b0bde810407047fef7a2f9014620460029f5d046f26870c2f20700006842f2d721c0f246018847014620460029e7d00968e029e4d14bf6d32e4ff0000cc0f24e0e0020002100220c23cdf804c0cdf800c0f0472046d3e710b5059c4ff23710c0f2460080472146fff7a2ff10bd00bf2de9f04f8bb0044600284ff0ff3000f031830d46002900f02d83217801f07f070a2f0edd102f27dc0b2f00f08482102f40f02482204629460bb0bde8f04ffff71fbd052f00f03081072f00f016830a2f40f01482022dc0f00d834ef66c6b4ff2a847ccf2ff0bc2f229074ff6ff764ff0000a4ff0010858e0112f00f0f682122f40f0fc81b5f1010b01f0728004f1010a00230021abeb03000628c0f0b1860aeb0304207962799d1d40ea0222abeb050082424ff0ff3000f2dd821af803306778a678e47843ea072343ea064343ea0463b3f5802f00f2ce82c3f580239a4200f2c982002a02eb050318bf01215b45d1d3002901f03d80fef7f3f8002800f080864ef66c674ff2a845ccf2ff07c2f229054ff6ff764ff0000800f02fbc48f2c731c0f24501bff32f8f8847d7f80090bff35f8f38680321cff680710140b1f1005fbff35f8f03d10168594500f0a2834ff43770fff71df8002800f052864ff62451cff6ff7142183d3182f8dca282f8dda282f8dea282f8dfa282f8e0a282f8e1a282f8e2a282f8e3a282f8e4a282f8e5a282f8e6a282f8e7a282f8e8a282f8e9a282f8eaa282f8eba282f8eca282f8eda282f8eea282f8efa282f8f0a282f8f1a282f8f2a282f8f3a282f8f4a282f8f5a282f8f6a282f8f7a282f8f8a282f8f9a282f8faa282f8fba282f8fca282f8fda282f8fea282f8ffa282f800a382f801a382f802a382f803a382f804a382f805a382f806a382f807a382f808a382f809a382f80aa382f80ba382f80ca382f80da382f80ea382f80fa382f810a382f811a382f812a382f813a382f814a382f815a382f816a382f817a382f818a382d1c0f800b080f80a808683c683068446848684c684068546858685c685068646868686c6860687468757e8001f49457ff446afbff35f8f47e80001002900f0fa8257e8001f4945f6d039e74ef66c664ff2a847ccf2ff06c2f229074ff6ff7b4ff000084ff00109022d2cbf6078ff20059006e048f2c731c0f24501bff32f8f8847d7f800a0bff35f8f38680321cff680710140b1f1005fbff35f8f03d10168b14200f091824ff43770fef743ff002800f0d9844ff62451cff6ff7142183d3182f8dc8282f8dd8282f8de8282f8df8282f8e08282f8e18282f8e28282f8e38282f8e48282f8e58282f8e68282f8e78282f8e88282f8e98282f8ea8282f8eb8282f8ec8282f8ed8282f8ee8282f8ef8282f8f08282f8f18282f8f28282f8f38282f8f48282f8f58282f8f68282f8f78282f8f88282f8f98282f8fa8282f8fb8282f8fc8282f8fd8282f8fe8282f8ff8282f8008382f8018382f8028382f8038382f8048382f8058382f8068382f8078382f8088382f8098382f80a8382f80b8382f80c8382f80d8382f80e8382f80f8382f8108382f8118382f8128382f8138382f8148382f8158382f8168382f8178382f8188382d1066080f80a90a0f81cb0a0f81eb0a0f820b0a0f822b0a0f824b0a0f826b0a0f828b0a0f82ab0a0f82cb0a0f82eb0a0f830b0a0f832b0a0f834b0a0f836b0a0f838b0a0f83ab057e8001f51457ff437afbff35f8f00bf47e80001002900f0d98157e8001f5145f6d029e70f2f9b4600f0f481a7f11300012840f2ef81092f00f05d83082f40f0d583002a4ff0ff3000f0e880022dc0f0e58094f80190b9f1000f00f0ad8402264ff0010848f2482ab21caa4200f29c84a019a15d407851ea002100f095848e18ae4200f29184a05cde4600f07f07153fffb2fd2f16d8c0b20f280ed9a0f1830cbcf10c0f4ff0ff3000f2b88008fa0cf741f249031f4205d1b0e008fa00f717ea0a0febd0a01800227346fff76dfd002840f06a84b9f10109c6d100f06dbc4ff2a846c2f229063468bff35f8f20466ff39600b0f1005f40f00f8620684ef66c67ccf2ff07b8424ff0000040f08780c4f8680184f8660184f86401d4f86c11c4f8600184f8650139b148f2c732c4f86c01c0f2450208469047d4f87802002818bf03f08ef90021c4f87812206c40f2030942f68d48cff68079c0f24408a4f8441040b1c047206c08f166018847002804bf0020206446f67560c0f2510080473568bff35f8f05ea0900b0f1005f2bd12868b84228d195f877014ff0000ac5f880a188b143f2c942c0f25902002044f2436185f877a1904748f6535bc0f25a0bd8470bf1bc008047d5f8840185f870a150b1c047d5f8840108f166018847002804bf0020c5f884013068bff35f8f00ea0901b1f1005f40f029850168b94240f0258590f8a811002900f01a85fff705f900f01cbd022d08bf112900f02b810bb0bde8f08f4ef66c6a4ff2a847ccf2ff0ac2f229074ff6ff764ff0000b4ff0010806e048f2c731c0f24501bff32f8f8847d7f80090bff35f8f38680321cff680710140b1f1005fbff35f8f03d10168514500f05e834ff43770fef75ffd002800f056834ff62451cff6ff7142183d3182f8dcb282f8ddb282f8deb282f8dfb282f8e0b282f8e1b282f8e2b282f8e3b282f8e4b282f8e5b282f8e6b282f8e7b282f8e8b282f8e9b282f8eab282f8ebb282f8ecb282f8edb282f8eeb282f8efb282f8f0b282f8f1b282f8f2b282f8f3b282f8f4b282f8f5b282f8f6b282f8f7b282f8f8b282f8f9b282f8fab282f8fbb282f8fcb282f8fdb282f8feb282f8ffb282f800b382f801b382f802b382f803b382f804b382f805b382f806b382f807b382f808b382f809b382f80ab382f80bb382f80cb382f80db382f80eb382f80fb382f810b382f811b382f812b382f813b382f814b382f815b382f816b382f817b382f818b382d1c0f800a080f80a808683c683068446848684c684068546858685c685068646868686c6860687468757e8001f49457ff446afbff35f8f47e80001002900f0b68257e8001f4945f6d039e790f84410059f61b1016c39b142f68d42c0f244020646084690473046002180f844100121002f40f04082032dc0f03d82a078082800f28a8446f67561c0f251019631884700f082bc164600f0a9fc002800f0c482611c142fa5f1010200f0b782132f5b4640f0b78200f0eefdb5e26678002e00f04581022e00f2b08240f03d84062dc0f0ab82a178e2782379677941ea022143ea072232290691079280f02784322100f029bc6078002840f097824cf6dd70c0f24500804701284ff000007ff4c7aecde9070040f20830c0f210000690ff208df8280044f25220c0f2010009904ef6a970c0f24700804798b147f2a620c2f2070000880122c1b264298df8272008d80721b0f5807f38bf03218df827108df8280040f2d260adf81c00052006ac8df81e00e01d09a90522f9f7e1fa4df60f17c0f247070120092122460c23b8470bb0bde8f08f48f2c7314846c0f24501bff32f8f88472c68bff35f8fd5f800900320cff6807000ea0900b0f1005fbff35f8f04d1d9f80000b84200f03b824ff43770fef7f3fb002800f0288281464ff62450cff6ff7000bf09eb00013d3081f8dc8281f8dd8281f8de8281f8df8281f8e08281f8e18281f8e28281f8e38281f8e48281f8e58281f8e68281f8e78281f8e88281f8e98281f8ea8281f8eb8281f8ec8281f8ed8281f8ee8281f8ef8281f8f08281f8f18281f8f28281f8f38281f8f48281f8f58281f8f68281f8f78281f8f88281f8f98281f8fa8281f8fb8281f8fc8281f8fd8281f8fe8281f8ff8281f8008381f8018381f8028381f8038381f8048381f8058381f8068381f8078381f8088381f8098381f80a8381f80b8381f80c8381f80d8381f80e8381f80f8381f8108381f8118381f8128381f8138381f8148381f8158381f8168381f8178381f8188381d10120c9f8007089f80a00a9f81c60a9f81e60a9f82060a9f82260a9f82460a9f82660a9f82860a9f82a60a9f82c60a9f82e60a9f83060a9f83260a9f83460a9f83660a9f83860a9f83a6055e8000fa0427ff42fafbff35f8f45e80090002800f07f8155e8000fa042f6d022e7002480f843414cf6dd70c0f2450080470146204601297ff49bad4df25f50c0f255000bb0bde8f04f004708064ff0210158bf11218d42c0f05181002804f101060ad54cf6dd70c0f24500154680472a46022818bf04f111063079717950ea01244ff0ff301ebfb179f37951ea03253ff46fad317b737b41ea03218c427ff468adb17bf37b41ea03218d427ff461ad3078717840ea012804eb0800b0f5207f4ff0ff303ff655adb178f37841ea0327e919b1f5f07f3ff64cad317a737a41ea032904eb0901b1f5207f3ff642adb17af37a41ea0326a919b1f5f07f3ff639ad924600f0defa002800f0f98041463a464b46cde90145009602f0adf9dbf800100f2909d80bebc1020131a2f80690168154819581cbf80010baf1000f40f0e78095e2f81e18bf0120bb1f18bf012318424ff0ff307ff40dad032dfff40aad032f00f0b281062f7ff404ad00200021164602f0edfa00f0a5fa002800f0c0800246601c691e4ff4f0774ff4a073009702f01efc002800f0b380dbf800100f2900f2b3800bebc1020023d38013814ff4207353814ff4f07301319381cbf80010a3e0059f00210020002f3ff4c0ad012f19d1052d17d3a378581e06284ff000003ff6c8ace17803293ff6c4ac2279002a3ff4c0ac46f67560c0f2510000f59a771846b84734e2022f05d146f67560c0f2510080472ce2032f40f01381072dc0f01081a078e278217940ea02206579a67901284ff0010498bf204644f62062904228bf104646f67562c0f2510202f5e272642928bf6421904746f2a070c2f207000068002800f0048245ea0621012988bf0c4642f68d41c0f24401a1f1400221469047f5e10020022d2cbf6178ff21002800f0ee81024602294ff0000025d0012920d000297ff466ac4cf67e21caf21011907610837960108150609683d683168456849684d684168556859685d685168656869686d6861687568782f83c000bb0bde8f08f01209072c2e190720bb0bde8f08f5b4600f0ecfe01e001f067fb20b14ff0ff300bb0bde8f08f002e00f0b081584601f0a7ffabe1d9f86c0100286ed14ff48020fef7b4f90028e9d000210022831881544032b2f5802f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c9f86c0100210aeb010006794579437846ea0525d9f86c611af8012087788c1d06eb0321c078114401eb074101eb00600aeb04012a46f8f7f0ff291959454ff00000e0d3fff799bb3a1f80460020b2fa82f2022d88bf012052091040084001284ff000007ff489ab4cf6cd42e91eccf6cc42a578a1fb0212b5eb920f88bf95082f4608f14603302d28bf3027e11c07eb870204461846f8f7c0ff002d88f8447088f8454000f0b480d8f8400038b94046f9f71dfc0028c8f8400000f0fc8042f68d41c0f24401a1f1400201219047d2e0080600f1d480082dfff415af07214ff0050c0123e71897f802804ff0ff30b8f1000f3ff442abfe78002e3ff43eab14f8039005914fea880101eb8903b3f5207f04913ff632ab97f801a0770007eb4a03b3f5f07f3ff629ab04eb0c0014f80c104078039241ea002081b2012002f00bf900f0c3f800283ff4deae05990aeb8a020c4400ebc2104fea4803691a00eb49022046009702f037fa00283ff4ccaedbf800100f290dd84fea89020bebc106f280049a4fea4a03013133817281b781cbf80010039900297ff4beae6ce090f8a911002918bffef7e7fb94f84301002684f8436158b14cf6dd70c0f245008047012804d14df25f50c0f255008047d4f83c0194f84251c4f8386184f84261a4f8406150b1c047d4f83c0108f166018847002804bf0020c4f83c010120a072ddb34af29f37c0f246070021002200230024b84720460bb0bde8f08fb1f5fa6f02d94ff4fa6106910121044680f843114cf6dd70c0f24500804701281dd14df25f55c0f25505a5f188008047022e08bf002801d058b910e048f2d31206a9c0f24b020220904740b10646a8473046002184f843110bb0bde8f08f00200bb0bde8f08f0c2dfff441aee078e17988427ff43cae2079217a88427ff437ae4cf6dd70c0f24500164680470523022808bf01230b214ff0090c324616e746f675600024c0f2510088f844408047a3e700bf2de9f04f81b04ef66c6b4ff2a8454ff6245848f2c73accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f0a9804ff43770fdf7b5ff002800f01a81414600bf42183d3182f8dc7282f8dd7282f8de7282f8df7282f8e07282f8e17282f8e27282f8e37282f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff44eafbff35f8f45e8000121b155e8001fa142f8d043e7d0f87812002974d104464ff4163002f0a5fa014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8781200e00021084601b0bde8f08f00bf092a1cbf4ff0ff3070472de9f04f8db08a4683460693fcf72dff002800f015824ef66c684ff2a847ccf2ff08c2f229074ff6ff740026012507e000bf48f2c731c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168414500f0ad804ff43770fdf758fe002800f0a5804ff62451cff6ff7100bf42183d3182f8dc6282f8dd6282f8de6282f8df6282f8e06282f8e16282f8e26282f8e36282f8e46282f8e56282f8e66282f8e76282f8e86282f8e96282f8ea6282f8eb6282f8ec6282f8ed6282f8ee6282f8ef6282f8f06282f8f16282f8f26282f8f36282f8f46282f8f56282f8f66282f8f76282f8f86282f8f96282f8fa6282f8fb6282f8fc6282f8fd6282f8fe6282f8ff6282f8006382f8016382f8026382f8036382f8046382f8056382f8066382f8076382f8086382f8096382f80a6382f80b6382f80c6382f80d6382f80e6382f80f6382f8106382f8116382f8126382f8136382f8146382f8156382f8166382f8176382f8186382d1c0f8008085728483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff447afbff35f8f00bf47e8000129b157e8001f4945f8d03be70020002800f03f819af800109af801209af802309af8037041ea022141ea034141ea07624ff6fe77c0f20307ba424ff0ff3100f28982d0f86c310846002b00f02481995c4ff0ff30002900f01e81134493f80190b9f1000f00f0178109fb01f09d1c4ff0000c4ff0000368b3a7f101089e18be4200f007819e462b441c78240904d00126a0421bd2fde000bf464500f0fa805c781cb10226a04211d2f3e00524cff6fc743444042cc0f0ed809c78db7854ea032400f0e7800426a042c0f0e380001b06eb0e03d3d19af804009af8052098469af806309af807609af80870cdf8009040ea022943ea0626b8060f2307f00f0403eae07000fb04f389204343db0a8df824300e2317f0200f08bf4ff00f0c08bf012304fb03f300fb03f34fead3238df825304ff00d0308bf022304fb03f300fb03f34fead3238df826304ff00c0308bf032304fb03f300fb03f34fead3238df827304ff00b0308bf042304fb03f300fb03f34fead3238df828304ff00a0308bf052304fb03f300fb03f34fead3238df829304ff0090308bf062304fb03f300fb03f34fead3238df82a304ff0080308bf072304fb03f300fb03f34fead3238df82b304ff0070308bf082304fb03f300fb03f34fead3238df82c304ff0060308bf092304fb03f300fb03f34fead3238df82d304ff0050308bf0a2304fb03f300fb03f34fead3238df82e304ff0040308bf0b2304fb03f300fb03f34fead3238df82f304ff0030308bf0c2304fb03f300fb03f34fead3238df830304ff0020308bf0d2304fb03f300fb03f34fead3238df831304ff0010308bf0e2363434343db0a8df832300cfb04f358434ff0010ec00ab8f1000fcdf814808df8330000f06f8107f010008eea1010002403904ff0000804950ce04ff0ff300db0bde8f08fdde90704049d04440598844280f05881285d0894020901d0012313e0059a171b012f00f04d812b195a780ab1022309e0042fc0f045819f78db7857ea032200f03f810423079310f00f0309a810f803a018bf012303984fea0a1e40ea030c12f00300474600f08080b8fbf1f300259f19b7f1ff3fc8bf012505ea0c05012d1dd103fb11834b44dd09042d17d87d090e2d14d807eb87050beb85155f08ec5ddb076ff00f03019408bf0f230290504608bf7046019c234003430298eb55012808f1010751d0b7fbf1f300249d19b5f1ff3fc8bf012404ea0c04012c1ad103fb11734b44dc09042c14d86c090e2c11d805eb85040beb84145d08db070290605d6ff00f03574604bf0f237746034002983b436355022808f1020726d0b7fbf1f300259c19b4f1ff3fc8bf012505ea0c05012d18d103fb11734b44dd09042d12d865090e2d0fd804eb84040beb84145d08db07605d6ff00f03574604bf0f23774603403b43635508f10307531e032b904405d246e700bf0437b8453ff442afb7fbf1f40025a319b3f1ff3fc8bf012505ea0c05012d18d104fb11744c44e509042d12d85d090e2d0fd803eb83030beb831365085a5de4076ff00f04504604bf0f2470462240104358557c1cb4fbf1f50020ab19b3f1ff3fc8bf012000ea0c00012819d105fb114000eb0904e009042812d858090e280fd803eb83000beb80106208835ce4076ff00f04554604bf0f24754623402b438354bc1cb4fbf1f50020ab19b3f1ff3fc8bf012000ea0c00012819d105fb114000eb0904e009042812d858090e280fd803eb83000beb80106208835ce4076ff00f04554604bf0f24754623402b438354fc1cb4fbf1f50020ab19b3f1ff3fc8bf012000ea0c0001287ff47baf05fb114000eb0904e00904283ff673af58090e283ff66faf03eb83000beb80106208835ce4076ff00f04554604bf0f24754623402b4383545de708460db0bde8f08f09eb01000099b0f5207f06eb0103a8bf4ff42070b3f5f07fa8bf4ff4f0730699484588bfb34203d800200db0bde8f08f0f680f2ff8d89a1ba0eb090001ebc7035881781ca3f806901e819a810860ebe70a2a3cbf4ff0ff3070472de9f04f95b017468a4605461c46fcf77afb002800f0f9809af8096006f10a0087424ff0ff3040f0f2809af800109af801209af802309af8037041ea022141ea034141ea07624ff68061c0f203018a4200f2dd8010960e95cde90c429af808004ef66c644ff2a8454ff62456ccf2ff04c2f229054ff6ff77cff6ff764ff0000b4ff001080f9007e000bf48f2c731c0f24501bff32f8f8847d5f80090bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168a14200f0ad804ff43770fdf77afa002800f0e681314642183d3182f8dcb282f8ddb282f8deb282f8dfb282f8e0b282f8e1b282f8e2b282f8e3b282f8e4b282f8e5b282f8e6b282f8e7b282f8e8b282f8e9b282f8eab282f8ebb282f8ecb282f8edb282f8eeb282f8efb282f8f0b282f8f1b282f8f2b282f8f3b282f8f4b282f8f5b282f8f6b282f8f7b282f8f8b282f8f9b282f8fab282f8fbb282f8fcb282f8fdb282f8feb282f8ffb282f800b382f801b382f802b382f803b382f804b382f805b382f806b382f807b382f808b382f809b382f80ab382f80bb382f80cb382f80db382f80eb382f80fb382f810b382f811b382f812b382f813b382f814b382f815b382f816b382f817b382f818b382d1046080f80a808783c783078447848784c784078547858785c785078647868786c7860787478755e8001f49457ff44bafbff35f8f00bf45e8000149b155e8001f4945f8d03fe74ff0ff3015b0bde8f08fd0f86c91109eb9f1000f00f039810f9c0f23a10604f00f0203eae171514389235943c90a8df844100e219af804c09af805709af806e09af8075014f0200f08bf012102fb01f103fb01f14fead1218df845104ff00d0108bf022102fb01f103fb01f14fead1218df846104ff00c0108bf032102fb01f103fb01f14fead1218df847104ff00b0108bf042102fb01f103fb01f14fead1218df848104ff00a0108bf052102fb01f103fb01f14fead1218df849104ff0090108bf062102fb01f103fb01f14fead1218df84a104ff0080108bf072102fb01f103fb01f14fead1218df84b104ff0070108bf082102fb01f103fb01f14fead1218df84c104ff0060108bf092102fb01f103fb01f14fead1218df84d104ff0050108bf0a2102fb01f103fb01f14fead1218df84e104ff0040108bf0b2102fb01f103fb01f14fead1218df84f104ff0030108bf0c2102fb01f103fb01f14fead1218df850104ff0020108bf0d2102fb01f103fb01f14fead1218df851104ff0010108bf0e2102fb01f103fb01f14fead1218df852104ff0000108bf0f21514359430024c90a002e8df853106ad00d994ff6fe7449440af10a0a4cea07284eea052b4ff0000cc0f203040d9104e010990cf1010c8c455ed01af80c104a1e1f2af5d34ab2202a4bdb0d9a02eb810111f8802c11f87f3c11f87e7c11f87d1c42ea032242ea074242ea0165a54238d819f805104ff0ff34a9b309eb050253788bb34ff6fe7402f1020e03fb01f60023c0f2030406e000bf0121be4221d3f61b0b44c5d05a19a2421bd00eeb03010f783f09f1d1671eba4213d04f781fb10221be42ecd20de00527cff6fc773a44042a07d38a78c97852ea012702d00421be42ddd24ff0ff34204615b0bde8f08f4ff0ff3015b0bde8f08f0c990122063100910f99002601f0100182ea1111cde9071a1af806101f2908d84144109f0b3901360024be428846f3d1dde7d0f86c214ff0ff34002ad7d00d9b03eb810111f8803c11f87f7c11f87e5c11f87d1c43ea072343ea054343ea01614ff6fe73c0f203039942c0d812f801e0bef1000fbbd053185f78002fb7d007fb0ef2ddf83890002acde9027600f0ac819d1c00244ff6fe736618c0f203039e42a3d02f193b781b0901d0012718e04ff6fe73c0f20303013b9e4296d07b780bb102270de00523cff6fc733344042bfff48cafbb78ff7853ea07233ff486af04279a42fff482afd21a3c44d3d1002c00f07b81002100220f91cde9054509e0dde90a12059c0a44ddf820a0069da24280f06b81a95c0b920e0901d0012212e0a71a012f00f06181ab185e780eb1022209e0042fc0f059819f78db7857ea032600f0538104220a9211f00f0111aa525c18bf0121079b0f9c19434fea021a16f00305a446099600f08c80b4fbfef7002607fb1e434344b3f1ff3fc8bf01260e40012e1fd117eb0b071cd4de09042e19d87e090e2e16d807eb870709eb871c5e081cf80670db076ff00f03019708bf0f230495154608bf5546019f3b402b43049d0cf80630012d04f1010c5ad0bcfbfef6002706fb1ec34344b3f1ff3fc8bf01270f40012f1fd116eb0b071cd4de09042e19d87e090e2e16d807eb870709eb871c5e081cf80670db076ff00f03019708bf0f230495154608bf5546019f3b402b43049d0cf80630022d04f1020c29d0bcfbfef5002705fb1ec34344b3f1ff3fc8bf01270f40012f1ad115eb0b0717d4de09042e14d87e090e2e11d807eb870709eb87175e08db0717f806c06ff00f03154604bf0f23554603ea0c032b43bb5504f1030c099d6b1e032b2c440f9407d237e700bf0f9b0cf1040c63453ff431afbcfbfef5002605fb1ec34344b3f1ff3fc8bf01260e40012e1bd115eb0b0518d4de09042e15d86e090e2e12d805eb850509eb85155e08db07af5d6ff00f03914604bf0f23d1463b4043ea0903ddf83890ab550cf10103b3fbfef5002605fb1e334344b3f1ff3fc8bf01260e40012e18d115eb0b0515d4de09042e12d86e090e2e0fd805eb850509eb85155e08db07af5d6ff00f03144604bf0f2354463b402343ab550cf10203b3fbfef5002405fb1e334344b3f1ff3fc8bf01240c40012c18d115eb0b0515d4dc09042c12d86c090e2c0fd805eb850409eb84145d08db07665d6ff00f03174604bf0f23574633403b4363550cf10303b3fbfef5002405fb1e334344b3f1ff3fc8bf01240c40012c7ff471af15eb0b053ff56dafdc09042c3ff669af6c090e2c3ff665af05eb850409eb84145d08db07665d6ff00f03174604bf0f23574633403b43635553e7029a08eb0e010beb0203b1f5207f0d4628eae872a8bf4ff42075b3f5f07fa8bf4ff4f07395421edd039e109f5b457ff606aeddf830e0def800400f2c3ff6ffada3eb0b0c009ba5eb020803ebc40523f83420621ca5f802b0a5f80480a5f806c0cef80020ebe5039e109fe8e5062a3cbf4ff0ff3070472de9f04fadf2944d9a46154688460f90fbf7fbfe002800f0d68098f80510881d854240f0298446f6ac10c2f20700d0f800b0bbf1000f00f01f849bf80c009bf80d209bf80e309bf80f7040ea022040ea034040ea0769a9f1810010f1800f4ff0ff30c0f0b2809bf810209bf811309bf8137042ea03229bf8123042ea034242ea07620692813a12f5817f40f29e800029cdf828b000f09d8008f1060b002426aa4ff4e01c00270ae000bf05f1004042f8240001378f4204f1010480f08e801bf80750681e1e28f0d968b21f2801dd012075e0a5f1c2000beb07061d28a1eb07000fd8012800f0c88396f9010010f1410f00f3c28300f03f0365f38a1302201d465de005f0f003e02b24d10328c0f0b48396f9013013f1410f00f3ae8396f9020010f1410f00f3a883e02ddeb202d1a02ec0f0a283ed2d02d19f2e00f29d832b039bb206f03f0643ea861300f03f001d18032034e004284ff0ff3036d3a5f1f50313f1050f31d396f9013013f1410f2cdc96f9020010f1410f00f37e8396f9036016f1410f00f37883f02ddbb202d1902bc0f07283f42d02d18f2b00f26d830cea854e03f03f054eea053300f03f0043ea801006f03f0326aac518042000bf074442f8245076e74ff0ff300df2944dbde8f08f0021012007915ee0002c57d0a4f1010bcdf86090cdf810a000250df1780a5f46914608e026aaab4505f1010509f10409a7f1010739d052f825100029f3d400202b4687421dd009eb80067268b2f1ff3f18dc5a1c934514d0b268b2f1ff3f11dc9a1c93450dd0f268b2f1ff3f0adcda1c934506d032690433002a00f10400e0d400e000220a9853461aae009601f0ecf8002800f008831a980028c3d046f2a1415046c0f24e018847bce7ddf810a0ddf828b0ddf860900020079404e00020ddf828b00790012098f804400f21a20604f00f0501eae271694389225143c90a8df8681001260e2198f800c098f801e098f8023098f8037014f0200f08bf0e2608bf012105fb01f102fb01f14fead1218df869104ff00d0108bf022105fb01f102fb01f14fead1218df86a104ff00c0108bf032105fb01f102fb01f14fead1218df86b104ff00b0108bf042105fb01f102fb01f14fead1218df86c104ff00a0108bf052105fb01f102fb01f14fead1218df86d104ff0090108bf062105fb01f102fb01f14fead1218df86e104ff0080108bf072105fb01f102fb01f14fead1218df86f104ff0070108bf082105fb01f102fb01f14fead1218df870104ff0060108bf092105fb01f102fb01f14fead1218df871104ff0050108bf0a2105fb01f102fb01f14fead1218df872104ff0040108bf0b2105fb01f102fb01f14fead1218df873104ff0030108bf0c2105fb01f102fb01f14fead1218df874104ff0020108bf0d2105fb01f102fb01f14fead1218df8751006fb05f102fb01f14fead1218df876104ff0000108bf0f2169435143c90a00284ff000008df877107ff4cdae43ea0720079a484403904cea0e290af10600571e00260df198080190cdf810a0029718e000bf46f2a1411ea8c0f24e0188479df87c009df87d10dde90ab9029fdde9072640ea01200df1980801369642814400f0ff8158f82610b1f1ff3f1edd33469f421fd008eb83004268b2f1ff3f1adc0133bb4216d08268b2f1ff3f13dc0133bb420fd0c268b2f1ff3f0cdc0133bb4208d002690133002ae2d404e001f01f000b38d2e7002258461eab19ad009500f0abff002800f0c781199900290d9100f0ba819df880209df881309df87e009df87f1052ea03259df8822040ea01279df8833010979df884704fea024208969df8856042ea0362069b4fea074747ea06672b4403eb2743039fcdf82c90a7eb030609eb22491aaf149500f05e810902109b014400f0030809f101004ff0010c099009f102000ceb530305900d980c934b1e0e930b9b0130121415900ceb510003eb020e9a1acde91180a1eb08001890d0074ff0000a17904feace70169013960ae014980af1010a824512981599139e0144159100f029810aeb06014b090e2befd810980028ecd00e9801eb810103280f984ff0000600eb811e80f0848011980028ded0dde90c105feac67c0afb01084fea560018f8000000f00f03c1b208bf0b09b3fa83f0400910ea141f14d106eb0901c80904280fd848081ef80020fb5c02f00f0b02f0f0021a431aafc90708bf4bea03120ef8002011980128b1d0701c400818f80000bcf1000fc1b24fea111308bf00f00f03d8b2b0fa80f0400910ea141f14d109983118c80904280fd848081ef80020fb5c02f00f0b02f0f0021a431aafc90708bf4bea03120ef80020119802283ff486afb01c400818f80000bcf1000f00f00f01c2b208bf1109b1fa81f0400910ea141f7ff474af05983318d80904283ff66eaf58081ef80020795c02f00f0602f0f0020a43db0708bf46ea01120ef800205de7ddf8548007e000bf18980436b04208f102083ff471af18f8011c0023c9b2102938bf012313ea141f09eb060c16d14feadc13042b12d84fea5c0309091ef80320795c02f00f0b02f0f0020a431aaf5feac97008bf4bea01120ef8032018f8010c00f00f01b1fa81f0400910ea141f15d10cf10103d809042810d858081ef80020795c02f00f03179d43ea011302f0f002002d08bf42ea01030ef8003098f80000c1b210294ff0000038bf012010ea141f15d10cf10203d809042810d8080959081ef80120385c02f00f0302f0f002169d0243002d08bf43ea00120ef8012098f8000000f00f01b1fa81f0400910ea141f8ad10cf10303d80904283ff685af58081ef80020795c02f00f03179d43ea011302f0f002002d08bf42ea01030ef8003072e700bf109809eb00011498b1f5207f06eb000229eae970a8bf4ff42071b2f5f07fa8bf4ff4f072ddf810a081427ff70fae26eae6739a427ff70aaedaf800700f2f3ff605ae019dd21a091a05ebc70625f83700781c7380b180f280caf80000f6e59df87c009df87d10079a40ea012001e64ff0ff300df2944dbde8f08f00200df2944dbde8f08f2de9f04f83b04ef66c654ff2a8464ff6245948f2c73bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b029002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f0a8804ff43770fcf7e4f9002800f0d280494642183d3182f8dc4282f8dd4282f8de4282f8df4282f8e04282f8e14282f8e24282f8e34282f8e44282f8e54282f8e64282f8e74282f8e84282f8e94282f8ea4282f8eb4282f8ec4282f8ed4282f8ee4282f8ef4282f8f04282f8f14282f8f24282f8f34282f8f44282f8f54282f8f64282f8f74282f8f84282f8f94282f8fa4282f8fb4282f8fc4282f8fd4282f8fe4282f8ff4282f8004382f8014382f8024382f8034382f8044382f8054382f8064382f8074382f8084382f8094382f80a4382f80b4382f80c4382f80d4382f80e4382f80f4382f8104382f8114382f8124382f8134382f8144382f8154382f8164382f8174382f8184382d1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff44fafbff35f8f00bf46e8000121b156e8001f4145f8d043e70446fef757f9002c18bf002805d102990120487103b0bde8f08fc4f8600101254ff4f07084f8645101904ff4207049f683570090c0f2470700200021002200230026b84740b184f864610298c4f86061457103b0bde8f08f0298057103b0bde8f08f0024cde700bf2de9f04f87b0dde91065924643ea0102ddf848b02a43d20722d14fea550800eb510900eb5304abf1010700252846564588bf384600eb0a01304401eb810100eb800009eb811104eb80104246f6f7f2ff013f781c05f10105e8d107b0bde8f08f4ff6fc722a4005f0030406926a1e002701920494cde902a005e000bf059f039801375f45e9d0fa435645059788bf0beb020707eb0a0202eb820200eb821cba1902eb8202042d00eb821e4ff00008c0f09c80ddf8049000bf40468b4288bf484600eb010200eb03044fea52001cf800706ff0010088ea000608f1010088bfa8196ff0020686ea080608f1020b88bf05eb060b6ff0030686ea080608f1030a4feac27288bf05eb060a07f00f06002a4fea540208bf3e091ef80270e40707f00f0407f0f007374408bf44ea06170ef80270421854081cf804401844d20704f00f064fea500208bf26091ef80240c00704f00f0004f0f004344408bf40ea06140beb01000ef8024042081cf802200beb0304c00702f00f064fea540008bf16091ef80020e40702f00f0402f0f002324408bf44ea06120ef800200aeb010042081cf802200aeb0304c00702f00f064fea540008bf16091ef80020e40702f00f0402f0f002324408bf44ea06120ef80020069808f104088045a9f104097ff46dafddf808a0109eddf848b0049c002c3ff446af6fea080047468b4288bf2f18781842081f441cf80220c0074fea57091ef8090002f00f0408bf140900f00f0200f0f0002044ff0708bf42ea0410049c0ef80900012c3ff423af08f10102a5eb08098b4288bfa9f102025418670802eb030ae4074fea5a041cf807701ef8042007f00f0002f00f0b02f0f00208bf380902445feaca77ddf808a008bf4bea00120498109eddf848b00ef80420049c02283ff4f6ae08f102008b4288bfa9f10300421854081cf8047000eb030cd2074fea5c021ef8020007f00f0400f00f0800f0f00008bf3c0920445feacc7708bf48ea0410049c0ef80200d2e600bf2de9f04f83b04ef66c664ff2a8474ff6245a48f2c738ccf2ff06c2f229074ff6ff74cff6ff7a00254ff0010bc0f24508cde9010103e000bfbff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168b14200f0a8804ff43770fbf76cff002800f00581514642183d3182f8dc5282f8dd5282f8de5282f8df5282f8e05282f8e15282f8e25282f8e35282f8e45282f8e55282f8e65282f8e75282f8e85282f8e95282f8ea5282f8eb5282f8ec5282f8ed5282f8ee5282f8ef5282f8f05282f8f15282f8f25282f8f35282f8f45282f8f55282f8f65282f8f75282f8f85282f8f95282f8fa5282f8fb5282f8fc5282f8fd5282f8fe5282f8ff5282f8005382f8015382f8025382f8035382f8045382f8055382f8065382f8075382f8085382f8095382f80a5382f80b5382f80c5382f80d5382f80e5382f80f5382f8105382f8115382f8125382f8135382f8145382f8155382f8165382f8175382f8185382d1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff44fafbff35f8f00bf47e8000121b157e8001f4945f8d043e7019a029b01210172b2b3014631f81c2f9a422cd0c28b9a4229d0028c9a4226d0428c9a4223d0828c9a4220d0c28c9a421dd0028d9a421ad0428d9a4217d0828d9a4214d0c28d9a4211d0028e9a420ed0428e9a420bd0828e9a4208d0c28e9a4205d0028f9a4202d0428f9a4208d10121817603b0bde8f08f417203b0bde8f08f427a72b98288029b9a1a13b2b3f1ff3f05dd92b2022a24bf0122427601e00122027600224272029ac38882809a4284bf029ac28090f83c20029b21f81230511c01f00f0180f83c1003b0bde8f08f00bf2de9f04f89b0129f029003fb07f000294fea400b069300f0d58100200890029807924ff0010a4ff000084ff0000e002400264ff0000c0022009107e04ff0000c03244e4601328a4200f0c181bcf1000f40f0bb8110f80290022cefd0012c15d0ddf81cc0129b002c554640f095805fea191409f00f070596089700f09b80a34580f0a1804ff0010c002499e1ddf81cc0129bb9f1000f00f08980cb45c0f0828008980392069a5546abeb090b00eb001700010596cdf810b0019016e010f80810089e01f0f001314300f8081008f10108a9f101090125904524bf4ff000080ef1010eb9f1000f00f062819e4580f05a810eeb8e00002d0ceb8010dfd0a2eb0801b1eb590f88bf4fea590169b38c0800eb080b1cd000220bf10106a2eb840a6ff0030c00bf06eb0c020cf1040c0aeb0c040434d770177157719771f3d10cf10406dde9062c129b11f0030404d10ce0002611f0030408d0012c0bf8067004d05e44022c777018bfb770a9eb4109b9f1000f88440dd09045aed210f80810019c01f00f012143a9f10109002500f80810a8e74ff000099fe700bf56ea09260ed0b34580f088804ff0010c00244be74ff0000c022447e74ff0000c012401e14ff0010c002400263ee708980392069aabeb040b00eb00170001cdf810b0019015e000bf1af80800089900f0f00008440af8080008f10108013c0125904524bf4ff000080ef1010e002c00f0d2809e4580f0ca800eeb8e00002d0ceb801ae1d0a2eb0800b0eb540f88bf600880b381080aeb08091ed00022ab4609f10106a2eb81016ff0030c00bf06eb0c020cf1040c01eb0c050435d770177157719771f3d10cf10401dde9062c129b5d4610f0030604d10de0002110f0030609d0012e09f8017005d04944022e4f7018bf8f7000bfa4eb400480446cb19045afd21af80800019900f00f000843013c00250af80800aae700bf0024a1e708980392069aabeb060b314600eb00170001cdf810b00190059613e01af80800089e00f0f00030430af8080008f1010801390125904524bf4ff000080ef1010e00295ad09e4553d20eeb8e00002d0ceb801ae3d0a2eb0800b0eb510f88bf480880b384080aeb08091ed00022ab4609f10106a2eb84046ff0030c00bf06eb0c020cf1040c04eb0c050435d770177157719771f3d10cf10406dde9062c129b5d4610f0030404d10de0002610f0030409d0012c09f8067005d04e44022c777018bfb77000bfa1eb4001804479b19045b1d21af80800019c00f00f002043013900250af808000029add107e000bf0021a1e7aa464ff0010c002403e0aa4600244ff0000c0df1080b00999be80508059e3fe60120012106e04ff0010cb4fa84f08cf001014009bbfa8bf252091140084009b0bde8f08f014640f258304cf20732c2f20000c0f248021047b0b54ff2ac44c2f229040146206846f23f52c5f28802b2eb500f40f258304cf2e9124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf2de9f04188b046f24f461c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f081f0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f6f739f906f1210506f1280029460722f6f731f9284621460722f6f72cf920465146032207f10905f6f725f906f11d0049460422f6f71ff9f07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14df22d77abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f6f7f3f8a81c4af28d5782b2c0f24607f02021460023b8474bb0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0b7e50846abe570b50446d0f83c0142f665360d46c0f2440668b94af2d550cff6ff707844002122460023b0470028c4f83c0108bf70bd06f594718847d4f83c0106f1e8022946bde87040104700bf2de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65c42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f31330000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a8900000000000000000", "desc": "append injected blobs to main-app payload" }, { "offset": 779114, "old": "846a3800", - "new": "0e073900", + "new": "7c1b3900", "desc": "main-app subheader payload size (ps)" }, { "offset": 152, "old": "046b3800", - "new": "8e073900", + "new": "fc1b3900", "desc": "main-app TOC entry size (ps + 128)" }, { "offset": 779234, "old": "846a3804", - "new": "0e073904", + "new": "7c1b3904", "desc": "main-app preamble length (low 24 bits)" }, { "offset": 779238, "old": "85c355a2", - "new": "21ab3673", + "new": "a1afb7e4", "desc": "[5] ota/s200_firmware_ota.bin preamble crc32" }, { "offset": 156, "old": "ed292ee4", - "new": "9e600c9c", + "new": "b1adc0d0", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)" }, { "offset": 779118, "old": "ed292ee4", - "new": "9e600c9c", + "new": "b1adc0d0", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)" } ] diff --git a/app/g2/glance-host.ts b/app/g2/glance-host.ts new file mode 100644 index 00000000..d58781c7 --- /dev/null +++ b/app/g2/glance-host.ts @@ -0,0 +1,280 @@ +/** + * Shows the Glanceboard while the shell sleeps. The board is not a window: + * it lives on its own full-screen opaque compositor surface above the shell + * (below only the lock screen), so it never composites with the sidebar, + * top bar, or the sleeping app's retained frame. The host owns that surface, + * the visibility state machine (glance-state.ts), its auto-hide timer, and + * the board's render loop; the controller feeds it sleep-time input and the + * wake barrier, and takes the compositor back to blank when the board hides. + */ +import { GrayImage, G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image"; +import { prepareFrameDraws } from "../graphics/glyph-wire"; +import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../graphics/plane"; +import * as frameTimings from "../native/frame-timings"; +import { type DisplayTarget } from "../native/preview-display"; +import { minWindowTop } from "../ui/shell/geometry"; +import { beginRenderPass, endRenderPass } from "../util/render-freshness"; +import { type GlanceBoardInstance, type GlanceboardProvider } from "../apps/app-definition"; +import { GLANCE_HIDDEN, glanceEventForGesture, reduceGlance, type GlanceEvent, type GlanceState } from "./glance-state"; + +export const GLANCE_SURFACE_ID = "glance"; +/** Above the shell (1) and every window (0); below the lock screen (1000). */ +export const GLANCE_SURFACE_Z_ORDER = 900; + +export type GlanceHostOptions = { + getDisplay: () => DisplayTarget | null; + getProvider: () => GlanceboardProvider | null; + /** Whether a board may show right now (connected or preview, not locked). */ + canShow: () => boolean; + /** + * The controller's wake barrier: restore the EvenHub session if it was + * suspended and unblank the compositor. Resolves once the frame is visible. + */ + ensureSessionActive: (frameId: number) => Promise; + /** + * The board hid on its own (timer or release) with the shell still + * asleep: the controller re-blanks and re-arms the screen-off power save. + */ + onHiddenWhileAsleep: () => void; + /** Visibility changed either way (phone mirror refresh). */ + onVisibilityChanged: () => void; + appendLog: (message: string) => void; +}; + +export class GlanceHost { + private state: GlanceState = GLANCE_HIDDEN; + private board: GlanceBoardInstance | null = null; + /** Whether the surface is currently visible on the compositor. */ + private shown = false; + private hideTimer: ReturnType | null = null; + private configuredFor: DisplayTarget | null = null; + /** Serializes show/hide against each other and against in-flight renders. */ + private queue: Promise = Promise.resolve(); + private rendering = false; + private renderPending = false; + private nextRenderWantsFreshData = false; + + constructor(private readonly options: GlanceHostOptions) {} + + isVisible(): boolean { + return this.state.visible; + } + + /** Whether sleep-time gestures should reach the board at all. */ + isEnabled(): boolean { + return this.options.getProvider()?.isEnabled() ?? false; + } + + /** + * The glance event a sleep-time gesture means under the board's settings, + * or null when the shell should see the input as usual: nothing while the + * board is disabled, no press from a tap when "Show on tap" is disabled, + * no hold when "Show on long press" is off, no press from a head-tilt when + * "Show on head tilt" is off (it then wakes the regular UI). A release + * always passes so a hold in progress can end. + */ + eventForGesture(gesture: "head-tilt" | string): GlanceEvent | null { + const provider = this.options.getProvider(); + if (!provider?.isEnabled()) return null; + if (gesture === "click" && !provider.showOnTap()) return null; + if ((gesture === "long-press" || gesture === "short-then-long-press") && !provider.showOnLongPress()) return null; + if (gesture === "head-tilt" && !provider.showOnHeadTilt()) return null; + return glanceEventForGesture(gesture, this.isVisible()); + } + + /** + * Apply a glance event from sleep-time input. The frame is owned from here: + * a show submits it with the board's first frame, anything else finishes it. + */ + async handleEvent(event: GlanceEvent, frameId: number): Promise { + const before = this.state; + const timeoutMs = this.options.getProvider()?.tapTimeoutMs(); + this.state = reduceGlance(before, event, Date.now(), timeoutMs); + this.armHideTimer(); + if (this.state.visible === before.visible) { + frameTimings.finishFrame(frameId, this.state.visible ? "glanceboard stays up" : "glance event while hidden"); + return; + } + if (this.state.visible) { + await this.enqueue(() => this.show(frameId)); + } else { + frameTimings.finishFrame(frameId, "glanceboard hidden"); + await this.enqueue(() => this.hide(true)); + } + } + + /** + * Hide because the regular UI is waking (double-tap, a notification, ...): + * the shell's own wake path handles the compositor from here, so no re-blank. + */ + dismiss(): void { + if (!this.state.visible && !this.shown && !this.board) return; + this.state = GLANCE_HIDDEN; + this.armHideTimer(); + void this.enqueue(() => this.hide(false)); + } + + /** The display target went away (disconnect, preview teardown): forget everything. */ + reset(): void { + this.state = GLANCE_HIDDEN; + this.armHideTimer(); + this.board?.stop(); + this.board = null; + this.shown = false; + this.configuredFor = null; + this.renderPending = false; + } + + private enqueue(operation: () => Promise): Promise { + const run = this.queue.then(operation, operation).catch((error) => { + this.options.appendLog(`glanceboard operation failed: ${String(error)}`); + }); + this.queue = run; + return run; + } + + private armHideTimer(): void { + if (this.hideTimer !== null) clearTimeout(this.hideTimer); + this.hideTimer = null; + const hideAtMs = this.state.hideAtMs; + if (!this.state.visible || hideAtMs === null) return; + this.hideTimer = setTimeout(() => { + this.hideTimer = null; + void this.handleEvent({ type: "timeout" }, frameTimings.startFrame("glanceboard timeout")); + }, Math.max(0, hideAtMs - Date.now())); + } + + private async configureSurface(display: DisplayTarget): Promise { + await display.configureSurface(GLANCE_SURFACE_ID, { + x: 0, + y: 0, + width: G2_LENS_WIDTH, + height: G2_LENS_HEIGHT, + zOrder: GLANCE_SURFACE_Z_ORDER, + transparency: "opaque", + }); + await display.setSurfaceVisible(GLANCE_SURFACE_ID, false); + this.configuredFor = display; + } + + private async show(frameId: number): Promise { + if (!this.state.visible) { + // Hidden again before this ran (a quick release); nothing to do. + frameTimings.finishFrame(frameId, "glanceboard show superseded"); + return; + } + const display = this.options.getDisplay(); + const provider = this.options.getProvider(); + if (!display || !provider || !this.options.canShow()) { + this.state = GLANCE_HIDDEN; + this.armHideTimer(); + frameTimings.finishFrame(frameId, "glanceboard unavailable"); + return; + } + if (this.configuredFor !== display) await this.configureSurface(display); + if (!this.board) { + this.board = provider.createBoard(() => this.requestRender()); + this.board.start(); + } + // Submit the first frame and reveal the surface while the compositor is + // still blanked, so the unblank below composites the board on top of the + // sleeping UI in one step rather than flashing the app first. + await this.render(frameId); + await display.setSurfaceVisible(GLANCE_SURFACE_ID, true); + this.shown = true; + const ready = await this.options.ensureSessionActive(frameId); + if (!ready) this.options.appendLog("glanceboard: wake barrier did not complete"); + this.options.onVisibilityChanged(); + } + + private async hide(stillAsleep: boolean): Promise { + const wasShown = this.shown; + this.shown = false; + const display = this.options.getDisplay(); + if (wasShown && display && this.configuredFor === display) { + // Blank before revealing what is under the board: hiding the surface + // first recomposites the sleeping UI's retained frames and transmits + // them, a visible flash of the main UI before the screen goes dark. + // Blanked, the surface change composites to the same black frame. (The + // controller's screen-off path below blanks again, harmlessly.) + if (stillAsleep) { + await display.setScreenBlanked(true); + } + await display.setSurfaceVisible(GLANCE_SURFACE_ID, false); + } + this.board?.stop(); + this.board = null; + this.renderPending = false; + if (wasShown && stillAsleep) this.options.onHiddenWhileAsleep(); + if (wasShown) this.options.onVisibilityChanged(); + } + + private requestRender(): void { + if (!this.board) return; + if (this.rendering) { + this.renderPending = true; + return; + } + void this.enqueue(() => this.render(frameTimings.startFrame("render:glanceboard"))); + } + + /** Paint the board into a full-screen frame and submit it to the surface. */ + private async render(frameId: number): Promise { + const board = this.board; + const display = this.options.getDisplay(); + if (!board || !display || this.configuredFor !== display) { + frameTimings.finishFrame(frameId, "discarded: glanceboard not showing"); + return; + } + this.rendering = true; + try { + frameTimings.annotateFrame(frameId, "glanceboard"); + const wantFreshData = this.nextRenderWantsFreshData; + this.nextRenderWantsFreshData = false; + beginRenderPass(!wantFreshData); + const paintStartedAtMs = Date.now(); + const frame = frameTimings.span(frameId, "paint", () => + frameTimings.runWithFrame(frameId, () => { + const boardImage = board.paint(); + const full = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0); + // Centred horizontally in the panel, in the standard window band + // vertically (Display > Vertical position). + const x = Math.max(0, ((G2_LENS_WIDTH - boardImage.width) / 2) | 0); + const y = Math.max(0, Math.min(G2_LENS_HEIGHT - boardImage.height, minWindowTop())); + boardImage.composeInto(full, x, y); + return full; + }), + ); + const paintUsedStaleData = endRenderPass(); + const paintMs = Date.now() - paintStartedAtMs; + const planes: Plane[] = [{ image: frame, x: 0, y: 0 }]; + const fingerprint = frameTimings.span(frameId, "fingerprint", () => planesFingerprint(planes)); + const { image, draws } = frameTimings.span(frameId, "flatten", () => flattenPlanesWithDraws(planes)); + const buffer = frameTimings.span(frameId, "to8bpp", () => image.to8bppBuffer()); + const preparedDraws = frameTimings.span(frameId, "prepareFrameDraws", () => prepareFrameDraws(draws)); + await frameTimings.spanAsync(frameId, "submit", () => + display.submitSurfaceFrame( + GLANCE_SURFACE_ID, + buffer, + { x: 0, y: 0, width: image.width, height: image.height }, + fingerprint, + paintMs, + frameId, + preparedDraws, + ), + ); + if (paintUsedStaleData) { + // Same contract as the windows: a paint that used cached data (the + // notification icons) gets one follow-up with fresh data. + this.nextRenderWantsFreshData = true; + this.renderPending = true; + } + } finally { + this.rendering = false; + if (this.renderPending && this.board) { + this.renderPending = false; + this.requestRender(); + } + } + } +} diff --git a/app/g2/glance-state.ts b/app/g2/glance-state.ts new file mode 100644 index 00000000..b8369486 --- /dev/null +++ b/app/g2/glance-state.ts @@ -0,0 +1,86 @@ +/** + * The Glanceboard's visibility rules, as a pure reducer so they can be tested + * without the display plumbing. The board is an alternate sleep-time display: + * while the shell is asleep a press (single tap, or a head-tilt wake) shows it + * for a short while, a hold (long-press or short-then-long-press) shows it until release, + * and a double-tap dismisses it in favour of the regular UI. GlanceHost feeds + * these events in and applies the resulting visibility to the compositor. + * + * No NativeScript imports: this module is compiled and run under plain node + * by tests/glance-state.test.cjs. + */ + +/** Fallback press timeout when the host supplies none; each further press restarts it. */ +export const GLANCE_TIMEOUT_MS = 3000; + +export type GlanceState = { + visible: boolean; + /** A long-press is holding the board up; the timer does not run meanwhile. */ + holding: boolean; + /** When the board hides on its own (epoch ms), or null while held / hidden. */ + hideAtMs: number | null; +}; + +export type GlanceEvent = + /** Single tap or head-tilt wake: show, and (re)start the auto-hide timer. */ + | { type: "press" } + /** Long-press: show and keep showing until the release. */ + | { type: "hold" } + /** The long-press ended. */ + | { type: "release" } + /** The auto-hide timer fired. */ + | { type: "timeout" } + /** Double-tap (or any other wake of the regular UI): hide now. */ + | { type: "dismiss" }; + +export const GLANCE_HIDDEN: GlanceState = Object.freeze({ visible: false, holding: false, hideAtMs: null }); + +export function reduceGlance( + state: GlanceState, + event: GlanceEvent, + nowMs: number, + timeoutMs: number = GLANCE_TIMEOUT_MS, +): GlanceState { + switch (event.type) { + case "press": + // A tap during a hold changes nothing: the hold decides when it ends. + if (state.holding) return state; + return { visible: true, holding: false, hideAtMs: nowMs + timeoutMs }; + case "hold": + return { visible: true, holding: true, hideAtMs: null }; + case "release": + // Releases delivered late or after a disabled hold gesture mean nothing here. + return state.holding ? GLANCE_HIDDEN : state; + case "timeout": + if (!state.visible || state.holding || state.hideAtMs === null || nowMs < state.hideAtMs) return state; + return GLANCE_HIDDEN; + case "dismiss": + return GLANCE_HIDDEN; + } +} + +/** + * Which glance event, if any, a shell input gesture means while the screen is + * off. A double-tap only concerns the board while it is showing (it then + * dismisses it before waking the regular UI); everything else the shell + * already handles or ignores while asleep. + */ +export function glanceEventForGesture( + gesture: "click" | "double-click" | "long-press" | "short-then-long-press" | "long-press-release" | "head-tilt" | string, + boardVisible: boolean, +): GlanceEvent | null { + switch (gesture) { + case "click": + case "head-tilt": + return { type: "press" }; + case "long-press": + case "short-then-long-press": + return { type: "hold" }; + case "long-press-release": + return { type: "release" }; + case "double-click": + return boardVisible ? { type: "dismiss" } : null; + default: + return null; + } +} diff --git a/app/g2/glasses-session.ts b/app/g2/glasses-session.ts index e18190b5..16251ed7 100644 --- a/app/g2/glasses-session.ts +++ b/app/g2/glasses-session.ts @@ -1,6 +1,8 @@ import * as protocol from './ble-protocol' import { iosBleTraffic } from './ble-traffic-counters' -import { buildBoundingBoxPayload } from './ble-image-optimizer' +import { buildBoundingBoxPayload, buildFullFrameBands } from './ble-image-optimizer' +import { CfwTransport, CFW_MAX_MESSAGE, parseCfwAcks } from './cfw-transport' +import { hasCompatibleFirmware, firmwareIncompatibilityMessage, REQUIRED_FACECLAW_FIRMWARE_VERSION } from './firmware-compat' import { hexToBytes } from '../util/hex-util' import { deviceAddressError } from './ios-peripheral-identity' @@ -25,7 +27,9 @@ class AckTimeout extends Error {} // Match Android ConnectionOptions.WINDOW_SIZE. This bounds complete image // messages queued for writing or awaiting ACK, not individual BLE packets. const DISPLAY_WINDOW_SIZE = 3 -type DisplayFrame = { packed: Uint8Array; payload: Uint8Array; offset: number; pending: number } +type CfwPending = { payload: Uint8Array; checksum: number; role: string; magic: number; ackLenses: number; retries: number; + retryPending: boolean; deadline: number; resolve: () => void; reject: (error: Error) => void } +type DisplayFrame = { packed: Uint8Array; commands: Uint8Array[]; offset: number; pending: number } /** G2 session independent of the phone OS. Images go to L, control to R, as on Android. */ export class GlassesSession { @@ -34,6 +38,9 @@ export class GlassesSession { private generation = 0 private ids: Record = {} private limits: Record = {} + private cfwPending: CfwPending[] = [] + private cfwTransports = new Map() + private cfwTimer: number | null = null private pending = new Map() private receiver = new protocol.MessageReceiver() private writes = new Map>() @@ -68,7 +75,6 @@ export class GlassesSession { private microphoneWork: Promise = Promise.resolve() private microphoneEnabled = false constructor(private readonly transport: SessionTransport, - private readonly deflate: (data: Uint8Array) => Uint8Array, private readonly onState: (state: SessionState) => void, private readonly onInput: (input: protocol.GlassesInput) => void, private readonly log: (message: string) => void = () => {}, @@ -114,9 +120,9 @@ export class GlassesSession { this.update('connecting', 'Checking glasses firmware…') const settings = await this.request('right', protocol.SID.settings, protocol.settingsQuery, 'Settings query') this.applySettings(settings) - const caps = this.state.capabilities.split(/\s+/) - if (!['img640', 'fbguard', 'wearnotify'].every(cap => caps.includes(cap))) - throw new Error('The glasses do not report compatible Faceclaw firmware (img640, fbguard, wearnotify). Bluetooth is working, but this display requires the modified firmware. Flashing remains available on Android.') + const firmware = { leftVersion: this.state.leftVersion, rightVersion: this.state.rightVersion, extension: this.state.capabilities } + if (!hasCompatibleFirmware(firmware)) + throw new Error((firmwareIncompatibilityMessage(firmware) || `The glasses must report Faceclaw firmware revision ${REQUIRED_FACECLAW_FIRMWARE_VERSION} or newer.`) + ' Flashing remains available on Android.') this.update('connecting', 'Starting glasses display…') await this.request('right', protocol.SID.launch, () => protocol.prelude(), 'App launch', 3500, 0x20, 156) await this.lease(true) @@ -176,7 +182,7 @@ export class GlassesSession { private nextMagic(): number { for (let i = 0; i < 156; i++) { const magic = this.magic; this.magic = this.magic === 255 ? 100 : this.magic + 1 - if (magic !== 156 && ![...this.pending.keys()].some(key => key.endsWith(`:${magic}`))) return magic + if (magic !== 156 && !this.cfwPending.some(item => item.magic === magic) && ![...this.pending.keys()].some(key => key.endsWith(`:${magic}`))) return magic } throw new Error('All message identifiers are in use') } @@ -200,15 +206,20 @@ export class GlassesSession { }) } private send(role: string, sid: number, flag: number, payload: Uint8Array): Promise { + return this.writePackets(role, () => protocol.frameMessage(payload, sid, flag, this.sequence++, this.limits[role])) + } + private writePackets(role: string, build: () => Uint8Array[], current = () => true): Promise { const identifier = this.ids[role], generation = this.generation if (!identifier) return Promise.reject(new Error(`No ${role} device connected`)) - const frames = protocol.frameMessage(payload, sid, flag, this.sequence++, this.limits[role]) const previous = this.writes.get(identifier) ?? Promise.resolve() // A failed write poisons this link's queue until reset: do not transmit // later fragments after a hole in the image stream. const work = previous.then(async () => { - for (const frame of frames) { + this.check(generation) + if (!current()) return + for (const frame of build()) { this.check(generation) + if (!current()) return await this.transport.write(identifier, protocol.G2_WRITE, frame) iosBleTraffic.recordWrite(frame.length) } @@ -221,6 +232,75 @@ export class GlassesSession { private lease(acquire: boolean): Promise { return Promise.all(['right', 'left'].map(role => this.send(role, protocol.SID.settings, 0x20, protocol.framebufferLease(acquire)))) } + private requestCfw(role: string, payload: Uint8Array): Promise { + if (payload.length > CFW_MAX_MESSAGE) return Promise.reject(new Error('CFW message too large')) + return new Promise((resolve, reject) => { + const item: CfwPending = { role, payload, checksum: protocol.crc16(payload), magic: this.nextMagic(), ackLenses: 0, retries: 0, + retryPending: false, deadline: 0, resolve, reject } + this.cfwPending.push(item) + this.sendCfw(item) + }) + } + private sendCfw(item: CfwPending): void { + const generation = this.generation, magic = item.magic + const current = () => generation === this.generation && item.magic === magic && this.cfwPending.includes(item) + void this.writePackets(item.role, () => { + let transport = this.cfwTransports.get(item.role) + if (!transport) { transport = new CfwTransport(); this.cfwTransports.set(item.role, transport) } + if (item.retries) transport.reset() + return transport.encode(item.payload, magic, 3, this.limits[item.role]) + }, current).then(() => { + if (!current()) return + item.deadline = Date.now() + 500 + this.scheduleCfwRecovery() + }).catch(error => { if (current()) this.fail(error, true) }) + } + private receiveCfw(identifier: string, packet: Uint8Array): void { + const acks = parseCfwAcks(packet) + if (!acks) return + for (const ack of acks) { + // The ingress temple relays the other lens's result on the SAME link. + const item = this.cfwPending.find(p => this.ids[p.role] === identifier && p.magic === ack.streamId) + if (!item || ack.messageId !== 0) continue + if (ack.nack) item.retryPending = true + else if (ack.size === item.payload.length && ack.checksum === item.checksum) item.ackLenses |= ack.lens + this.log(`CFW ${ack.nack ? 'NACK' : 'ACK'} stream=${ack.streamId} lens=${ack.lens} size=${ack.size} crc=${ack.checksum} confirmed=${item.ackLenses}`) + } + while (this.cfwPending.length) { + const head = this.cfwPending[0] + if (head.retryPending || head.ackLenses !== 3) break + this.cfwPending.shift(); head.resolve() + } + this.scheduleCfwRecovery() + } + private scheduleCfwRecovery(): void { + if (this.cfwTimer !== null) clearTimeout(this.cfwTimer) + this.cfwTimer = null + let deadline = Infinity + for (const item of this.cfwPending) { + if (item.retryPending) deadline = 0 + else if (item.ackLenses !== 3 && item.deadline) deadline = Math.min(deadline, item.deadline) + } + if (deadline === Infinity) return + this.cfwTimer = setTimeout(() => { + this.cfwTimer = null + this.recoverCfw() + }, Math.max(0, deadline - Date.now())) + } + private recoverCfw(): void { + if (!this.cfwPending.some(p => p.retryPending || (p.ackLenses !== 3 && p.deadline > 0 && p.deadline <= Date.now()))) { + this.scheduleCfwRecovery(); return + } + if (this.cfwPending.some(p => p.retries >= 3)) { this.fail(new Error('CFW recovery retry limit'), true); return } + this.log(`CFW recovery: replay ${this.cfwPending.length} unresolved messages`) + // Go back to the oldest unresolved command, including any ACKed tail. + // Fresh stream IDs reject stale ACKs; each replay resets compression history. + for (const item of this.cfwPending) { + item.magic = this.nextMagic(); item.retries++; item.ackLenses = 0 + item.deadline = 0; item.retryPending = false + } + for (const item of this.cfwPending) this.sendCfw(item) + } private receive(event: TransportEvent): void { if (!Object.values(this.ids).includes(event.identifier ?? '')) return if (event.kind === 'disconnected') { @@ -252,6 +332,10 @@ export class GlassesSession { } for (const message of this.receiver.receive(event.identifier!, data)) { this.log(`RX ${event.identifier === this.ids.left ? 'L' : 'R'} sid=${message.sid.toString(16)} flag=${message.flag.toString(16)} cmd=${message.command} magic=${message.magic}`) + if (message.sid === protocol.SID.cfw) { + this.receiveCfw(event.identifier!, message.packet!) + continue + } if (![1, 6].includes(message.flag)) { // A master arm can relay the other arm's ACK; magic is allocated // across BOTH links, matching Android's communicator. @@ -343,32 +427,32 @@ export class GlassesSession { // Compare with the last enqueued image, not the last ACKed one. In an // A -> B -> A sequence, B may still be in flight when A is requested. if (this.lastEnqueued && packed.every((value, i) => value === this.lastEnqueued![i])) continue - const delta = buildBoundingBoxPayload(this.lastEnqueued, packed, 640, 480, this.nextImageFrameId, this.deflate) - const payload = delta ?? protocol.concat(new Uint8Array([6]), this.deflate(protocol.rle4(packed))) - if (payload.length > 165888) throw new Error('Compressed frame exceeds the glasses image buffer') - if (delta) { + const delta = buildBoundingBoxPayload(this.lastEnqueued, packed, 640, 480, this.nextImageFrameId) + const payload = delta ?? protocol.concat(new Uint8Array([6]), protocol.rle4(packed)) + if (delta) this.nextImageFrameId = this.nextImageFrameId >= 0xfffe ? 1 : this.nextImageFrameId + 1 + const commands = payload.length <= CFW_MAX_MESSAGE ? [payload] : buildFullFrameBands(packed, 640, 480, this.nextImageFrameId) + if (payload.length > CFW_MAX_MESSAGE) for (const _ of commands) this.nextImageFrameId = this.nextImageFrameId >= 0xfffe ? 1 : this.nextImageFrameId + 1 - this.log(`Display bbox ${delta[3] * 4}x${delta[4] * 2}+${delta[1] * 4}+${delta[2] * 2} fid=${delta[5] | (delta[6] << 8)} (${payload.length} bytes)`) - } else this.log(`Display full 640x480 (${payload.length} bytes)`) - this.displaySending = { packed, payload, offset: 0, pending: 0 } + this.log(`Display ${delta ? 'bbox' : 'full'} (${commands.length} CFW commands)`) + this.displaySending = { packed, commands, offset: 0, pending: 0 } this.displayFrames.push(this.displaySending); this.lastEnqueued = packed } - const frame = this.displaySending, offset = frame.offset - frame.offset += 3800; frame.pending++; this.displayInFlight++ - if (frame.offset >= frame.payload.length) this.displaySending = null - // send() serializes whole messages on L, but request() waits for each - // magic's ACK independently. Fill the other slots without awaiting it. - void this.request('left', protocol.SID.hub, magic => protocol.imageFragment(magic, frame.payload, offset), 'Display frame').then(() => { + const frame = this.displaySending, payload = frame.commands[frame.offset++] + frame.pending++; this.displayInFlight++ + if (frame.offset >= frame.commands.length) this.displaySending = null + // Writes serialize on L while up to three complete commands await their + // two-lens ACKs. Retire commands in submission order. + void this.requestCfw('left', payload).then(() => { if (generation !== this.generation) return frame.pending--; this.displayInFlight--; this.lastHeartbeat = Date.now() // Retire in submission order even if relayed ACKs arrive out of order. - // A frame counts only after every fragment has been acknowledged. + // A frame counts only after every command has been acknowledged. while (this.displayFrames.length) { const completed = this.displayFrames[0] - if (completed.offset < completed.payload.length || completed.pending) break + if (completed.offset < completed.commands.length || completed.pending) break this.displayFrames.shift(); this.displayed = completed.packed this.state.frames++; iosBleTraffic.recordDisplayFrame(); this.onState({ ...this.state }) - this.log(`Display frame ${this.state.frames} acknowledged (${completed.payload.length} bytes)`) + this.log(`Display frame ${this.state.frames} acknowledged (${completed.commands.length} commands)`) } this.wake() }).catch(error => { if (generation === this.generation) this.fail(error, true) }) @@ -404,6 +488,11 @@ export class GlassesSession { this.timer = this.retryTimer = null; this.pumping = false const pending = [...this.pending.values()]; this.pending.clear() for (const request of pending) { if (request.timer) clearTimeout(request.timer); request.reject(new Error('Connection ended')) } + if (this.cfwTimer !== null) clearTimeout(this.cfwTimer) + this.cfwTimer = null + const custom = this.cfwPending; this.cfwPending = [] + for (const item of custom) item.reject(new Error('Connection ended')) + this.cfwTransports.clear() this.receiver.clear(); this.writes.clear(); this.latest = this.displayed = null this.lastEnqueued = null; this.displayFrames = []; this.displaySending = null; this.displayInFlight = 0 } @@ -436,12 +525,7 @@ export class GlassesSession { this.update('disconnecting', 'Disconnecting…'); this.reset() try { if (cleanup) { - if (this.state.capabilities.split(/\s+/).includes('cleanup11')) - await this.request('left', protocol.SID.hub, magic => protocol.imageFragment(magic, new Uint8Array([11]), 0), 'Display cleanup', 1200) - else { - await this.request('right', protocol.SID.hub, protocol.shutdown, 'Close display', 1200) - await this.lease(false) - } + await this.requestCfw('left', new Uint8Array([11])) } } catch (error) { this.log(`Disconnect cleanup: ${this.message(error)}`) } finally { this.reset(); this.closeLinks(); this.update('disconnected', 'Preview only') } diff --git a/app/g2/ios-preview-controller.ts b/app/g2/ios-preview-controller.ts index 582ce85d..21cdbf31 100644 --- a/app/g2/ios-preview-controller.ts +++ b/app/g2/ios-preview-controller.ts @@ -308,8 +308,7 @@ export class IosPreviewController { const addresses = loadDeviceAddresses(), error = deviceAddressError(addresses) if (error) { this.onError(error); return } if (!this.session) { - const { deflate } = require('pako') as { deflate: (data: Uint8Array) => Uint8Array } - this.session = new GlassesSession(iosBluetooth(), deflate, state => { + this.session = new GlassesSession(iosBluetooth(), state => { if (state.phase !== 'connected') iosVoiceInput.handleSessionEnded() shell.setBatteryLevels({ headset: state.battery, headsetCharging: state.charging }) this.syncRuntime() diff --git a/app/g2/wear-remote.ts b/app/g2/wear-remote.ts index 629d9d96..4e5a464d 100644 --- a/app/g2/wear-remote.ts +++ b/app/g2/wear-remote.ts @@ -14,6 +14,12 @@ * stream to the watch as events so a query made from the wrist can be read * from the wrist. * + * The watch's own battery flows the other way for the glasses' top-bar and + * Glanceboard indicators: the phone polls it (the watch answers from a + * listener service even while its app is closed) and the open watch app + * pushes changes unprompted. The level lives in shell.getBatteryLevels() + * beside the G2 and R1 ones and is cleared when no watch is reachable. + * * Transport is app/native/wear-bridge.ts (Java FaceclawWearBridge); the * message shapes are documented in wear/PROTOCOL.md. */ @@ -88,6 +94,14 @@ const MAX_TEXT_LENGTH = 2000; const STATE_PUBLISH_DEBOUNCE_MS = 150; const STATE_REFRESH_INTERVAL_MS = 30_000; const ASSISTANT_STREAM_MIN_INTERVAL_MS = 250; +// Each poll wakes the watch app's process for a moment; the level changes +// slowly, and a charger being plugged in is pushed at once whenever the +// watch app is open, so a leisurely cadence is enough. +const WATCH_BATTERY_POLL_INTERVAL_MS = 5 * 60_000; +// Floor between polls that state changes (a watch coming into range, the +// glasses connecting) would otherwise trigger back to back. +const WATCH_BATTERY_POLL_MIN_GAP_MS = 20_000; +const WATCH_BATTERY_URGENT_POLL_LIMIT = 3; /** What the dashboard controller lends the watch remote. */ export type WearRemoteHost = { @@ -120,6 +134,11 @@ export class WearRemote { private assistantStreamTimer: ReturnType | null = null; private assistantPendingText: string | null = null; private lastAssistantSentAtMs = 0; + private lastWatchBatteryPollAtMs = 0; + private watchBatteryKnown = false; + // Urgent polls that got no answer; a watch app too old to answer them + // must not be poked every publish, so after a few the cadence drops back. + private watchBatteryPollsUnanswered = 0; constructor(private readonly host: WearRemoteHost) { this.active = wearBridge.isAvailable(); @@ -141,8 +160,16 @@ export class WearRemote { connection.reachable ? `watch: ${connection.watchName || "watch"} reachable` : "watch: no watch reachable", ); } - // A watch that just came into range gets the current state at once. - if (connection.reachable) this.publishNow(true); + // A watch that just came into range gets the current state at once, + // and is asked for its battery; one that left takes its indicator + // with it (no placeholder). + if (changed) this.watchBatteryPollsUnanswered = 0; + if (connection.reachable) { + this.publishNow(true); + this.pollWatchBattery(true); + } else if (changed) { + this.setWatchBattery(null, null); + } }); shell.onAssistantActivity((event) => this.forwardAssistantActivity(event)); shell.onAlertShown((text) => { @@ -155,9 +182,38 @@ export class WearRemote { // Catch-all refresh for state the controller does not announce (cheap: // identical states are dropped on the Java side). setInterval(() => this.schedulePublish(), STATE_REFRESH_INTERVAL_MS); + setInterval(() => this.pollWatchBattery(false), WATCH_BATTERY_POLL_INTERVAL_MS); this.schedulePublish(); } + /** + * Ask the reachable watch for its battery. `urgent` skips the poll gap for + * a level that is not known yet (the glasses just connected, the watch + * just appeared); a level already on screen waits for the regular cadence. + */ + private pollWatchBattery(urgent: boolean): void { + if (!this.active || !this.watchReachable) return; + const now = Date.now(); + const hurry = urgent && !this.watchBatteryKnown && this.watchBatteryPollsUnanswered < WATCH_BATTERY_URGENT_POLL_LIMIT; + const gap = hurry ? WATCH_BATTERY_POLL_MIN_GAP_MS : WATCH_BATTERY_POLL_INTERVAL_MS; + if (now - this.lastWatchBatteryPollAtMs < gap) return; + this.lastWatchBatteryPollAtMs = now; + this.watchBatteryPollsUnanswered++; + wearBridge.sendToWatch(WEAR_PATHS.batteryRequest, {}); + } + + /** Record a watch battery report (or its absence) and repaint the indicators. */ + private setWatchBattery(battery: number | null, charging: boolean | null): void { + const current = shell.getBatteryLevels(); + if (current.watch === battery && current.watchCharging === charging) return; + this.watchBatteryKnown = battery !== null; + shell.setBatteryLevels({ watch: battery, watchCharging: charging }); + // Repaint the top bar, as the controller does for G2/R1 reports. + const phase = this.host.getState().phase; + if (phase === "connected" || phase === "charging") this.host.requestShellRender(); + this.host.appendLog(battery === null ? "watch: battery unknown" : `watch: battery ${battery}%${charging ? " (charging)" : ""}`); + } + /** Whether a watch running the Faceclaw watch app is reachable right now. */ isWatchReachable(): boolean { return this.watchReachable; @@ -183,6 +239,10 @@ export class WearRemote { } catch (error) { this.host.appendLog(`watch: state publish failed: ${formatError(error)}`); } + // The indicator is only ever drawn while the glasses are connected, so + // a still-unknown level is worth asking for as soon as they are. + const phase = this.host.getState().phase; + if (phase === "connected" || phase === "charging") this.pollWatchBattery(true); } private buildState(): Record { @@ -240,6 +300,15 @@ export class WearRemote { ack(true); return; } + if (message.path === WEAR_PATHS.battery) { + // Status, not control: not gated by the remote setting and never + // acked (the watch sends it fire-and-forget, without a seq). + this.watchBatteryPollsUnanswered = 0; + const battery = readNumber(message.payload.battery, -1); + const valid = Number.isInteger(battery) && battery >= 0 && battery <= 100; + this.setWatchBattery(valid ? battery : null, valid ? message.payload.charging === true : null); + return; + } if (!watchRemoteEnabledSetting.get()) { ack(false, "Watch control is turned off in Faceclaw's Settings > Watch."); return; diff --git a/app/graphics/battery.ts b/app/graphics/battery.ts index 2cba1b32..e3b0e1f0 100644 --- a/app/graphics/battery.ts +++ b/app/graphics/battery.ts @@ -1,20 +1,36 @@ import { GrayImage, imageFromAsciiArt } from "./image"; -const EMPTY_BATTERY_ICON = imageFromAsciiArt( - [ - " ################## ", - " #................# ", - " #................###", - " #................###", - " #................###", - " #................###", - " #................###", - " #................###", - " #................# ", - " ################## ", - ], - 120, -); +/** + * Top-bar battery gauge: a 10px-tall outlined body with a nub on the right, + * filled left-to-right in proportion to the charge. The fill is drawn as + * BATTERY_BAR_COUNT bars of BATTERY_BAR_WIDTH px separated by dimmed + * BATTERY_BAR_GAP-px columns; the body outline is sized from those + * constants so they can be tuned freely. The fill level is continuous (not + * quantized to whole bars): the rightmost lit bar is cut to a partial width. + */ +export const BATTERY_BAR_COUNT = 4; +export const BATTERY_BAR_WIDTH = 3; +export const BATTERY_BAR_GAP = 1; + +const OUTLINE_VALUE = 120; +const BAR_VALUE = 190; +/** The separator columns inside the lit portion of the fill. */ +const BAR_GAP_VALUE = 70; + +const ICON_HEIGHT = 10; +/** Outline stroke plus one clear pixel between it and the fill, per side. */ +const BODY_INSET = 2; +const NUB_WIDTH = 2; +const NUB_TOP = 2; +const NUB_HEIGHT = 6; + +const FILL_X = BODY_INSET; +const FILL_Y = BODY_INSET; +const FILL_WIDTH = BATTERY_BAR_COUNT * BATTERY_BAR_WIDTH + (BATTERY_BAR_COUNT - 1) * BATTERY_BAR_GAP; +const FILL_HEIGHT = ICON_HEIGHT - 2 * BODY_INSET; +const BODY_WIDTH = FILL_WIDTH + 2 * BODY_INSET; + +export const BATTERY_ICON_WIDTH = BODY_WIDTH + NUB_WIDTH; const BATTERY_BOLT_ICON = imageFromAsciiArt( [ @@ -29,25 +45,48 @@ const BATTERY_BOLT_ICON = imageFromAsciiArt( 255, ); -export const BATTERY_ICON_WIDTH = EMPTY_BATTERY_ICON.width; +/** The empty outline, built once from the geometry constants. */ +const EMPTY_BATTERY_ICON = buildEmptyBattery(); -const BATTERY_FILL_X = 3; -const BATTERY_FILL_Y = 2; -const BATTERY_FILL_WIDTH = 14; -const BATTERY_FILL_HEIGHT = 6; +function buildEmptyBattery(): GrayImage { + const icon = new GrayImage(BATTERY_ICON_WIDTH, ICON_HEIGHT, 0); + icon.fillRect(0, 0, BODY_WIDTH, 1, OUTLINE_VALUE); + icon.fillRect(0, ICON_HEIGHT - 1, BODY_WIDTH, 1, OUTLINE_VALUE); + icon.fillRect(0, 0, 1, ICON_HEIGHT, OUTLINE_VALUE); + icon.fillRect(BODY_WIDTH - 1, 0, 1, ICON_HEIGHT, OUTLINE_VALUE); + icon.fillRect(BODY_WIDTH, NUB_TOP, NUB_WIDTH, NUB_HEIGHT, OUTLINE_VALUE); + return icon; +} export function drawBattery(percentCharge: number, isCharging: boolean): GrayImage { const icon = new GrayImage(EMPTY_BATTERY_ICON.width, EMPTY_BATTERY_ICON.height, 0); icon.bitBlt(EMPTY_BATTERY_ICON, 0, 0); const clamped = Math.max(0, Math.min(100, percentCharge)); - const fillWidth = Math.round((BATTERY_FILL_WIDTH * clamped) / 100); - icon.fillRect(BATTERY_FILL_X, BATTERY_FILL_Y, fillWidth, BATTERY_FILL_HEIGHT, 190); + const litWidth = Math.round((FILL_WIDTH * clamped) / 100); + drawSegmentedFill(icon, litWidth); if (isCharging) { - overlayImage(icon, BATTERY_BOLT_ICON, 7, 1, clamped > 50 ? 0 : 255); + const boltX = FILL_X + (((FILL_WIDTH - BATTERY_BOLT_ICON.width) / 2) | 0); + overlayImage(icon, BATTERY_BOLT_ICON, boltX, 1, clamped > 50 ? 0 : 255); } return icon; } +/** + * Light the leftmost `litWidth` columns of the fill area as bars with dim + * separator columns. Columns past the lit width stay clear, so a partial + * charge ends mid-bar rather than snapping to a bar boundary. A separator is + * only drawn between two lit bars: when the lit width ends exactly on one it + * is left clear rather than dangling past the last bar. + */ +function drawSegmentedFill(icon: GrayImage, litWidth: number): void { + const pitch = BATTERY_BAR_WIDTH + BATTERY_BAR_GAP; + for (let column = 0; column < litWidth; column++) { + const isBar = column % pitch < BATTERY_BAR_WIDTH; + if (!isBar && column + BATTERY_BAR_GAP >= litWidth) continue; + icon.fillRect(FILL_X + column, FILL_Y, 1, FILL_HEIGHT, isBar ? BAR_VALUE : BAR_GAP_VALUE); + } +} + function overlayImage(target: GrayImage, source: GrayImage, dx: number, dy: number, value: number): void { for (let y = 0; y < source.height; y++) { for (let x = 0; x < source.width; x++) { diff --git a/app/graphics/icons.ts b/app/graphics/icons.ts index 0439cfb6..49d8afbe 100644 --- a/app/graphics/icons.ts +++ b/app/graphics/icons.ts @@ -16,6 +16,10 @@ const ICON_STROKE_WIDTH = 2; // Lucide icons (MIT/ISC licensed). Kept verbatim so they can be diffed // against upstream if an icon needs updating. export const ICON_SVGS = { + "message-circle": + '', + eye: + '', "layout-grid": '', timer: @@ -30,6 +34,8 @@ export const ICON_SVGS = { // Not a Lucide icon: a ball above two angled flippers, for Pinball. pinball: '', + bird: + '', spade: '', terminal: diff --git a/app/native/ambient-light.ts b/app/native/ambient-light.ts index 81f3b099..51334d46 100644 --- a/app/native/ambient-light.ts +++ b/app/native/ambient-light.ts @@ -1,6 +1,6 @@ /** * Ambient light sensor access through the custom firmware (CFW image-handler - * mode 16, capability token "als16"; see g2flash/patches/als_sensor.c). + * mode 16; see g2flash/patches/als_sensor.c). * * The stock firmware only reads its OPT3001 light sensor while auto-brightness * is on, and then steps the panel brightness itself (visible flicker). The CFW diff --git a/app/native/asr-model.ts b/app/native/asr-model.ts index 3c71e31a..591bdc73 100644 --- a/app/native/asr-model.ts +++ b/app/native/asr-model.ts @@ -4,50 +4,107 @@ declare const com: any; declare const java: any; /** - * Download management for the on-device transcription model (Moonshine, via - * sherpa-onnx). The model is no longer bundled in the APK; it is fetched on - * demand into the same filesDir location that earlier releases copied the - * bundled files to, so upgraded installs that already used on-device - * transcription need no download. FaceclawVoiceController reads the files - * from this directory. + * Download management for the on-device transcription models (sherpa-onnx + * offline recognizers). Models are fetched on demand into filesDir rather + * than bundled in the APK; FaceclawVoiceController reads the files from the + * directory each model's `dirName` names. * - * Mirrors the on-phone assistant model flow in llama.ts, except the model is - * three files rather than one; they download sequentially through + * Two models, same shape: + * - "moonshine": the original on-device option (three files). The model is + * no longer bundled in the APK; it is fetched into the same filesDir + * location that earlier releases copied the bundled files to, so + * upgraded installs that already used on-device transcription need no + * download. + * - "whisper-base-en": sherpa-onnx's offline Whisper backend, base.en, + * int8-quantized. Picked over tiny.en for materially better accuracy + * (Whisper's own tiny/base WER gap is real and well documented) on the + * reasoning that FaceclawVoiceController.java no longer re-decodes a + * Whisper segment on every live-partial tick — see its ASR_WHISPER_* + * comment — so base.en's extra compute is a one-time cost per utterance, + * not a cost paid ~1.4x/second while the user is speaking. tiny.en is an + * easy swap (this file's numbers only) if base.en proves too slow on a + * real phone; nobody has measured that yet. Files are csukuangfj's own + * (the sherpa-onnx maintainer's) HF mirror of the upstream sherpa-onnx + * release asset, matching the mirror-not-the-GH-tarball approach already + * used for Moonshine below. Every hash here was computed locally from a + * freshly downloaded copy of the file, not copied from a doc page. + * + * Mirrors the on-phone assistant model flow in llama.ts, except each model + * here is multiple files rather than one; they download sequentially through * FaceclawModelDownloader (resume + pinned sha256 per file). */ +export type AsrModelId = "moonshine" | "whisper-base-en"; + type AsrModelFile = { name: string; sha256: string; sizeBytes: number; }; -export const ASR_MODEL = { - label: "Moonshine (English)", - dirName: "sherpa-onnx-moonshine-base-en-quantized-2026-02-27", - // Hugging Face mirror of the sherpa-onnx release asset of the same name. - // The GitHub release only offers a tar.bz2, which the phone can't unpack; - // this mirror serves the same files (sha256-verified) individually. - baseUrl: - "https://huggingface.co/csukuangfj2/sherpa-onnx-moonshine-base-en-quantized-2026-02-27/resolve/main/", - files: [ - { - name: "decoder_model_merged.ort", - sha256: "d9d7b333af34bc552580576ddcf248a1c6c839e0d3b43b09afb9376ed009899d", - sizeBytes: 109424400, - }, - { - name: "encoder_model.ort", - sha256: "7c66495948d0d08ec1af454cd4b5514862ae6511e94712a60e6d83eaec8dc8cf", - sizeBytes: 31326816, - }, - { - name: "tokens.txt", - sha256: "2870d843e14c1e187bf1913a521562a63b53933814bd7f2145120468f494a049", - sizeBytes: 549350, - }, - ] as AsrModelFile[], - totalBytes: 141300566, +type AsrModelDef = { + label: string; + dirName: string; + baseUrl: string; + files: AsrModelFile[]; + totalBytes: number; +}; + +export const ASR_MODELS: Record = { + moonshine: { + label: "Moonshine (English)", + dirName: "sherpa-onnx-moonshine-base-en-quantized-2026-02-27", + // Hugging Face mirror of the sherpa-onnx release asset of the same name. + // The GitHub release only offers a tar.bz2, which the phone can't unpack; + // this mirror serves the same files (sha256-verified) individually. + baseUrl: + "https://huggingface.co/csukuangfj2/sherpa-onnx-moonshine-base-en-quantized-2026-02-27/resolve/main/", + files: [ + { + name: "decoder_model_merged.ort", + sha256: "d9d7b333af34bc552580576ddcf248a1c6c839e0d3b43b09afb9376ed009899d", + sizeBytes: 109424400, + }, + { + name: "encoder_model.ort", + sha256: "7c66495948d0d08ec1af454cd4b5514862ae6511e94712a60e6d83eaec8dc8cf", + sizeBytes: 31326816, + }, + { + name: "tokens.txt", + sha256: "2870d843e14c1e187bf1913a521562a63b53933814bd7f2145120468f494a049", + sizeBytes: 549350, + }, + ], + totalBytes: 141300566, + }, + "whisper-base-en": { + label: "Whisper (English, base)", + dirName: "sherpa-onnx-whisper-base-en-int8", + // csukuangfj/sherpa-onnx-whisper-base.en on Hugging Face: the sherpa-onnx + // maintainer's own mirror of the project's whisper export, individual + // files (no tar.bz2-unpack problem to begin with, but kept as the same + // per-file-with-pinned-hash shape as Moonshine above for consistency). + baseUrl: "https://huggingface.co/csukuangfj/sherpa-onnx-whisper-base.en/resolve/main/", + files: [ + { + name: "base.en-encoder.int8.onnx", + sha256: "ef6b936f4c9b1d90a3b68634b60c4ed8576b26172b33c2535ec0e933c9edb823", + sizeBytes: 29120534, + }, + { + name: "base.en-decoder.int8.onnx", + sha256: "f7162ad6db2dbef16cfaeaa7f945b9d7dd9c1b8d472f6aca82f2273d185e4d41", + sizeBytes: 130669978, + }, + { + name: "base.en-tokens.txt", + sha256: "306cd27f03c1a714eca7108e03d66b7dc042abe8c258b44c199a7ed9838dd930", + sizeBytes: 835554, + }, + ], + totalBytes: 160626066, + }, }; export type AsrModelState = { @@ -56,121 +113,141 @@ export type AsrModelState = { totalBytes: number; }; -let downloader: any = null; -// Bytes of files already fully downloaded in this run, plus progress within -// the file currently downloading; drives the aggregate percentage. -let completedBytes = 0; -let currentFileBytes = 0; -const stateListeners = new Set<(state: AsrModelState) => void>(); +type ModelRuntime = { + downloader: any; + // Bytes of files already fully downloaded in this run, plus progress within + // the file currently downloading; drives the aggregate percentage. + completedBytes: number; + currentFileBytes: number; + stateListeners: Set<(state: AsrModelState) => void>; +}; -function modelDirPath(): string { +function freshRuntime(): ModelRuntime { + return { downloader: null, completedBytes: 0, currentFileBytes: 0, stateListeners: new Set() }; +} + +const runtimes: Record = { + moonshine: freshRuntime(), + "whisper-base-en": freshRuntime(), +}; + +function modelDirPath(id: AsrModelId): string { const context = Utils.android.getApplicationContext(); - return `${context.getFilesDir().getAbsolutePath()}/faceclaw-voice-asr/${ASR_MODEL.dirName}`; + return `${context.getFilesDir().getAbsolutePath()}/faceclaw-voice-asr/${ASR_MODELS[id].dirName}`; } -function filePath(file: AsrModelFile): string { - return `${modelDirPath()}/${file.name}`; +function filePath(id: AsrModelId, file: AsrModelFile): string { + return `${modelDirPath(id)}/${file.name}`; } -function isFilePresent(file: AsrModelFile): boolean { +function isFilePresent(id: AsrModelId, file: AsrModelFile): boolean { try { - const javaFile = new java.io.File(filePath(file)); + const javaFile = new java.io.File(filePath(id, file)); return javaFile.exists() && javaFile.length() > 0; } catch { return false; } } -export function isAsrModelReady(): boolean { +export function isAsrModelReady(id: AsrModelId): boolean { if (!global.isAndroid) return false; - return ASR_MODEL.files.every(isFilePresent); + return ASR_MODELS[id].files.every((file) => isFilePresent(id, file)); } -export function asrModelState(): AsrModelState { - if (downloader) { +export function asrModelState(id: AsrModelId): AsrModelState { + const runtime = runtimes[id]; + const totalBytes = ASR_MODELS[id].totalBytes; + if (runtime.downloader) { return { status: "downloading", - bytesDownloaded: completedBytes + currentFileBytes, - totalBytes: ASR_MODEL.totalBytes, + bytesDownloaded: runtime.completedBytes + runtime.currentFileBytes, + totalBytes, }; } return { - status: isAsrModelReady() ? "ready" : "absent", + status: isAsrModelReady(id) ? "ready" : "absent", bytesDownloaded: 0, - totalBytes: ASR_MODEL.totalBytes, + totalBytes, }; } -export function onAsrModelStateChanged(listener: (state: AsrModelState) => void): () => void { - stateListeners.add(listener); - return () => stateListeners.delete(listener); +export function onAsrModelStateChanged(id: AsrModelId, listener: (state: AsrModelState) => void): () => void { + const runtime = runtimes[id]; + runtime.stateListeners.add(listener); + return () => runtime.stateListeners.delete(listener); } -function notifyStateChanged(): void { - const state = asrModelState(); - stateListeners.forEach((listener) => listener(state)); +function notifyStateChanged(id: AsrModelId): void { + const state = asrModelState(id); + runtimes[id].stateListeners.forEach((listener) => listener(state)); } -export function startAsrModelDownload(): void { - if (!global.isAndroid || downloader || isAsrModelReady()) return; - completedBytes = ASR_MODEL.files.filter(isFilePresent).reduce((sum, f) => sum + f.sizeBytes, 0); - downloadNextFile(); - notifyStateChanged(); +export function startAsrModelDownload(id: AsrModelId): void { + const runtime = runtimes[id]; + if (!global.isAndroid || runtime.downloader || isAsrModelReady(id)) return; + runtime.completedBytes = ASR_MODELS[id].files + .filter((file) => isFilePresent(id, file)) + .reduce((sum, f) => sum + f.sizeBytes, 0); + downloadNextFile(id); + notifyStateChanged(id); } -function downloadNextFile(): void { - const nextFile = ASR_MODEL.files.find((file) => !isFilePresent(file)); +function downloadNextFile(id: AsrModelId): void { + const runtime = runtimes[id]; + const def = ASR_MODELS[id]; + const nextFile = def.files.find((file) => !isFilePresent(id, file)); if (!nextFile) { - downloader = null; - notifyStateChanged(); + runtime.downloader = null; + notifyStateChanged(id); return; } - currentFileBytes = 0; + runtime.currentFileBytes = 0; const listener = new com.faceclaw.app.FaceclawModelDownloaderListener({ onProgress: (bytes: number, _total: number) => { - currentFileBytes = Number(bytes); - notifyStateChanged(); + runtime.currentFileBytes = Number(bytes); + notifyStateChanged(id); }, onDone: () => { - completedBytes += nextFile.sizeBytes; - currentFileBytes = 0; - downloadNextFile(); + runtime.completedBytes += nextFile.sizeBytes; + runtime.currentFileBytes = 0; + downloadNextFile(id); }, onError: (message: string) => { - console.error(`Voice model download failed (${nextFile.name}): ${message}`); - downloader = null; - notifyStateChanged(); + console.error(`Voice model download failed (${id}/${nextFile.name}): ${message}`); + runtime.downloader = null; + notifyStateChanged(id); }, }); - downloader = new com.faceclaw.app.FaceclawModelDownloader( - `${ASR_MODEL.baseUrl}${nextFile.name}`, - filePath(nextFile), + runtime.downloader = new com.faceclaw.app.FaceclawModelDownloader( + `${def.baseUrl}${nextFile.name}`, + filePath(id, nextFile), nextFile.sha256, nextFile.sizeBytes, listener, ); - downloader.start(); + runtime.downloader.start(); } /** Stops the download; already-fetched bytes are kept and resumed next time. */ -export function cancelAsrModelDownload(): void { - if (!downloader) return; - downloader.cancel(); - downloader = null; - notifyStateChanged(); +export function cancelAsrModelDownload(id: AsrModelId): void { + const runtime = runtimes[id]; + if (!runtime.downloader) return; + runtime.downloader.cancel(); + runtime.downloader = null; + notifyStateChanged(id); } -export function deleteAsrModel(): void { +export function deleteAsrModel(id: AsrModelId): void { if (!global.isAndroid) return; - cancelAsrModelDownload(); + cancelAsrModelDownload(id); try { - for (const file of ASR_MODEL.files) { - new java.io.File(filePath(file)).delete(); - new java.io.File(`${filePath(file)}.part`).delete(); + for (const file of ASR_MODELS[id].files) { + new java.io.File(filePath(id, file)).delete(); + new java.io.File(`${filePath(id, file)}.part`).delete(); } - new java.io.File(modelDirPath()).delete(); + new java.io.File(modelDirPath(id)).delete(); } catch (error) { - console.error(`Voice model delete failed: ${String(error)}`); + console.error(`Voice model delete failed (${id}): ${String(error)}`); } - notifyStateChanged(); + notifyStateChanged(id); } diff --git a/app/native/bandwidth-benchmark.ts b/app/native/bandwidth-benchmark.ts new file mode 100644 index 00000000..c480c7d3 --- /dev/null +++ b/app/native/bandwidth-benchmark.ts @@ -0,0 +1,71 @@ +declare const com: any; + +/** + * BLE bandwidth benchmark controls (Developer app). The Java communicator + * streams no-op image payloads for a fixed duration with a selectable message + * size and pipeline window, then reports throughput. Progress and results are + * polled with getBandwidthBenchmarkStatus. + * + * Talks to the active communicator via the FaceclawBleCommunicator.getActive() + * static, so it works from any isolate without threading the bridge through. + */ + +export type BandwidthBenchmarkStatus = { + state: "idle" | "starting" | "running" | "done"; + messageSize: number; + windowSize: number; + linkMode: number; + elapsedMs: number; + messagesSent: number; + messagesAcked: number; + timeouts: number; + payloadBytesAcked: number; + wireBytesAcked: number; + aborted: boolean; +}; + +function activeCommunicator(): any { + if (!global.isAndroid) return null; + try { + return com.faceclaw.app.FaceclawBleCommunicator.getActive(); + } catch { + return null; + } +} + +/** Start a run. False if not connected or a run is already active. */ +export function startBandwidthBenchmark(messageSize: number, windowSize: number, durationMs: number, linkMode = 0): boolean { + const active = activeCommunicator(); + if (!active) return false; + try { + return Boolean( + active.startBandwidthBenchmarkWithLinkMode( + Math.round(messageSize), Math.round(windowSize), Math.round(durationMs), Math.round(linkMode), + ), + ); + } catch (error) { + console.warn(`startBandwidthBenchmark failed: ${error}`); + return false; + } +} + +/** Cancel an in-progress run. Safe to call when idle. */ +export function cancelBandwidthBenchmark(): void { + try { + activeCommunicator()?.cancelBandwidthBenchmark(); + } catch (error) { + console.warn(`cancelBandwidthBenchmark failed: ${error}`); + } +} + +/** Status of the current or most recent run; null when not connected. */ +export function getBandwidthBenchmarkStatus(): BandwidthBenchmarkStatus | null { + const active = activeCommunicator(); + if (!active) return null; + try { + return JSON.parse(String(active.getBandwidthBenchmarkStatus())) as BandwidthBenchmarkStatus; + } catch (error) { + console.warn(`getBandwidthBenchmarkStatus failed: ${error}`); + return null; + } +} diff --git a/app/native/device-info-probe.ts b/app/native/device-info-probe.ts index dec0ab0f..5a891a59 100644 --- a/app/native/device-info-probe.ts +++ b/app/native/device-info-probe.ts @@ -1,19 +1,17 @@ import { Utils } from "@nativescript/core"; +import { type FirmwareInfo } from "../g2/firmware-compat"; + declare const com: any; -export type DeviceInfo = { - leftVersion: string; - rightVersion: string; - capabilities: string; -}; +export type DeviceInfo = FirmwareInfo; export type DeviceInfoState = "connecting" | "authenticating" | "querying"; /** * TS wrapper around the native FaceclawDeviceInfoProbe — a one-shot, * stock-compatible connect + firmware/device-info read. `run()` resolves with - * the firmware versions and CFW capability string, or rejects on failure. + * the firmware versions and the firmware-extension string, or rejects on failure. */ export class DeviceInfoProbe { private readonly probe: any; @@ -34,11 +32,11 @@ export class DeviceInfoProbe { onLog: (line: string) => this.emit(this.logListeners, String(line)), onState: (state: string, detail: string) => this.emit(this.stateListeners, String(state) as DeviceInfoState, String(detail ?? "")), - onResult: (leftVersion: string, rightVersion: string, capabilities: string) => + onResult: (leftVersion: string, rightVersion: string, extension: string) => this.settle(null, { leftVersion: String(leftVersion), rightVersion: String(rightVersion), - capabilities: String(capabilities), + extension: String(extension), }), onError: (message: string) => this.settle(new Error(String(message)), null), }); diff --git a/app/native/even-app-conflict.ts b/app/native/even-app-conflict.ts index c01642fd..d1b3fc7a 100644 --- a/app/native/even-app-conflict.ts +++ b/app/native/even-app-conflict.ts @@ -1,4 +1,4 @@ -import { Utils } from "@nativescript/core"; +import { Dialogs, Utils } from "@nativescript/core"; declare const com: any; @@ -23,11 +23,19 @@ export function readEvenAppNotificationState(): EvenAppNotificationState { } export function openEvenAppSettings(): void { - if (!global.isAndroid) return; - const context = Utils.android.getApplicationContext(); - if (context) { - com.faceclaw.app.FaceclawEvenAppDetector.openEvenAppSettings(context); - } + const context = global.isAndroid ? Utils.android.getApplicationContext() : null; + const result = context + ? com.faceclaw.app.FaceclawEvenAppDetector.openEvenAppSettings(context) + : "failed"; + if (result === "opened") return; + const notInstalled = result === "not-installed"; + void Dialogs.alert({ + title: notInstalled ? "Even app not installed" : "Unable to open Even app settings", + message: notInstalled + ? "The official Even Realities app isn't installed on this phone. If your glasses are connected to another app or phone, disconnect them there. Otherwise, you can continue." + : "Open your phone's settings manually to manage the Even app, or disconnect your glasses from within the app that's connected to them.", + okButtonText: "OK", + }); } export function openNotificationAccessSettings(): void { diff --git a/app/native/faceclaw-communicator.ts b/app/native/faceclaw-communicator.ts index f8ddbe89..e312272c 100644 --- a/app/native/faceclaw-communicator.ts +++ b/app/native/faceclaw-communicator.ts @@ -22,6 +22,8 @@ export type CommunicatorState = { export type HeadsetBatteryState = { battery: number; chargingStatus: number; + ringBattery?: number; + ringChargingStatus?: number; }; export type FrameMetrics = { @@ -30,11 +32,9 @@ export type FrameMetrics = { tileCount: number; }; -export type FirmwareInfo = { - leftVersion: string; - rightVersion: string; - capabilities: string; -}; +import { type FirmwareInfo } from "../g2/firmware-compat"; + +export type { FirmwareInfo }; /** * Compositor surface configuration. Position/size are in screen pixels; @@ -189,10 +189,12 @@ export class FaceclawCommunicatorBridge { frameTimings.logFrame(event.frameId, "input event received on JS side"); this.emitAsync(this.ringListeners, event); }, - onBatteryState: (headsetBattery: number, headsetCharging: number) => { + onBatteryState: (headsetBattery: number, headsetCharging: number, ringBattery: number, ringCharging: number) => { const state = { battery: Number(headsetBattery), chargingStatus: Number(headsetCharging), + ringBattery: Number(ringBattery), + ringChargingStatus: Number(ringCharging), }; this.emitAsync(this.batteryListeners, state); }, @@ -226,11 +228,11 @@ export class FaceclawCommunicatorBridge { onFrameFinished: (frameId: number, outcome: string) => { this.recordFrameFinished(Number(frameId), String(outcome)); }, - onFirmwareInfo: (leftVersion: string, rightVersion: string, capabilities: string) => { - const info = { + onFirmwareInfo: (leftVersion: string, rightVersion: string, extension: string) => { + const info: FirmwareInfo = { leftVersion: String(leftVersion), rightVersion: String(rightVersion), - capabilities: String(capabilities), + extension: String(extension), }; this.emitAsync(this.firmwareInfoListeners, info); }, diff --git a/app/native/open-url.ts b/app/native/open-url.ts new file mode 100644 index 00000000..781e03a2 --- /dev/null +++ b/app/native/open-url.ts @@ -0,0 +1,25 @@ +/** + * Open a URL in the phone's browser. Uses the application context with + * NEW_TASK so it works from worker threads (no Activity in hand). Returns + * false when no browser is available or on a non-Android platform. + */ +import { Utils } from "@nativescript/core"; + +declare const android: any; +declare const global: any; + +export function openUrlOnPhone(url: string): boolean { + if (!global.isAndroid) return false; + try { + const context = Utils.android.getApplicationContext(); + if (!context) return false; + const intent = new android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(url)); + intent.addCategory(android.content.Intent.CATEGORY_BROWSABLE); + intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + return true; + } catch (error) { + console.warn(`open-url: could not open ${url}: ${error}`); + return false; + } +} diff --git a/app/native/voice-control.ios.ts b/app/native/voice-control.ios.ts index 873c4e2d..9aad3654 100644 --- a/app/native/voice-control.ios.ts +++ b/app/native/voice-control.ios.ts @@ -23,14 +23,14 @@ export class IosVoiceControlBridge { private log: (message: string) => void = () => {} onStatus(listener: (state: VoiceControlState) => void): () => void { - this.statuses.add(listener); listener({ status: this.status }); return () => { this.statuses.delete(listener) } + this.statuses.add(listener); listener({ status: this.status, listening: this.capturing, detail: '' }); return () => { this.statuses.delete(listener) } } onTranscript(listener: (event: VoiceTranscriptEvent) => void): () => void { this.transcripts.add(listener); return () => { this.transcripts.delete(listener) } } onSpeechEnd(listener: () => void): () => void { this.ends.add(listener); return () => { this.ends.delete(listener) } } onSpeechPause(_listener: () => void): () => void { return () => {} } - private setStatus(status: string): void { this.status = status; for (const fn of [...this.statuses]) fn({ status }) } + private setStatus(status: string): void { this.status = status; for (const fn of [...this.statuses]) fn({ status, listening: this.capturing, detail: '' }) } private ensureNative(): any { if (!this.native) { this.native = FaceclawSpeech.new() diff --git a/app/native/voice-control.ts b/app/native/voice-control.ts index f0e5669a..f3acadab 100644 --- a/app/native/voice-control.ts +++ b/app/native/voice-control.ts @@ -11,10 +11,27 @@ import { toUint8Array } from "../util/array-util"; declare const com: any; export type VoiceControlState = { + /** One-line state of the capture: progress, "Listening...", or an error. */ status: string; + /** + * Whether audio is actually being captured and transcribed right now. False + * while the mic is starting, while the phone is showing the permission + * prompt, and after an error, so a dialog must not claim to be listening. + */ + listening: boolean; + /** + * Longer guidance to show in place of the (still empty) transcript, e.g. + * what the user has to do on the phone. Empty when there is nothing to say. + */ + detail: string; }; -export type VoiceProviderKind = "onboard" | "elevenlabs" | "whisper" | "soniox"; +// "whisper" (no "onboard-" prefix) is the OpenAI CLOUD provider (gpt-realtime-whisper, +// see openai-stt.ts) -- an unfortunate pre-existing name collision with the model +// family, not with "onboard-whisper" below, which is the on-device sherpa-onnx +// Whisper backend added alongside "onboard" (Moonshine). Kept as-is rather than +// renamed, since it's a persisted settings value on real installs already. +export type VoiceProviderKind = "onboard" | "onboard-whisper" | "elevenlabs" | "whisper" | "soniox"; export type VoiceTranscriptEvent = CloudSttTranscriptEvent & { /** @@ -88,7 +105,12 @@ export class FaceclawVoiceControlBridge { private controller: any | null = null; private listenerProxy: any | null = null; private status = "Voice control stopped."; + private listening = false; + private detail = ""; private started = false; + private nativeCaptureFinished: Promise = Promise.resolve(); + private nextNativeCaptureId = 1; + private readonly nativeCaptureResolvers = new Map void>(); // The mic is a single shared stream; these are the reasons it is running. // The first holder starts capture (choosing the provider); the mic stops // when the last one releases. Transcript events broadcast to every @@ -118,7 +140,7 @@ export class FaceclawVoiceControlBridge { onStatus(listener: (state: VoiceControlState) => void): () => void { this.statusListeners.add(listener); - listener({ status: this.status }); + listener(this.state()); return () => this.statusListeners.delete(listener); } @@ -142,14 +164,41 @@ export class FaceclawVoiceControlBridge { return () => this.speechPauseListeners.delete(listener); } + /** + * The capture is blocked on the phone's system microphone-permission + * prompt. Reported by the controller before it asks Android, so the dialog + * on the glasses can send the user to the phone instead of claiming to + * listen; the next status (from the capture start, or reportPermissionDenied) + * replaces it. + */ + reportPermissionPrompt(): void { + this.setStatus( + "Waiting for microphone permission...", + "Allow microphone access in the prompt on your phone.", + ); + } + + /** The user declined the microphone permission (or the prompt could not be shown). */ + reportPermissionDenied(): void { + this.setStatus( + "Microphone access denied.", + "Enable the microphone for Faceclaw in the phone's app settings, then try again.", + ); + } + /** Begin push-to-talk capture (momentary; released with stopPushToTalk). */ startPushToTalk(options: PushToTalkOptions): void { this.acquireCapture("ptt", options); } /** End push-to-talk: for cloud, commit for a final result if it was the last holder. */ - stopPushToTalk(): void { + stopPushToTalk(): Promise | void { + // Shared continuous capture keeps running; cloud providers finalize via + // their own callbacks. Only a stopped native recognizer must be awaited. + const finished = !this.cloudClient && this.captureHolders.has("ptt") && this.captureHolders.size === 1 + ? this.nativeCaptureFinished : undefined; this.releaseCapture("ptt", true); + return finished; } /** Begin continuous capture (Transcribe): the mic stays on until released. */ @@ -262,6 +311,9 @@ export class FaceclawVoiceControlBridge { } this.speechPause.reset(); + // Replaces whatever the last capture left behind ("Listening...", an + // error, the permission prompt) until the controller reports progress. + this.setStatus("Starting microphone..."); // A previous push-to-talk commit may still be awaiting its final result. this.cloudClient?.stop(); const cloudClient = this.createCloudClient(options); @@ -275,7 +327,12 @@ export class FaceclawVoiceControlBridge { this.cloudClient = null; this.started = true; - this.controller?.start("onboard"); + // Which on-device model to load; a no-op setter for every provider except + // "onboard-whisper" (FaceclawVoiceController defaults to Moonshine). + this.controller?.setOnboardModelKind(options.provider === "onboard-whisper" ? "whisper" : "moonshine"); + const captureId = this.nextNativeCaptureId++; + this.nativeCaptureFinished = new Promise((resolve) => { this.nativeCaptureResolvers.set(captureId, resolve); }); + this.controller?.start("onboard", captureId); } /** @@ -284,7 +341,7 @@ export class FaceclawVoiceControlBridge { * than failing the capture outright. */ private createCloudClient(options: PushToTalkOptions): CloudSttClient | null { - if (options.provider === "onboard") return null; + if (options.provider === "onboard" || options.provider === "onboard-whisper") return null; const sttOptions = { apiKey: "", onTranscript: (event: CloudSttTranscriptEvent) => @@ -444,6 +501,10 @@ export class FaceclawVoiceControlBridge { onTranscript: (text: string, isFinal: boolean) => { this.emitTranscript(String(text), Boolean(isFinal)); }, + onStopped: (captureId: number) => { + this.nativeCaptureResolvers.get(captureId)?.(); + this.nativeCaptureResolvers.delete(captureId); + }, onPcm: (pcm: any) => { const bytes = toUint8Array(pcm); this.cloudClient?.acceptPcm(bytes); @@ -492,12 +553,21 @@ export class FaceclawVoiceControlBridge { } } - private setStatus(status: string): void { + private setStatus(status: string, detail = ""): void { this.status = status; + this.detail = detail; + // Every "audio is flowing" report — from the Java controller and from the + // cloud providers — is phrased "Listening..." / "Listening (X)...". + this.listening = status.startsWith("Listening"); + const state = this.state(); for (const listener of this.statusListeners) { - listener({ status }); + listener(state); } } + + private state(): VoiceControlState { + return { status: this.status, listening: this.listening, detail: this.detail }; + } } function toJavaFloats(values: Float32Array): any { diff --git a/app/native/wear-bridge.ts b/app/native/wear-bridge.ts index 7981809f..6a4e7ca2 100644 --- a/app/native/wear-bridge.ts +++ b/app/native/wear-bridge.ts @@ -24,6 +24,10 @@ export const WEAR_PATHS = { text: "/faceclaw/text", /** Watch -> phone: please re-publish the state item. */ stateRequest: "/faceclaw/state/request", + /** Watch -> phone: the watch's own battery ({battery, charging}); never acked. */ + battery: "/faceclaw/battery", + /** Phone -> watch: please report the watch battery (answered even while the watch app is closed). */ + batteryRequest: "/faceclaw/battery/request", /** Phone -> watch: reply to any of the above. */ ack: "/faceclaw/ack", /** Phone -> watch: assistant activity, alerts, voice-dialog transcripts. */ @@ -157,7 +161,12 @@ class WearBridge { /** Send an event to every reachable watch. */ sendEvent(payload: Record): void { - this.getJava()?.sendToWatch(WEAR_PATHS.event, JSON.stringify(payload)); + this.sendToWatch(WEAR_PATHS.event, payload); + } + + /** Send a message on any phone -> watch path to every reachable watch. */ + sendToWatch(path: string, payload: Record): void { + this.getJava()?.sendToWatch(path, JSON.stringify(payload)); } /** Acknowledge a watch message; `seq` echoes the watch's sequence number. */ diff --git a/app/phone-ui/main-page.xml b/app/phone-ui/main-page.xml index c10ee6a5..e73180b6 100644 --- a/app/phone-ui/main-page.xml +++ b/app/phone-ui/main-page.xml @@ -7,14 +7,13 @@