Gyroscope/DeviceMotion events

Following on from the thread last week and comments from Maciej, here's a new proposal for the movement events in Device Orientation.

Actually, I'm presenting some alternatives. I don't have strong opinions either way, but I've already started on implementation, so the earlier the feedback the better. I think we'll do something like C+D even if the standard doesn't support it. Option A without B is the smallest change to the specification. If I had to choose, I'd pick B to replace the existing AccelerometerEvent and the proposal in A. 

A. Gyroscope Event

This is similar to the Accelerometer Event.

event.type = "gyroscope"

interface GyroscopeEvent : Event {

    readonly attribute double? xRotationRate;
    readonly attribute double? yRotationRate;
    readonly attribute double? zRotationRate;
    readonly attribute double? interval;

    void initGyroscopeEvent(in DOMString type,
                                in boolean bubbles,
                                in boolean cancelable,
                                in double xRotationRate,
                                in double yRotationRate,
                                in double zRotationRate,
                                in double interval);
}


B. Device Motion Event

This comes from Maciej's proposal to have a single event cover both pieces of hardware.

interface DeviceMotionEvent : Event {

    readonly attribute double? xAcceleration;
    readonly attribute double? yAcceleration;
    readonly attribute double? zAcceleration;
    readonly attribute double? accelerometerInterval;

    readonly attribute double? xRotationRate;
    readonly attribute double? yRotationRate;
    readonly attribute double? zRotationRate;
    readonly attribute double? gyroscopeInterval;

    void initDeviceMotionEvent(in DOMString type,
                                in boolean bubbles,
                                in boolean cancelable,
                                in double xAcceleration,
                                in double yAcceleration,
                                in double zAcceleration,
                                in double accelerometerInterval,
                                in double xRotationRate,
                                in double yRotationRate,
                                in double zRotationRate,
                                in double gyroscopeInterval);
    }


C. Testing for hardware support

Something on the navigator object that tells the author what the hardware supports.

readonly attribute bool supportsAccelerometer;
readonly attribute bool supportsGyroscope;

D. Allow the user to specify sampling intervals

window.accelerometerInterval = 0.1; // 10 updates a second
window.gyroscopeInterval = 0.1;

Received on Tuesday, 3 August 2010 01:17:29 UTC