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 /// GyroscopeRotationVectorSensor Class. Used for registering callbacks for gyroscope rotation vector sensor and getting gyroscope rotation vector data
16 public class GyroscopeRotationVectorSensor : Sensor
18 private const string GyroscopeRVKey = "http://tizen.org/feature/sensor.gyroscope_rotation_vector";
21 /// Gets the X component of the gyroscope rotation vector.
23 public float X { get; private set; }
26 /// Gets the Y component of the gyroscope rotation vector.
28 public float Y { get; private set; }
31 /// Gets the Z component of the gyroscope rotation vector.
33 public float Z { get; private set; }
36 /// Gets the W component of the gyroscope rotation vector.
38 public float W { get; private set; }
41 /// Gets the Accuracy of the gyroscope rotation vector data.
43 public SensorDataAccuracy Accuracy { get; private set; }
46 /// Returns true or false based on whether gyroscope rotation vector sensor is supported by device.
48 public static bool IsSupported
52 Log.Info(Globals.LogTag, "Checking if the GyroscopeRotationVectorSensor is supported");
53 return CheckIfSupported(SensorType.GyroscopeRotationVectorSensor, GyroscopeRVKey);
58 /// Returns the number of gyroscope rotation vector sensors available on the device.
60 public static int Count
64 Log.Info(Globals.LogTag, "Getting the count of gyroscope rotation vector sensors");
70 /// Initializes a new instance of the <see cref="Tizen.Sensor.GyroscopeRotationVectorSensor"/> class.
72 /// <exception cref="ArgumentException">Thrown when an invalid argument is used</exception>
73 /// <exception cref="NotSupportedException">Thrown when the sensor is not supported</exception>
74 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid for the current state</exception>
75 /// <param name='index'>
76 /// Index. Default value for this is 0. Index refers to a particular gyroscope rotation vector sensor in case of multiple sensors
78 public GyroscopeRotationVectorSensor(uint index = 0) : base(index)
80 Log.Info(Globals.LogTag, "Creating GyroscopeRotationVectorSensor object");
83 internal override SensorType GetSensorType()
85 return SensorType.GyroscopeRotationVectorSensor;
89 /// Event Handler for storing the callback functions for event corresponding to change in gyroscope rotation vector sensor data.
92 public event EventHandler<GyroscopeRotationVectorSensorDataUpdatedEventArgs> DataUpdated;
94 private static int GetCount()
98 int error = Interop.SensorManager.GetSensorList(SensorType.GyroscopeRotationVectorSensor, out list, out count);
99 if (error != (int)SensorError.None)
101 Log.Error(Globals.LogTag, "Error getting sensor list for gyroscope rotation vector");
105 Interop.Libc.Free(list);
109 protected override void EventListenStart()
111 int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, SensorEventCallback, IntPtr.Zero);
112 if (error != (int)SensorError.None)
114 Log.Error(Globals.LogTag, "Error setting event callback for gyroscope rotation vector sensor");
115 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for gyroscope rotation vector");
119 protected override void EventListenStop()
121 int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
122 if (error != (int)SensorError.None)
124 Log.Error(Globals.LogTag, "Error unsetting event callback for gyroscope rotation vector sensor");
125 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for gyroscope rotation vector");
129 private void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
131 Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
132 TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
133 X = sensorData.values[0];
134 Y = sensorData.values[1];
135 Z = sensorData.values[2];
136 Accuracy = sensorData.accuracy;
138 DataUpdated?.Invoke(this, new GyroscopeRotationVectorSensorDataUpdatedEventArgs(sensorData.values, sensorData.accuracy));