[Sensor] Adding new sensor type 08/87308/4
authorMichal Kolodziej <m.kolodziej@samsung.com>
Mon, 29 Aug 2016 08:10:43 +0000 (10:10 +0200)
committerMichal Kolodziej <m.kolodziej@samsung.com>
Tue, 20 Sep 2016 08:48:59 +0000 (10:48 +0200)
[Feature] Added linear acceleration sensor

Change-Id: I2f8f3b3d12ad68cb4d1853bb748e5f544b1290a7
Signed-off-by: Michal Kolodziej <m.kolodziej@samsung.com>
src/sensor/sensor_api.js
src/sensor/sensor_service.cc

index d590e63ebe48173282ce62c0a3ec3acbcc8c5a00..9c810e819ebfbcb80c546774d69acf7ce1b68e1c 100755 (executable)
@@ -33,6 +33,7 @@ var SensorType = {
     GRAVITY : 'GRAVITY',
     GYROSCOPE : 'GYROSCOPE',
     GYROSCOPE_ROTATION_VECTOR : 'GYROSCOPE_ROTATION_VECTOR',
+    LINEAR_ACCELERATION : 'LINEAR_ACCELERATION'
 };
 
 var ProximityState = {
@@ -156,6 +157,7 @@ var _sensorListeners = {
     'GRAVITY'     : {},
     'GYROSCOPE'   : {},
     'GYROSCOPE_ROTATION_VECTOR' : {},
+    'LINEAR_ACCELERATION' : {}
 };
 
 var _listener = function(object) {
@@ -212,6 +214,8 @@ function getDefaultSensor() {
         return new GyroscopeSensor();
     } else if (_supportedSensors[index] === SensorType.GYROSCOPE_ROTATION_VECTOR){
         return new GyroscopeRotationVectorSensor();
+    } else if (_supportedSensors[index] === SensorType.LINEAR_ACCELERATION){
+        return new LinearAccelerationSensor();
     }
 };
 
@@ -502,7 +506,14 @@ GravitySensor.prototype.getGravitySensorData = function() {
        }
     ]);
 
-    _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
+    function errorWrapper(err) {
+        if (err.name === "UnknownError") {
+            args.errorCallback(new WebAPIException(WebAPIException.ABORT_ERR, err.message));
+        } else {
+            args.errorCallback(err);
+        }
+    }
+    _sensorListeners[this.sensorType].getData(args.successCallback, errorWrapper);
 };
 
 
@@ -529,7 +540,14 @@ GyroscopeSensor.prototype.getGyroscopeSensorData = function() {
        }
     ]);
 
-    _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
+    function errorWrapper(err) {
+        if (err.name === "UnknownError") {
+            args.errorCallback(new WebAPIException(WebAPIException.ABORT_ERR, err.message));
+        } else {
+            args.errorCallback(err);
+        }
+    }
+    _sensorListeners[this.sensorType].getData(args.successCallback, errorWrapper);
 };
 
 //// GyroscopeRotationVectorSensor
@@ -555,9 +573,50 @@ GyroscopeRotationVectorSensor.prototype.getGyroscopeRotationVectorSensorData = f
        }
     ]);
 
-    _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
+    function errorWrapper(err) {
+        if (err.name === "UnknownError") {
+            args.errorCallback(new WebAPIException(WebAPIException.ABORT_ERR, err.message));
+        } else {
+            args.errorCallback(err);
+        }
+    }
+    _sensorListeners[this.sensorType].getData(args.successCallback, errorWrapper);
 };
 
+//// LinearAccelerationSensor
+var LinearAccelerationSensor = function(data) {
+    Sensor.call(this, SensorType.LINEAR_ACCELERATION);
+};
+
+LinearAccelerationSensor.prototype = new Sensor();
+
+LinearAccelerationSensor.prototype.constructor = Sensor;
+
+LinearAccelerationSensor.prototype.getLinearAccelerationSensorData = function() {
+    var args = validator_.validateArgs(arguments, [
+       {
+           name : 'successCallback',
+           type : types_.FUNCTION
+       },
+       {
+           name : 'errorCallback',
+           type : types_.FUNCTION,
+           optional : true,
+           nullable : true
+       }
+    ]);
+
+    function errorWrapper(err) {
+        if (err.name === "UnknownError") {
+            args.errorCallback(new WebAPIException(WebAPIException.ABORT_ERR, err.message));
+        } else {
+            args.errorCallback(err);
+        }
+    }
+    _sensorListeners[this.sensorType].getData(args.successCallback, errorWrapper);
+};
+
+
 ////////////////////// Sensor Data classes/////////////////////////////////////////////////////
 ////Base SensorData class
 var SensorData = function () {
@@ -676,8 +735,6 @@ SensorGravityData.prototype.constructor = SensorData;
 _sensorListeners[SensorType.GRAVITY] = new SensorListener(SensorType.GRAVITY,
         SensorGravityData);
 
-
-
 //// SensorGyroscopeData
 var SensorGyroscopeData = function(data) {
     SensorData.call(this);
@@ -713,6 +770,24 @@ SensorGyroscopeRotationVectorData.prototype.constructor = SensorData;
 _sensorListeners[SensorType.GYROSCOPE_ROTATION_VECTOR] = new SensorListener(SensorType.GYROSCOPE_ROTATION_VECTOR,
         SensorGyroscopeRotationVectorData);
 
+//// SensorLinearAccelerationData
+var SensorLinearAccelerationData = 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},
+    });
+};
+
+SensorLinearAccelerationData.prototype = new SensorData();
+
+SensorLinearAccelerationData.prototype.constructor = SensorData;
+
+_sensorListeners[SensorType.LINEAR_ACCELERATION] = new SensorListener(SensorType.LINEAR_ACCELERATION,
+        SensorLinearAccelerationData);
+
+
 //////////////////////SensorHardwareInfo classes//////////////////////////////////////////////////////////
 function SensorHardwareInfo(data) {
     Object.defineProperties(this, {
index 5a4286032b6c482f72c5c36ad378f61c82db18f7..ae76ba086c661487a818a23958dcf41ae37915bd 100755 (executable)
@@ -122,6 +122,12 @@ void ReportSensorData(sensor_type_e sensor_type, sensor_event_s* sensor_event,
       (*out)["w"] = picojson::value(static_cast<double>(sensor_event->values[3]));
       break;
     }
+    case SENSOR_LINEAR_ACCELERATION: {
+      (*out)["x"] = picojson::value(static_cast<double>(sensor_event->values[0]));
+      (*out)["y"] = picojson::value(static_cast<double>(sensor_event->values[1]));
+      (*out)["z"] = picojson::value(static_cast<double>(sensor_event->values[2]));
+      break;
+    }
     default: {
       LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unsupported type"), out);
       return;
@@ -699,6 +705,7 @@ SensorService::SensorService(SensorInstance& instance)
   AddSensor(new SensorData(instance, SENSOR_GRAVITY, "GRAVITY"));
   AddSensor(new SensorData(instance, SENSOR_GYROSCOPE, "GYROSCOPE"));
   AddSensor(new SensorData(instance, SENSOR_GYROSCOPE_ROTATION_VECTOR, "GYROSCOPE_ROTATION_VECTOR"));
+  AddSensor(new SensorData(instance, SENSOR_LINEAR_ACCELERATION, "LINEAR_ACCELERATION"));
 }
 
 SensorService::~SensorService() {