[sensor] impl gyroscope and gyroscope_rotation_vector sensor
authorbg.chun <bg.chun@samsung.com>
Wed, 23 Mar 2016 06:53:45 +0000 (15:53 +0900)
committerbg.chun <bg.chun@samsung.com>
Wed, 23 Mar 2016 08:53:16 +0000 (17:53 +0900)
[Verification] Code compiles, TCT pass rate: 100% (58/58/0/0/0)

Change-Id: I6ad590c7411a4749e38b5b0cd9d0c16455def374
Signed-off-by: bg.chun <bg.chun@samsung.com>
src/sensor/sensor_api.js [changed mode: 0644->0755]
src/sensor/sensor_service.cc [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index dad1018..151c17b
@@ -31,6 +31,8 @@ var SensorType = {
     ULTRAVIOLET : 'ULTRAVIOLET',
     HRM_RAW : 'HRM_RAW',
     GRAVITY : 'GRAVITY',
+    GYROSCOPE : 'GYROSCOPE',
+    GYROSCOPE_ROTATION_VECTOR : 'GYROSCOPE_ROTATION_VECTOR',
 };
 
 var ProximityState = {
@@ -148,6 +150,8 @@ var _sensorListeners = {
     'ULTRAVIOLET' : {},
     'HRM_RAW'     : {},
     'GRAVITY'     : {},
+    'GYROSCOPE'   : {},
+    'GYROSCOPE_ROTATION_VECTOR' : {},
 };
 
 var _listener = function(object) {
@@ -200,6 +204,10 @@ function getDefaultSensor() {
         return new HRMRawSensor();
     } else if (_supportedSensors[index] === SensorType.GRAVITY) {
         return new GravitySensor();
+    } else if(_supportedSensors[index] === SensorType.GYROSCOPE){
+        return new GyroscopeSensor();
+    } else if(_supportedSensors[index] === SensorType.GYROSCOPE_ROTATION_VECTOR){
+        return new GyroscopeRotationVectorSensor();
     }
 };
 
@@ -457,6 +465,60 @@ GravitySensor.prototype.getGravitySensorData = function() {
 
     _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
 };
+
+
+//// GyroscopeSensor
+var GyroscopeSensor = function(data) {
+    Sensor.call(this, SensorType.GYROSCOPE);
+};
+
+GyroscopeSensor.prototype = new Sensor();
+
+GyroscopeSensor.prototype.constructor = Sensor;
+
+GyroscopeSensor.prototype.getGyroscopeSensorData = 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, args.errorCallback);
+};
+
+//// GyroscopeRotationVectorSensor
+var GyroscopeRotationVectorSensor = function(data) {
+    Sensor.call(this, SensorType.GYROSCOPE);
+};
+
+GyroscopeRotationVectorSensor.prototype = new Sensor();
+
+GyroscopeRotationVectorSensor.prototype.constructor = Sensor;
+
+GyroscopeRotationVectorSensor.prototype.getGyroscopeRotationVectorSensorData = 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, args.errorCallback);
+};
+
 ////////////////////// Sensor Data classes/////////////////////////////////////////////////////
 ////Base SensorData class
 var SensorData = function () {
@@ -576,5 +638,41 @@ _sensorListeners[SensorType.GRAVITY] = new SensorListener(SensorType.GRAVITY,
         SensorGravityData);
 
 
+
+//// SensorGyroscopeData
+var SensorGyroscopeData = 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},
+    });
+};
+
+SensorGyroscopeData.prototype = new SensorData();
+
+SensorGyroscopeData.prototype.constructor = SensorData;
+
+_sensorListeners[SensorType.GYROSCOPE] = new SensorListener(SensorType.GYROSCOPE,
+        SensorGyroscopeData);
+
+//// SensorGyroscopeRotationVectorData
+var SensorGyroscopeRotationVectorData = 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},
+        w : {value: data.w, writable: false, enumerable: true},
+    });
+};
+
+SensorGyroscopeRotationVectorData.prototype = new SensorData();
+
+SensorGyroscopeRotationVectorData.prototype.constructor = SensorData;
+
+_sensorListeners[SensorType.GYROSCOPE_ROTATION_VECTOR] = new SensorListener(SensorType.GYROSCOPE_ROTATION_VECTOR,
+        SensorGyroscopeRotationVectorData);
+
 // Exports
 exports = new SensorService();
old mode 100644 (file)
new mode 100755 (executable)
index dc767ea..52d868c
@@ -107,6 +107,19 @@ void ReportSensorData(sensor_type_e sensor_type, sensor_event_s* sensor_event,
       (*out)["z"] = picojson::value(static_cast<double>(sensor_event->values[2]));
       break;
     }
+    case SENSOR_GYROSCOPE: {
+      (*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;
+    }
+    case SENSOR_GYROSCOPE_ROTATION_VECTOR: {
+      (*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]));
+      (*out)["w"] = picojson::value(static_cast<double>(sensor_event->values[3]));
+      break;
+    }
     default: {
       LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unsupported type"), out);
       return;
@@ -568,6 +581,8 @@ SensorService::SensorService(SensorInstance& instance)
   AddSensor(new SensorData(instance, SENSOR_ULTRAVIOLET, "ULTRAVIOLET"));
   AddSensor(new HrmSensorData(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"));
 }
 
 SensorService::~SensorService() {