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 41e5e2d..d0189e2 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 21b5382..555b604 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 d604bc5..2032cd7 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 5684b75..6023151 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 24693b1..c896f61 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 dfff1aa..3ff750e 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 29e8fd7..aedca39 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>