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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
20-projet-ce-2020
SensorApp
Commits
03f6f634
Commit
03f6f634
authored
4 years ago
by
Augustin Jaujay
Browse files
Options
Downloads
Patches
Plain Diff
Enregistrement fonctionnel
parent
ce89ad7b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
www/index.html
+1
-2
1 addition, 2 deletions
www/index.html
www/js/index.js
+43
-9
43 additions, 9 deletions
www/js/index.js
with
44 additions
and
11 deletions
www/index.html
+
1
−
2
View file @
03f6f634
...
...
@@ -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>
...
...
This diff is collapsed.
Click to expand it.
www/js/index.js
+
43
−
9
View file @
03f6f634
...
...
@@ -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
,
100
0
)
}
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
);
});
}
...
...
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