mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Add calibration indicator to glanceboard compass
This commit is contained in:
1 parent
df95cc4064
commit
22c31f4240
4 files changed
+45
-13
No files matched your search
@@ -7,6 +7,7 @@
|
||||
* Bottom-bar app switcher switches two a multi-row layout when it runs out of space
|
||||
* T3 Code client: Add options (worktree, host, etc) when creating threads
|
||||
* Add configuration options to the glanceboard system card and music player
|
||||
* Glanceboard compass shows calibration-accuracy indicator
|
||||
|
||||
### Bug fixes
|
||||
|
||||
|
||||
@@ -23,7 +23,14 @@ import {
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import { ensureLocationPermission, hasLocationPermission } from "../../native/location-permissions";
|
||||
import { isCompassCalibrated, normalizeHeading } from "./calibration";
|
||||
import { cardinalDirection, createCompassBackground, drawCompassRose, layoutCompassRose, TICK_HEIGHT } from "./compass-rose";
|
||||
import {
|
||||
cardinalDirection,
|
||||
createCompassBackground,
|
||||
drawCompassRose,
|
||||
layoutCompassRose,
|
||||
magneticAccuracyDots,
|
||||
TICK_HEIGHT,
|
||||
} from "./compass-rose";
|
||||
import { CompassCalibrationLayer } from "./calibration-layer";
|
||||
import { getDeclinationAvailability, onDeclinationChanged, refreshDeclination } from "./declination";
|
||||
import { getNorthReference, resolveHeading, setNorthReference, type NorthReference } from "./heading";
|
||||
@@ -277,14 +284,7 @@ function frameStatusText(): string {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The firmware's magnetometer calibration readiness (0-3) as filled/empty
|
||||
* dots, e.g. "Calibration: ●●○" for 2/3. This is the glasses' own sensor
|
||||
* calibration, not the wearer-fit offset set on the calibration screen.
|
||||
*/
|
||||
/** The firmware's magnetometer calibration readiness, e.g. "Calibration: ●●○" for 2/3. */
|
||||
function magneticAccuracyText(diagnostics: CompassDiagnostics | null): string {
|
||||
const accuracy = diagnostics && (diagnostics.flags & 0x80) ? diagnostics.magneticAccuracy : -1;
|
||||
if (accuracy < 0) return "Calibration: --";
|
||||
const filled = Math.min(3, accuracy);
|
||||
return `Calibration: ${"●".repeat(filled)}${"○".repeat(3 - filled)}`;
|
||||
return `Calibration: ${magneticAccuracyDots(diagnostics) ?? "--"}`;
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
* own the magnetometer lifecycle and the readout text around it.
|
||||
*/
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { type CompassDiagnostics } from "../../native/compass-types";
|
||||
import { normalizeHeading } from "./calibration";
|
||||
|
||||
/**
|
||||
@@ -102,6 +103,19 @@ export function cardinalDirection(heading: number): string {
|
||||
return names[Math.round(normalizeHeading(heading) / 45) % names.length]!;
|
||||
}
|
||||
|
||||
/**
|
||||
* The firmware's magnetometer calibration readiness (0-3) as filled/empty
|
||||
* dots, e.g. "●●○" for 2/3, or null when the firmware doesn't report it. This
|
||||
* is the glasses' own sensor calibration, not the wearer-fit offset set on the
|
||||
* calibration screen.
|
||||
*/
|
||||
export function magneticAccuracyDots(diagnostics: CompassDiagnostics | null): string | null {
|
||||
const accuracy = diagnostics && (diagnostics.flags & 0x80) ? diagnostics.magneticAccuracy : -1;
|
||||
if (accuracy < 0) return null;
|
||||
const filled = Math.min(3, accuracy);
|
||||
return "●".repeat(filled) + "○".repeat(3 - filled);
|
||||
}
|
||||
|
||||
interface Point {
|
||||
x: number;
|
||||
y: number;
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import { type GrayImage } from "../../../graphics/image";
|
||||
import { hasLocationPermission } from "../../../native/location-permissions";
|
||||
import { addCompassListener, COMPASS_CHANGED, setCompassEnabled } from "../../../native/compass";
|
||||
import { addCompassListener, COMPASS_CHANGED, setCompassEnabled, type CompassDiagnostics } from "../../../native/compass";
|
||||
import { isCompassCalibrated, normalizeHeading } from "../../compass/calibration";
|
||||
import { cardinalDirection, createCompassBackground, drawCompassRose, layoutCompassRose, TICK_HEIGHT } from "../../compass/compass-rose";
|
||||
import {
|
||||
cardinalDirection,
|
||||
createCompassBackground,
|
||||
drawCompassRose,
|
||||
layoutCompassRose,
|
||||
magneticAccuracyDots,
|
||||
TICK_HEIGHT,
|
||||
} from "../../compass/compass-rose";
|
||||
import { getDeclinationAvailability, onDeclinationChanged, refreshDeclination } from "../../compass/declination";
|
||||
import { getNorthReference, resolveHeading } from "../../compass/heading";
|
||||
import { glanceFont } from "../glance-font";
|
||||
@@ -14,16 +21,21 @@ const TOP_PAD = 4;
|
||||
const BOTTOM_PAD = 4;
|
||||
const EDGE_PAD = 8;
|
||||
const MAX_ROSE_RADIUS = 60;
|
||||
/** Inset of the top-right magnetometer calibration dots from the card edges. */
|
||||
const ACCURACY_TOP_PAD = TOP_PAD;
|
||||
const ACCURACY_RIGHT_PAD = EDGE_PAD;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* already known, otherwise the readout says it is magnetic. The firmware's
|
||||
* magnetometer calibration shows as the Compass app's dots, without a label.
|
||||
*/
|
||||
export class CompassWidget implements GlanceWidget {
|
||||
private rawHeading: number | null = null;
|
||||
private diagnostics: CompassDiagnostics | null = null;
|
||||
private unsubscribe: (() => void) | null = null;
|
||||
private unsubscribeDeclination: (() => void) | null = null;
|
||||
private enabled = false;
|
||||
@@ -33,6 +45,7 @@ export class CompassWidget implements GlanceWidget {
|
||||
this.unsubscribe = addCompassListener((event) => {
|
||||
if (event.command === COMPASS_CHANGED && event.headingDegrees >= 0) {
|
||||
this.rawHeading = normalizeHeading(event.headingDegrees);
|
||||
this.diagnostics = event.diagnostics ?? null;
|
||||
requestRender();
|
||||
}
|
||||
});
|
||||
@@ -96,5 +109,9 @@ export class CompassWidget implements GlanceWidget {
|
||||
if (status) {
|
||||
image.drawText(small, Math.round(cx - small.measureText(status) / 2), y + medium.lineHeight + 2, status, 125);
|
||||
}
|
||||
const accuracyDots = magneticAccuracyDots(this.diagnostics);
|
||||
if (accuracyDots) {
|
||||
image.drawText(small, width - ACCURACY_RIGHT_PAD - small.measureText(accuracyDots), ACCURACY_TOP_PAD, accuracyDots, 175);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user