PhoneGap Plugin for Sensors
C Java JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
jni
js
src
test
README

README

This is a work still in progress.
This is a PhoneGap plugin that allows you to get access to the sensors available from a device.
The implementation is based on Android's NDK public interface to sensors. 


Examples of use are:

var sensorCnx = new SensorConnection('Temperature');
sensorCnx.onsensordata = function(e) {
	if(e.data > 20.0) {
		window.console.log('Temperature is too high!!!!');
	}
};

var watchOptions = { interval: (15 * 60 * 1000) };
sensorCnx.startWatch(watchOptions);

-----------

var sensorReq = navigator.sensors.list();
sensorReq.onsuccess = function() {
  for(var count = 0; count < this.result.length; count++) {
    window.console.log("Hosted Sensor: " + this.result[count].type);
  }
};
sensorReq.onerror = function() {
  window.console.error(this.error.code);
};

-------------

var accel = new SensorConnection('Accelerometer');
accel.onsensordata = function(e) {
  window.console.log("Accelerometer data: " + e.data.x + ", " + e.data.y)
};
accel.startWatch(1000);

The API spec is at http://cantera.orgfree.com/specs/sensors/latest