Skip to content
Snippets Groups Projects
Commit 03f6f634 authored by Augustin Jaujay's avatar Augustin Jaujay
Browse files

Enregistrement fonctionnel

parent ce89ad7b
Branches
No related tags found
No related merge requests found
......@@ -41,6 +41,7 @@
</head>
<body>
<div class="app">
<p><button onclick="startOrStopTimer()">Start 10Hz signal</button></p>
<h1>Apache Cordova</h1>
<h3>GPS</h3>
<pre><code id="gpsData"></code></pre>
......@@ -53,8 +54,6 @@
<h3>Magnetometer</h3>
<pre><code id="magnetometerData"></code></pre>
<button onclick="startOrStopTimer()">Start 10Hz signal</button>
</div>
<script src="cordova.js"></script>
<script type="text/javascript" src="js/APIKeys.js"></script>
......
......@@ -57,18 +57,27 @@ function onDeviceReady() {
//start watching magneto
cordova.plugins.magnetometer.watchReadings((magn) => {magnetometer = magn;}, (error) => handleError(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);
// Creating a file to save data
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
console.log('file system open : ' + fs.name);
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);
readFile(saveFile);
writeFile(saveFile, 'Je suis beau');
readFile(saveFile);
}
......@@ -85,7 +94,6 @@ function handleButtonEvent() {
+ "\n speed: " + position.coords.speed
+ "\n accuracy: " + position.coords.accuracy
}
console.log(position);
//Set acceleration in html
document.getElementById('accelerometerData').innerHTML = ""
+ " timestamp: " + acceleration.timestamp
......@@ -108,7 +116,7 @@ function handleButtonEvent() {
// + "\n Z: " + magnetometer.z;
//TODO: save to file / db
// save(position, acceleration, gyroscope, magnetometer);
save(position, acceleration, gyroscope, magnetometer);
}
function handleError(error) {
......@@ -118,13 +126,38 @@ function handleError(error) {
function startOrStopTimer() {
if (!timer) {
timer = setInterval(handleButtonEvent, 100)
timer = setInterval(handleButtonEvent, 1000)
} else {
clearInterval(timer);
timer = null;
}
}
function save(positionData, accelerationData, gyroscopeData, magnetometerData) {
newLine = `${positionData.timestamp};
${positionData.coords.latitude};
${positionData.coords.longitude};
${positionData.coords.altitude};
${positionData.coords.heading};
${positionData.coords.speed};
${positionData.coords.accuracy};
${accelerationData.timestamp};
${accelerationData.x};
${accelerationData.y};
${accelerationData.z}\n`;
// ${gyroscopeData.timestamp};
// ${gyroscopeData.x};
// ${gyroscopeData.y};
// ${gyroscopeData.z};
// ${accelerationData.timestamp};
// ${magnetometerData.x};
// ${magnetometer.y};
// ${magnetometer.z}\n`;
writeFile(saveFile, new Blob([newLine]));
readFile(saveFile);
}
function writeFile(fileEntry, dataObj) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwritend = function() {
......@@ -134,10 +167,11 @@ function writeFile(fileEntry, dataObj) {
console.log('Erreur d\'écriture');
}
if (dataObj) {
if (!dataObj) {
console.log('pas de données d\'entrée');
}
fileWriter.seek(fileWriter.length);
fileWriter.write(dataObj);
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment