dorukeker / gyronorm.js

JavaScript project for accessing and normalizing the accelerometer and gyroscope data on mobile devices
MIT License
641 stars 65 forks source link

Cannot read property 'getScreenAdjustedEuler' of null #20

Closed lgg closed 8 years ago

lgg commented 8 years ago

I am using script from /dist/ w.isAvailable @ gyronorm.complete.min.js:12 image

ios8.1.4 google chrome/safari win7 last chrome+dev tools/mobile emulation in dev tools

My code:

var gn;
var Promise = Promise || ES6Promise.Promise; //fix for promises
gn = new GyroNorm();
if (gn.isAvailable(GyroNorm.ACCELERATION)) {
        console.log("device supported");
    } else {
        console.log("Sorry, your device isn't supported");
    }

The trouble is gn.isAvailable()

dorukeker commented 8 years ago

Hi, I think you are using dist/gyronorm.min.js. This does not include any dependencies. That is why you get an error from another library.

Please use dist/gyronorm.complete.min.js

Cheers, Doruk

lgg commented 8 years ago

@dorukeker Nope, I used dist/gyronorm.complete.min.js

Proof: https://jsfiddle.net/04gxf0az/

dorukeker commented 8 years ago

Now had a closer look. I see you point. The isAvailable() function works only after gn is initialised.

var gn;
var Promise = Promise || ES6Promise.Promise; //fix for promises
gn = new GyroNorm();
gn.init().then(function(){
    if (gn.isAvailable(GyroNorm.ACCELERATION)) {
        console.log("Acceleration is available");
    } else {
        console.log("Acceleration is not available");
    }
}).catch(function(e){
    console.log("Device not supported.");
    console.log(e);
})

There are two cases: 1) The device does not support orientation at all. In this case the promise will not resolve and you will get an error. 2) Device is said to be supporting, but the values returned from the device are not as expected. In this case isAvailable() function will be useful.

You can read more about it in the API here https://github.com/dorukeker/gyronorm.js/wiki/API-Documentaion#isavailable

And please note that this function is not derived from the standard, but rather from own experience and testing. The details are also in the API section.

I hope this is useful. Cheers, D.