1.0.2 • Published 8 years ago

cordova-plugin-barometer v1.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

cordova-plugin-barometer

This plugin provides access to the device's barometer.

This plugin based on https://github.com/zanderso/cordova-plugin-barometer. Thanks Zachary Anderson for this work.

Installation

cordova plugin add cordova-plugin-barometer (from npm)
cordova plugin add https://github.com/olton/cordova-plugin-barometer.git (from git)

Supported Platforms

  • Android

Methods

  • navigator.barometer.getCurrentPressure
  • navigator.barometer.watchPressure
  • navigator.barometer.clearWatch

Objects

  • Pressure

navigator.barometer.getCurrentPressure

Get the current atmospheric pressure.

The pressure values are returned to the barometerSuccess callback function.

navigator.barometer.getCurrentPressure(barometerSuccess, barometerError);

Example

function onSuccess(pressure) {
    alert('Pressure: '  + pressure.val + '\n' +
          'Timestamp: ' + pressure.timestamp + '\n');
};

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

navigator.barometer.getCurrentPressure(onSuccess, onError);

navigator.barometer.watchPressure

Retrieves the device's current Pressure at a regular interval, executing the barometerSuccess callback function each time. Specify the interval in milliseconds via the barometerOptions object's frequency parameter.

The returned watch ID references the barometers's watch interval, and can be used with navigator.barometer.clearWatch to stop watching the accelerometer.

var watchID = navigator.barometer.watchPressure(barometerSuccess,
                                                barometerError,
                                                [barometerOptions]);
  • barometerOptions: An object with the following optional keys:
  • frequency: How often to retrieve the Pressure in milliseconds. (Number) (Default: 10000)

Example

function onSuccess(pressure) {
    alert('Pressure: '  + pressure.val + '\n' +
          'Timestamp: ' + pressure.timestamp + '\n');
};

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

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

var watchID = navigator.barometer.watchPressure(onSuccess, onError, options);

navigator.barometer.clearWatch

Stop watching the Pressure referenced by the watchID parameter.

navigator.barometer.clearWatch(watchID);
  • watchID: The ID returned by navigator.barometer.watchPressure.

Example

var watchID = navigator.barometer.watchPressure(onSuccess, onError, options);

// ... later on ...

navigator.barometer.clearWatch(watchID);

Pressure

Contains Pressure data captured at a specific point in time.

Properties

  • val: Amount of pressure. (Number)
  • timestamp: Creation timestamp in milliseconds. (DOMTimeStamp)
1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago