Add a compass using the G2's magnetometer

This commit is contained in:
James Babcock committed 2026-08-04 02:09:32 -07:00
1 parent 4022f06d49
commit 852626e950
10 files changed
+424 -23

No files matched your search

@@ -57,6 +57,8 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
private volatile FaceclawBleCommunicatorListener listener;
private final java.util.List<FaceclawImuListener> imuListeners =
new java.util.concurrent.CopyOnWriteArrayList<>();
private final java.util.List<FaceclawCompassListener> compassListeners =
new java.util.concurrent.CopyOnWriteArrayList<>();
private volatile Thread workerThread;
private volatile boolean running;
private volatile boolean userDisconnectRequested;
@@ -77,6 +79,10 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
// overlay state is re-asserted on every reconnect and whenever the value changes.
private volatile boolean firmwareDebugFlagsEnabled;
private int firmwareDebugFlagsLastSent = -1;
// Desired CFW mode-10 compass state. It survives reconnects; lastSent is
// reset with each session so an open Compass window is re-asserted.
private boolean compassEnabled;
private int compassControlLastSent = -1;
private boolean startupProbePending;
// Desired ownership of CFW's fail-open stock-wake lease (dashboard launch
// and Even AI foreground takeover). This survives a transport reconnect;
@@ -413,6 +419,25 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
interruptibleSleep.interrupt();
}
/**
* Enable/disable the stock compass through CFW image-handler mode 10. The
* desired state is retained across reconnects; headings arrive through
* stock sid-0x08 navigation notifications and FaceclawCompassListeners.
*/
public void setCompassEnabled(boolean enable) {
synchronized (lock) {
compassEnabled = enable;
compassControlLastSent = -1;
clearMessagesOfKindLocked("compass-control");
if (running && sessionReady && !shutdownRequested && fixedLayoutCreated && warmedUp) {
enqueueCompassControlLocked(true);
} else {
logLine("defer compass " + (enable ? "enable" : "disable") + "; display path not ready");
}
}
interruptibleSleep.interrupt();
}
/**
* Set the lens brightness. Fire-and-forget, like the IMU control: the
* message is queued ahead of other traffic and any not-yet-sent brightness
@@ -472,6 +497,18 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
}
}
public void addCompassListener(FaceclawCompassListener listener) {
if (listener != null) {
compassListeners.add(listener);
}
}
public void removeCompassListener(FaceclawCompassListener listener) {
if (listener != null) {
compassListeners.remove(listener);
}
}
// The most recently started communicator; lets app worker threads submit
// surface frames without holding a cross-isolate reference to the bridge
@@ -955,6 +992,9 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
Log.d(TAG, "onNotification: address=" + address + " characteristicUuid=" + characteristicUuid + " data.length=" + data.length);
BleProtocol.ParsedFrame frame = BleProtocol.parseFrame(data);
int decodedWearState = BleProtocol.parseWearState(frame);
BleProtocol.CompassEvent compassEvent = address.equalsIgnoreCase(rightAddress)
? BleProtocol.parseCompassEvent(frame)
: null;
boolean emitWearState = false;
G2Event event = null;
synchronized (lock) {
@@ -1065,6 +1105,9 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
logLine(decodedWearState > 0 ? "wear state ON_HEAD" : "wear state OFF_HEAD");
emitWearState(decodedWearState > 0);
}
if (compassEvent != null) {
emitCompassEvent(compassEvent.command, compassEvent.headingDegrees);
}
if (event != null) {
if (event.hasImu) {
emitImuData(event.imuX, event.imuY, event.imuZ, event.eventSource);
@@ -1477,6 +1520,13 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
enqueueFirmwareDebugFlagsLocked();
}
if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated && warmedUp
&& (compassEnabled ? 1 : 0) != compassControlLastSent
&& pendingMessages.isEmpty() && inFlightMessages.isEmpty()) {
Log.i(TAG, "enqueueing compass " + (compassEnabled ? "enable" : "disable"));
enqueueCompassControlLocked(false);
}
// 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);
@@ -1946,6 +1996,28 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
logLine("queue firmware debug flags " + (show ? "show" : "hide"));
}
/** Send CFW image-handler mode 10: [10][1] start, [10][0] stop. */
private void enqueueCompassControlLocked(boolean priority) {
boolean enable = compassEnabled;
int sentState = enable ? 1 : 0;
byte[] payload = new byte[] { (byte) 10, (byte) sentState };
OutboundMessage message = messageBuilder.imagePayload(
"compass-control",
DASHBOARD_TILE,
nextMapSessionId(),
payload,
"compass " + (enable ? "enable" : "disable"),
connectionOptions.sendImagesToLeft);
message.onTimeout = () -> {
compassControlLastSent = -1;
logLine("compass control ack timeout");
};
if (priority) pendingMessages.addFirst(message);
else pendingMessages.addLast(message);
compassControlLastSent = sentState;
logLine("queue " + message.label);
}
private void enqueueDesiredImageLocked() {
String fingerprint = getDesiredFingerprint();
byte[] packed;
@@ -2558,6 +2630,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
lastAudioControlAckMagic = 0;
audioCaptureActive = false;
audioPacketListener = null;
compassControlLastSent = -1;
faceclawWakePendingNonce = -1;
lastFaceclawWakeLeaseQueuedAtMs = 0;
faceclawWakeControlSentCount = 0;
@@ -2620,6 +2693,21 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
});
}
private void emitCompassEvent(int command, int headingDegrees) {
if (compassListeners.isEmpty()) {
return;
}
mainHandler.post(() -> {
for (FaceclawCompassListener compassListener : compassListeners) {
try {
compassListener.onCompassEvent(command, headingDegrees);
} catch (Throwable t) {
Log.w(TAG, "listener onCompassEvent failed", t);
}
}
});
}
private void emitSilentMode(boolean silent) {
final FaceclawBleCommunicatorListener current = listener;
if (current == null) {
@@ -0,0 +1,6 @@
package com.faceclaw.app;
/** Receives stock compass heading and calibration notifications on the main thread. */
public interface FaceclawCompassListener {
void onCompassEvent(int command, int headingDegrees);
}
@@ -54,6 +54,10 @@ public class BleProtocol {
// Payload is g2.even_ai.EvenAIDataPackage (see
// g2-kit-unofficial/ble/gen/even_ai_pb.ts).
public static final int SID_EVEN_AI = 0x07;
public static final int SID_NAVIGATION = 0x08;
public static final int NAV_CMD_COMPASS_CHANGED = 15;
public static final int NAV_CMD_COMPASS_CALIBRATION_STARTED = 16;
public static final int NAV_CMD_COMPASS_CALIBRATION_COMPLETE = 17;
// eEvenAICommandId
public static final int EVEN_AI_CMD_CTRL = 1;
// eEvenAIStatus, carried in EvenAIDataPackage.ctrl.status (field 3, sub 1).
@@ -602,6 +606,29 @@ public class BleProtocol {
return Arrays.copyOf(pb, pb.length - 2);
}
/** Decode the stock firmware's compass navigation notifications (sid 0x08). */
public static CompassEvent parseCompassEvent(ParsedFrame frame) {
if (frame == null
|| !frame.ok
|| frame.sid != SID_NAVIGATION
|| (frame.flag != FLAG_NOTIFY && frame.flag != FLAG_NOTIFY_ALT)) {
return null;
}
byte[] root = stripTrailingCrc(frame.pb);
int command = readVarintFieldValue(root, 1, -1);
if (command == NAV_CMD_COMPASS_CHANGED) {
byte[] compass = readFieldBytes(root, 10);
if (compass == null) return null;
int heading = readVarintFieldValue(compass, 1, -1);
return heading >= 0 ? new CompassEvent(command, heading) : null;
}
if (command == NAV_CMD_COMPASS_CALIBRATION_STARTED
|| command == NAV_CMD_COMPASS_CALIBRATION_COMPLETE) {
return new CompassEvent(command, -1);
}
return null;
}
/**
* Display wake notification observed after a ring or right-arm double tap
* while no EvenHub page is running:
@@ -832,6 +859,16 @@ public class BleProtocol {
}
}
public static final class CompassEvent {
public final int command;
public final int headingDegrees;
CompassEvent(int command, int headingDegrees) {
this.command = command;
this.headingDegrees = headingDegrees;
}
}
public static final class ImageTileOptions {
final String name;
final int containerId;
@@ -60,12 +60,23 @@ public class MessageBuilder {
byte[] payload,
String label,
boolean leftArm
) {
return imagePayload("sound", tile, sessionId, payload, label, leftArm);
}
public OutboundMessage imagePayload(
String kind,
BleProtocol.ImageTileOptions tile,
int sessionId,
byte[] payload,
String label,
boolean leftArm
) {
BleProtocol.ImageFragment fragment =
new BleProtocol.ImageFragment(0, payload, payload.length);
int magic = magicPool.allocate();
return new OutboundMessage(
"sound",
kind,
label,
BleProtocol.SID_EVENHUB,
BleProtocol.FLAG_REQUEST,
+2
View File
@@ -10,6 +10,7 @@ import notificationsApp from "./notifications";
import calendarApp from "./calendar";
import weatherApp from "./weather";
import navigateApp from "./navigate";
import compassApp from "./compass";
import roamApp from "./roam";
import blocksApp from "./blocks";
import minesweeperApp from "./minesweeper";
@@ -35,6 +36,7 @@ export const ALL_APPS: readonly AppDefinition[] = [
calendarApp,
weatherApp,
navigateApp,
compassApp,
roamApp,
blocksApp,
minesweeperApp,
+189
View File
@@ -0,0 +1,189 @@
import { getDefaultLargeFont, getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/bdffont";
import { GrayImage } from "../../graphics/image";
import {
COMPASS_CALIBRATION_COMPLETE,
COMPASS_CALIBRATION_STARTED,
COMPASS_CHANGED,
addCompassListener,
setCompassEnabled,
type CompassEvent,
} from "../../native/compass";
import { type DashboardInputEvent, type Layer, type LayerContext } from "../../ui/layers";
import {
createInProcessWindow,
YieldAtRootLayer,
type InProcessAppOptions,
type InProcessWindow,
} from "../../ui/shell/in-process-window";
import { shell } from "../../ui/shell/shell";
export const COMPASS_WINDOW_ID = "compass";
export const COMPASS_SURFACE_ID = "window:compass";
const RECONCILE_INTERVAL_MS = 400;
class CompassLayer implements Layer {
private heading: number | null = null;
private status = "Waiting for compass data…";
private enabled = false;
private removed = false;
private timer: ReturnType<typeof setInterval> | null = null;
private unsubscribe: (() => void) | null = null;
constructor(private readonly requestRender: () => void) {}
start(): void {
this.unsubscribe = addCompassListener((event) => this.onCompassEvent(event));
this.timer = setInterval(() => this.reconcile(), RECONCILE_INTERVAL_MS);
this.reconcile();
}
stop(): void {
if (this.removed) return;
this.removed = true;
if (this.timer !== null) clearInterval(this.timer);
this.timer = null;
this.unsubscribe?.();
this.unsubscribe = null;
if (this.enabled) setCompassEnabled(false);
this.enabled = false;
}
onRemoved(): void {
this.stop();
}
private reconcile(): void {
if (this.removed) return;
const visible = shell.isWindowVisible(COMPASS_WINDOW_ID);
if (visible === this.enabled) return;
this.enabled = visible;
setCompassEnabled(visible);
this.status = visible ? "Waiting for compass data…" : "Compass paused";
this.requestRender();
}
private onCompassEvent(event: CompassEvent): void {
if (this.removed) return;
if (event.command === COMPASS_CHANGED && event.headingDegrees >= 0) {
this.heading = normalizeHeading(event.headingDegrees);
this.status = "Magnetic heading";
} else if (event.command === COMPASS_CALIBRATION_STARTED) {
this.status = "Calibrating — move the glasses";
} else if (event.command === COMPASS_CALIBRATION_COMPLETE) {
this.status = "Calibration complete";
}
this.requestRender();
}
paint(ctx: LayerContext): GrayImage {
const { width, height } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const small = getDefaultSmallFont();
const medium = getDefaultMediumFont();
const large = getDefaultLargeFont();
const cx = Math.round(width * 0.28);
const cy = Math.round(height * 0.51);
const radius = Math.min(94, Math.round(height * 0.34));
drawCompassRose(image, cx, cy, radius, this.heading);
if (this.heading !== null) {
const headingText = `${Math.round(this.heading)}°`;
const direction = cardinalDirection(this.heading);
const textX = Math.round(width * 0.57);
image.drawText(large, textX, 72, headingText, 255);
image.drawText(large, textX, 108, direction, 210);
} else {
image.drawText(medium, Math.round(width * 0.56), 84, "--°", 150);
image.drawText(small, Math.round(width * 0.56), 116, "No heading yet", 130);
}
image.drawText(small, Math.round(width * 0.56), 158, this.status, 125);
return image;
}
handleInput(_event: DashboardInputEvent, _ctx: LayerContext): void {}
}
export function createCompassAppWindow(options: InProcessAppOptions): InProcessWindow {
let app: InProcessWindow;
let requestRender = () => {};
const layer = new CompassLayer(() => requestRender());
app = createInProcessWindow({
appId: "compass",
windowId: COMPASS_WINDOW_ID,
title: "Compass",
iconLetter: "C",
icon: "compass",
closeable: true,
actions: options.actions,
baseLayer: new YieldAtRootLayer(layer),
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface,
onClosed: () => {
layer.stop();
options.onClosed();
},
});
requestRender = app.requestRender;
layer.start();
return app;
}
function normalizeHeading(value: number): number {
return ((value % 360) + 360) % 360;
}
function cardinalDirection(heading: number): string {
const names = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"];
return names[Math.round(normalizeHeading(heading) / 45) % names.length]!;
}
/** Draw a compass rose whose bright needle points toward magnetic north. */
function drawCompassRose(image: GrayImage, cx: number, cy: number, radius: number, heading: number | null): void {
drawCircle(image, cx, cy, radius, 105);
const small = getDefaultSmallFont();
const medium = getDefaultMediumFont();
const cardinals: Array<[string, number]> = [["N", -90], ["E", 0], ["S", 90], ["W", 180]];
for (const [label, degrees] of cardinals) {
const angle = (degrees - (heading ?? 0)) * Math.PI / 180;
const x = cx + Math.cos(angle) * (radius - 14) - medium.measureText(label) / 2;
const y = cy + Math.sin(angle) * (radius - 14) - medium.lineHeight / 2;
image.drawText(medium, Math.round(x), Math.round(y), label, label === "N" ? 230 : 105);
}
const intercardinals: Array<[string, number]> = [["NE", -45], ["SE", 45], ["SW", 135], ["NW", -135]];
for (const [label, degrees] of intercardinals) {
const angle = (degrees - (heading ?? 0)) * Math.PI / 180;
const x = cx + Math.cos(angle) * (radius - 14) - small.measureText(label) / 2;
const y = cy + Math.sin(angle) * (radius - 14) - small.lineHeight / 2;
image.drawText(small, Math.round(x), Math.round(y), label, 85);
}
image.fillRect(cx - 2, cy - 2, 5, 5, 180);
if (heading === null) return;
const northAngle = (-90 - heading) * Math.PI / 180;
const nx = cx + Math.cos(northAngle) * (radius - 30);
const ny = cy + Math.sin(northAngle) * (radius - 30);
const sx = cx - Math.cos(northAngle) * (radius - 38);
const sy = cy - Math.sin(northAngle) * (radius - 38);
drawThickLine(image, cx, cy, nx, ny, 255);
image.drawLine(cx, cy, sx, sy, 75);
}
function drawCircle(image: GrayImage, cx: number, cy: number, radius: number, value: number): void {
let x = radius;
let y = 0;
let error = 1 - x;
while (x >= y) {
const points = [[x, y], [y, x], [-y, x], [-x, y], [-x, -y], [-y, -x], [y, -x], [x, -y]];
for (const [dx, dy] of points) image.setPixel(cx + dx!, cy + dy!, value);
y++;
if (error < 0) error += 2 * y + 1;
else { x--; error += 2 * (y - x) + 1; }
}
}
function drawThickLine(image: GrayImage, x0: number, y0: number, x1: number, y1: number, value: number): void {
image.drawLine(x0, y0, x1, y1, value);
image.drawLine(x0 - 1, y0, x1 - 1, y1, value);
image.drawLine(x0 + 1, y0, x1 + 1, y1, value);
}
+11
View File
@@ -0,0 +1,11 @@
import { type AppDefinition } from "../app-definition";
import { COMPASS_SURFACE_ID, COMPASS_WINDOW_ID, createCompassAppWindow } from "./compass-app";
const compassApp: AppDefinition = {
appId: "compass",
title: "Compass",
icon: "compass",
launch: (ctx) => ctx.launchInProcessApp(COMPASS_WINDOW_ID, COMPASS_SURFACE_ID, createCompassAppWindow),
};
export default compassApp;
+28 -22
View File
@@ -19,7 +19,7 @@ export type FirmwarePatchSet = {
export const CFW_PATCH_SET: FirmwarePatchSet = {
"base": "g2_2.2.6.10.bin",
"baseSha256": "f4dfb0b49ad3de3c2daf17f8a27a157c3dc98411d6a0d3ab2cfd0918f41b9afa",
"outputSha256": "cf929ae83ff351cfe81df97460560420fe05a744253e57da564be797df91f2a9",
"outputSha256": "673bf69ce3fcfa28376998de191ed6c23588619fc3c39451bc2416076446a67f",
"patches": [
{
"offset": 1449549,
@@ -42,127 +42,133 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
{
"offset": 1447919,
"old": "7ef7fefd",
"new": "baf2ccfa",
"new": "baf20cfb",
"desc": "bl snapshot_side @ 0x4db968"
},
{
"offset": 1448931,
"old": "7ef704fc",
"new": "baf2d2f8",
"new": "baf212f9",
"desc": "bl snapshot_side @ 0x4dbd5c"
},
{
"offset": 1165461,
"old": "45f0cefd",
"new": "fff27dfa",
"new": "fff2bdfa",
"desc": "bl image_deferred (deferred consumer -> FIFO restore + worker, both lenses)"
},
{
"offset": 1186287,
"old": "d9f7d4ff",
"new": "fbf256f9",
"new": "fbf296f9",
"desc": "bl settings_send_wrapper (append caps field 100)"
},
{
"offset": 1183983,
"old": "f4f75aff",
"new": "fbf212fb",
"new": "fbf252fb",
"desc": "bl settings_decode_wrapper (Faceclaw lease field 101)"
},
{
"offset": 926945,
"old": "08f068fa",
"new": "3af335f8",
"new": "3af375f8",
"desc": "bl faceclaw_display_start @ 0x45c65a (fail-open double-tap takeover)"
},
{
"offset": 927137,
"old": "08f008fa",
"new": "39f3d5ff",
"new": "3af315f8",
"desc": "bl faceclaw_display_start @ 0x45c71a (fail-open double-tap takeover)"
},
{
"offset": 822553,
"old": "28f003f8",
"new": "53f3f1ff",
"new": "54f363f8",
"desc": "bl evenhub_longpress (replaces force-quit dialog)"
},
{
"offset": 823369,
"old": "1cf09bfb",
"new": "53f375fe",
"new": "53f3e7fe",
"desc": "bl ring_release (forward ring release-long-press)"
},
{
"offset": 1474137,
"old": "7fb50600",
"new": "b4f20fbf",
"new": "b4f24fbf",
"desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline"
},
{
"offset": 1022741,
"old": "f8f7c1fe",
"new": "20f3abfb",
"new": "20f3ebfb",
"desc": "bl display_copy_hook @ 0x473c8e (640x480 direct framebuffer)"
},
{
"offset": 1022959,
"old": "f8f754fe",
"new": "20f33efb",
"new": "20f37efb",
"desc": "bl display_copy_hook @ 0x473d68 (640x480 direct framebuffer)"
},
{
"offset": 1198787,
"old": "dff770fb",
"new": "f7f238fc",
"new": "f7f278fc",
"desc": "bl faceclaw_send_wear_event @ 0x49ec3c (outside onboarding)"
},
{
"offset": 1198881,
"old": "dff741fb",
"new": "f7f209fc",
"new": "f7f249fc",
"desc": "bl faceclaw_send_wear_event @ 0x49ec9a (outside onboarding)"
},
{
"offset": 823567,
"old": "1cf038fb",
"new": "51f3aef8",
"desc": "bl compass_event_forward (global IMU heading -> stock nav BLE notifier)"
},
{
"offset": 4301227,
"old": "",
"new": "02fb01f044f6d341c0f24701084700bf084644f61751c0f24701084770b500284ed001684ef66262ccf2ff02914218bf70bd90f8081190f8095142f6c52c8d42c0f2500c2ad205eb8501014491f80d2191f80e4191f80ae191f80b3191f80c1142ea0424012c4ff0010298bf14466e1c054680f80961b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f80811bde870406047e047d5f8040138b149f29942c0f244022146bde87040104770bd00bf2de9f04f99b043f6fc76c2f20006d6f8009048466ff39600b0f1005f40f04d81d9f800004ef66267ccf2ff07b84240f0448199f82802002800f02d81d9f82442002c00f0288140f2b870c2f20000d0f8008004a801f006f9b8f1000f00f0fb8140f2030c45f24075cff6807ca4f1600008f160026ff0bf03c0f20205016ed4182166416ec0336166816eab42a166c16ee166016f2167416f6167816fa167c16fe167d0f88010c4f88010d0f88410c4f88410d0f88810c4f88810d0f88c10c4f88c10d0f89010c4f89010d0f89410c4f89410d0f89810c4f89810d0f89c10c4f89c10d0f8a010c4f8a010d0f8a410c4f8a410d0f8a810c4f8a810d0f8ac10c4f8ac10d0f8b010c4f8b010d0f8b410c4f8b410d0f8b810c4f8b810d0f8bc10c4f8bc1050f8c01fc4f8c0104168c4f8c4108168c4f8c810c168c4f8cc100169c4f8d0104169c4f8d4108169c4f8d810c169c4f8dc10016ac4f8e010416ac4f8e410816ac4f8e810c16ac4f8ec10016bc4f8f010416bc4f8f410816bc4f8f810c16bc4f8fc10016cc4f80011416cc4f80411816cc4f80811c16cc4f80c11016dc4f81011416dc4f81411816dc4f81811c16dc4f81c117ff462afd6f800e00eea0c00b0f1005f40f08180def80000b8427cd19ef8ce00002840f050819ef8dc00002100288df8141000f0b08105aa505c002800f0838153185878002800f059819878002800f05781d878002800f055811879002800f053815879002800f051819879002800f04f81d879002800f04d81187a002800f04b81587a002800f04981987a002800f04781d87a002800f04581187b002800f04381587b002800f04181987b002800f03f81d87b002800f03d81187c002800f03b81587c002800f03981987c002800f03781d87c002800f0358114315029abd155e199f82a0270b1d9f82c0240b144f63421c2f207010968401a002800f3fb80002089f82a024cf61520c0f2460019b0bde8f04f004744f6d341c0f247014ff40c708847002800f0cc804ff6d051cff6ff7100224318463183f8302283f8312283f8322283f8332283f8342283f8352283f8362283f8372283f8382283f8392283f83a2283f83b2283f83c2283f83d2283f83e2283f83f2283f8402283f8412283f8422283f8432283f8442283f8452283f8462283f8472283f8482283f8492283f84a2283f84b2283f84c2283f84d2283f84e2283f84f2283f8502283f8512283f8522283f8532283f8542283f8552283f8562283f8572283f8582283f8592283f85a2283f85b2283f85c2283f85d2283f85e2283f85f2283f8602283f8612283f8622283f8632283f8642283f8652283f8662283f8672283f8682283f8692283f86a2283f86b2283f86c2283f86d2283f86e2283f86f2283f8702283f8712283f8722283f8732283f8742283f875227ff470af012180f8ce104ff0ff310760a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe1010e0002089f82802c9f8240289f82a02012089f829024cf61520c0f24600804714e000203060002089f82802c9f824024ff4163045f20f11069005a8c0f24701cdf814808847012089f82a0204a801f017f8c9f8d40019b0bde8f08f013122e0023120e003311ee004311ce005311ae0063118e0073116e0083114e0093112e00a3110e00b310ee00c310ce00d310ae00e3108e00f3106e0103104e0113102e0123100e013314f2921d84ff0520050541dd00a4445204e29507018d04f204d29907014d052204c29d07010d044204b2910710cd045204a29507108d052204929907104d020204829d07140f08d8600208df8630001219ef8dd00002870d0002205ab985c00284fd09f18787838b3b87838b3f87838b3387938b3787938b3b87938b3f87938b3387a38b3787a38b3b87a38b3f87a38b3387b38b3787b38b3b87b38b3f87b38b3387c38b3787c38b3b87c38b3f87c38b31432502ad2d13ce0013222e0023220e003321ee004321ce005321ae0063218e0073216e0083214e0093212e00a3210e00b320ee00c320ce00d320ae00e3208e00f3206e0103204e0113202e0123200e013324f2a15d84ff05300985411d013444b204e2a58700cd049204d2a987008d050204c2ad87004d020204b2a187140f0608100208df8630001319ef8de0000286cd0002105aa505c00284fd05318587838b3987838b3d87838b3187938b3587938b3987938b3d87938b3187a38b3587a38b3987a38b3d87a38b3187b38b3587b38b3987b38b3d87b38b3187c38b3587c38b3987c38b3d87c38b314315029d2d138e0013122e0023120e003311ee004311ce005311ae0063118e0073116e0083114e0093112e00a3110e00b310ee00c310ce00d310ae00e3108e00f3106e0103104e0113102e0123100e013314f2911d84ff0440050540dd00a4455204e29507008d050204d29907004d020204c29d07040f0ec8000208df8630001219ef8df0000284dd0002105aa505c002800f0bc8053185878002800f092809878002800f09080d878002800f08e801879002800f08c805879002800f08a809879002800f08880d879002800f08680187a002800f08480587a002800f08280987a002800f08080d87a00287ed0187b00287dd0587b00287cd0987b00287bd0d87b00287ad0187c002879d0587c002878d0987c002877d0d87c002876d014315029b4d1d0e0002940f0d180002105aa505c002800f0b88053185878002800f08e809878002800f08c80d878002800f08a801879002800f088805879002800f086809879002800f08480d879002800f08280187a002800f08080587a00287ed0987a00287dd0d87a00287cd0187b00287bd0587b00287ad0987b002879d0d87b002878d0187c002877d0587c002876d0987c002875d0d87c002874d014315029b6d181e0013122e0023120e003311ee004311ce005311ae0063118e0073116e0083114e0093112e00a3110e00b310ee00c310ce00d310ae00e3108e00f3106e0103104e0113102e0123100e013314f295ad84ff05300505456d00a444e204e29507051d041204d2990704dd050204c29d07049d04f204b29107145d046204a29507141d02020492990713dd00020d0713de00020107113e7002058719fe6013122e002312Line truncated
"new": "02fb01f044f6d341c0f24701084700bf084644f61751c0f24701084770b500284ed001684ef66362ccf2ff02914218bf70bd90f8081190f8095142f6c52c8d42c0f2500c2ad205eb8501014491f80d2191f80e4191f80ae191f80b3191f80c1142ea0424012c4ff0010298bf14466e1c054680f80961b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f80811bde870406047e047d5f8040138b149f29942c0f244022146bde87040104770bd00bf70b54ff6fd03c0f2450314460d46984743f6fc71c2f200010e6831466ff39601b1f1005f0ad131684ef66362ccf2ff02914218bf0026412d03d070bd0026412dfbd1002cf9d04af26951c0f2450105468847002e01462846efd00129edd196f807120029e9d02168002948bf70bd47f25d02c0f2580208469047284670bd00bf2de9f04f99b043f6fc76c2f20006d6f8009048466ff39600b0f1005f40f04d81d9f800004ef66367ccf2ff07b84240f0448199f82802002800f02d81d9f82442002c00f0288140f2b870c2f20000d0f8008004a801f006f9b8f1000f00f0fb8140f2030c45f24075cff6807ca4f1600008f160026ff0bf03c0f20205016ed4182166416ec0336166816eab42a166c16ee166016f2167416f6167816fa167c16fe167d0f88010c4f88010d0f88410c4f88410d0f88810c4f88810d0f88c10c4f88c10d0f89010c4f89010d0f89410c4f89410d0f89810c4f89810d0f89c10c4f89c10d0f8a010c4f8a010d0f8a410c4f8a410d0f8a810c4f8a810d0f8ac10c4f8ac10d0f8b010c4f8b010d0f8b410c4f8b410d0f8b810c4f8b810d0f8bc10c4f8bc1050f8c01fc4f8c0104168c4f8c4108168c4f8c810c168c4f8cc100169c4f8d0104169c4f8d4108169c4f8d810c169c4f8dc10016ac4f8e010416ac4f8e410816ac4f8e810c16ac4f8ec10016bc4f8f010416bc4f8f410816bc4f8f810c16bc4f8fc10016cc4f80011416cc4f80411816cc4f80811c16cc4f80c11016dc4f81011416dc4f81411816dc4f81811c16dc4f81c117ff462afd6f800e00eea0c00b0f1005f40f08180def80000b8427cd19ef8ce00002840f050819ef8dc00002100288df8141000f0b08105aa505c002800f0838153185878002800f059819878002800f05781d878002800f055811879002800f053815879002800f051819879002800f04f81d879002800f04d81187a002800f04b81587a002800f04981987a002800f04781d87a002800f04581187b002800f04381587b002800f04181987b002800f03f81d87b002800f03d81187c002800f03b81587c002800f03981987c002800f03781d87c002800f0358114315029abd155e199f82a0270b1d9f82c0240b144f63421c2f207010968401a002800f3fb80002089f82a024cf61520c0f2460019b0bde8f04f004744f6d341c0f247014ff40c708847002800f0cc804ff6d051cff6ff7100224318463183f8302283f8312283f8322283f8332283f8342283f8352283f8362283f8372283f8382283f8392283f83a2283f83b2283f83c2283f83d2283f83e2283f83f2283f8402283f8412283f8422283f8432283f8442283f8452283f8462283f8472283f8482283f8492283f84a2283f84b2283f84c2283f84d2283f84e2283f84f2283f8502283f8512283f8522283f8532283f8542283f8552283f8562283f8572283f8582283f8592283f85a2283f85b2283f85c2283f85d2283f85e2283f85f2283f8602283f8612283f8622283f8632283f8642283f8652283f8662283f8672283f8682283f8692283f86a2283f86b2283f86c2283f86d2283f86e2283f86f2283f8702283f8712283f8722283f8732283f8742283f875227ff470af012180f8ce104ff0ff310760a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe1010e0002089f82802c9f8240289f82a02012089f829024cf61520c0f24600804714e000203060002089f82802c9f824024ff4163045f20f11069005a8c0f24701cdf814808847012089f82a0204a801f017f8c9f8d40019b0bde8f08f013122e0023120e003311ee004311ce005311ae0063118e0073116e0083114e0093112e00a3110e00b310ee00c310ce00d310ae00e3108e00f3106e0103104e0113102e0123100e013314f2921d84ff0520050541dd00a4445204e29507018d04f204d29907014d052204c29d07010d044204b2910710cd045204a29507108d052204929907104d020204829d07140f08d8600208df8630001219ef8dd00002870d0002205ab985c00284fd09f18787838b3b87838b3f87838b3387938b3787938b3b87938b3f87938b3387a38b3787a38b3b87a38b3f87a38b3387b38b3787b38b3b87b38b3f87b38b3387c38b3787c38b3b87c38b3f87c38b31432502ad2d13ce0013222e0023220e003321ee004321ce005321ae0063218e0073216e0083214e0093212e00a3210e00b320ee00c320ce00d320ae00e3208e00f3206e0103204e0113202e0123200e013324f2a15d84ff05300985411d013444b204e2a58700cd049204d2a987008d050204c2ad87004d020204b2a187140f0608100208df8630001319ef8de0000286cd0002105aa505c00284fd05318587838b3987838b3d87838b3187938b3587938b3987938b3d87938b3187a38b3587a38b3987a38b3d87a38b3187b38b3587b38b3987b38b3d87b38b3187c38b3587c38b3987c38b3d87c38b314315029d2d138e0013122e0023120e003311ee004311ce005311ae0063118e0073116e0083114e0093112e00a3110e00b310ee00c310ce00d310ae00e3108e00f3106e0103104e0113102e0123100e013314f2911d84ff0440050540dd00a4455204e29507008d050204d29907004d020204c29d07040f0ec8000208df8630001219ef8df0000284dd0002105aa505c002800f0bc8053185878002800f092809878002800f09080d878002800f08e801879002800f08c805879002800f08a809879002800f08880d879002800f08680187a002800f08480587a002800f08280987a002800f08080d87a00287ed0187b00287dd0587b00287cd0987b00287bd0d87b00287ad0187c002879d0587c002878d0987c002877d0d87c002876d014315029b4d1d0e0002940f0d180002105aa505c002800f0b88053185878002800f08e809878002800f08c80d878002800f08a801879002800f088805879002800f086809879002800f08480d879002800f08280187a002800f08080587a00287ed0987a00287dd0d87a00287cd0187b00287bd0587b00287ad0987b002879d0d87b002878d0187c002877d0587c002876d0987c002875d0d87c002874d014315029b6d181e0013122e0023120e003311ee004311ce005311ae0063118e0073116e0083114e00Line truncated
"desc": "append injected blobs to main-app payload"
},
{
"offset": 777711,
"old": "44c33500",
"new": "850e3600",
"new": "e3113600",
"desc": "main-app subheader payload size (ps)"
},
{
"offset": 152,
"old": "c4c33500",
"new": "050f3600",
"new": "63123600",
"desc": "main-app TOC entry size (ps + 128)"
},
{
"offset": 777831,
"old": "44c33504",
"new": "850e3604",
"new": "e3113604",
"desc": "main-app preamble length (low 24 bits)"
},
{
"offset": 777835,
"old": "df8110c9",
"new": "739a2743",
"new": "ed57a2d7",
"desc": "[5] ota/s200_firmware_ota.bin preamble crc32"
},
{
"offset": 156,
"old": "c1be0fb1",
"new": "44359374",
"new": "05b02fc2",
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)"
},
{
"offset": 777715,
"old": "c1be0fb1",
"new": "44359374",
"new": "05b02fc2",
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)"
}
]
+2
View File
@@ -68,6 +68,8 @@ export const ICON_SVGS = {
'<svg viewBox="0 0 24 24" fill="none"><path d="M12 19v3"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><rect x="9" y="2" width="6" height="13" rx="3"/></svg>',
map:
'<svg viewBox="0 0 24 24" fill="none"><path d="M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z"/><path d="M15 5.764v15"/><path d="M9 3.236v15"/></svg>',
compass:
'<svg viewBox="0 0 24 24" fill="none"><circle cx="12" cy="12" r="10"/><path d="m16.24 7.76-2.12 6.36-6.36 2.12 2.12-6.36z"/></svg>',
// The Roam Research logo, potrace-traced from the official PNG (no
// fill="none", so the renderer fills it; hole contours wind opposite).
roam:
+49
View File
@@ -0,0 +1,49 @@
declare const com: any;
declare const global: any;
export const COMPASS_CHANGED = 15;
export const COMPASS_CALIBRATION_STARTED = 16;
export const COMPASS_CALIBRATION_COMPLETE = 17;
export type CompassEvent = {
command: number;
/** Magnetic heading in degrees, or -1 for calibration-only events. */
headingDegrees: number;
};
function activeCommunicator(): any {
if (!global.isAndroid) return null;
try {
return com.faceclaw.app.FaceclawBleCommunicator.getActive();
} catch {
return null;
}
}
/** Request CFW mode 10 to start/stop the stock firmware compass. */
export function setCompassEnabled(enabled: boolean): void {
try {
activeCommunicator()?.setCompassEnabled(enabled);
} catch (error) {
console.warn(`setCompassEnabled failed: ${error}`);
}
}
/** Subscribe to stock compass heading/calibration notifications. */
export function addCompassListener(listener: (event: CompassEvent) => void): () => void {
const active = activeCommunicator();
if (!active) return () => {};
const proxy = new com.faceclaw.app.FaceclawCompassListener({
onCompassEvent: (command: number, headingDegrees: number) => {
listener({ command: Number(command), headingDegrees: Number(headingDegrees) });
},
});
active.addCompassListener(proxy);
return () => {
try {
activeCommunicator()?.removeCompassListener(proxy);
} catch {
// The communicator may have been replaced during a disconnect.
}
};
}