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 /// UncalibratedGyroscope Sensor Class. Used for registering callbacks for uncalibrated gyroscope and getting uncalibrated gyroscope data
24 public sealed class UncalibratedGyroscope : Sensor
26 private static string UncalibratedGyroscopeKey = "http://tizen.org/feature/sensor.gyroscope.uncalibrated";
29 /// Gets the X component of the acceleration.
31 /// <since_tizen> 3 </since_tizen>
32 /// <value> X </value>
33 public float X { get; private set; } = float.MinValue;
36 /// Gets the Y component of the acceleration.
38 /// <since_tizen> 3 </since_tizen>
39 /// <value> Y </value>
40 public float Y { get; private set; } = float.MinValue;
43 /// Gets the Z component of the acceleration.
45 /// <since_tizen> 3 </since_tizen>
46 /// <value> Z </value>
47 public float Z { get; private set; } = float.MinValue;
50 /// Gets the BiasX component of the uncalibrated gyroscope data.
52 /// <since_tizen> 3 </since_tizen>
53 /// <value> X bias </value>
54 public float BiasX { get; private set; } = 0;
57 /// Gets the BiasY component of the uncalibrated gyroscope data.
59 /// <since_tizen> 3 </since_tizen>
60 /// <value> Y bias </value>
61 public float BiasY { get; private set; } = 0;
64 /// Gets the BiasZ component of the uncalibrated gyroscope data.
66 /// <since_tizen> 3 </since_tizen>
67 /// <value> Z bias </value>
68 public float BiasZ { get; private set; } = 0;
71 /// Returns true or false based on whether uncalibrated gyroscope sensor is supported by device.
73 /// <since_tizen> 3 </since_tizen>
74 /// <value><c>true</c> if supported; otherwise, <c>false</c>.</value>
75 public static bool IsSupported
79 Log.Info(Globals.LogTag, "Checking if the UncalibratedGyroscope sensor is supported");
80 return CheckIfSupported(SensorType.UncalibratedGyroscope, UncalibratedGyroscopeKey);
85 /// Returns the number of uncalibrated gyroscope sensors available on the device.
87 /// <since_tizen> 3 </since_tizen>
88 /// <value> The count of uncalibrated gyroscope sensors </value>
89 public static int Count
93 Log.Info(Globals.LogTag, "Getting the count of uncalibrated gyroscope sensors");
99 /// Initializes a new instance of the <see cref="Tizen.Sensor.UncalibratedGyroscope"/> class.
101 /// <since_tizen> 3 </since_tizen>
102 /// <feature>http://tizen.org/feature/sensor.gyroscope.uncalibrated</feature>
103 /// <exception cref="ArgumentException">Thrown when an invalid argument is used</exception>
104 /// <exception cref="NotSupportedException">Thrown when the sensor is not supported</exception>
105 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid for the current state</exception>
106 /// <param name='index'>
107 /// Index. Default value for this is 0. Index refers to a particular uncalibrated gyroscope sensor in case of multiple sensors
109 public UncalibratedGyroscope(uint index = 0) : base(index)
111 Log.Info(Globals.LogTag, "Creating UncalibratedGyroscope object");
114 internal override SensorType GetSensorType()
116 return SensorType.UncalibratedGyroscope;
120 /// Event Handler for storing the callback functions for event corresponding to change in uncalibrated gyroscope sensor data.
122 /// <since_tizen> 3 </since_tizen>
124 public event EventHandler<UncalibratedGyroscopeDataUpdatedEventArgs> DataUpdated;
126 private static int GetCount()
130 int error = Interop.SensorManager.GetSensorList(SensorType.UncalibratedGyroscope, out list, out count);
131 if (error != (int)SensorError.None)
133 Log.Error(Globals.LogTag, "Error getting sensor list for uncalibrated gyroscope");
137 Interop.Libc.Free(list);
141 private static Interop.SensorListener.SensorEventCallback _callback;
143 internal override void EventListenStart()
145 _callback = (IntPtr sensorHandle, IntPtr eventPtr, IntPtr data) => {
146 Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(eventPtr);
148 TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
149 X = sensorData.values[0];
150 Y = sensorData.values[1];
151 Z = sensorData.values[2];
152 BiasX = sensorData.values[3];
153 BiasY = sensorData.values[4];
154 BiasZ = sensorData.values[5];
156 DataUpdated?.Invoke(this, new UncalibratedGyroscopeDataUpdatedEventArgs(sensorData.values));
159 int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, _callback, IntPtr.Zero);
160 if (error != (int)SensorError.None)
162 Log.Error(Globals.LogTag, "Error setting event callback for uncalibrated gyroscope sensor");
163 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for uncalibrated gyroscope");
167 internal override void EventListenStop()
169 int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
170 if (error != (int)SensorError.None)
172 Log.Error(Globals.LogTag, "Error unsetting event callback for uncalibrated gyroscope sensor");
173 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for uncalibrated gyroscope");