From: Michal Kolodziej Date: Mon, 29 Aug 2016 08:10:43 +0000 (+0200) Subject: [Sensor] Adding new sensor type X-Git-Tag: submit/tizen/20160920.235405~5^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3eecb108284a4b5f36e7e7098e65348613ab338c;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Sensor] Adding new sensor type [Feature] Added linear acceleration sensor Change-Id: I2f8f3b3d12ad68cb4d1853bb748e5f544b1290a7 Signed-off-by: Michal Kolodziej --- diff --git a/src/sensor/sensor_api.js b/src/sensor/sensor_api.js index d590e63e..9c810e81 100755 --- a/src/sensor/sensor_api.js +++ b/src/sensor/sensor_api.js @@ -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, { diff --git a/src/sensor/sensor_service.cc b/src/sensor/sensor_service.cc index 5a428603..ae76ba08 100755 --- a/src/sensor/sensor_service.cc +++ b/src/sensor/sensor_service.cc @@ -122,6 +122,12 @@ void ReportSensorData(sensor_type_e sensor_type, sensor_event_s* sensor_event, (*out)["w"] = picojson::value(static_cast(sensor_event->values[3])); break; } + case SENSOR_LINEAR_ACCELERATION: { + (*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; + } 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() {