From: bg.chun Date: Wed, 23 Mar 2016 06:53:45 +0000 (+0900) Subject: [sensor] impl gyroscope and gyroscope_rotation_vector sensor X-Git-Tag: submit/tizen/20160324.000143^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b62b24c7fb3c6daea5246fe10d5b05cbb6910a51;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [sensor] impl gyroscope and gyroscope_rotation_vector sensor [Verification] Code compiles, TCT pass rate: 100% (58/58/0/0/0) Change-Id: I6ad590c7411a4749e38b5b0cd9d0c16455def374 Signed-off-by: bg.chun --- diff --git a/src/sensor/sensor_api.js b/src/sensor/sensor_api.js old mode 100644 new mode 100755 index dad10189..151c17bd --- a/src/sensor/sensor_api.js +++ b/src/sensor/sensor_api.js @@ -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(); diff --git a/src/sensor/sensor_service.cc b/src/sensor/sensor_service.cc old mode 100644 new mode 100755 index dc767ea8..52d868c4 --- a/src/sensor/sensor_service.cc +++ b/src/sensor/sensor_service.cc @@ -107,6 +107,19 @@ void ReportSensorData(sensor_type_e sensor_type, sensor_event_s* sensor_event, (*out)["z"] = picojson::value(static_cast(sensor_event->values[2])); break; } + case SENSOR_GYROSCOPE: { + (*out)["x"] = picojson::value(static_cast(sensor_event->values[0])); + (*out)["y"] = picojson::value(static_cast(sensor_event->values[1])); + (*out)["z"] = picojson::value(static_cast(sensor_event->values[2])); + break; + } + case SENSOR_GYROSCOPE_ROTATION_VECTOR: { + (*out)["x"] = picojson::value(static_cast(sensor_event->values[0])); + (*out)["y"] = picojson::value(static_cast(sensor_event->values[1])); + (*out)["z"] = picojson::value(static_cast(sensor_event->values[2])); + (*out)["w"] = picojson::value(static_cast(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() {