Merge remote-tracking branch 'origin/tizen_3.0' into tizen_4.0
[platform/core/api/webapi-plugins.git] / src / sensor / sensor_api.js
index 17d280a..9305c4f 100755 (executable)
@@ -33,7 +33,10 @@ var SensorType = {
     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 = {
@@ -99,9 +102,7 @@ SensorListener.prototype.start = function(successCallback, errorCallback) {
 
 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);
         }
@@ -182,7 +183,10 @@ var _sensorListeners = {
     GRAVITY: {},
     GYROSCOPE: {},
     GYROSCOPE_ROTATION_VECTOR: {},
-    LINEAR_ACCELERATION: {}
+    LINEAR_ACCELERATION: {},
+    MAGNETIC_UNCALIBRATED: {},
+    GYROSCOPE_UNCALIBRATED: {},
+    ACCELERATION: {}
 };
 
 var errorWrapper = function(err) {
@@ -251,6 +255,12 @@ function getDefaultSensor() {
         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();
     }
 }
 
@@ -266,7 +276,7 @@ SensorService.prototype.getAvailableSensors = function() {
     return _supportedSensors.slice();
 };
 
-//////////////////////Sensor classes//////////////////////
+//////////////////////Sensor classes/////////////////////////////
 //// Base Sensor class
 var Sensor = function(type) {
     Object.defineProperties(this, {
@@ -595,7 +605,6 @@ var GyroscopeRotationVectorSensor = function(data) {
 GyroscopeRotationVectorSensor.prototype = new Sensor();
 
 GyroscopeRotationVectorSensor.prototype.constructor = Sensor;
-
 // prettier-ignore
 GyroscopeRotationVectorSensor.prototype.getGyroscopeRotationVectorSensorData =
 function() {
@@ -647,7 +656,94 @@ LinearAccelerationSensor.prototype.getLinearAccelerationSensorData = 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() {};
 
@@ -655,11 +751,7 @@ 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 }
     });
 };
 
@@ -713,11 +805,7 @@ _sensorListeners[SensorType.PRESSURE] = new SensorListener(
 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 }
     });
 };
 
@@ -756,11 +844,7 @@ var SensorHRMRawData = function(data) {
     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 }
     });
 };
 
@@ -850,7 +934,70 @@ _sensorListeners[SensorType.LINEAR_ACCELERATION] = new SensorListener(
     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 },
@@ -858,21 +1005,9 @@ function SensorHardwareInfo(data) {
         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