forked from anssiko/ambient-light
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.bs
161 lines (125 loc) · 5.51 KB
/
index.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<pre class="metadata">
Title: Ambient Light Sensor
Status: ED
Level: 2
ED: https://w3c.github.io/ambient-light/
Shortname: ambient-light
TR: http://www.w3.org/TR/ambient-light/
Previous Version: http://www.w3.org/TR/2015/WD-ambient-light-20150903/
Editor: Anssi Kostiainen, Intel Corporation, http://intel.com/
Editor: Tobie Langel 78102, Intel Corporation, http://intel.com/
Former Editor: Doug Turner, Mozilla Corporation, http://mozilla.com/
Group: dap
Abstract:
This specification defines a concrete sensor interface to monitor
the ambient light level or illuminance of the device's environment.
Version History: https://github.com/w3c/ambient-light/commits/gh-pages/index.bs
!Bug Reports: <a href="https://www.github.com/w3c/ambient-light/issues/new">via the w3c/ambient-light repository on GitHub</a>
Indent: 2
Repository: w3c/ambient-light
Markup Shorthands: markdown on
Inline Github Issues: true
!Issue Tracking: <a href="https://github.com/w3c/ambient-light/milestones/Level%202">Level 2 Issues</a>
Boilerplate: omit issues-index
</pre>
<pre class="anchors">
urlPrefix: https://w3c.github.io/permissions/; spec: PERMISSIONS
type: dfn
text: permission; url: idl-def-Permission
text: associated PermissionDescriptor; url: dfn-associated-permissiondescriptor
urlPrefix: https://w3c.github.io/sensors; spec: GENERIC-SENSOR
type: dfn
text: high-level
text: sensor subclass
text: sensorreading subclass
text: default sensor
text: supported reporting mode; url: supported-reporting-modes
text: auto
text: construct a sensor object; url: construct-sensor-object
</pre>
Introduction {#intro}
============
The Ambient Light Sensor extends the Generic Sensor API [[GENERIC-SENSOR]]
to provide information about ambient light levels,
as detected by the device's main light detector, in terms of lux units.
The 'light-level' media feature [[MEDIAQUERIES-4]] provides
less granular information about the ambient light level.
Note: it might be worthwhile to provide a <a>high-level</a> Light Level Sensor
which would mirror the 'light-level' media feature, but in JavaScript.
This sensor would _not require additional user permission to be activated_
in user agents that exposed the 'light-level' media feature.
Examples {#examples}
========
<div class="example">
<pre highlight="js">
let sensor = new AmbientLightSensor();
sensor.onchange = function(event) {
console.log(event.reading.illuminance);
};
sensor.onerror = function(event) {
console.log(event.error.name, event.error.message);
};
</pre>
</div>
Security and Privacy Considerations {#security-and-privacy}
===================================
There are no specific security and privacy considerations
beyond those described in the Generic Sensor API [[!GENERIC-SENSOR]].
Model {#model}
=====
The Ambient Light Sensor's associated <a>Sensor subclass</a>
is the {{AmbientLightSensor}} class.
The Ambient Light Sensor's associated <a>SensorReading subclass</a>
is the {{AmbientLightSensorReading}} class.
The Ambient Light Sensor has a <a>default sensor</a>,
which is the device's main light detector.
The Ambient Light Sensor has a single <a>supported reporting mode</a>
which is "<a>auto</a>".
The Ambient Light Sensor's <a>permission</a> name is `"ambient-light"`.
It has no <a>associated PermissionDescriptor</a>.
The Ambient Light Sensor has an associated abstract operation
to <dfn>retrieve the sensor permission</dfn> which
must simply return a <a>permission</a> whose name is "ambient-light".
The Ambient Light Sensor has an associated abstract operation
to <dfn lt="Construct SensorReading Object">construct a SensorReading object</dfn>
which creates a new {{AmbientLightSensorReading}} object and sets its
<a attribute for="AmbientLightSensorReading">illuminance</a> attribute to
the <a>current light level</a>.
The <dfn>current light level</dfn> or <dfn>illuminance</dfn>
is a value that represents the ambient light levels
around the hosting device. Its unit is the lux (lx) [[SI]].
Note: The precise lux value reported by
different devices in the same light can be different,
due to differences in detection method, sensor construction, etc.
API {#api}
===
The AmbientLightSensor Interface {#ambient-light-sensor-interface}
--------------------------------
<pre class="idl">
[Constructor(optional SensorOptions sensorOptions)]
interface AmbientLightSensor : Sensor {
readonly attribute AmbientLightSensorReading? reading;
};
</pre>
To <dfn>Construct an AmbientLightSensor Object</dfn> the user agent must invoke the
<a ls="Construct Sensor Object">construct a Sensor object</a> abstract operation.
The AmbientLightSensorReading Interface {#ambient-light-sensor-reading-interface}
---------------------------------------
<pre class="idl">
[Constructor(AmbientLightSensorReadingInit ambientLightSensorReadingInit)]
interface AmbientLightSensorReading : SensorReading {
readonly attribute unrestricted double illuminance;
};
dictionary AmbientLightSensorReadingInit {
unrestricted double illuminance;
};
</pre>
### The AmbientLightSensorReading constructor ### {#ambient-light-sensor-reading-constructor}
### The illuminance attribute ### {#ambient-light-sensor-reading-attribute}
The <a attribute for="AmbientLightSensorReading">illuminance</a> attribute of the {{AmbientLightSensorReading}}
interface represents the <a>current light level</a>.
Acknowledgements {#acknowledgements}
================
Doug Turner for the initial prototype and
Marcos Caceres for the test suite.
Paul Bakaus for the LightLevelSensor idea.