Skip to content

Commit 58e823f

Browse files
authored
sensor webapp
initial commit of app made for displaying sensor values of accelerometer
1 parent 5de8d96 commit 58e823f

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

sensor_webapp/app.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
if ('serviceWorker' in navigator) {
2+
navigator.serviceWorker.register('service-worker.js');
3+
}
4+
5+
window.addEventListener('devicemotion', function(event) {
6+
document.getElementById('acc-x').textContent = event.accelerationIncludingGravity.x.toFixed(2);
7+
document.getElementById('acc-y').textContent = event.accelerationIncludingGravity.y.toFixed(2);
8+
document.getElementById('acc-z').textContent = event.accelerationIncludingGravity.z.toFixed(2);
9+
});
10+
11+
window.addEventListener('deviceorientation', function(event) {
12+
document.getElementById('ori-alpha').textContent = event.alpha.toFixed(2);
13+
document.getElementById('ori-beta').textContent = event.beta.toFixed(2);
14+
document.getElementById('ori-gamma').textContent = event.gamma.toFixed(2);
15+
});

sensor_webapp/index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6+
<meta name="theme-color" content="#317EFB"/>
7+
<link rel="manifest" href="manifest.json">
8+
<link rel="stylesheet" href="style.css">
9+
<title>Sensor WebApp</title>
10+
</head>
11+
<body>
12+
<h1>Sensor Readings</h1>
13+
<div class="sensor">
14+
<h2>Accelerometer</h2>
15+
<p>X: <span id="acc-x">0</span></p>
16+
<p>Y: <span id="acc-y">0</span></p>
17+
<p>Z: <span id="acc-z">0</span></p>
18+
</div>
19+
<div class="sensor">
20+
<h2>Orientation</h2>
21+
<p>Alpha: <span id="ori-alpha">0</span></p>
22+
<p>Beta: <span id="ori-beta">0</span></p>
23+
<p>Gamma: <span id="ori-gamma">0</span></p>
24+
</div>
25+
<script src="app.js"></script>
26+
</body>
27+
</html>

sensor_webapp/manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Sensor WebApp",
3+
"short_name": "Sensors",
4+
"start_url": "./index.html",
5+
"display": "standalone",
6+
"background_color": "#ffffff",
7+
"theme_color": "#317EFB",
8+
"icons": [
9+
{
10+
"src": "icon.png",
11+
"sizes": "192x192",
12+
"type": "image/png"
13+
}
14+
]
15+
}

sensor_webapp/service-worker.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
self.addEventListener('install', function(e) {
2+
e.waitUntil(
3+
caches.open('sensor-cache').then(function(cache) {
4+
return cache.addAll([
5+
'/',
6+
'/index.html',
7+
'/style.css',
8+
'/app.js',
9+
'/manifest.json'
10+
]);
11+
})
12+
);
13+
});
14+
15+
self.addEventListener('fetch', function(e) {
16+
e.respondWith(
17+
caches.match(e.request).then(function(response) {
18+
return response || fetch(e.request);
19+
})
20+
);
21+
});

sensor_webapp/style.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
body {
2+
font-family: sans-serif;
3+
text-align: center;
4+
background: #f2f2f2;
5+
color: #333;
6+
}
7+
.sensor {
8+
background: white;
9+
margin: 20px auto;
10+
padding: 15px;
11+
border-radius: 10px;
12+
width: 80%;
13+
max-width: 400px;
14+
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
15+
}

0 commit comments

Comments
 (0)