[sensor] implement Gravity sensor
authorHyunjin Park <hj.na.park@samsung.com>
Wed, 23 Mar 2016 05:40:53 +0000 (14:40 +0900)
committerHyunjin Park <hj.na.park@samsung.com>
Wed, 23 Mar 2016 05:40:53 +0000 (14:40 +0900)
TWDAPI-91

[Verification] Code compiles, TCT pass rate: 100% (58/58/0/0/0)

Change-Id: I1f09c530f79837ac40622c9318648f8d6c360d79

src/sensor/sensor_api.js
src/sensor/sensor_service.cc

index 2b70cc65f8db8dc6c10e0175d33bb45bc5bd049d..dad101891f505095c99638e86f0f8f15c7137c65 100644 (file)
@@ -30,6 +30,7 @@ var SensorType = {
     PROXIMITY : 'PROXIMITY',
     ULTRAVIOLET : 'ULTRAVIOLET',
     HRM_RAW : 'HRM_RAW',
+    GRAVITY : 'GRAVITY',
 };
 
 var ProximityState = {
@@ -146,6 +147,7 @@ var _sensorListeners = {
     'PROXIMITY'   : {},
     'ULTRAVIOLET' : {},
     'HRM_RAW'     : {},
+    'GRAVITY'     : {},
 };
 
 var _listener = function(object) {
@@ -196,6 +198,8 @@ function getDefaultSensor() {
     } else if (_supportedSensors[index] === SensorType.HRM_RAW) {
         utils_.checkPrivilegeAccess(privilege_.HEALTHINFO);
         return new HRMRawSensor();
+    } else if (_supportedSensors[index] === SensorType.GRAVITY) {
+        return new GravitySensor();
     }
 };
 
@@ -428,6 +432,31 @@ HRMRawSensor.prototype.getHRMRawSensorData = function() {
   getHRMRawSensorData.apply(this, arguments);
 };
 
+//// GravitySensor
+var GravitySensor = function(data) {
+    Sensor.call(this, SensorType.GRAVITY);
+};
+
+GravitySensor.prototype = new Sensor();
+
+GravitySensor.prototype.constructor = Sensor;
+
+GravitySensor.prototype.getGravitySensorData = 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 () {
@@ -529,5 +558,23 @@ SensorHRMRawData.prototype.constructor = SensorData;
 _sensorListeners[SensorType.HRM_RAW] = new SensorListener(SensorType.HRM_RAW,
         SensorHRMRawData);
 
+//// SensorGravityData
+var SensorGravityData = 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},
+    });
+};
+
+SensorGravityData.prototype = new SensorData();
+
+SensorGravityData.prototype.constructor = SensorData;
+
+_sensorListeners[SensorType.GRAVITY] = new SensorListener(SensorType.GRAVITY,
+        SensorGravityData);
+
+
 // Exports
 exports = new SensorService();
index 9165f4479d364db7d8ccad2e128a0c857140ba4d..dc767ea88144231a574a20c1748cf1c82f2b5a16 100644 (file)
@@ -101,6 +101,12 @@ void ReportSensorData(sensor_type_e sensor_type, sensor_event_s* sensor_event,
       (*out)["lightIntensity"] = picojson::value(static_cast<double>(sensor_event->values[0]));
       break;
     }
+    case SENSOR_GRAVITY: {
+      (*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;
@@ -561,6 +567,7 @@ SensorService::SensorService(SensorInstance& instance)
   AddSensor(new SensorData(instance, SENSOR_PROXIMITY, "PROXIMITY"));
   AddSensor(new SensorData(instance, SENSOR_ULTRAVIOLET, "ULTRAVIOLET"));
   AddSensor(new HrmSensorData(instance));
+  AddSensor(new SensorData(instance, SENSOR_GRAVITY, "GRAVITY"));
 }
 
 SensorService::~SensorService() {