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.System.Sensor
14 /// InVehicleActivityDetector Class. Used for registering callbacks for in vehicle activity detector and getting the in vehicle state
16 public class InVehicleActivityDetector : ActivityDetector
19 /// Gets the state of in-vehicle activity detector
21 public DetectorState InVehicle { get; private set; }
24 /// Returns true or false based on whether in-vehicle activity detector is supported by device.
26 public static bool IsSupported
30 Log.Info(Globals.LogTag, "Checking if the in-vehicle activity detector is supported");
31 return CheckIfSupported();
36 /// Returns the number of in-vehicle activity detector available on the device.
38 public static int Count
42 Log.Info(Globals.LogTag, "Getting the count of in-vehicle activity detectors");
48 /// Initializes a new instance of the <see cref="Tizen.System.Sensor.InVehicleActivityDetector"/> class.
50 /// <param name='index'>
51 /// Index. Default value for this is 0. Index refers to a particular in-vehicle activity detector in case of multiple sensors.
53 public InVehicleActivityDetector(int index = 0) : base(index)
55 SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.InVehicle);
56 Log.Info(Globals.LogTag, "Creating in-vehicle activity detector object");
59 private static bool CheckIfSupported()
62 int error = Interop.SensorManager.SensorIsSupported(SensorType.InVehicleActivityDetector, out isSupported);
63 if (error != (int)SensorError.None)
65 Log.Error(Globals.LogTag, "Error checking if in-vehicle activity detector is supported");
71 private static int GetCount()
75 int error = Interop.SensorManager.GetSensorList(SensorType.InVehicleActivityDetector, out list, out count);
76 if (error != (int)SensorError.None)
78 Log.Error(Globals.LogTag, "Error getting sensor list for in-vehicle activity detector");
82 Interop.Libc.Free(list);
87 /// Event Handler for storing the callback functions for event corresponding to change in in-vehicle activity detector data.
89 public event EventHandler<InVehicleActivityDetectorDataUpdatedEventArgs> DataUpdated;
91 protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
93 Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
94 TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
95 InVehicle = (DetectorState)sensorData.values[0];
96 ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy;
98 DataUpdated?.Invoke(this, new InVehicleActivityDetectorDataUpdatedEventArgs(sensorData.values[0]));
101 internal override SensorType GetSensorType()
103 return SensorType.InVehicleActivityDetector;