1 // Copyright 2016 by Samsung Electronics, Inc.,
3 // This software is the confidential and proprietary information
4 // of Samsung Electronics, Inc. ("Confidential Information"). You
5 // shall not disclose such Confidential Information and shall use
6 // it only in accordance with the terms of the license agreement
7 // you entered into with Samsung.
11 namespace Tizen.System.Sensor
13 public class StationaryActivityDetector : ActivityDetector
16 /// Gets the state of stationary activity detector
18 public DetectorState Stationary { get; private set; }
21 /// Returns true or false based on whether stationary activity detector is supported by device.
23 public static bool IsSupported
27 Log.Info(Globals.LogTag, "Checking if the stationary activity detector is supported");
28 return CheckIfSupported();
33 /// Returns the number of stationary activity detector available on the device.
35 public static int Count
39 Log.Info(Globals.LogTag, "Getting the count of stationary activity detectors");
45 /// Initializes a new instance of the <see cref="Tizen.System.Sensor.stationaryActivityDetector"/> class.
47 /// <param name='index'>
48 /// Index. Default value for this is 0. Index refers to a particular stationary activity detector in case of multiple sensors.
50 public StationaryActivityDetector(int index) : base(index)
52 SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.Stationary);
53 Log.Info(Globals.LogTag, "Creating stationary activity detector object");
56 private static bool CheckIfSupported()
59 int error = Interop.SensorManager.SensorIsSupported(SensorType.StationaryActivityDetector, out isSupported);
60 if (error != (int)SensorError.None)
62 Log.Error(Globals.LogTag, "Error checking if stationary activity detector is supported");
68 private static int GetCount()
72 int error = Interop.SensorManager.GetSensorList(SensorType.StationaryActivityDetector, out list, out count);
73 if (error != (int)SensorError.None)
75 Log.Error(Globals.LogTag, "Error getting sensor list for stationary activity detector");
79 Interop.Libc.Free(list);
84 /// Event Handler for storing the callback functions for event corresponding to change in stationary activity detector data.
86 public event EventHandler<StationaryActivityDetectorDataUpdatedEventArgs> DataUpdated;
88 protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
90 Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
91 TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
92 Stationary = (DetectorState)sensorData.values[0];
93 ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy;
95 DataUpdated?.Invoke(this, new StationaryActivityDetectorDataUpdatedEventArgs(sensorData.values[0]));
98 internal override SensorType GetSensorType()
100 return SensorType.StationaryActivityDetector;