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
a8f83589
Commit
a8f83589
authored
4 years ago
by
Augustin Jaujay
Browse files
Options
Downloads
Patches
Plain Diff
Enregistrement fonctionnel II le retour
parent
03f6f634
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
+50
-26
50 additions, 26 deletions
www/js/index.js
with
50 additions
and
26 deletions
www/js/index.js
+
50
−
26
View file @
a8f83589
...
...
@@ -33,8 +33,9 @@ var gyroscope = navigator.gyroscope;
var
magnetometer
=
navigator
.
magnetometer
;
var
sensors
=
navigator
.
orientation
;
var
rotation
=
navigator
.
rotationvector
;
var
saveFile
;
var
saveFile
;
var
errorsFile
;
///var IndoorAtlas = navigator.indooratlas;
...
...
@@ -49,35 +50,21 @@ function onDeviceReady() {
document
.
addEventListener
(
"
volumeupbutton
"
,
handleButtonEvent
,
false
);
document
.
addEventListener
(
"
volumedownbutton
"
,
handleButtonEvent
,
false
);
//start watching gps
navigator
.
geolocation
.
watchPosition
((
pos
)
=>
{
position
=
pos
;},
(
error
)
=>
handleError
(
error
),
{
timeout
:
100
,
enableHighAccuracy
:
true
});
navigator
.
geolocation
.
watchPosition
((
pos
)
=>
{
position
=
pos
;},
(
error
)
=>
console
.
log
(
error
),
{
timeout
:
100
,
enableHighAccuracy
:
true
});
//start watching acceleration
navigator
.
accelerometer
.
watchAcceleration
((
acc
)
=>
{
acceleration
=
acc
;},
(
error
)
=>
handleError
(
error
),
{
frequency
:
100
});
navigator
.
accelerometer
.
watchAcceleration
((
acc
)
=>
{
acceleration
=
acc
;},
(
error
)
=>
console
.
log
(
error
),
{
frequency
:
100
});
//start watching gyroscope
navigator
.
gyroscope
.
watch
((
gyro
)
=>
{
gyroscope
=
gyro
;},
(
error
)
=>
handleError
(
error
),
{
frequency
:
100
});
navigator
.
gyroscope
.
watch
((
gyro
)
=>
{
gyroscope
=
gyro
;},
(
error
)
=>
console
.
log
(
error
),
{
frequency
:
100
});
//start watching magneto
cordova
.
plugins
.
magnetometer
.
watchReadings
((
magn
)
=>
{
magnetometer
=
magn
;},
(
error
)
=>
handleError
(
error
),
{
frequency
:
100
});
cordova
.
plugins
.
magnetometer
.
watchReadings
((
magn
)
=>
{
magnetometer
=
magn
;},
(
error
)
=>
console
.
log
(
error
),
{
frequency
:
100
});
// Removing file from last session
window
.
requestFileSystem
(
LocalFileSystem
.
PERSISTENT
,
0
,
function
(
fs
)
{
fs
.
root
.
getFile
(
'
sessionData.csv
'
,
{
create
:
false
,
exclusive
:
false
},
function
(
fileEntry
)
{
fileEntry
.
remove
(
function
(
file
)
{
console
.
log
(
'
File removed
'
)},
handleError
);
},
handleError
)
},
handleError
);
setTimeout
(
clearFile
,
100
,
'
sessionData.csv
'
);
setTimeout
(
clearFile
,
100
,
'
errors.csv
'
);
// Creating a file to save data
window
.
requestFileSystem
(
LocalFileSystem
.
PERSISTENT
,
0
,
function
(
fs
)
{
fs
.
root
.
getFile
(
'
sessionData.csv
'
,
{
create
:
true
,
exclusive
:
true
},
function
(
fileEntry
)
{
saveFile
=
fileEntry
;
readFile
(
saveFile
);
writeFile
(
saveFile
,
new
Blob
([
`position timestamp;latitude;longitude;altitude;heading;speed;accuracy;
acceleration timestamp;acceleration x;acceleration y;acceleration z\n`
// gytorsope timestamp;gyroscope x;gyroscope y;gyroscope z;
// magnetometer timestamp;magnetometer x;magnetometer y;magnetometer z
]));
console
.
log
(
'
File opened ; fileEntry is file ?
'
+
fileEntry
.
isFile
.
toString
());
},
handleError
);
},
handleError
);
setTimeout
(
createDataFile
,
100
);
setTimeout
(
createErrorsFile
,
100
);
}
...
...
@@ -122,6 +109,7 @@ function handleButtonEvent() {
function
handleError
(
error
)
{
//TODO: log error to error file / db
console
.
log
(
error
);
writeFile
(
error
.
toString
());
}
function
startOrStopTimer
()
{
...
...
@@ -156,12 +144,48 @@ function save(positionData, accelerationData, gyroscopeData, magnetometerData) {
writeFile
(
saveFile
,
new
Blob
([
newLine
]));
readFile
(
saveFile
);
readFile
(
errorsFile
);
}
// FILE MANAGING FUNCTIONS
function
clearFile
(
name
)
{
window
.
requestFileSystem
(
LocalFileSystem
.
PERSISTENT
,
0
,
function
(
fs
)
{
fs
.
root
.
getFile
(
name
,
{
create
:
false
,
exclusive
:
false
},
function
(
fileEntry
)
{
fileEntry
.
remove
(
function
(
file
)
{
console
.
log
(
'
File removed
'
)},
function
()
{});
},
function
()
{});
},
function
()
{});
}
function
createDataFile
()
{
window
.
requestFileSystem
(
LocalFileSystem
.
PERSISTENT
,
0
,
function
(
fs
)
{
fs
.
root
.
getFile
(
'
sessionData.csv
'
,
{
create
:
true
,
exclusive
:
true
},
function
(
fileEntry
)
{
saveFile
=
fileEntry
;
writeFile
(
saveFile
,
new
Blob
([
`position timestamp;latitude;longitude;altitude;heading;speed;accuracy;
acceleration timestamp;acceleration x;acceleration y;acceleration z\n`
// gytorsope timestamp;gyroscope x;gyroscope y;gyroscope z;
// magnetometer timestamp;magnetometer x;magnetometer y;magnetometer z
]));
console
.
log
(
'
Data file opened
'
);
},
function
()
{});
},
function
()
{});
}
function
createErrorsFile
()
{
window
.
requestFileSystem
(
LocalFileSystem
.
PERSISTENT
,
0
,
function
(
fs
)
{
fs
.
root
.
getFile
(
'
errors.csv
'
,
{
create
:
true
,
exclusive
:
true
},
function
(
fileEntry
)
{
errorsFile
=
fileEntry
;
writeFile
(
errorsFile
,
new
Blob
([
'
enregistrement des erreurs
\n
'
]));
console
.
log
(
'
Errors file opened
'
);
},
function
()
{});
},
function
()
{});
}
function
writeFile
(
fileEntry
,
dataObj
)
{
fileEntry
.
createWriter
(
function
(
fileWriter
)
{
fileWriter
.
onwritend
=
function
()
{
console
.
log
(
'
x
riting successful
'
);
console
.
log
(
'
W
riting successful
'
);
}
fileWriter
.
onerror
=
function
()
{
console
.
log
(
'
Erreur d
\'
écriture
'
);
...
...
@@ -181,7 +205,7 @@ function readFile(fileEntry) {
var
reader
=
new
FileReader
();
reader
.
onloadend
=
function
()
{
console
.
log
(
'
Success :
'
+
this
.
result
);
console
.
log
(
'
Success :
\n
'
+
this
.
result
);
}
reader
.
readAsText
(
file
);
...
...
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