Skip to content

Commit acce2d7

Browse files
Add function live for accelerometer
1 parent 07165a3 commit acce2d7

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

hf-data/assets/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,8 @@
9090

9191
#record-div {
9292
margin-top: 20px;
93+
}
94+
95+
#accelerometer-live {
96+
background-color: red;
9397
}

hf-data/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ <h2 class="card-title">Stored Data Visualisation</h2>
144144
<div class="spaced" id="record-div">
145145
<select name="recording-select" id="recording-select">
146146
</select>
147-
<button id="accelerometer-show" class="btn btn-primary mb-2">Show</button>
147+
<div>
148+
<button id="accelerometer-live" class="btn btn-primary mb-2">Live</button>
149+
<button id="accelerometer-show" class="btn btn-primary mb-2">Show</button>
150+
</div>
151+
148152
</div>
149153

150154
<br />

hf-data/js/mobile.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ let currentRecording = [];
1616
let is_recording;
1717
let recordings = [];
1818
let is_showing;
19+
let is_live;
20+
let recordingTimeout = [];
21+
let lastBatch;
1922

20-
const samplingAccRate = 30;
23+
const samplingAccRate = 15;
2124
/* Build mobile version */
2225
function buildMobile() {
2326
let accelerometerCanvas = document.getElementById('accelerometer-canvas');
@@ -46,6 +49,8 @@ function buildMobile() {
4649
accelerometerRecordCounter = document.getElementById('counter-accelerometer');
4750
const accelerometerButtonShow = document.getElementById('accelerometer-show');
4851
accelerometerButtonShow.addEventListener('click', showRecording);
52+
const accelerometerButtonLive = document.getElementById('accelerometer-live');
53+
accelerometerButtonLive.addEventListener('click', showLive);
4954

5055
recordSelect = document.getElementById('recording-select');
5156

@@ -131,6 +136,15 @@ function recordAccelerometer(pointsAlpha, pointsBeta, pointsGamma, l) {
131136
for (let i = 0; i < l; i++) {
132137
if (pointsAlpha[i] != IMAGE_START && pointsAlpha[i] != IMAGE_END) {
133138
currentRecording.push([pointsAlpha[i], pointsBeta[i], pointsGamma[i]]);
139+
if(is_live){
140+
time = samplingAccRate * i;
141+
recordingTimeout[i] = setTimeout(() => {
142+
cubeAlphaVisu = pointsAlpha[i];
143+
cubeBetaVisu = pointsBeta[i];
144+
cubeGammaVisu = pointsGamma[i];
145+
}, time)
146+
147+
}
134148
} else if (pointsAlpha[i] == IMAGE_START) {
135149
currentRecording = [];
136150
} else if (pointsAlpha[i] == IMAGE_END) {
@@ -150,6 +164,7 @@ function recordAccelerometer(pointsAlpha, pointsBeta, pointsGamma, l) {
150164
}
151165

152166
function showRecording() {
167+
is_live = false;
153168
const selected = recordSelect.value;
154169
if (selected == '') {
155170
alert('No recording available');
@@ -162,7 +177,7 @@ function showRecording() {
162177
for (let i = 0; i < recording.length; i++) {
163178
let point = recording[i];
164179
time = samplingAccRate * i;
165-
setTimeout(() => {
180+
recordingTimeout[i] = setTimeout(() => {
166181
cubeAlphaVisu = point[0];
167182
cubeBetaVisu = point[1];
168183
cubeGammaVisu = point[2];
@@ -174,3 +189,16 @@ function showRecording() {
174189
}, samplingAccRate * recording.length);
175190
}
176191
}
192+
193+
function showLive() {
194+
// Stop to show the recording
195+
emptyRecordingBuffer();
196+
is_showing = false;
197+
is_live = true;
198+
}
199+
200+
function emptyRecordingBuffer(){
201+
for(let i=0; i<recordingTimeout.length; ++i){
202+
clearTimeout(recordingTimeout[i]);
203+
}
204+
}

0 commit comments

Comments
 (0)