Proximity Sensor

W3C Working Draft,

This version:
http://www.w3.org/TR/2016/WD-proximity-20160719/
Latest published version:
http://www.w3.org/TR/proximity/
Editor's Draft:
https://w3c.github.io/proximity/
Previous Versions:
http://www.w3.org/TR/2015/WD-proximity-20150903/
Version History:
https://github.com/w3c/proximity/commits/gh-pages/index.bs
Feedback:
public-device-apis@w3.org with subject line “[proximity] … message topic …” (archives)
Issue Tracking:
GitHub
Issues
Editors:
Anssi Kostiainen (Intel Corporation)
Rijubrata Bhaumik (Intel Corporation)
Former Editor:
Dzung D Tran (Intel Corporation)
Bug Reports:
via the w3c/proximity repository on GitHub
Test Suite:
web-platform-tests on GitHub

Abstract

This specification defines a concrete sensor interface to monitor the presence of nearby objects without physical contact.

Status of this document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document was published by the Device and Sensors Working Group as a Working Draft. This document is intended to become a W3C Recommendation.

If you wish to make comments regarding this document, please send them to public-device-apis@w3.org (subscribe, archives). When sending e-mail, please put the text “proximity” in the subject, preferably like this: “[proximity] …summary of comment…”. All comments are welcome.

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 1 September 2015 W3C Process Document.

1. Introduction

The Proximity Sensor extends the Generic Sensor API [GENERIC-SENSOR] to provide information about proximity level, as detected by the device’s primary proximity sensor. The proximity level is reported as the distance (in centimeter) from the sensor to the closest visible surface. §6 Limitations of Proximity Sensors describes more about the potential limitations, why the precise distance value reported by different devices can be different, due to differences in detection method, sensor construction, etc. Moreover some proximity sensors might be only able to provide just a boolean to indicate if there is an object which is near, more like presence detection, than an absolute value for the distance.

2. Examples

let sensor = new ProximitySensor();
sensor.start();

sensor.onchange = event => console.log(event.reading.distance);

sensor.onerror = function(event) {
    console.log(event.error.name, event.error.message);
};

3. Security and Privacy Considerations

There are no specific security and privacy considerations beyond those described in the Generic Sensor API [GENERIC-SENSOR].

4. Model

The Proximity Sensor’s associated Sensor subclass is the ProximitySensor class.

The Proximity Sensor’s associated SensorReading subclass is the ProximitySensorReading class.

The Proximity Sensor has a default sensor, which is the device’s main proximity detector.

The Proximity Sensor has a single supported reporting mode which is "auto".

The Proximity Sensor’s permission name is "proximity". It has no associated PermissionDescriptor.

The Proximity Sensor has an associated abstract operation to retrieve the sensor permission which must simply return a permission whose name is "proximity".

The Proximity Sensor has an associated abstract operation to construct a SensorReading object which creates a new ProximitySensorReading object and sets its distance attribute to positive infinity.

Distance is a value that represents the distance between a device and the closest visible surface. Its unit is the centimeter (cm).

5. API

5.1. The ProximitySensor Interface

[Constructor(optional SensorOptions sensorOptions)]
interface ProximitySensor : Sensor {
  readonly attribute ProximitySensorReading? reading;
};

To Construct a ProximitySensor Object the user agent must invoke the construct a Sensor object abstract operation.

5.2. The ProximitySensorReading Interface

[Constructor(ProximitySensorReadingInit proximitySensorReadingInit)]
interface ProximitySensorReading : SensorReading {
    readonly attribute unrestricted double distance;
    readonly attribute unrestricted double max;
    readonly attribute boolean? near;
};

dictionary ProximitySensorReadingInit {
  unrestricted double distance = Infinity;
  unrestricted double max = Infinity;
  boolean? near;
};

5.2.1. The ProximitySensorReading constructor

5.2.2. The distance attribute

The distance attribute of the ProximitySensorReading interface represents the distance between the sensor and the closest visible surface, in centimeters.

5.2.3. The max attribute

The max attribute of the ProximitySensorReading interface represents the maximum sensing range for the primary proximity sensor, in centimeters.

5.2.4. The near attribute

The near attribute of the ProximitySensorReading interface represents the the presence of a visible surface in the vicinity of the primary proximity sensor, in centimeters.

Note: If the implementation is unable to provide the near value, it could infer the near value from the value of distance. For example, if distance is not equal to max or default value (Infinity), it could imply there is an object in the sensing range.

6. Limitations of Proximity Sensors

Since most proximity sensors detect electromagnetic radiation (e.g., an infrared light or a magnetic field), certain material properties can interfere with the sensor’s ability to sense the presence of a physical object. Things that can interfere with a sensor include, but are not limited to, the material’s translucency, reflectiveness, color, temperature, chemical composition, and even the angle at which the object is reflecting the radiation back at the sensor. As such, proximity sensors should not be relied on as a means to measure distance. The only thing that can be deduced from a proximity sensor is that an object is somewhere in the distance between the minimum sensing distance and the maximum sensing distance with some degree of certainty.

7. Acknowledgements

Tobie Langel for the work on Generic Sensor API and inputs on this specification. Doug Turner for the initial prototype and Marcos Caceres for the test suite.

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Conformance Classes

A conformant user agent must implement all the requirements listed in this specification that are applicable to user agents.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[GENERIC-SENSOR]
Tobie Langel; Rick Waldron. Generic Sensor API. 24 March 2016. WD. URL: https://www.w3.org/TR/generic-sensor/
[PERMISSIONS]
Mounir Lamouri; Marcos Caceres. The Permissions API. 7 April 2015. WD. URL: https://www.w3.org/TR/permissions/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119

IDL Index

[Constructor(optional SensorOptions sensorOptions)]
interface ProximitySensor : Sensor {
  readonly attribute ProximitySensorReading? reading;
};

[Constructor(ProximitySensorReadingInit proximitySensorReadingInit)]
interface ProximitySensorReading : SensorReading {
    readonly attribute unrestricted double distance;
    readonly attribute unrestricted double max;
    readonly attribute boolean? near;
};

dictionary ProximitySensorReadingInit {
  unrestricted double distance = Infinity;
  unrestricted double max = Infinity;
  boolean? near;
};