You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+82-23Lines changed: 82 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,42 +8,55 @@ Add the JS file to your HTML
8
8
9
9
<script src="js/gyronorm.js"></script>
10
10
11
-
Initialiize and start the <em>gn</em> object
11
+
Initialize and start the <em>gn</em> object. Good practice is to start the object in the `ready` callback function, which you pass when initializing.
12
12
13
13
Access the values in the callback function of the `gn.start()`
14
14
15
15
<script src="/js/gyronorm.js"></script>
16
16
17
-
var gn = new GyroNorm();
18
-
gn.start(function(data){
19
-
// Process:
17
+
var args = {read:ongnReady};
18
+
var gn = new GyroNorm(args);
19
+
20
+
var ongnReady = function(){
21
+
gn.start(function(data){
22
+
// Process:
20
23
// data.do.alpha ( deviceorientation event alpha value )
21
24
// data.do.beta ( deviceorientation event beta value )
22
25
// data.do.gamma ( deviceorientation event gamma value )
23
26
// data.do.absolute ( deviceorientation event absolute value )
24
-
27
+
25
28
// data.dm.x ( devicemotion event acceleration x value )
26
29
// data.dm.y ( devicemotion event acceleration y value )
27
30
// data.dm.z ( devicemotion event acceleration z value )
28
-
31
+
29
32
// data.dm.gx ( devicemotion event accelerationIncludingGravity x value )
30
33
// data.dm.gy ( devicemotion event accelerationIncludingGravity y value )
31
34
// data.dm.gz ( devicemotion event accelerationIncludingGravity z value )
32
-
35
+
33
36
// data.dm.alpha ( devicemotion event rotationRate alpha value )
34
37
// data.dm.beta ( devicemotion event rotationRate beta value )
35
38
// data.dm.gamma ( devicemotion event rotationRate gamma value )
36
39
});
40
+
}
41
+
42
+
###Backward Compatibility
43
+
In the previous version you were able to initialize and start the <em>gn</em> object directly, without the `ready` function
44
+
45
+
var gn = new GyroNorm();
46
+
gn.start(function(data){ ... });
47
+
48
+
This method still works. However the return values from the `gn.isAvailable()` function will not be reliable. I recommend to use the `ready` callback function as described above.
37
49
38
50
###Options
39
-
You can pass arguments as an object to the `gn.init()` method. The values you pass overwrites the default values. Below is the list of available options and their default values.
51
+
You can pass arguments as an object to the to the constructor method. The values you pass overwrites the default values. Below is the list of available options and their default values.
40
52
41
53
var args = {
42
54
frequency:50, // ( how often the object sends the values - milliseconds )
43
55
gravityNormalized:true, // ( if the garvity related values to be normalized )
44
56
directionAbsolute:false, // ( if the do.alpha value is absolute, if false the value is relative to the initial position of the device )
45
57
decimalCount:2 // ( how many digits after the decimal point wil there be in the return values )
46
58
logger:null // ( function to be called to log messages from GyroNorm )
59
+
ready:null // ( callback function to be called when the availability of the events and values are known )
47
60
}
48
61
49
62
var gn = new GyroNorm(args);
@@ -74,7 +87,44 @@ Starts returning values via the callback function. The callback function is call
74
87
75
88
callback - function(data) - Function that returns values via the <em>data</em> object. The available values via <em>data</em> are listed above.
76
89
90
+
####isAvailable()
91
+
92
+
Tells the availability of device orientation or device motion values on the device+browser combination.
93
+
94
+
#####Syntax
95
+
96
+
gn.isAvailable(valueType);
97
+
98
+
// or
99
+
100
+
gn.isAvailable();
101
+
102
+
#####Parameters
103
+
104
+
valueType - string - optional - If passed, the method returns `true` or `false`, depending on the availablity of the specified value. Possible values are `deviceorientation`,`acceleration`,`accelerationinludinggravity`,`rotationrate` or `compassneedscalibration`
105
+
106
+
When called without a parameter returns availibility for values.
77
107
108
+
#####Example
109
+
110
+
var args = {ready:ongnReady};
111
+
var gn = new GyroNorm(args);
112
+
var ongnReady = function(){
113
+
var doAvailable = gn.isAvailable("deviceorientation");
114
+
// Parameter can also be "acceleration","accelerationinludinggravity","rotationrate" or "compassneedscalibration"
115
+
// This example returns true if deviceorientation is available. Returns false if not.
@@ -90,10 +140,13 @@ flag - boolean - <em>true</em> sets the option <em>gravityNormalized</em> on, <e
90
140
91
141
#####Example
92
142
93
-
var gn = new GyroNorm();
94
-
gn.start(function(){
95
-
// Process return values here
96
-
});
143
+
var args = {ready:ongnReady};
144
+
var gn = new GyroNorm(args);
145
+
var ongnReady = function(){
146
+
gn.start(function(){
147
+
// Process return values here
148
+
});
149
+
}
97
150
98
151
// At this point callback function returns normalized gravity-related values.
99
152
@@ -115,10 +168,13 @@ flag - boolean - <em>true</em> sets the option <em>directionAbsolute</em> on, <e
115
168
116
169
#####Example
117
170
118
-
var gn = new GyroNorm();
119
-
gn.start(function(){
120
-
// Process return values here
121
-
});
171
+
var args = {ready:ongnReady};
172
+
var gn = new GyroNorm(args);
173
+
var ongnReady = function(){
174
+
gn.start(function(){
175
+
// Process return values here
176
+
});
177
+
}
122
178
123
179
// At this point callback function returns do.alpha values relative to the initial position of the device
124
180
@@ -138,16 +194,19 @@ Once this method is called <em>directionAbsolute</em> option is also set to <em>
138
194
139
195
#####Example
140
196
141
-
var gn = new GyroNorm();
142
-
gn.start(function(){
143
-
// Process return values here
144
-
});
197
+
var args = {ready:ongnReady};
198
+
var gn = new GyroNorm(args);
199
+
var ongnReady = function(){
200
+
gn.start(function(){
201
+
// Process return values here
202
+
});
203
+
}
145
204
146
205
// At this point callback function returns do.alpha values relative to the initial position of the device
147
206
148
207
gn.setHeadDirection();
149
208
150
-
// At this point callback function returns do.alpha values relative to the position of the device when the above line is called
209
+
// At this point callback function starts to return do.alpha values relative to the position of the device when the above line is called
151
210
152
211
####stop()
153
212
@@ -217,7 +276,7 @@ The human-readable message.
217
276
218
277
Below is a list of device/operating system/browser combinations. The demo.html file worked on them out of the box. I will update this list in the future. Please also share your findings so we can have a more complete list.
219
278
220
-
- iPhone 5 - iOS 8 beta - Safari
279
+
- iPhone 5 - iOS 8.0.2 - Safari
221
280
- iPhone 4 - iOS 6.x - Safari
222
281
- HTC One - Android 4.2.2 - Native Browser
223
282
- HTC One - Android 4.2.2 - Chrome 35.0.1916.141
@@ -231,8 +290,8 @@ Below is a list of things I plan to add in the future. Please note that it is no
231
290
232
291
- Option to track deviceorientation and devicemotion events seperately
233
292
- Providing alpha values even in the calibration mode
234
-
- Boolean values to check if events are available in the device
235
293
- Option to get snap shot of the values (currently it is only tracking)
294
+
- Boolean value to check if GyroNorm is tracking or not
0 commit comments