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
|
define.class("$system/base/node", function(require) {
this.name = "accelerometer";
this.attributes = {
supported:Config({type:Boolean, value:false}),
acceleration:Config({type:vec3, value:vec3(0,0,0)}),
x: Config({alias:'acceleration', index:0}),
y: Config({alias:'acceleration', index:1}),
z: Config({alias:'acceleration', index:2})
};
this.init = function() {
window.addEventListener('devicemotion', function(ev) {
var accel = ev.accelerationIncludingGravity
if (accel) {
for (var key in accel) {
if (accel.hasOwnProperty(key)) {
var value = ev.accelerationIncludingGravity[key]
if (typeof(value) !== "undefined") {
if (!this._supported) {
this.supported = true;
}
this[key] = value
}
}
}
}
}.bind(this));
};
var accelerometer = this.constructor;
this.constructor.examples = {
Usage: function() {
var label = require("$ui/label");
return [
accelerometer({
onacceleration:function(ev,v,o) {
o.find("accel").text = "Current acceleration is x:" + v[0] +", y:" + v[1] + ", z:" + v[2]
}
}),
label({name:"accel", text:"Searching for accelerometer ..."})
]
}
}
});
|