forked from Blendman974/faceclaw
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
|
* 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
|
* T3 Code client: Add options (worktree, host, etc) when creating threads
|
||||||
* Add configuration options to the glanceboard system card and music player
|
* Add configuration options to the glanceboard system card and music player
|
||||||
|
* Glanceboard compass shows calibration-accuracy indicator
|
||||||
|
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,14 @@ import {
|
|||||||
import { shell } from "../../ui/shell/shell";
|
import { shell } from "../../ui/shell/shell";
|
||||||
import { ensureLocationPermission, hasLocationPermission } from "../../native/location-permissions";
|
import { ensureLocationPermission, hasLocationPermission } from "../../native/location-permissions";
|
||||||
import { isCompassCalibrated, normalizeHeading } from "./calibration";
|
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 { CompassCalibrationLayer } from "./calibration-layer";
|
||||||
import { getDeclinationAvailability, onDeclinationChanged, refreshDeclination } from "./declination";
|
import { getDeclinationAvailability, onDeclinationChanged, refreshDeclination } from "./declination";
|
||||||
import { getNorthReference, resolveHeading, setNorthReference, type NorthReference } from "./heading";
|
import { getNorthReference, resolveHeading, setNorthReference, type NorthReference } from "./heading";
|
||||||
@@ -277,14 +284,7 @@ function frameStatusText(): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** The firmware's magnetometer calibration readiness, e.g. "Calibration: ●●○" for 2/3. */
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
function magneticAccuracyText(diagnostics: CompassDiagnostics | null): string {
|
function magneticAccuracyText(diagnostics: CompassDiagnostics | null): string {
|
||||||
const accuracy = diagnostics && (diagnostics.flags & 0x80) ? diagnostics.magneticAccuracy : -1;
|
return `Calibration: ${magneticAccuracyDots(diagnostics) ?? "--"}`;
|
||||||
if (accuracy < 0) return "Calibration: --";
|
|
||||||
const filled = Math.min(3, accuracy);
|
|
||||||
return `Calibration: ${"●".repeat(filled)}${"○".repeat(3 - filled)}`;
|
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
* own the magnetometer lifecycle and the readout text around it.
|
* own the magnetometer lifecycle and the readout text around it.
|
||||||
*/
|
*/
|
||||||
import { GrayImage } from "../../graphics/image";
|
import { GrayImage } from "../../graphics/image";
|
||||||
|
import { type CompassDiagnostics } from "../../native/compass-types";
|
||||||
import { normalizeHeading } from "./calibration";
|
import { normalizeHeading } from "./calibration";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,6 +103,19 @@ export function cardinalDirection(heading: number): string {
|
|||||||
return names[Math.round(normalizeHeading(heading) / 45) % names.length]!;
|
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 {
|
interface Point {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import { type GrayImage } from "../../../graphics/image";
|
import { type GrayImage } from "../../../graphics/image";
|
||||||
import { hasLocationPermission } from "../../../native/location-permissions";
|
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 { 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 { getDeclinationAvailability, onDeclinationChanged, refreshDeclination } from "../../compass/declination";
|
||||||
import { getNorthReference, resolveHeading } from "../../compass/heading";
|
import { getNorthReference, resolveHeading } from "../../compass/heading";
|
||||||
import { glanceFont } from "../glance-font";
|
import { glanceFont } from "../glance-font";
|
||||||
@@ -14,16 +21,21 @@ const TOP_PAD = 4;
|
|||||||
const BOTTOM_PAD = 4;
|
const BOTTOM_PAD = 4;
|
||||||
const EDGE_PAD = 8;
|
const EDGE_PAD = 8;
|
||||||
const MAX_ROSE_RADIUS = 60;
|
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
|
* 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
|
* 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).
|
* 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
|
* 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 {
|
export class CompassWidget implements GlanceWidget {
|
||||||
private rawHeading: number | null = null;
|
private rawHeading: number | null = null;
|
||||||
|
private diagnostics: CompassDiagnostics | null = null;
|
||||||
private unsubscribe: (() => void) | null = null;
|
private unsubscribe: (() => void) | null = null;
|
||||||
private unsubscribeDeclination: (() => void) | null = null;
|
private unsubscribeDeclination: (() => void) | null = null;
|
||||||
private enabled = false;
|
private enabled = false;
|
||||||
@@ -33,6 +45,7 @@ export class CompassWidget implements GlanceWidget {
|
|||||||
this.unsubscribe = addCompassListener((event) => {
|
this.unsubscribe = addCompassListener((event) => {
|
||||||
if (event.command === COMPASS_CHANGED && event.headingDegrees >= 0) {
|
if (event.command === COMPASS_CHANGED && event.headingDegrees >= 0) {
|
||||||
this.rawHeading = normalizeHeading(event.headingDegrees);
|
this.rawHeading = normalizeHeading(event.headingDegrees);
|
||||||
|
this.diagnostics = event.diagnostics ?? null;
|
||||||
requestRender();
|
requestRender();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -96,5 +109,9 @@ export class CompassWidget implements GlanceWidget {
|
|||||||
if (status) {
|
if (status) {
|
||||||
image.drawText(small, Math.round(cx - small.measureText(status) / 2), y + medium.lineHeight + 2, status, 125);
|
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