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
14 /// WristUpGestureDetector Class. Used for registering callbacks for wrist up gesture detector and getting the wrist up state
16 public class WristUpGestureDetector : Sensor
19 /// Gets the state of the wrist up gesture.
21 public DetectorState WristUp { get; private set; }
24 /// Returns true or false based on whether wrist up gesture detector is supported by device.
26 public static bool IsSupported
30 Log.Info(Globals.LogTag, "Checking if the wrist up gesture detector is supported");
31 return CheckIfSupported();
36 /// Returns the number of wrist up gesture detector available on the device.
38 public static int Count
42 Log.Info(Globals.LogTag, "Getting the count of wrist up gesture detectors");
48 /// Initializes a new instance of the <see cref="Tizen.System.Sensor.WristUpGestureDetector"/> class.
50 /// <param name='index'>
51 /// Index. Default value for this is 0. Index refers to a particular wrist up gesture detector in case of multiple sensors.
53 public WristUpGestureDetector(int index = 0) : base(index)
55 Log.Info(Globals.LogTag, "Creating wrist up gesture detector object");
58 internal override SensorType GetSensorType()
60 return SensorType.WristUpGestureDetector;
63 private static bool CheckIfSupported()
66 int error = Interop.SensorManager.SensorIsSupported(SensorType.WristUpGestureDetector, out isSupported);
67 if (error != (int)SensorError.None)
69 Log.Error(Globals.LogTag, "Error checking if wrist up gesture detector is supported");
75 private static int GetCount()
79 int error = Interop.SensorManager.GetSensorList(SensorType.WristUpGestureDetector, out list, out count);
80 if (error != (int)SensorError.None)
82 Log.Error(Globals.LogTag, "Error getting sensor list for wrist up gesture detector");
86 Interop.Libc.Free(list);
91 /// Event Handler for storing the callback functions for event corresponding to change in wrist up gesture detector data.
93 public event EventHandler<WristUpGestureDetectorDataUpdatedEventArgs> DataUpdated;
95 protected override void EventListenStart()
97 int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, SensorEventCallback, IntPtr.Zero);
98 if (error != (int)SensorError.None)
100 Log.Error(Globals.LogTag, "Error setting event callback for wrist up gesture detector");
101 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for wrist up gesture detector");
105 protected override void EventListenStop()
107 int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
108 if (error != (int)SensorError.None)
110 Log.Error(Globals.LogTag, "Error unsetting event callback for wrist up gesture detector");
111 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for wrist up gesture detector");
115 private void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
117 Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
118 TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
119 WristUp = (DetectorState) sensorData.values[0];
121 DataUpdated?.Invoke(this, new WristUpGestureDetectorDataUpdatedEventArgs(sensorData.values[0]));