forked from aritra43/steadystridenew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.html
400 lines (355 loc) · 14.1 KB
/
report.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SteadyStride Monitor</title>
<link rel="stylesheet" href="output.css">
<!-- Add Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<!-- Add Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<style>
.dashboard {
display: flex;
min-height: 100vh;
}
.sidebar {
width: 250px;
padding: 20px;
background: #f5f5f5;
}
.main-content {
flex: 1;
padding: 20px;
}
.card {
background: white;
padding: 20px;
margin-bottom: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.chart-container {
height: 300px;
margin: 20px 0;
}
.connection-status {
display: flex;
align-items: center;
margin: 15px 0;
}
.status-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: red;
margin-right: 10px;
}
.status-dot.connected {
background: green;
}
.data-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
}
.data-item {
padding: 10px;
background: #f8f9fa;
border-radius: 4px;
}
.data-label {
font-size: 0.9em;
color: #666;
}
.data-value {
font-size: 1.2em;
font-weight: bold;
margin-top: 5px;
}
.tremor-indicator {
padding: 10px;
border-radius: 4px;
margin-top: 10px;
text-align: center;
font-weight: bold;
}
.stage-0 { background: #4CAF50; color: white; }
.stage-1 { background: #FFC107; color: black; }
.stage-2 { background: #FF9800; color: white; }
.stage-3 { background: #f44336; color: white; }
.btn {
padding: 10px 20px;
background: #2196F3;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
transition: background-color 0.3s;
}
.btn:hover {
background: #1976D2;
}
.btn:disabled {
background: #ccc;
cursor: not-allowed;
}
</style>
</head>
<body>
<div class="dashboard">
<div class="sidebar">
<h2>SteadyStride Monitor</h2>
<div class="connection-status">
<div class="status-dot" id="connectionDot"></div>
<span id="connectionStatus">Disconnected</span>
</div>
<button class="btn" id="connectButton">
<i class="fas fa-bluetooth"></i>
Connect Device
</button>
<button class="btn mt-10" id="connectButton">
<i class="fas fa-bluetooth"></i>
<a href="home.html">Home Page</a>
</button>
</div>
<div class="main-content">
<div class="card">
<h3>Current Tremor Stage</h3>
<div class="tremor-indicator" id="tremorStageIndicator">
Stage: 0 - Normal
</div>
</div>
<div class="card">
<h3>Accelerometer Data</h3>
<div class="data-grid">
<div class="data-item">
<div class="data-label">X-Axis</div>
<div class="data-value" id="xValue">0.00</div>
</div>
<div class="data-item">
<div class="data-label">Y-Axis</div>
<div class="data-value" id="yValue">0.00</div>
</div>
<div class="data-item">
<div class="data-label">Z-Axis</div>
<div class="data-value" id="zValue">0.00</div>
</div>
<div class="data-item">
<div class="data-label">Magnitude</div>
<div class="data-value" id="magnitudeValue">0.00</div>
</div>
</div>
</div>
<div class="card">
<h3>Real-time Graph</h3>
<div class="chart-container">
<canvas id="accelerationChart"></canvas>
</div>
</div>
<div class="card">
<h3>Magnitude History</h3>
<div class="chart-container">
<canvas id="magnitudeChart"></canvas>
</div>
</div>
</div>
</div>
<script>
// Global variables
let bluetoothDevice;
let accelerationChart;
let magnitudeChart;
const maxDataPoints = 50;
const dataHistory = {
x: Array(maxDataPoints).fill(0),
y: Array(maxDataPoints).fill(0),
z: Array(maxDataPoints).fill(0),
magnitude: Array(maxDataPoints).fill(0),
labels: Array(maxDataPoints).fill('')
};
// Initialize Charts
function initializeCharts() {
const accCtx = document.getElementById('accelerationChart').getContext('2d');
const magCtx = document.getElementById('magnitudeChart').getContext('2d');
accelerationChart = new Chart(accCtx, {
type: 'line',
data: {
labels: dataHistory.labels,
datasets: [{
label: 'X-Axis',
data: dataHistory.x,
borderColor: '#f44336',
tension: 0.4
}, {
label: 'Y-Axis',
data: dataHistory.y,
borderColor: '#4CAF50',
tension: 0.4
}, {
label: 'Z-Axis',
data: dataHistory.z,
borderColor: '#2196F3',
tension: 0.4
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
animation: {
duration: 0
},
scales: {
y: {
beginAtZero: true,
suggestedMin: -4,
suggestedMax: 4
}
}
}
});
magnitudeChart = new Chart(magCtx, {
type: 'line',
data: {
labels: dataHistory.labels,
datasets: [{
label: 'Magnitude',
data: dataHistory.magnitude,
borderColor: '#9C27B0',
backgroundColor: 'rgba(156, 39, 176, 0.1)',
fill: true,
tension: 0.4
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
animation: {
duration: 0
},
scales: {
y: {
beginAtZero: true,
suggestedMin: 0,
suggestedMax: 4
}
}
}
});
}
// Update tremor stage indicator
function updateTremorStage(magnitude) {
const indicator = document.getElementById('tremorStageIndicator');
let stage, description, className;
if (magnitude < 1.1) {
stage = 0;
description = "Normal";
className = "stage-0";
} else if (magnitude >= 1.1 && magnitude <= 1.6) {
stage = 1;
description = "Mild Tremor";
className = "stage-1";
} else if (magnitude > 1.6 && magnitude <= 1.9) {
stage = 2;
description = "Moderate Tremor";
className = "stage-2";
} else {
stage = 3;
description = "Severe Tremor";
className = "stage-3";
}
indicator.className = "tremor-indicator " + className;
indicator.textContent = `Stage ${stage} - ${description}`;
}
// Update data display and charts
function updateData(x, y, z, magnitude) {
// Update numeric display
document.getElementById('xValue').textContent = x.toFixed(3);
document.getElementById('yValue').textContent = y.toFixed(3);
document.getElementById('zValue').textContent = z.toFixed(3);
document.getElementById('magnitudeValue').textContent = magnitude.toFixed(3);
// Update tremor stage
updateTremorStage(magnitude);
// Update chart data
dataHistory.x.shift();
dataHistory.y.shift();
dataHistory.z.shift();
dataHistory.magnitude.shift();
dataHistory.labels.shift();
dataHistory.x.push(x);
dataHistory.y.push(y);
dataHistory.z.push(z);
dataHistory.magnitude.push(magnitude);
dataHistory.labels.push(new Date().toLocaleTimeString());
accelerationChart.update('none'); // Use 'none' to disable animation
magnitudeChart.update('none');
}
// BLE Connection
async function connectToDevice() {
try {
bluetoothDevice = await navigator.bluetooth.requestDevice({
acceptAllDevices: 'True',
// filters: [
// { namePrefix: 'Steady' },
// { namePrefix: 'steady' },
// { services: ['19b10000-e8f2-537e-4f6c-d104768a1214'] }
// ],
optionalServices: ['19b10000-e8f2-537e-4f6c-d104768a1214']
});
const server = await bluetoothDevice.gatt.connect();
const service = await server.getPrimaryService('19b10000-e8f2-537e-4f6c-d104768a1214');
// Get all characteristics
const xCharacteristic = await service.getCharacteristic('19b10001-e8f2-537e-4f6c-d104768a1214');
const yCharacteristic = await service.getCharacteristic('19b10002-e8f2-537e-4f6c-d104768a1214');
const zCharacteristic = await service.getCharacteristic('19b10003-e8f2-537e-4f6c-d104768a1214');
const magnitudeCharacteristic = await service.getCharacteristic('19b10004-e8f2-537e-4f6c-d104768a1214');
// Start notifications
await xCharacteristic.startNotifications();
await yCharacteristic.startNotifications();
await zCharacteristic.startNotifications();
await magnitudeCharacteristic.startNotifications();
// Add event listeners
let currentX = 0, currentY = 0, currentZ = 0, currentMagnitude = 0;
xCharacteristic.addEventListener('characteristicvaluechanged', (event) => {
currentX = event.target.value.getFloat32(0, true);
updateData(currentX, currentY, currentZ, currentMagnitude);
});
yCharacteristic.addEventListener('characteristicvaluechanged', (event) => {
currentY = event.target.value.getFloat32(0, true);
updateData(currentX, currentY, currentZ, currentMagnitude);
});
zCharacteristic.addEventListener('characteristicvaluechanged', (event) => {
currentZ = event.target.value.getFloat32(0, true);
updateData(currentX, currentY, currentZ, currentMagnitude);
});
magnitudeCharacteristic.addEventListener('characteristicvaluechanged', (event) => {
currentMagnitude = event.target.value.getFloat32(0, true);
updateData(currentX, currentY, currentZ, currentMagnitude);
});
document.getElementById('connectionDot').classList.add('connected');
document.getElementById('connectionStatus').textContent = 'Connected';
document.getElementById('connectButton').style.display = 'none';
} catch (error) {
console.error('Bluetooth Error:', error);
alert('Bluetooth connection failed: ' + error);
}
}
// Initialize
document.addEventListener('DOMContentLoaded', () => {
if (!navigator.bluetooth) {
alert('Web Bluetooth API is not supported in this browser. Please use Chrome, Edge, or Opera.');
document.getElementById('connectButton').disabled = true;
return;
}
initializeCharts();
document.getElementById('connectButton').addEventListener('click', connectToDevice);
});
</script>
</body>
</html>