csapi-sensor: fix activity sensors properly
authorkibak.yoon <kibak.yoon@samsung.com>
Tue, 23 Aug 2016 08:21:36 +0000 (17:21 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Tue, 23 Aug 2016 08:32:37 +0000 (17:32 +0900)
Change-Id: I06aa679e235e7ea63b429787e0fadfa5d85f88ef
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
Tizen.System.Sensor/Tizen.System.Sensor/Plugins/ActivityDetector.cs
Tizen.System.Sensor/Tizen.System.Sensor/Plugins/InVehicleActivityDetector.cs
Tizen.System.Sensor/Tizen.System.Sensor/Plugins/RunningActivityDetector.cs
Tizen.System.Sensor/Tizen.System.Sensor/Plugins/StationaryActivityDetector.cs
Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WalkingActivityDetector.cs
Tizen.System.Sensor/Tizen.System.Sensor/Sensor.cs
Tizen.System.Sensor/Tizen.System.Sensor/SensorEnumerations.cs

index 41e5e2dbf0e43fa1ffedac9f9f70175713c3a78d..d0189e23e908c984f4f5995958e4863e510fa33d 100644 (file)
@@ -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,
+        };
+
         /// <summary>
         /// Gets the activity accuracy of activity detector
         /// </summary>
index 21b5382ca8f1db3cea2376ef59c9874bca7622d5..555b60438bd8902458b871665ff3565c620a610e 100644 (file)
@@ -49,6 +49,7 @@ namespace Tizen.System.Sensor
         /// </param>
         public InVehicleActivityDetector(int index) : base(index)
         {
+            SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.InVehicle);
             Log.Info(Globals.LogTag, "Creating in-vehicle activity detector object");
         }
 
index d604bc530b52a43abeaf05977f923c1e1b92509c..2032cd75527102512cf36e0ba3eba50c4dd037c3 100644 (file)
@@ -49,6 +49,7 @@ namespace Tizen.System.Sensor
         /// </param>
         public RunningActivityDetector(int index) : base(index)
         {
+            SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.Running);
             Log.Info(Globals.LogTag, "Creating running activity detector object");
         }
 
index 5684b7574ab8f0f9ce69405b7649745334cfb662..6023151ae41193aabd23f0a844ff0a90c56b2a28 100644 (file)
@@ -49,6 +49,7 @@ namespace Tizen.System.Sensor
         /// </param>
         public StationaryActivityDetector(int index) : base(index)
         {
+            SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.Stationary);
             Log.Info(Globals.LogTag, "Creating stationary activity detector object");
         }
 
index 24693b13c7acdcae323f6181baca63893b43b02e..c896f6155709a794e425cf4a7ab626adedd2dc59 100644 (file)
@@ -49,6 +49,7 @@ namespace Tizen.System.Sensor
         /// </param>
         public WalkingActivityDetector(int index) : base(index)
         {
+            SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.Walking);
             Log.Info(Globals.LogTag, "Creating walking activity gesture detector object");
         }
 
index dfff1aa84ba24eca2d9aa3b118742d680cf35089..3ff750ec3b2b87ae8f1247ae1f54f9387448214b 100644 (file)
@@ -192,7 +192,7 @@ namespace Tizen.System.Sensor
         }
 
         /// <summary>
-        /// Gets the attribute.
+        /// Sets the pause policy of the sensor.
         /// </summary>
         /// <value>
         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;
index 29e8fd740a88bab2cb4b7e42ee4d77d4758d2e75..aedca395038d1cca74eed0ba7ef0d2d80732127c 100644 (file)
@@ -102,19 +102,19 @@ namespace Tizen.System.Sensor
         /// <summary>
         /// Walking activity detector.
         /// </summary>
-        WalkingActivityDetector = 0x401,
+        WalkingActivityDetector = 0x1A00,
         /// <summary>
         /// Running activity detector.
         /// </summary>
-        RunningActivityDetector = 0x402,
+        RunningActivityDetector = 0x1A00,
         /// <summary>
         /// Stationary activity detector.
         /// </summary>
-        StationaryActivityDetector = 0x408,
+        StationaryActivityDetector = 0x1A00,
         /// <summary>
         /// InVehicle activity detector.
         /// </summary>
-        InVehicleActivityDetector = 0x409,
+        InVehicleActivityDetector = 0x1A00,
         /// <summary>
         /// Wrist up gesture detector.
         /// </summary>