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 /// UncalibratedGyroscope Sensor Class. Used for registering callbacks for uncalibrated gyroscope and getting uncalibrated gyroscope data
16 public class UncalibratedGyroscope : Sensor
18 private static string UncalibratedGyroscopeKey = "http://tizen.org/feature/sensor.gyroscope.uncalibrated";
21 /// Gets the X component of the acceleration.
23 public float X { get; private set; }
26 /// Gets the Y component of the acceleration.
28 public float Y { get; private set; }
31 /// Gets the Z component of the acceleration.
33 public float Z { get; private set; }
36 /// Gets the BiasX component of the uncalibrated gyroscope data.
38 public float BiasX { get; private set; }
41 /// Gets the BiasY component of the uncalibrated gyroscope data.
43 public float BiasY { get; private set; }
46 /// Gets the BiasZ component of the uncalibrated gyroscope data.
48 public float BiasZ { get; private set; }
51 /// Returns true or false based on whether uncalibrated gyroscope sensor is supported by device.
53 public static bool IsSupported
57 Log.Info(Globals.LogTag, "Checking if the UncalibratedGyroscope sensor is supported");
58 return CheckIfSupported(SensorType.UncalibratedGyroscope, UncalibratedGyroscopeKey);
63 /// Returns the number of uncalibrated gyroscope sensors available on the device.
65 public static int Count
69 Log.Info(Globals.LogTag, "Getting the count of uncalibrated gyroscope sensors");
75 /// Initializes a new instance of the <see cref="Tizen.Sensor.UncalibratedGyroscope"/> class.
77 /// <exception cref="ArgumentException">Thrown when an invalid argument is used</exception>
78 /// <exception cref="NotSupportedException">Thrown when the sensor is not supported</exception>
79 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid for the current state</exception>
80 /// <param name='index'>
81 /// Index. Default value for this is 0. Index refers to a particular uncalibrated gyroscope sensor in case of multiple sensors
83 public UncalibratedGyroscope(int index = 0) : base(index)
85 Log.Info(Globals.LogTag, "Creating UncalibratedGyroscope object");
88 internal override SensorType GetSensorType()
90 return SensorType.UncalibratedGyroscope;
94 /// Event Handler for storing the callback functions for event corresponding to change in uncalibrated gyroscope sensor data.
97 public event EventHandler<UncalibratedGyroscopeDataUpdatedEventArgs> DataUpdated;
99 private static int GetCount()
103 int error = Interop.SensorManager.GetSensorList(SensorType.UncalibratedGyroscope, out list, out count);
104 if (error != (int)SensorError.None)
106 Log.Error(Globals.LogTag, "Error getting sensor list for uncalibrated gyroscope");
110 Interop.Libc.Free(list);
114 protected override void EventListenStart()
116 int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, SensorEventCallback, IntPtr.Zero);
117 if (error != (int)SensorError.None)
119 Log.Error(Globals.LogTag, "Error setting event callback for uncalibrated gyroscope sensor");
120 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for uncalibrated gyroscope");
124 protected override void EventListenStop()
126 int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
127 if (error != (int)SensorError.None)
129 Log.Error(Globals.LogTag, "Error unsetting event callback for uncalibrated gyroscope sensor");
130 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for uncalibrated gyroscope");
134 private void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
136 Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
137 TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
138 X = sensorData.values[0];
139 Y = sensorData.values[1];
140 Z = sensorData.values[2];
141 BiasX = sensorData.values[3];
142 BiasY = sensorData.values[4];
143 BiasZ = sensorData.values[5];
145 DataUpdated?.Invoke(this, new UncalibratedGyroscopeDataUpdatedEventArgs(sensorData.values));