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.Sensor
14 /// FaceDownGestureDetector Class. Used for registering callbacks for face down gesture detector and getting the face down state
16 public class FaceDownGestureDetector : Sensor
18 private static string GestureDetectorKey = "http://tizen.org/feature/sensor.gesture_recognition";
21 /// Gets the state of the face down gesture.
23 public DetectorState FaceDown { get; private set; }
26 /// Returns true or false based on whether face down gesture detector is supported by device.
28 public static bool IsSupported
32 Log.Info(Globals.LogTag, "Checking if the face down gesture detector is supported");
33 return CheckIfSupported(SensorType.FaceDownGestureDetector, GestureDetectorKey);
38 /// Returns the number of face down gesture detector available on the device.
40 public static int Count
44 Log.Info(Globals.LogTag, "Getting the count of face down gesture detectors");
50 /// Initializes a new instance of the <see cref="Tizen.Sensor.FaceDownGestureDetector"/> class.
52 /// <exception cref="ArgumentException">Thrown when an invalid argument is used</exception>
53 /// <exception cref="NotSupportedException">Thrown when the sensor is not supported</exception>
54 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid for the current state</exception>
55 /// <param name='index'>
56 /// Index. Default value for this is 0. Index refers to a particular face down gesture detector in case of multiple sensors.
58 public FaceDownGestureDetector(int index = 0) : base(index)
60 Log.Info(Globals.LogTag, "Creating face down gesture detector object");
63 internal override SensorType GetSensorType()
65 return SensorType.FaceDownGestureDetector;
68 private static int GetCount()
72 int error = Interop.SensorManager.GetSensorList(SensorType.FaceDownGestureDetector, out list, out count);
73 if (error != (int)SensorError.None)
75 Log.Error(Globals.LogTag, "Error getting sensor list for face down gesture detector");
79 Interop.Libc.Free(list);
84 /// Event Handler for storing the callback functions for event corresponding to change in face down gesture detector data.
86 public event EventHandler<FaceDownGestureDetectorDataUpdatedEventArgs> DataUpdated;
88 protected override void EventListenStart()
90 int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, SensorEventCallback, IntPtr.Zero);
91 if (error != (int)SensorError.None)
93 Log.Error(Globals.LogTag, "Error setting event callback for face down gesture detector");
94 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for face down gesture detector");
98 protected override void EventListenStop()
100 int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
101 if (error != (int)SensorError.None)
103 Log.Error(Globals.LogTag, "Error unsetting event callback for face down gesture detector");
104 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for face down gesture detector");
108 private void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
110 Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
111 TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
112 FaceDown = (DetectorState) sensorData.values[0];
114 DataUpdated?.Invoke(this, new FaceDownGestureDetectorDataUpdatedEventArgs(sensorData.values[0]));