From 380e116dc859fa8261723bbde7f4303828998fd2 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 23 Aug 2016 17:21:36 +0900 Subject: [PATCH] csapi-sensor: fix activity sensors properly Change-Id: I06aa679e235e7ea63b429787e0fadfa5d85f88ef Signed-off-by: kibak.yoon --- .../Plugins/ActivityDetector.cs | 12 +++++++++ .../Plugins/InVehicleActivityDetector.cs | 1 + .../Plugins/RunningActivityDetector.cs | 1 + .../Plugins/StationaryActivityDetector.cs | 1 + .../Plugins/WalkingActivityDetector.cs | 1 + Tizen.System.Sensor/Tizen.System.Sensor/Sensor.cs | 30 +++++++++++----------- .../Tizen.System.Sensor/SensorEnumerations.cs | 8 +++--- 7 files changed, 35 insertions(+), 19 deletions(-) diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/ActivityDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/ActivityDetector.cs index 41e5e2d..d0189e2 100644 --- a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/ActivityDetector.cs +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/ActivityDetector.cs @@ -12,6 +12,18 @@ namespace Tizen.System.Sensor { public abstract class ActivityDetector : Sensor { + protected const int ActivityAttribute = (((int)SensorType.InVehicleActivityDetector << 8) | 0x80 | 0x1); + + protected enum ActivityType + { + Unknown = 1, + Stationary = 2, + Walking = 4, + Running = 8, + InVehicle = 16, + OnBicycle = 32, + }; + /// /// Gets the activity accuracy of activity detector /// diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/InVehicleActivityDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/InVehicleActivityDetector.cs index 21b5382..555b604 100644 --- a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/InVehicleActivityDetector.cs +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/InVehicleActivityDetector.cs @@ -49,6 +49,7 @@ namespace Tizen.System.Sensor /// public InVehicleActivityDetector(int index) : base(index) { + SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.InVehicle); Log.Info(Globals.LogTag, "Creating in-vehicle activity detector object"); } diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/RunningActivityDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/RunningActivityDetector.cs index d604bc5..2032cd7 100644 --- a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/RunningActivityDetector.cs +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/RunningActivityDetector.cs @@ -49,6 +49,7 @@ namespace Tizen.System.Sensor /// public RunningActivityDetector(int index) : base(index) { + SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.Running); Log.Info(Globals.LogTag, "Creating running activity detector object"); } diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/StationaryActivityDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/StationaryActivityDetector.cs index 5684b75..6023151 100644 --- a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/StationaryActivityDetector.cs +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/StationaryActivityDetector.cs @@ -49,6 +49,7 @@ namespace Tizen.System.Sensor /// public StationaryActivityDetector(int index) : base(index) { + SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.Stationary); Log.Info(Globals.LogTag, "Creating stationary activity detector object"); } diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WalkingActivityDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WalkingActivityDetector.cs index 24693b1..c896f61 100644 --- a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WalkingActivityDetector.cs +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WalkingActivityDetector.cs @@ -49,6 +49,7 @@ namespace Tizen.System.Sensor /// public WalkingActivityDetector(int index) : base(index) { + SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.Walking); Log.Info(Globals.LogTag, "Creating walking activity gesture detector object"); } diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Sensor.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Sensor.cs index dfff1aa..3ff750e 100644 --- a/Tizen.System.Sensor/Tizen.System.Sensor/Sensor.cs +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Sensor.cs @@ -192,7 +192,7 @@ namespace Tizen.System.Sensor } /// - /// Gets the attribute. + /// Sets the pause policy of the sensor. /// /// public SensorPausePolicy PausePolicy @@ -201,7 +201,7 @@ namespace Tizen.System.Sensor { Log.Info(Globals.LogTag, "Setting the pause policy of the sensor"); _pausePolicy = value; - SetPausePolicy(); + SetAttribute(SensorAttribute.PausePolicy, (int)_pausePolicy); } get { @@ -311,6 +311,19 @@ namespace Tizen.System.Sensor _disposed = true; } + protected void SetAttribute(SensorAttribute attribute, int option) + { + if (CheckListenerHandle()) + { + int error = Interop.SensorListener.SetAttribute(_listenerHandle, attribute, option); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error setting sensor pause policy"); + throw SensorErrorFactory.CheckAndThrowException(error, "Setting Sensor.PausePolicy Failed"); + } + } + } + private void GetHandleList(SensorType type, int index) { IntPtr list; @@ -427,19 +440,6 @@ namespace Tizen.System.Sensor } } - private void SetPausePolicy() - { - if (CheckListenerHandle()) - { - int error = Interop.SensorListener.SetAttribute(_listenerHandle, SensorAttribute.PausePolicy, (int)_pausePolicy); - if (error != (int)SensorError.None) - { - Log.Error(Globals.LogTag, "Error setting sensor pause policy"); - throw SensorErrorFactory.CheckAndThrowException(error, "Setting Sensor.PausePolicy Failed"); - } - } - } - private bool CheckListenerHandle() { bool result = false; diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/SensorEnumerations.cs b/Tizen.System.Sensor/Tizen.System.Sensor/SensorEnumerations.cs index 29e8fd7..aedca39 100644 --- a/Tizen.System.Sensor/Tizen.System.Sensor/SensorEnumerations.cs +++ b/Tizen.System.Sensor/Tizen.System.Sensor/SensorEnumerations.cs @@ -102,19 +102,19 @@ namespace Tizen.System.Sensor /// /// Walking activity detector. /// - WalkingActivityDetector = 0x401, + WalkingActivityDetector = 0x1A00, /// /// Running activity detector. /// - RunningActivityDetector = 0x402, + RunningActivityDetector = 0x1A00, /// /// Stationary activity detector. /// - StationaryActivityDetector = 0x408, + StationaryActivityDetector = 0x1A00, /// /// InVehicle activity detector. /// - InVehicleActivityDetector = 0x409, + InVehicleActivityDetector = 0x1A00, /// /// Wrist up gesture detector. /// -- 2.7.4