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

@@ -3,6 +3,8 @@ package com.faceclaw.app
/**
* Receives IMU (accelerometer) readings decoded from the glasses' sys-event stream. Registered on
* FaceclawBleCommunicator via addImuListener; callbacks are delivered on the Android main thread.
* x, y, z are in g, in the canonical frame of every glasses model (+x forward, +y left, +z up;
* see ImuOrientation).
*/
interface FaceclawImuListener {
fun onImuData(x: Double, y: Double, z: Double, eventSource: Int): Unit
@@ -653,14 +653,16 @@ internal fun GlassesSessionCore.finishFrame(frameId: Int, outcome: String) {
}
}
/** [x], [y], [z] as the hardware reports them; listeners get them in [ImuOrientation]'s frame. */
internal fun GlassesSessionCore.emitImuData(x: Double, y: Double, z: Double, eventSource: Int) {
if (imuListeners.isEmpty()) {
return
}
val (cx, cy, cz) = ImuOrientation.toCanonical(glassesType, x, y, z)
host.postToMain {
for (imuListener in imuListeners) {
try {
imuListener.onImuData(x, y, z, eventSource)
imuListener.onImuData(cx, cy, cz, eventSource)
} catch (t: Throwable) {
logWarn("listener onImuData failed", t)
}
@@ -299,7 +299,8 @@ internal fun GlassesSessionCore.g1StopAudioCapture() {
}
/**
* There is no magnetometer on a G1, only the accelerometer and gyroscope: x, y, z in g, head frame, from the right arm.
* There is no magnetometer on a G1, only the accelerometer and gyroscope: x, y, z in g from the right arm, in the
* G1's own axes, which [emitImuData] rotates into the G2's ([ImuOrientation]).
* [enable] raises the sample rate and polls it; [g1MaxSleepMs] follows.
*/
internal fun GlassesSessionCore.g1SetImuReport(enable: Boolean) {
@@ -0,0 +1,29 @@
package com.faceclaw.app
/**
* Faceclaw's accelerometer frame. Every model's samples are rotated into it before they reach a
* FaceclawImuListener ([GlassesSessionCore.emitImuData]), so Faceclaw apps and EvenHub pages see
* the same frame whichever glasses are worn. It is the G2's own frame, in g, glasses worn:
*
* +x forward (the way the wearer faces), +y to the wearer's left, +z up through the top of the head.
*
* At rest a reading is the "up" direction (the reaction to gravity): head level reads (0, 0, 1),
* looking 45° up (0.71, 0, 0.71), and the head tilted 45° to the right (right ear down)
* (0, 0.71, 0.71). Pitch above level is atan2(x, hypot(y, z)).
*/
object ImuOrientation {
/**
* A sample as [type]'s hardware reports it, in the canonical frame. Axes measured on hardware
* with the Developer app's accelerometer page:
* - G2: already canonical.
* - G1 (g1v0): +x right, +y up, +z back. Level reads (0, 1, 0), 45° up (0, 0.71, -0.71),
* 45° to the right (-0.71, 0.71, 0).
* - RayNeo iO: no accelerometer stream yet, so nothing to rotate; measure its axes when one
* is added.
*/
fun toCanonical(type: GlassesType, x: Double, y: Double, z: Double): DoubleArray = when (type) {
GlassesType.G2 -> doubleArrayOf(x, y, z)
GlassesType.G1 -> doubleArrayOf(-z, -x, y)
GlassesType.RAYNEO_IO -> doubleArrayOf(x, y, z)
}
}