Skip to content

Commit

Permalink
updated sensor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tigoe committed Jun 9, 2024
1 parent ace1750 commit faf4a90
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
5 changes: 3 additions & 2 deletions sensor-tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
<div id="qr"></div>
<br />
<div id="text">
The sensor API only works on devices which have the sensors and provide access to them,
and when served via HTTPS.
The Sensor API only works on devices which have the sensors and provide access to them,
and when served via HTTPS.<br>
The Sensor API isn't supported on Safara on iOS.
</div>
<br />
<div id="networkType"></div>
Expand Down
16 changes: 6 additions & 10 deletions sensor-tests/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,17 @@
Uses a responsive CSS to adjust the size of the type as well.
created 14 Feb 2021
modified 9 Jun 2024
by Tom Igoe
*/

// get the network connection intefface (depends on device):
let connection =
navigator.connection || navigator.mozConnection || navigator.webkitConnection;

// variables for the sensors:
let accel, gyro, light, compass;

function setup() {
// get the network type and effective network type and display them:
var netSpan = document.getElementById("networkType");
netSpan.innerHTML =
"Network type: " +
connection.type +
"<br>Effective connection: " +
connection.effectiveType;

netSpan.innerHTML = "Sensors found:<br>";
// get the error div so you can show errors:
var errorDiv = document.getElementById("error");

Expand All @@ -38,6 +30,7 @@ function setup() {
accel = new Accelerometer({ frequency: 60 });
accel.addEventListener("reading", accelReading);
accel.start();
netSpan.innerHTML += "Accelerometer started.<br>";
} catch (error) {
errorDiv.innerHTML += error + "<br>";
}
Expand All @@ -46,6 +39,7 @@ function setup() {
gyro = new Gyroscope({ frequency: 60 });
gyro.addEventListener("reading", gyroReading);
gyro.start();
netSpan.innerHTML += "Gyrometer started.<br>";
} catch (error) {
errorDiv.innerHTML += error + "<br>";
}
Expand All @@ -55,6 +49,7 @@ function setup() {
light = new AmbientLightSensor({ frequency: 60 });
light.addEventListener("reading", lightReading);
light.start();
netSpan.innerHTML += "Ambient light sensor started.<br>";
} catch (error) {
errorDiv.innerHTML += error + "<br>";
}
Expand All @@ -63,6 +58,7 @@ function setup() {
compass = new Magnetometer({ frequency: 60 });
compass.addEventListener("reading", compassReading);
compass.start();
netSpan.innerHTML += "Magnetometer started.<br>";
} catch (error) {
errorDiv.innerHTML += error + "<br>";
}
Expand Down

0 comments on commit faf4a90

Please sign in to comment.