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 /// <param name='index'>
78 /// Index. Default value for this is 0. Index refers to a particular uncalibrated gyroscope sensor in case of multiple sensors
80 public UncalibratedGyroscope(int index = 0) : base(index)
82 Log.Info(Globals.LogTag, "Creating UncalibratedGyroscope object");
85 internal override SensorType GetSensorType()
87 return SensorType.UncalibratedGyroscope;
91 /// Event Handler for storing the callback functions for event corresponding to change in uncalibrated gyroscope sensor data.
94 public event EventHandler<UncalibratedGyroscopeDataUpdatedEventArgs> DataUpdated;
96 private static int GetCount()
100 int error = Interop.SensorManager.GetSensorList(SensorType.UncalibratedGyroscope, out list, out count);
101 if (error != (int)SensorError.None)
103 Log.Error(Globals.LogTag, "Error getting sensor list for uncalibrated gyroscope");
107 Interop.Libc.Free(list);
111 protected override void EventListenStart()
113 int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, SensorEventCallback, IntPtr.Zero);
114 if (error != (int)SensorError.None)
116 Log.Error(Globals.LogTag, "Error setting event callback for uncalibrated gyroscope sensor");
117 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for uncalibrated gyroscope");
121 protected override void EventListenStop()
123 int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
124 if (error != (int)SensorError.None)
126 Log.Error(Globals.LogTag, "Error unsetting event callback for uncalibrated gyroscope sensor");
127 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for uncalibrated gyroscope");
131 private void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
133 Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
134 TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
135 X = sensorData.values[0];
136 Y = sensorData.values[1];
137 Z = sensorData.values[2];
138 BiasX = sensorData.values[3];
139 BiasY = sensorData.values[4];
140 BiasZ = sensorData.values[5];
142 DataUpdated?.Invoke(this, new UncalibratedGyroscopeDataUpdatedEventArgs(sensorData.values));