Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SensorApp
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
20-projet-ce-2020
SensorApp
Commits
11b9ae35
Commit
11b9ae35
authored
4 years ago
by
Augustin Jaujay
Browse files
Options
Downloads
Patches
Plain Diff
Commentaires
parent
9e169fd2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
www/js/index.js
+30
-9
30 additions, 9 deletions
www/js/index.js
with
30 additions
and
9 deletions
www/js/index.js
+
30
−
9
View file @
11b9ae35
...
...
@@ -26,6 +26,7 @@
// See https://cordova.apache.org/docs/en/latest/cordova/events/events.html#deviceready
document
.
addEventListener
(
'
deviceready
'
,
onDeviceReady
,
false
);
// Variables to save data temporarily
var
timer
=
null
;
var
position
;
var
acceleration
=
navigator
.
accelerometer
;
...
...
@@ -35,10 +36,16 @@ var sensors = navigator.orientation;
var
rotation
=
navigator
.
rotationvector
;
var
constraints
=
[];
// Variables to access data and errors files
var
saveFile
;
var
errorsFile
;
var
nbProbes
=
6
;
// Number of constraints propes used
var
nbProbes
=
1
;
var
probeHeader
=
``
;
for
(
let
i
=
0
;
i
<
6
;
i
++
)
{
probeHeader
+=
`;constraint
${
i
+
1
}
`
;
}
///var IndoorAtlas = navigator.indooratlas;
...
...
@@ -47,21 +54,23 @@ function onDeviceReady() {
console
.
log
(
'
Running cordova-
'
+
cordova
.
platformId
+
'
@
'
+
cordova
.
version
);
// Removing file from last session
// Removing file
s
from last session
clearFile
(
'
sessionData.csv
'
);
setTimeout
(
clearFile
,
100
,
'
errors.csv
'
);
// Creating
a
file to save data
// Creating file
s
to save data
setTimeout
(
createDataFile
,
200
);
setTimeout
(
createErrorsFile
,
300
);
// Initializing connexion with Arduino card
setTimeout
(
setArduinoConnexion
,
400
);
// Asking for a first set of data
setTimeout
(
askArduinoData
,
500
);
setTimeout
(
beginMeasures
,
500
);
}
// MAIN FUNCTION
// MAIN FUNCTION
S
function
handleButtonEvent
()
{
//Set position in html
...
...
@@ -106,14 +115,17 @@ function handleButtonEvent() {
}
},
error
=>
handleError
(
`Error while reading data from Arduino`
,
error
));
// Asking next set of constraints data
askArduinoData
();
// Saving all the data
save
(
position
,
acceleration
,
gyroscope
,
magnetometer
,
constraints
);
}
// Function to start or stop measuring
function
startOrStopTimer
()
{
if
(
!
timer
)
{
timer
=
setInterval
(
handleButtonEvent
,
100
0
)
timer
=
setInterval
(
handleButtonEvent
,
100
);
}
else
{
clearInterval
(
timer
);
timer
=
null
;
...
...
@@ -122,6 +134,7 @@ function startOrStopTimer() {
// SETUP FUNCTIONS
// Initializing phone instruments
function
beginMeasures
()
{
//Add volume buttons events:
document
.
addEventListener
(
"
volumeupbutton
"
,
handleButtonEvent
,
false
);
...
...
@@ -136,6 +149,7 @@ function beginMeasures() {
cordova
.
plugins
.
magnetometer
.
watchReadings
((
magn
)
=>
{
magnetometer
=
magn
;},
(
error
)
=>
handleError
(
`Error while setting magnetometer`
,
error
),
{
frequency
:
100
});
}
// Initializing arduino measures
function
setArduinoConnexion
()
{
serial
.
requestPermission
(
function
(
successMessage
)
{
serial
.
open
({},
function
(
successMessage
)
{
...
...
@@ -170,20 +184,23 @@ function save(positionData, accelerationData, gyroscopeData, magnetometerData, a
${
magnetometerData
.
x
}
;
${
magnetometerData
.
y
}
;
${
magnetometerData
.
z
}
;
${
arduinoData
[
0
]}
;
${
arduinoData
[
1
]}
;
${
arduinoData
[
2
]}
;
${
arduinoData
[
3
]}
;
${
arduinoData
[
4
]}
;
${
arduinoData
[
5
]}
;
${
arduinoData
[
6
]}
\n`
;
${
arduinoData
[
5
]}
\n`
;
writeFile
(
saveFile
,
new
Blob
([
newLine
]));
// Debug
readFile
(
saveFile
);
readFile
(
errorsFile
);
}
// FILE MANAGING FUNCTIONS
// Deleting files from previous sessions
function
clearFile
(
name
)
{
window
.
requestFileSystem
(
LocalFileSystem
.
PERSISTENT
,
0
,
function
(
fs
)
{
fs
.
root
.
getFile
(
name
,
{
create
:
false
,
exclusive
:
false
},
function
(
fileEntry
)
{
...
...
@@ -192,6 +209,7 @@ function clearFile(name) {
},
error
=>
handleError
(
`Error while using file manager`
,
error
));
}
// Creating new file to save recorded data
function
createDataFile
()
{
window
.
requestFileSystem
(
LocalFileSystem
.
PERSISTENT
,
0
,
function
(
fs
)
{
fs
.
root
.
getFile
(
'
sessionData.csv
'
,
{
create
:
true
,
exclusive
:
true
},
function
(
fileEntry
)
{
...
...
@@ -200,14 +218,15 @@ function createDataFile() {
`position timestamp;latitude;longitude;altitude;heading;speed;accuracy;
acceleration timestamp;acceleration x;acceleration y;acceleration z;
gyrorsope timestamp;gyroscope x;gyroscope y;gyroscope z;
magnetometer timestamp;magnetometer x;magnetometer y;magnetometer z
;
constraint 1;constraint 2;constraint 3;constraint 4;constraint 5;constraint 6
\n`
magnetometer timestamp;magnetometer x;magnetometer y;magnetometer z
${
probeHeader
}
\n`
]));
console
.
log
(
'
Data file opened
'
);
},
error
=>
handleError
(
`Error while getting file
${
fileEntry
.
name
}
`
,
error
));
},
error
=>
handleError
(
`Error while using file manager`
,
error
));
}
// Creating new file to save errors recorded during the session
function
createErrorsFile
()
{
window
.
requestFileSystem
(
LocalFileSystem
.
PERSISTENT
,
0
,
function
(
fs
)
{
fs
.
root
.
getFile
(
'
errors.csv
'
,
{
create
:
true
,
exclusive
:
true
},
function
(
fileEntry
)
{
...
...
@@ -218,6 +237,7 @@ function createErrorsFile() {
},
error
=>
handleError
(
`Error while using file manager`
,
error
));
}
// Function to write in a file given its fileEntry
function
writeFile
(
fileEntry
,
dataObj
)
{
fileEntry
.
createWriter
(
function
(
fileWriter
)
{
fileWriter
.
onwritend
=
function
()
{
...
...
@@ -236,6 +256,7 @@ function writeFile(fileEntry, dataObj) {
});
}
// Function to read the text content of a file (debug, maybe transmission to another device)
function
readFile
(
fileEntry
)
{
fileEntry
.
file
(
function
(
file
)
{
var
reader
=
new
FileReader
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment