Skip to content

Commit

Permalink
fix chrome browser rotationRate
Browse files Browse the repository at this point in the history
 - convert radians to degrees and swap rotationRate names
  • Loading branch information
Martin Hunt committed Mar 6, 2015
1 parent f1dec61 commit 042a761
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions js/accelerometer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,21 @@ if (hasNativeEvents && !device.isSimulator) {
};

fixedEvent.__proto__ = evt;
module.exports.emit('devicemotion', fixedEvent);
});
} else if (device.isMobileBrowser && device.isAndroid) {
// android chrome returns radians, not degrees
var RAD_TO_DEGREES = 180 / Math.PI;
window.addEventListener('devicemotion', function (evt) {
var fixedEvent = {
rotationRate: {
alpha: evt.rotationRate.gamma * RAD_TO_DEGREES,
beta: evt.rotationRate.alpha * RAD_TO_DEGREES,
gamma: evt.rotationRate.beta * RAD_TO_DEGREES
}
};

fixedEvent.__proto__ = evt;
module.exports.emit('devicemotion', fixedEvent);
});
} else {
Expand Down

0 comments on commit 042a761

Please sign in to comment.