Giter Club home page Giter Club logo

com-idoctum-deviceattitude's Introduction

com.idoctum.deviceattitude

This plugin provides access to the device's motion sensor and getting a mathematical representation of attitude as Euler angles (roll, pitch, and yaw values).

iPhone attitude

Access is via a global navigator.devicemotion object.

Although the object is attached to the global scoped navigator, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(navigator.devicemotion);
}

Installation

cordova plugin add https://github.com/bdi/com-idoctum-deviceattitude.git

Supported Platforms

  • iOS

Methods

  • navigator.devicemotion.getCurrentAttitude
  • navigator.devicemotion.watchAttitude
  • navigator.devicemotion.clearWatch

Objects

  • Attitude

navigator.devicemotion.getCurrentAttitude

Get the current attitude along the x, y, and z (roll, pitch, and yaw) axes.

These attitude values are returned to the onSuccess callback function.

navigator.devicemotion.getCurrentAttitude(onSuccess, [onError]);

Example

function onSuccess(attitude) {
    alert('Attitude alpha: ' + attitude.alpha + '\n' +
          'Attitude beta:  ' + attitude.beta  + '\n' +
          'Attitude gamma: ' + attitude.gamma + '\n' +
          'Timestamp: '  + attitude.timestamp + '\n');
};

function onError() {
    alert('onError!');
};

navigator.devicemotion.getCurrentAttitude(onSuccess, onError);

navigator.devicemotion.watchAttitude

The returned watch ID references the attitude watch interval. The watch ID can be used with navigator.devicemotion.clearWatch to stop watching the navigator.devicemotion.

var watchID = navigator.devicemotion.watchAttitude(onSuccess, [onError], [options]);

options may contain the following keys:

  • frequency: How often to retrieve the motion data in milliseconds. (Number) (Default: 1000/60 = 60 fps)

Example

function onSuccess(attitude) {
    var element = document.getElementById('attitude');
    element.innerHTML = 'Attitude alpha: ' + attitude.alpha + '<br>' +
                        'Attitude beta:  ' + attitude.beta  + '<br>' +
                        'Attitude gamma: ' + attitude.gamma + '<br>' +
                        'Timestamp: '  + attitude.timestamp + '<br>';
};

function onError(error) {
    alert('Sensor error: ' + error);
};

var options = {
    frequency: 3000
}; // Update every 3 seconds

var watchID = navigator.devicemotion.watchAttitude(onSuccess, onError, options);

iOS Quirks

Only one watchAttitude can be in effect at one time in iOS.

navigator.compass.clearWatch

Stop watching the attitude referenced by the watch ID parameter.

navigator.devicemotion.clearWatch(watchID);
  • watchID: The ID returned by navigator.devicemotion.watchAttitude.

Example

var watchID = navigator.devicemotion.watchAttitude(onSuccess, onError, options);

// ... later on ...

navigator.devicemotion.clearWatch(watchID);

Attitude

An attitude object is returned to the onSuccess callback function.

Properties

  • alpha: The roll of the device, in degree. (Number)

  • beta: The pitch of the device, in degree. (Number)

  • gamma: The yaw of the device, in degree. (Number)

  • timestamp: The time at which this attitude was determined. (milliseconds)

com-idoctum-deviceattitude's People

Contributors

bdi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.