-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmotion-only.js
85 lines (71 loc) · 1.72 KB
/
motion-only.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { Button, TextView, ui } = require('tabris')
function onSuccess(acceleration) {
txvAccelerationX.text = 'Acceleration X: ' + acceleration.x
txvAccelerationY.text = 'Acceleration Y: ' + acceleration.y
txvAccelerationZ.text = 'Acceleration Z: ' + acceleration.z
txvTimeStamp.text = 'Timestamp: ' + getFormattedDate(acceleration.timestamp)
}
function onError() {
console.log('onError!')
}
// updates every 1/4 second, 250 ms.
const options = { frequency: 250 }
let watchID = navigator.accelerometer.watchAcceleration(
onSuccess,
onError,
options
)
let txvAccelerationX = new TextView({
left: 10,
top: 'prev() 10',
right: 10,
text: 'Acceleration X: ',
alignment: 'left'
}).appendTo(ui.contentView)
let txvAccelerationY = new TextView({
left: 10,
top: 'prev() 10',
right: 10,
text: 'Acceleration Y: ',
alignment: 'left'
}).appendTo(ui.contentView)
let txvAccelerationZ = new TextView({
left: 10,
top: 'prev() 10',
right: 10,
text: 'Acceleration Z: ',
alignment: 'left'
}).appendTo(ui.contentView)
let txvTimeStamp = new TextView({
left: 10,
top: 'prev() 10',
right: 10,
text: 'Timestamp: ',
alignment: 'left'
}).appendTo(ui.contentView)
function getFormattedDate () {
let date = new Date()
let month = date.getMonth() + 1
let day = date.getDate()
let hour = date.getHours()
let min = date.getMinutes()
let sec = date.getSeconds()
month = (month < 10 ? '0' : '') + month
day = (day < 10 ? '0' : '') + day
hour = (hour < 10 ? '0' : '') + hour
min = (min < 10 ? '0' : '') + min
sec = (sec < 10 ? '0' : '') + sec
let str =
date.getFullYear() +
'-' +
month +
'-' +
day +
' » ' +
hour +
':' +
min +
':' +
sec
return str
}