csapi-sensor: set default value to properties
[platform/core/csapi/tizenfx.git] / src / Tizen.Sensor / Tizen.Sensor / Plugins / WalkingActivityDetector.cs
1 // Copyright 2016 by Samsung Electronics, Inc.,
2 //
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.
8
9 using System;
10
11 namespace Tizen.Sensor
12 {
13     /// <summary>
14     /// WalkingActivityDetector Class. Used for registering callbacks for walking activity detector and getting the walking state
15     /// </summary>
16     public class WalkingActivityDetector : ActivityDetector
17     {
18         private static string ActivityDetectorKey = "http://tizen.org/feature/sensor.activity_recognition";
19
20         /// <summary>
21         /// Gets the state of walking activity detector
22         /// </summary>
23         public DetectorState Walking { get; private set; } = DetectorState.Unknown;
24
25         /// <summary>
26         /// Returns true or false based on whether walking activity detector is supported by device.
27         /// </summary>
28         public static bool IsSupported
29         {
30             get
31             {
32                 Log.Info(Globals.LogTag, "Checking if the walking activity detector is supported");
33                 return CheckIfSupported(SensorType.WalkingActivityDetector, ActivityDetectorKey);
34             }
35         }
36
37         /// <summary>
38         /// Returns the number of walking activity detector available on the device.
39         /// </summary>
40         public static int Count
41         {
42             get
43             {
44                 Log.Info(Globals.LogTag, "Getting the count of walking activity detectors");
45                 return GetCount();
46             }
47         }
48
49         /// <summary>
50         /// Initializes a new instance of the <see cref="Tizen.Sensor.walkingActivityDetector"/> class.
51         /// </summary>
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 walking activity detector in case of multiple sensors.
57         /// </param>
58         public WalkingActivityDetector(uint index = 0) : base(index)
59         {
60             SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.Walking);
61             Log.Info(Globals.LogTag, "Creating walking activity gesture detector object");
62         }
63
64         private static int GetCount()
65         {
66             IntPtr list;
67             int count;
68             int error = Interop.SensorManager.GetSensorList(SensorType.WalkingActivityDetector, out list, out count);
69             if (error != (int)SensorError.None)
70             {
71                 Log.Error(Globals.LogTag, "Error getting sensor list for walking activity detector");
72                 count = 0;
73             }
74             else
75                 Interop.Libc.Free(list);
76             return count;
77         }
78
79         /// <summary>
80         /// Event Handler for storing the callback functions for event corresponding to change in walking activity gesture detector data.
81         /// </summary>
82         public event EventHandler<WalkingActivityDetectorDataUpdatedEventArgs> DataUpdated;
83
84         protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
85         {
86             Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
87             TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
88             Walking = (DetectorState)sensorData.values[0];
89             ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy;
90
91             DataUpdated?.Invoke(this, new WalkingActivityDetectorDataUpdatedEventArgs(sensorData.values[0]));
92         }
93
94         internal override SensorType GetSensorType()
95         {
96             return SensorType.WalkingActivityDetector;
97         }
98     }
99 }