- From: Dominique Hazael-Massieux <dom@w3.org>
- Date: Mon, 28 Nov 2011 11:21:05 +0100
- To: public-device-apis@w3.org
Hi, 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: navigator.proximity.addEventListener("distancechange", 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; }; Dom 1. http://developer.android.com/reference/android/hardware/SensorEvent.html#values
Received on Monday, 28 November 2011 10:21:30 UTC