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

Commentaires

parent 9e169fd2
No related branches found
No related tags found
No related merge requests found
......@@ -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 files from last session
clearFile('sessionData.csv');
setTimeout(clearFile, 100, 'errors.csv');
// Creating a file to save data
// Creating files 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 FUNCTIONS
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, 1000)
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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment