Simplify glanceboard-trigger angle setting; fix incorrectly-rotated accelerometer readings on G1

The glanceboard head-tilt option was more complicated than necessary,
because it wanted the user to take two angle measurements, a baseline
angle and a tilt angle. That was a workaround to not knowing the
accelerometer's orientation/calibration, but actually, we do know those.

(Except, as it turns out, on the G1, the accelerometer orientation is
different than it is on the G2, and there was a bug where EvenHub apps
got their accelerometer readings in the wrong orientation. So for
example the EvenHub Level app didn't work correctly.)
This commit is contained in:
James Babcock committed 2026-11-15 23:29:02 -08:00
1 parent 37d81d0308
commit e09f8eae96
17 files changed
+255 -281

No files matched your search

+5 -3
View File
@@ -1,7 +1,7 @@
import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
import { GrayImage } from "../../graphics/image";
import { clamp } from "../../util/numeric-util";
import { addImuListener, imuSourceLabel, setImuReportEnabled, type ImuReading } from "../../native/imu";
import { addImuListener, imuPitchDegrees, imuSourceLabel, setImuReportEnabled, type ImuReading } from "../../native/imu";
import { type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers";
import { shell } from "../../ui/shell/shell";
@@ -23,7 +23,8 @@ const BAR_RIGHT_INSET = 4;
/**
* Accelerometer demo: turns the IMU stream on while this page is visible (the
* Developer window is foregrounded and the screen is on), off otherwise, and
* shows the latest x/y/z reading with a simple per-axis bar.
* shows the latest x/y/z reading (Faceclaw's frame, imu-types.ts) with a
* simple per-axis bar, and the head's pitch.
*
* The IMU stream is experimental — the firmware may never populate it — so the
* page also reports how many samples have arrived.
@@ -92,7 +93,8 @@ export class AccelerometerDemoLayer implements Layer {
const bodyX = padding.left + BODY_INDENT;
image.drawText(small, padding.left, top, "Accelerometer", 220);
const status = this.enabled ? "IMU on" : "IMU off";
const pitch = this.reading ? `pitch ${Math.round(imuPitchDegrees(this.reading))}° ` : "";
const status = pitch + (this.enabled ? "IMU on" : "IMU off");
image.drawText(small, right - small.measureText(status), top, status, 150);
if (this.reading) {
+10 -58
View File
@@ -5,16 +5,9 @@ import { enumSettingMenuItem, onAnySettingChanged, toggleSettingMenuItem } from
import { uiFontOverridePickerMenuItem } from "../../ui/font-picker";
import { type InputEvent } from "../../ui/gestures";
import { type Layer, type LayerContext } from "../../ui/layers";
import { drawRightValueMenuItem, drawSelectionHighlight, isMenuItemDisabled, MenuLayer, openModalMenu, submenuItem, type MenuItem } from "../../ui/menu";
import {
captureHeadAngleStep,
glassesHeadUpTrigger,
headAngleCaptureRunning,
headAngleCaptureStep,
resetHeadAngleCapture,
syncGlanceAngleOriginal,
} from "../../g2/head-angle";
import { getHeadUpStatus, headUpControlsAvailable } from "../../native/glasses-controls";
import { drawSelectionHighlight, isMenuItemDisabled, MenuLayer, openModalMenu, submenuItem, type MenuItem } from "../../ui/menu";
import { liveHeadPitchFooter } from "../../g2/head-angle";
import { headUpControlsAvailable } from "../../native/glasses-controls";
import { Menu } from "../../ui/menu-core";
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics";
import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window";
@@ -342,8 +335,13 @@ function openGlanceSettings(ctx: LayerContext): void {
toggleSettingMenuItem(glanceShowOnHeadTiltSetting),
enumSettingMenuItem(glanceTiltTimeoutSetting),
// Only Android can change the glasses' head-up setting (glasses-controls.ts).
// The controller's settings listener sends a new angle to the glasses.
...(headUpControlsAvailable() ? [enumSettingMenuItem(glanceAngleSetting), headAngleCaptureMenuItem()] : []),
// The controller's settings listener sends a new angle to the glasses; the
// picker shows the head's current angle to choose by.
...(headUpControlsAvailable()
? [enumSettingMenuItem(glanceAngleSetting, {
pickerFooter: liveHeadPitchFooter(() => shell.isWindowVisible(GLANCEBOARD_WINDOW_ID)),
})]
: []),
toggleSettingMenuItem(glanceShowLinesSetting),
uiFontOverridePickerMenuItem(glanceFont, {
title: "Glanceboard font",
@@ -353,56 +351,10 @@ function openGlanceSettings(ctx: LayerContext): void {
enumSettingMenuItem(glanceDepthSetting),
...widgetSettingsMenuItems(),
];
resetHeadAngleCapture();
headAngleCapture = null;
const layer = new MenuLayer("Glanceboard settings", items(), PAGE_MENU_LAYOUT);
ctx.stack.push(layer);
}
/**
* "Set to current head angle", in two selects: one with the head level, one
* tilted up to where the display should wake (head-angle.ts). The row shows
* the step or the last result; otherwise the glasses' current trigger. A
* result is shown only while the Head tilt angle still has the value it was
* shown with, and only until the menu is reopened.
*/
let headAngleCapture: { status: string; angleSetting: string } | null = null;
function headAngleCaptureMenuItem(): MenuItem {
const label = "Set to current head angle";
const setStatus = (status: string) => {
headAngleCapture = { status, angleSetting: glanceAngleSetting.get() };
};
return {
label,
description:
"Two steps. Look straight ahead, keep still and select; then tilt your head up to where the display should wake, keep still and select again. " +
"Faceclaw reads the glasses' angle for about a second each time and saves the difference, rounded to 5°, as the Head tilt angle. Keep your head level side to side.",
onSelect: async (ctx) => {
// Selects during a measurement are ignored; it would share the IMU stream.
if (headAngleCaptureRunning()) return;
setStatus("Measuring...");
ctx.actions.requestRender();
const status = await captureHeadAngleStep();
if (status !== null) setStatus(status);
ctx.actions.requestRender();
},
render: ({ image, x, y, width }) => {
const status = getHeadUpStatus();
syncGlanceAngleOriginal(status);
let value: string;
if (headAngleCapture && headAngleCapture.angleSetting === glanceAngleSetting.get() &&
(headAngleCaptureRunning() || headAngleCaptureStep() === "tilt" || !headAngleCapture.status.startsWith("Now"))) {
value = headAngleCapture.status;
} else {
const current = glassesHeadUpTrigger(status);
value = current === null ? "" : current === 0 ? "glasses: off" : `glasses: ${current}°`;
}
drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width, label, value);
},
};
}
/**
* One row per widget on the board, in slot order: a submenu of the widget's
* settings, or a disabled row for a widget that has none.
+1 -1
View File
@@ -173,7 +173,7 @@ export const glanceAngleSetting = new ConfigSettingEnum<GlanceAngle>({
values: GLANCE_ANGLE_VALUES,
formatValue: (value) => (value === "glasses" ? "Glasses default" : `${value}°`),
description:
"How far you tilt your head up to wake the display. Glasses default uses the glasses' own setting from the Even app. " +
"How far you tilt your head up to wake the display; the list shows your head's angle now. Glasses default uses the glasses' own setting from the Even app. " +
"The board hides when your head drops 20° below this angle; under 25°, looking straight ahead may not count, so it hides after the tap duration instead.",
});