2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Sensor
22 /// The FaceDownGestureDetector class is used for registering callbacks for the face down gesture detector and getting the face down state.
24 /// <since_tizen> 3 </since_tizen>
25 public sealed class FaceDownGestureDetector : Sensor
27 private static string GestureDetectorKey = "http://tizen.org/feature/sensor.gesture_recognition";
30 /// Gets the state of the face down gesture.
32 /// <since_tizen> 3 </since_tizen>
33 /// <value> The face down state. </value>
34 public DetectorState FaceDown { get; private set; } = DetectorState.Unknown;
37 /// Returns true or false based on whether the face down gesture detector is supported by the device.
39 /// <since_tizen> 3 </since_tizen>
40 /// <value><c>true</c> if supported; otherwise <c>false</c>.</value>
41 public static bool IsSupported
45 Log.Info(Globals.LogTag, "Checking if the face down gesture detector is supported");
46 return CheckIfSupported(SensorType.FaceDownGestureDetector, GestureDetectorKey);
51 /// Returns the number of face down gesture detectors available on the device.
53 /// <since_tizen> 3 </since_tizen>
54 /// <value> The count of face down gesture detectors. </value>
55 public static int Count
59 Log.Info(Globals.LogTag, "Getting the count of face down gesture detectors");
65 /// Initializes a new instance of the <see cref="Tizen.Sensor.FaceDownGestureDetector"/> class.
67 /// <since_tizen> 3 </since_tizen>
68 /// <feature>http://tizen.org/feature/sensor.gesture_recognition</feature>
69 /// <exception cref="ArgumentException">Thrown when an invalid argument is used.</exception>
70 /// <exception cref="NotSupportedException">Thrown when the sensor is not supported.</exception>
71 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid for the current state.</exception>
72 /// <param name='index'>
73 /// Index. Default value for this is 0. Index refers to a particular face down gesture detector in case of multiple sensors.
75 public FaceDownGestureDetector(uint index = 0) : base(index)
77 Log.Info(Globals.LogTag, "Creating face down gesture detector object");
80 internal override SensorType GetSensorType()
82 return SensorType.FaceDownGestureDetector;
85 private static int GetCount()
89 int error = Interop.SensorManager.GetSensorList(SensorType.FaceDownGestureDetector, out list, out count);
90 if (error != (int)SensorError.None)
92 Log.Error(Globals.LogTag, "Error getting sensor list for face down gesture detector");
96 Interop.Libc.Free(list);
101 /// An event handler for storing the callback functions for the event corresponding to the change in the face down gesture detector data.
103 /// <since_tizen> 3 </since_tizen>
104 public event EventHandler<FaceDownGestureDetectorDataUpdatedEventArgs> DataUpdated;
106 private static Interop.SensorListener.SensorEventCallback _callback;
108 internal override void EventListenStart()
110 _callback = (IntPtr sensorHandle, IntPtr eventPtr, IntPtr data) => {
111 Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(eventPtr);
113 TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
114 FaceDown = (DetectorState) sensorData.values[0];
116 DataUpdated?.Invoke(this, new FaceDownGestureDetectorDataUpdatedEventArgs(sensorData.values[0]));
119 int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, _callback, IntPtr.Zero);
120 if (error != (int)SensorError.None)
122 Log.Error(Globals.LogTag, "Error setting event callback for face down gesture detector");
123 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for face down gesture detector");
127 internal override void EventListenStop()
129 int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
130 if (error != (int)SensorError.None)
132 Log.Error(Globals.LogTag, "Error unsetting event callback for face down gesture detector");
133 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for face down gesture detector");