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 /// UltravioletSensor Class. Used for registering callbacks for ultraviolet sensor and getting ultraviolet data
16 public class UltravioletSensor : Sensor
18 private static string UltravioletSensorKey = "http://tizen.org/feature/sensor.ultraviolet";
21 /// Gets the value of the ultraviolet sensor.
23 public float UltravioletIndex { get; private set; }
26 /// Returns true or false based on whether ultraviolet sensor is supported by device.
28 public static bool IsSupported
32 Log.Info(Globals.LogTag, "Checking if the UltravioletSensor is supported");
33 return CheckIfSupported(SensorType.UltravioletSensor, UltravioletSensorKey);
38 /// Returns the number of ultraviolet sensors available on the device.
40 public static int Count
44 Log.Info(Globals.LogTag, "Getting the count of ultraviolet sensors");
50 /// Initializes a new instance of the <see cref="Tizen.Sensor.UltravioletSensor"/> class.
52 /// <exception cref="ArgumentException">Thrown when an invalid argument is used</exception>
53 /// <exception cref="NotSupportedException">Thrown when the sensor is not supported</exception>
54 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid for the current state</exception>
55 /// <param name='index'>
56 /// Index. Default value for this is 0. Index refers to a particular ultraviolet sensor in case of multiple sensors
58 public UltravioletSensor(int index = 0) : base(index)
60 Log.Info(Globals.LogTag, "Creating UltravioletSensor object");
63 internal override SensorType GetSensorType()
65 return SensorType.UltravioletSensor;
69 /// Event Handler for storing the callback functions for event corresponding to change in ultraviolet sensor data.
72 public event EventHandler<UltravioletSensorDataUpdatedEventArgs> DataUpdated;
75 private static int GetCount()
79 int error = Interop.SensorManager.GetSensorList(SensorType.UltravioletSensor, out list, out count);
80 if (error != (int)SensorError.None)
82 Log.Error(Globals.LogTag, "Error getting sensor list for ultraviolet");
86 Interop.Libc.Free(list);
90 protected override void EventListenStart()
92 int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, SensorEventCallback, IntPtr.Zero);
93 if (error != (int)SensorError.None)
95 Log.Error(Globals.LogTag, "Error setting event callback for ultraviolet sensor");
96 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for ultraviolet");
100 protected override void EventListenStop()
102 int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
103 if (error != (int)SensorError.None)
105 Log.Error(Globals.LogTag, "Error unsetting event callback for ultraviolet sensor");
106 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for ultraviolet");
110 private void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
112 Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
113 TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
114 UltravioletIndex = sensorData.values[0];
116 DataUpdated?.Invoke(this, new UltravioletSensorDataUpdatedEventArgs(sensorData.values[0]));