GRAVITY: 'GRAVITY',
GYROSCOPE: 'GYROSCOPE',
GYROSCOPE_ROTATION_VECTOR: 'GYROSCOPE_ROTATION_VECTOR',
- LINEAR_ACCELERATION: 'LINEAR_ACCELERATION'
+ LINEAR_ACCELERATION: 'LINEAR_ACCELERATION',
+ MAGNETIC_UNCALIBRATED: 'MAGNETIC_UNCALIBRATED',
+ GYROSCOPE_UNCALIBRATED: 'GYROSCOPE_UNCALIBRATED',
+ ACCELERATION: 'ACCELERATION'
};
var ProximityState = {
SensorListener.prototype.stop = function() {
if (SensorStates.NOT_STARTED != this.state) {
- var result = native_.callSync('Sensor_stop', {
- sensorType: this.sensorType
- });
+ var result = native_.callSync('Sensor_stop', { sensorType: this.sensorType });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
GRAVITY: {},
GYROSCOPE: {},
GYROSCOPE_ROTATION_VECTOR: {},
- LINEAR_ACCELERATION: {}
+ LINEAR_ACCELERATION: {},
+ MAGNETIC_UNCALIBRATED: {},
+ GYROSCOPE_UNCALIBRATED: {},
+ ACCELERATION: {}
};
var errorWrapper = function(err) {
return new GyroscopeRotationVectorSensor();
} else if (_supportedSensors[index] === SensorType.LINEAR_ACCELERATION) {
return new LinearAccelerationSensor();
+ } else if (_supportedSensors[index] === SensorType.MAGNETIC_UNCALIBRATED) {
+ return new MagneticUncalibratedSensor();
+ } else if (_supportedSensors[index] === SensorType.GYROSCOPE_UNCALIBRATED) {
+ return new GyroscopeUncalibratedSensor();
+ } else if (_supportedSensors[index] === SensorType.ACCELERATION) {
+ return new AccelerationSensor();
}
}
return _supportedSensors.slice();
};
-//////////////////////Sensor classes//////////////////////
+//////////////////////Sensor classes/////////////////////////////
//// Base Sensor class
var Sensor = function(type) {
Object.defineProperties(this, {
GyroscopeRotationVectorSensor.prototype = new Sensor();
GyroscopeRotationVectorSensor.prototype.constructor = Sensor;
-
// prettier-ignore
GyroscopeRotationVectorSensor.prototype.getGyroscopeRotationVectorSensorData =
function() {
);
};
-////////////////////// Sensor Data classes//////////////////////
+//// MagneticUncalibratedSensor
+var MagneticUncalibratedSensor = function(data) {
+ Sensor.call(this, SensorType.MAGNETIC_UNCALIBRATED);
+};
+
+MagneticUncalibratedSensor.prototype = new Sensor();
+
+MagneticUncalibratedSensor.prototype.constructor = Sensor;
+
+MagneticUncalibratedSensor.prototype.getMagneticUncalibratedSensorData = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
+
+ _sensorListeners[this.sensorType].getData(
+ args.successCallback,
+ errorWrapper.bind(args)
+ );
+};
+
+//// GyroscopeUncalibratedSensor
+var GyroscopeUncalibratedSensor = function(data) {
+ Sensor.call(this, SensorType.GYROSCOPE_UNCALIBRATED);
+};
+
+GyroscopeUncalibratedSensor.prototype = new Sensor();
+
+GyroscopeUncalibratedSensor.prototype.constructor = Sensor;
+
+GyroscopeUncalibratedSensor.prototype.getGyroscopeUncalibratedSensorData = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
+
+ _sensorListeners[this.sensorType].getData(
+ args.successCallback,
+ errorWrapper.bind(args)
+ );
+};
+
+//// AccelerationSensor
+var AccelerationSensor = function(data) {
+ Sensor.call(this, SensorType.ACCELERATION);
+};
+
+AccelerationSensor.prototype = new Sensor();
+
+AccelerationSensor.prototype.constructor = Sensor;
+
+AccelerationSensor.prototype.getAccelerationSensorData = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'successCallback',
+ type: types_.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
+
+ _sensorListeners[this.sensorType].getData(
+ args.successCallback,
+ errorWrapper.bind(args)
+ );
+};
+
+////////////////////// Sensor Data classes/////////////////////////////
////Base SensorData class
var SensorData = function() {};
var SensorLightData = function(data) {
SensorData.call(this);
Object.defineProperties(this, {
- lightLevel: {
- value: data.lightLevel,
- writable: false,
- enumerable: true
- }
+ lightLevel: { value: data.lightLevel, writable: false, enumerable: true }
});
};
var SensorProximityData = function(data) {
SensorData.call(this);
Object.defineProperties(this, {
- proximityState: {
- value: data.proximityState,
- writable: false,
- enumerable: true
- }
+ proximityState: { value: data.proximityState, writable: false, enumerable: true }
});
};
SensorData.call(this);
Object.defineProperties(this, {
lightType: { value: data.lightType, writable: false, enumerable: true },
- lightIntensity: {
- value: data.lightIntensity,
- writable: false,
- enumerable: true
- }
+ lightIntensity: { value: data.lightIntensity, writable: false, enumerable: true }
});
};
SensorLinearAccelerationData
);
-//////////////////////SensorHardwareInfo classes//////////////////////
+//// SensorMagneticUncalibratedData
+var SensorMagneticUncalibratedData = function(data) {
+ SensorData.call(this);
+ Object.defineProperties(this, {
+ x: { value: data.x, writable: false, enumerable: true },
+ y: { value: data.y, writable: false, enumerable: true },
+ z: { value: data.z, writable: false, enumerable: true },
+ xAxisBias: { value: data.xAxisBias, writable: false, enumerable: true },
+ yAxisBias: { value: data.yAxisBias, writable: false, enumerable: true },
+ zAxisBias: { value: data.zAxisBias, writable: false, enumerable: true }
+ });
+};
+
+SensorMagneticUncalibratedData.prototype = new SensorData();
+
+SensorMagneticUncalibratedData.prototype.constructor = SensorData;
+
+_sensorListeners[SensorType.MAGNETIC_UNCALIBRATED] = new SensorListener(
+ SensorType.MAGNETIC_UNCALIBRATED,
+ SensorMagneticUncalibratedData
+);
+
+//// SensorGyroscopeUncalibratedData
+var SensorGyroscopeUncalibratedData = function(data) {
+ SensorData.call(this);
+ Object.defineProperties(this, {
+ x: { value: data.x, writable: false, enumerable: true },
+ y: { value: data.y, writable: false, enumerable: true },
+ z: { value: data.z, writable: false, enumerable: true },
+ xAxisDrift: { value: data.xAxisDrift, writable: false, enumerable: true },
+ yAxisDrift: { value: data.yAxisDrift, writable: false, enumerable: true },
+ zAxisDrift: { value: data.zAxisDrift, writable: false, enumerable: true }
+ });
+};
+
+SensorGyroscopeUncalibratedData.prototype = new SensorData();
+
+SensorGyroscopeUncalibratedData.prototype.constructor = SensorData;
+
+_sensorListeners[SensorType.GYROSCOPE_UNCALIBRATED] = new SensorListener(
+ SensorType.GYROSCOPE_UNCALIBRATED,
+ SensorGyroscopeUncalibratedData
+);
+
+//// SensorAccelerationData
+var SensorAccelerationData = function(data) {
+ SensorData.call(this);
+ Object.defineProperties(this, {
+ x: { value: data.x, writable: false, enumerable: true },
+ y: { value: data.y, writable: false, enumerable: true },
+ z: { value: data.z, writable: false, enumerable: true }
+ });
+};
+
+SensorAccelerationData.prototype = new SensorData();
+
+SensorAccelerationData.prototype.constructor = SensorData;
+
+_sensorListeners[SensorType.ACCELERATION] = new SensorListener(
+ SensorType.ACCELERATION,
+ SensorAccelerationData
+);
+
+//////////////////////SensorHardwareInfo classes/////////////////////////////
function SensorHardwareInfo(data) {
Object.defineProperties(this, {
name: { value: data.name, writable: false, enumerable: true },
vendor: { value: data.vendor, writable: false, enumerable: true },
minValue: { value: data.minValue, writable: false, enumerable: true },
maxValue: { value: data.maxValue, writable: false, enumerable: true },
- resolution: {
- value: data.resolution,
- writable: false,
- enumerable: true
- },
- minInterval: {
- value: data.minInterval,
- writable: false,
- enumerable: true
- },
- maxBatchCount: {
- value: data.batchCount,
- writable: false,
- enumerable: true
- }
+ resolution: { value: data.resolution, writable: false, enumerable: true },
+ minInterval: { value: data.minInterval, writable: false, enumerable: true },
+ maxBatchCount: { value: data.batchCount, writable: false, enumerable: true }
});
}
// Exports