blob: afc91f60d53703b550e30f6c6828a243c02e9e4b (
plain)
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
|
---
title: Sensor
slug: Web/API/Sensor
tags:
- API
- Generic Sensor API
- Interface
- NeedsTranslation
- Reference
- Sensor
- Sensor APIs
- Sensors
- TopicStub
translation_of: Web/API/Sensor
---
<div>{{APIRef("Generic Sensor API")}}</div>
<p><span class="seoSummary">The <strong><code>Sensor</code></strong> interface of the the <a href="/docs/Web/API/Sensor_APIs">Sensor APIs</a> is the base class for all the other sensor interfaces. This interface cannot be used directly. Instead it provides properties, event handlers, and methods accessed by interfaces that inherit from it.</span></p>
<p>If a feature policy blocks use of a feature it is because your code is inconsistent with the policies set on your server. This is not something that would ever be shown to a user. See {{httpheader('Feature-Policy')}} for implementation instructions.</p>
<h2 id="Interfaces_based_on_Sensor">Interfaces based on Sensor</h2>
<p>Below is a list of interfaces based on the Sensor interface.</p>
<div class="index">
<ul>
<li>{{domxref('Accelerometer')}}</li>
<li>{{domxref('AmbientLightSensor')}}</li>
<li>{{domxref('Gyroscope')}}</li>
<li>{{domxref('LinearAccelerationSensor')}}</li>
<li>{{domxref('Magnetometer')}}</li>
<li>{{domxref('OrientationSensor')}}</li>
</ul>
</div>
<h2 id="Properties">Properties</h2>
<dl>
<dt>{{domxref('Sensor.activated')}} {{readonlyinline}}</dt>
<dd>Returns a {{jsxref("Boolean")}} indicating whether the sensor is active.</dd>
<dt>{{domxref('Sensor.hasReading')}} {{readonlyinline}}</dt>
<dd>Returns a {{jsxref("Boolean")}} indicating whether the sensor has a reading.</dd>
<dt>{{domxref('Sensor.timestamp')}} {{readonlyinline}}</dt>
<dd>Returns the time stamp of the latest sensor reading.</dd>
</dl>
<h3 id="Event_handlers">Event handlers</h3>
<dl>
<dt>{{domxref('Sensor.onerror')}}</dt>
<dd>Called when an error occurs on one of the child interfaces of the <code>Sensor</code> interface.</dd>
<dt>{{domxref('Sensor.onreading')}}</dt>
<dd>Called when a reading is taken on one of the child interfaces of the Sensor interface.</dd>
<dt>{{domxref('Sensor.onactivate')}}</dt>
<dd>Called when one of the Sensor interface's becomes active.</dd>
</dl>
<h2 id="Methods">Methods</h2>
<dl>
<dt>{{domxref('Sensor.start()')}}</dt>
<dd>Activates one of the sensors based on <code>Sensor</code>.</dd>
<dt>{{domxref('Sensor.stop()')}}</dt>
<dd>Deactivates one of the sensors based on <code>Sensor</code>.</dd>
</dl>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('Generic Sensor','#the-sensor-interface','Sensor')}}</td>
<td>{{Spec2('Generic Sensor')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("api.Sensor")}}</p>
|