GravitySensor screen-frame rotation

Issue 506189182 New / P3 / S3 Android Generic Sensor API

Live test

  1. Open this page in Chrome on an Android phone.
  2. Enable screen auto-rotation, then hold the phone nearly vertical.
  3. Rotate into each landscape orientation with the page bottom pointing down.
  4. The label should remain upright and the screen-frame Y value should be positive.
Waiting to start.
orientation: unknown
This label should remain upright No screen-frame reading yet

Device reference frame

x
--
y
--
z
--
magnitude
--

Screen reference frame

x
--
y
--
z
--
magnitude
--
Waiting

For a vertical screen whose rendered bottom points toward the floor, the specification example expects screen.y > 0.

What this detects

Incorrect 270-degree mapping

In the failing implementation, a landscape-secondary reading with device-frame x ~= -9.8 was mapped directly to screen-frame Y, producing y ~= -9.8. The correct transform negates that X component, producing y ~= +9.8.

Minimal API usage

const sensor = new GravitySensor({
  frequency: 60,
  referenceFrame: 'screen'
});

sensor.addEventListener('reading', () => {
  console.log(sensor.x, sensor.y, sensor.z);
});
sensor.start();

Links