W3C home > Mailing lists > Public > public-device-apis@w3.org > November 2011

Proposal for proximity sensor API

From: Dominique Hazael-Massieux <dom@w3.org>
Date: Mon, 28 Nov 2011 11:21:05 +0100
Message-ID: <1322475665.2416.189.camel@altostratustier>
To: public-device-apis@w3.org

During our TPAC F2F, I took an action item (ACTION-467) to make a
concrete proposal for an API that reacts to the proximity sensors
available on many mobile devices.

I'm proposing that we use a model similar to the Battery Status API,
with a navigator.proximity (or navigator.sensors.proximity?) object
representing the current state of the proximity sensors, completed with
events on changes:
  funtion(event) { 
    if (navigator.proximity.distance < Math.INFINITY) {
      console.log("The device is facing an object at " +
(navigator.proximity.distance * 100) + " centimeters"); 
    } else {
      console.log("No object nearby"); 
  }, false);

Some proximity sensors can only report a boolean value (near/far) based
on the presence of an object within a given range of distance; for
those, I propose that we also have an "accuracy" property. A sensor that
reports only whether there is an object within 9 cm of range would
report proximity.distance = 4.5cm and proximity.accuracy = 4.5cm. We
might also want a pure boolean property (proximity.near?).b

This would mean something like this in Web IDL:

Navigator implements NavigatorProximity;
[NoInterfaceObject] interface NavigatorProximity {
  readonly attribute ProximityManager proximity;

[NoInterfaceObject] interface ProximityManager: EventTarget {
  readonly attribute boolean near;
  readonly attribute double distance; // in meters
  attribute Function? ondistancechange;


Received on Monday, 28 November 2011 10:21:30 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:32:32 UTC