Repository navigation
Expand file tree
/
Copy pathaccelerometer.html
More file actions
90 lines (75 loc) · 2.91 KB
/
Copy pathaccelerometer.html
File metadata and controls
90 lines (75 loc) · 2.91 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Accelerometer Baseline</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-50 flex items-center justify-center min-h-screen">
<div class="bg-white p-8 rounded-xl shadow-md w-full max-w-lg text-center">
<img src="logo.jpg" alt="Stroke Detection Logo" class="h-16 mx-auto" />
<h1 class="text-2xl font-bold mb-4 text-indigo-600">Arm Movement Baseline</h1>
<p class="mb-4 text-gray-600">Fold/unfold your <span id="arm">left</span> arm repeatedly for 10 seconds.</p>
<button id="startBtn" class="bg-blue-600 text-white px-6 py-2 rounded-xl hover:bg-blue-700">Start</button>
<p id="status" class="mt-4 text-sm text-gray-700"></p>
<button id="nextBtn" disabled class="mt-4 bg-green-600 text-white px-6 py-2 rounded-xl hover:bg-green-700">Next</button>
</div>
<script>
let arm = "left";
let foldCount = 0;
let lastState = null;
let lastTime = 0;
const cooldown = 300; // minimum time between folds in ms
const threshold = 2.5;
const startBtn = document.getElementById("startBtn");
const nextBtn = document.getElementById("nextBtn");
const armLabel = document.getElementById("arm");
const status = document.getElementById("status");
function reset() {
foldCount = 0;
lastState = null;
lastTime = 0;
}
function startRecording() {
reset();
status.textContent = "Recording... move your arm naturally.";
startBtn.disabled = true;
nextBtn.disabled = true;
window.addEventListener("devicemotion", detectFold);
setTimeout(() => {
window.removeEventListener("devicemotion", detectFold);
// Save fold count as baseline
localStorage.setItem(`${arm}ArmBaseline`, JSON.stringify({
foldCount: foldCount
}));
status.textContent = `${arm.toUpperCase()} arm baseline saved: ${foldCount} folds`;
nextBtn.disabled = false;
}, 10000);
}
function detectFold(event) {
const y = event.accelerationIncludingGravity.y;
const now = Date.now();
if (Math.abs(y) < threshold) return; // Ignore small noise
let currentState = y > 0 ? "up" : "down";
if (lastState && currentState !== lastState && (now - lastTime) > cooldown) {
foldCount++;
lastTime = now;
}
lastState = currentState;
}
startBtn.addEventListener("click", startRecording);
nextBtn.addEventListener("click", () => {
if (arm === "left") {
arm = "right";
armLabel.textContent = "right";
nextBtn.disabled = true;
startBtn.disabled = false;
status.textContent = "";
} else {
alert("Baseline for both arms saved.");
window.location.href = "index.html";
}
});
</script>
</body>
</html>