@@ -16,8 +16,11 @@ let currentRecording = [];
16
16
let is_recording ;
17
17
let recordings = [ ] ;
18
18
let is_showing ;
19
+ let is_live ;
20
+ let recordingTimeout = [ ] ;
21
+ let lastBatch ;
19
22
20
- const samplingAccRate = 30 ;
23
+ const samplingAccRate = 15 ;
21
24
/* Build mobile version */
22
25
function buildMobile ( ) {
23
26
let accelerometerCanvas = document . getElementById ( 'accelerometer-canvas' ) ;
@@ -46,6 +49,8 @@ function buildMobile() {
46
49
accelerometerRecordCounter = document . getElementById ( 'counter-accelerometer' ) ;
47
50
const accelerometerButtonShow = document . getElementById ( 'accelerometer-show' ) ;
48
51
accelerometerButtonShow . addEventListener ( 'click' , showRecording ) ;
52
+ const accelerometerButtonLive = document . getElementById ( 'accelerometer-live' ) ;
53
+ accelerometerButtonLive . addEventListener ( 'click' , showLive ) ;
49
54
50
55
recordSelect = document . getElementById ( 'recording-select' ) ;
51
56
@@ -131,6 +136,15 @@ function recordAccelerometer(pointsAlpha, pointsBeta, pointsGamma, l) {
131
136
for ( let i = 0 ; i < l ; i ++ ) {
132
137
if ( pointsAlpha [ i ] != IMAGE_START && pointsAlpha [ i ] != IMAGE_END ) {
133
138
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
+ }
134
148
} else if ( pointsAlpha [ i ] == IMAGE_START ) {
135
149
currentRecording = [ ] ;
136
150
} else if ( pointsAlpha [ i ] == IMAGE_END ) {
@@ -150,6 +164,7 @@ function recordAccelerometer(pointsAlpha, pointsBeta, pointsGamma, l) {
150
164
}
151
165
152
166
function showRecording ( ) {
167
+ is_live = false ;
153
168
const selected = recordSelect . value ;
154
169
if ( selected == '' ) {
155
170
alert ( 'No recording available' ) ;
@@ -162,7 +177,7 @@ function showRecording() {
162
177
for ( let i = 0 ; i < recording . length ; i ++ ) {
163
178
let point = recording [ i ] ;
164
179
time = samplingAccRate * i ;
165
- setTimeout ( ( ) => {
180
+ recordingTimeout [ i ] = setTimeout ( ( ) => {
166
181
cubeAlphaVisu = point [ 0 ] ;
167
182
cubeBetaVisu = point [ 1 ] ;
168
183
cubeGammaVisu = point [ 2 ] ;
@@ -174,3 +189,16 @@ function showRecording() {
174
189
} , samplingAccRate * recording . length ) ;
175
190
}
176
191
}
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