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

Les débuts de la sauvegarde

parent 91810e0c
No related branches found
No related tags found
No related merge requests found
......@@ -428,6 +428,12 @@
"integrity": "sha1-FJ1RJQ3vwwnw0D0wb+KOiYgbqE0=",
"dev": true
},
"cordova-plugin-file": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/cordova-plugin-file/-/cordova-plugin-file-6.0.2.tgz",
"integrity": "sha512-m7cughw327CjONN/qjzsTpSesLaeybksQh420/gRuSXJX5Zt9NfgsSbqqKDon6jnQ9Mm7h7imgyO2uJ34XMBtA==",
"dev": true
},
"cordova-plugin-gyroscope": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/cordova-plugin-gyroscope/-/cordova-plugin-gyroscope-0.1.4.tgz",
......
......@@ -17,6 +17,7 @@
"cordova-browser": "^6.0.0",
"cordova-plugin-device-motion": "^2.0.1",
"cordova-plugin-device-orientation": "^2.0.1",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-gyroscope": "^0.1.4",
"cordova-plugin-indooratlas": "git+https://github.com/IndoorAtlas/cordova-plugin.git",
"cordova-plugin-magnetometer": "git+https://github.com/sdesalas/cordova-plugin-magnetometer.git",
......@@ -31,7 +32,8 @@
"cordova-plugin-gyroscope": {},
"cordova-plugin-magnetometer": {},
"cordova-plugin-indooratlas": {},
"cordova-plugin-sensors": {}
"cordova-plugin-sensors": {},
"cordova-plugin-file": {}
},
"platforms": [
"android",
......
......@@ -33,6 +33,7 @@ var gyroscope = navigator.gyroscope;
var magnetometer = navigator.magnetometer;
var sensors = navigator.orientation;
var rotation = navigator.rotationvector;
var saveFile;
///var IndoorAtlas = navigator.indooratlas;
......@@ -55,6 +56,19 @@ function onDeviceReady() {
navigator.gyroscope.watch((gyro) => {gyroscope = gyro;}, (error) => handleError(error), { frequency: 100 });
//start watching magneto
cordova.plugins.magnetometer.watchReadings((magn) => {magnetometer = magn;}, (error) => handleError(error), { frequency: 100 });
// 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;
console.log('File opened ; fileEntry is file ? ' + fileEntry.isFile.toString());
}, handleError);
}, handleError);
readFile(saveFile);
writeFile(saveFile, 'Je suis beau');
readFile(saveFile);
}
......@@ -69,8 +83,9 @@ function handleButtonEvent() {
+ "\n alti: " + position.coords.altitude
+ "\n heading: " + position.coords.heading
+ "\n speed: " + position.coords.speed
+ "\n accuracy: " + position.coords.accuracy;
+ "\n accuracy: " + position.coords.accuracy
}
console.log(position);
//Set acceleration in html
document.getElementById('accelerometerData').innerHTML = ""
+ " timestamp: " + acceleration.timestamp
......@@ -79,26 +94,26 @@ function handleButtonEvent() {
+ "\n Z: " + acceleration.z;
//Set gyroscope in html
document.getElementById('gyroscopeData').innerHTML = ""
+ " timestamp: " + gyroscope.timestamp
+ "\n X: " + gyroscope.x
+ "\n Y: " + gyroscope.y
+ "\n Z: " + gyroscope.z;
// document.getElementById('gyroscopeData').innerHTML = ""
// + " timestamp: " + gyroscope.timestamp
// + "\n X: " + gyroscope.x
// + "\n Y: " + gyroscope.y
// + "\n Z: " + gyroscope.z;
//Set magnetometer in html
document.getElementById('magnetometerData').innerHTML = ""
+ " timestamp: " + acceleration.timestamp
+ "\n X: " + magnetometer.x
+ "\n Y: " + magnetometer.y
+ "\n Z: " + magnetometer.z;
// document.getElementById('magnetometerData').innerHTML = ""
// + " timestamp: " + acceleration.timestamp
// + "\n X: " + magnetometer.x
// + "\n Y: " + magnetometer.y
// + "\n Z: " + magnetometer.z;
//TODO: save to file / db
// save(position, acceleration, gyroscope, magnetometer);
}
function handleError(error) {
//TODO: log error to error file / db
console.log('error');
console.log(error);
}
function startOrStopTimer() {
......@@ -109,3 +124,32 @@ function startOrStopTimer() {
timer = null;
}
}
function writeFile(fileEntry, dataObj) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwritend = function() {
console.log('xriting successful');
}
fileWriter.onerror = function() {
console.log('Erreur d\'écriture');
}
if (dataObj) {
console.log('pas de données d\'entrée');
}
fileWriter.write(dataObj);
});
}
function readFile(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function() {
console.log('Success : ' + this.result);
}
reader.readAsText(file);
}, handleError);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment