-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgyronorm-element.html
More file actions
102 lines (79 loc) · 3.56 KB
/
Copy pathgyronorm-element.html
File metadata and controls
102 lines (79 loc) · 3.56 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!-- Add gyronorm.js including all dependencies -->
<script type="text/javascript" src="/bower_components/gyronorm/dist/gyronorm.complete.min.js"></script>
<dom-module id="gyronorm-element">
<script>
Polymer({
is: "gyronorm-element",
properties:{
// Values for the deviceorientation and devicemotion as return from the Gyronorm.js
alpha:{type: Number , notify: true , value: 0 , readOnly: true},
beta:{type: Number , notify: true , value: 0 , readOnly: true},
gamma:{type: Number , notify: true , value: 0 , readOnly: true},
accelerationX:{type: Number , notify: true , value: 0 , readOnly: true},
accelerationY:{type: Number , notify: true , value: 0 , readOnly: true},
accelerationZ:{type: Number , notify: true , value: 0 , readOnly: true},
gravityX:{type: Number , notify: true , value: 0 , readOnly: true},
gravityY:{type: Number , notify: true , value: 0 , readOnly: true},
gravityZ:{type: Number , notify: true , value: 0 , readOnly: true},
rotationRateAlpha:{type: Number , notify: true , value: 0 , readOnly: true},
rotationRateBeta:{type: Number , notify: true , value: 0 , readOnly: true},
rotationRateGamma:{type: Number , notify: true , value: 0 , readOnly: true},
// Log message attribute to pass the logs to the host
logMessage:{type: String , notify: true , value: '', readOnly: true},
decimalCount:{type: Number, value: 2, observer: '_initGyronorm'},
frequency:{type: Number, value: 50, observer: '_initGyronorm'},
gravityNormalized:{type: Boolean, value: true, observer: '_onGravityNormalizedChanged'},
orientationBase:{type: String, value: GyroNorm.GAME, observer: '_initGyronorm'},
screenAdjusted:{type: Boolean, value: false, observer: '_initGyronorm'},
},
ready: function(){
this._initGyronorm();
},
_initGyronorm: function(){
if(this.gn){
this.gn.stop();
}
if(this.orientationBase !== GyroNorm.GAME && this.orientationBase !== GyroNorm.WORLD){
this.orientationBase = GyroNorm.GAME;
}
this.gn = new GyroNorm();
var args = {
logger:this._onLogHandler,
decimalCount: this.decimalCount,
frequency: this.frequency,
gravityNormalized: this.gravityNormalized,
orientationBase:this.orientationBase,
screenAdjusted:this.screenAdjusted
};
// Initialize gn object.
this.gn.init(args).then(function(){
this.gn.start(function(data){
this._setAlpha(data.do.alpha);
this._setBeta(data.do.beta);
this._setGamma(data.do.gamma);
this._setAccelerationX(data.dm.x);
this._setAccelerationY(data.dm.y);
this._setAccelerationZ(data.dm.z);
this._setGravityX(data.dm.gx);
this._setGravityY(data.dm.gy);
this._setGravityZ(data.dm.gz);
this._setRotationRateAlpha(data.dm.alpha);
this._setRotationRateBeta(data.dm.beta);
this._setRotationRateGamma(data.dm.gamma);
}.bind(this));
}.bind(this)).catch(function(e){
this._setLogMessage(e);
}.bind(this));
},
_onLogHandler: function(data){
this._setLogMessage(data.message);
},
_onGravityNormalizedChanged: function(){
this.gn.normalizeGravity(this.gravityNormalized);
},
setHeadDirection: function(){
this.gn.setHeadDirection();
}
});
</script>
</dom-module>