Skip to content

Commit 1422bad

Browse files
arskamawbamberg
andauthored
Adding GravitySensor API documentation. (#3541)
* Adding GravitySensor API documentation. Fixes #3524 Implementation of GravitySensor API for Chrome 91 [1] Dependency with update of compat-data [2] [1] https://chromestatus.com/features/5384099747332096 [2] mdn/browser-compat-data#9628 * Fixing comments GravitySensor API documentation. Fixes #3524 Implementation of GravitySensor API for Chrome 91 [1] Dependency with update of compat-data [2] [1] https://chromestatus.com/features/5384099747332096 [2] mdn/browser-compat-data#9628 * Fixing comments part 2 GravitySensor API documentation. Fixes #3524 Implementation of GravitySensor API for Chrome 91 [1] Dependency with update of compat-data [2] [1] https://chromestatus.com/features/5384099747332096 [2] mdn/browser-compat-data#9628 * Update files/en-us/web/api/gravitysensor/gravitysensor/index.html Co-authored-by: wbamberg <[email protected]>
1 parent c4b2d25 commit 1422bad

File tree

5 files changed

+160
-2
lines changed

5 files changed

+160
-2
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: GravitySensor.GravitySensor()
3+
slug: Web/API/GravitySensor/GravitySensor
4+
tags:
5+
- API
6+
- Accelerometer
7+
- Constructor
8+
- Generic Sensor API
9+
- GravitySensor
10+
- Reference
11+
- Sensor
12+
- Sensor APIs
13+
- Sensors
14+
---
15+
<div>{{APIRef("Generic Sensor API")}}</div>
16+
17+
<p><span class="seoSummary">The <strong><code>GravitySensor</code></strong>
18+
constructor creates a new {{domxref("GravitySensor")}} object which
19+
provides on each reading the gravity applied to the device along all three axes.</span></p>
20+
21+
<h2 id="Syntax">Syntax</h2>
22+
23+
<pre
24+
class="brush: js">let <var>gravitySensor</var> = new GravitySensor([<em>options</em>])</pre>
25+
26+
<h3 id="Parameters">Parameters</h3>
27+
28+
<dl>
29+
<dt><em>options</em> {{optional_inline}}</dt>
30+
<dd>Options are as follows:
31+
<ul>
32+
<li><code>frequency</code>: The desired number of times per second a sample should
33+
be taken, meaning the number of times per second that
34+
{{domxref('sensor.onreading')}} will be called. A whole number or decimal may be
35+
used, the latter for frequencies less than a second. The actual reading frequency
36+
depends on device hardware and consequently may be less than requested. The default
37+
frequency is the one defined by the underlying platform.</li>
38+
<li><code>referenceFrame</code>: The local coordinate system representing
39+
the reference frame. It can be either <code>'device'</code> or
40+
<code>'screen'</code>. The default is <code>'device'</code>.</li>
41+
</ul>
42+
</dd>
43+
</dl>
44+
45+
<h3 id="Exceptions">Exceptions</h3>
46+
47+
<dl>
48+
<dt>SecurityError</dt>
49+
<dd>Use of this feature was blocked by a feature policy. If a feature policy blocks use of a feature,
50+
it is because your code is inconsistent with the policies set on your server.
51+
This is not something that would ever be shown to a user. See {{httpheader('Feature-Policy')}} for implementation instructions.</dd>
52+
</dl>
53+
54+
<h2 id="Specifications">Specifications</h2>
55+
56+
<table class="standard-table">
57+
<tbody>
58+
<tr>
59+
<th scope="col">Specification</th>
60+
<th scope="col">Status</th>
61+
<th scope="col">Comment</th>
62+
</tr>
63+
<tr>
64+
<td>{{SpecName('Generic Sensor')}}</td>
65+
<td>{{Spec2('Generic Sensor')}}</td>
66+
<td>Defines sensors in general.</td>
67+
</tr>
68+
<tr>
69+
<td>
70+
{{SpecName('Accelerometer','#dom-gravitysensor-gravitysensor','GravitySensor')}}
71+
</td>
72+
<td>{{Spec2('Accelerometer')}}</td>
73+
<td></td>
74+
</tr>
75+
</tbody>
76+
</table>
77+
78+
<h2 id="Browser_compatibility">Browser compatibility</h2>
79+
80+
<p>{{Compat("api.GravitySensor.GravitySensor")}}</p>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: GravitySensor
3+
slug: Web/API/GravitySensor
4+
tags:
5+
- API
6+
- Accelerometer
7+
- Accelerometer API
8+
- Generic Sensor API
9+
- GravitySensor
10+
- Interface
11+
- Reference
12+
- Sensor
13+
- Sensor APIs
14+
- Sensors
15+
---
16+
<div>{{APIRef("Generic Sensor API")}}</div>
17+
18+
<p><span class="seoSummary">The <strong><code>GravitySensor</code></strong> interface of the <a href="/en-US/docs/Web/API/Sensor_APIs">Sensor APIs</a> provides on each reading the gravity applied to the device along all three axes. </span></p>
19+
20+
<p>To use this sensor, the user must grant permission to the <code>'accelerometer'</code> device sensor through the {{domxref('Permissions')}} API.</p>
21+
22+
<h2 id="Constructor">Constructor</h2>
23+
24+
<dl>
25+
<dt>{{domxref("GravitySensor.GravitySensor()")}}</dt>
26+
<dd>Creates a new <code>GravitySensor</code> object.</dd>
27+
</dl>
28+
29+
<h2 id="Properties">Properties</h2>
30+
31+
<p><em>Inherits properties from its ancestor, {{domxref('Accelerometer')}}.</em></p>
32+
33+
<h2 id="Example">Example</h2>
34+
35+
<p>Gravity is typically read in the {{domxref('Sensor.onreading')}} event callback. In the example below this occurs sixty times a second.</p>
36+
37+
<pre class="brush: js">let gravitySensor = new GravitySensor({frequency: 60});
38+
39+
gravitySensor.addEventListener("reading", e =&gt; {
40+
  console.log(`Gravity along the X-axis ${gravitySensor.x}`);
41+
  console.log(`Gravity along the Y-axis ${gravitySensor.y}`);
42+
  console.log(`Gravity along the Z-axis ${gravitySensor.z}`);
43+
});
44+
45+
gravitySensor.start();</pre>
46+
47+
<h2 id="Specifications">Specifications</h2>
48+
49+
<table class="standard-table">
50+
<tbody>
51+
<tr>
52+
<th scope="col">Specification</th>
53+
<th scope="col">Status</th>
54+
<th scope="col">Comment</th>
55+
</tr>
56+
<tr>
57+
<td>{{SpecName('Generic Sensor')}}</td>
58+
<td>{{Spec2('Generic Sensor')}}</td>
59+
<td>Defines sensors in general.</td>
60+
</tr>
61+
<tr>
62+
<td>{{SpecName('Accelerometer','#gravitysensor-interface','GravitySensor')}}</td>
63+
<td>{{Spec2('Accelerometer')}}</td>
64+
<td></td>
65+
</tr>
66+
</tbody>
67+
</table>
68+
69+
<h2 id="Browser_compatibility">Browser compatibility</h2>
70+
71+
<p>{{Compat("api.GravitySensor")}}</p>

files/en-us/web/api/linearaccelerationsensor/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
---
1616
<div>{{APIRef("Generic Sensor API")}}</div>
1717

18-
<p><span class="seoSummary">The <strong><code>LinearAccelerationSensor</code></strong> interface of the <a href="/docs/Web/API/Sensor_APIs">Sensor APIs</a> provides on each reading the acceleration applied to the device along all three axes, but without the contribution of gravity. </span></p>
18+
<p><span class="seoSummary">The <strong><code>LinearAccelerationSensor</code></strong> interface of the <a href="/en-US/docs/Web/API/Sensor_APIs">Sensor APIs</a> provides on each reading the acceleration applied to the device along all three axes, but without the contribution of gravity. </span></p>
1919

2020
<p>To use this sensor, the user must grant permission to the <code>'accelerometer'</code> device sensor through the {{domxref('Permissions')}} API.</p>
2121

files/en-us/web/api/sensor/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ <h2 id="Interfaces_based_on_Sensor">Interfaces based on Sensor</h2>
2424
<ul>
2525
<li>{{domxref('Accelerometer')}}</li>
2626
<li>{{domxref('AmbientLightSensor')}}</li>
27+
<li>{{domxref('GravitySensor')}}</li>
2728
<li>{{domxref('Gyroscope')}}</li>
2829
<li>{{domxref('LinearAccelerationSensor')}}</li>
2930
<li>{{domxref('Magnetometer')}}</li>

files/en-us/web/api/sensor_apis/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ <h3 id="permissions_and_feature_policy">Permissions and Feature Policy</h3>
128128
<td><code>AmbientLightSensor</code></td>
129129
<td><code>'ambient-light-sensor'</code></td>
130130
</tr>
131+
<tr>
132+
<td><code>GravitySensor</code></td>
133+
<td><code>'accelerometer'</code></td>
134+
</tr>
131135
<tr>
132136
<td><code>Gyroscope</code></td>
133137
<td><code>'gyroscope'</code></td>
@@ -175,6 +179,8 @@ <h2 id="interfaces">Interfaces</h2>
175179
<dd>Provides the acceleration applied to the device along all three axes.</dd>
176180
<dt>{{domxref('AmbientLightSensor')}}{{securecontext_inline}}</dt>
177181
<dd>Returns the current light level or illuminance of the ambient light around the hosting device.</dd>
182+
<dt>{{domxref('GravitySensor')}}{{securecontext_inline}}</dt>
183+
<dd>Provides the gravity applied to the device along all three axes.</dd>
178184
<dt>{{domxref('Gyroscope')}}{{securecontext_inline}}</dt>
179185
<dd>Provides the angular velocity of the device along all three axes.</dd>
180186
<dt>{{domxref('LinearAccelerationSensor')}}{{securecontext_inline}}</dt>
@@ -208,7 +214,7 @@ <h2 id="Specifications">Specifications</h2>
208214
<tr>
209215
<td>{{SpecName('Accelerometer')}}</td>
210216
<td>{{Spec2('Accelerometer')}}</td>
211-
<td>Defines <code>Accelerometer</code> and <code>LinearAccerationSensor</code>.</td>
217+
<td>Defines <code>Accelerometer</code>, <code>GravitySensor</code>, and <code>LinearAccelerationSensor</code>.</td>
212218
</tr>
213219
<tr>
214220
<td>{{SpecName('AmbientLight')}}</td>

0 commit comments

Comments
 (0)