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 /// WalkingActivityDetector Class. Used for registering callbacks for walking activity detector and getting the walking state
16 public class WalkingActivityDetector : ActivityDetector
18 private static string ActivityDetectorKey = "http://tizen.org/feature/sensor.activity_recognition";
21 /// Gets the state of walking activity detector
23 public DetectorState Walking { get; private set; }
26 /// Returns true or false based on whether walking activity detector is supported by device.
28 public static bool IsSupported
32 Log.Info(Globals.LogTag, "Checking if the walking activity detector is supported");
33 return CheckIfSupported(SensorType.WalkingActivityDetector, ActivityDetectorKey);
38 /// Returns the number of walking activity detector available on the device.
40 public static int Count
44 Log.Info(Globals.LogTag, "Getting the count of walking activity detectors");
50 /// Initializes a new instance of the <see cref="Tizen.Sensor.walkingActivityDetector"/> 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 walking activity detector in case of multiple sensors.
58 public WalkingActivityDetector(uint index = 0) : base(index)
60 SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.Walking);
61 Log.Info(Globals.LogTag, "Creating walking activity gesture detector object");
64 private static int GetCount()
68 int error = Interop.SensorManager.GetSensorList(SensorType.WalkingActivityDetector, out list, out count);
69 if (error != (int)SensorError.None)
71 Log.Error(Globals.LogTag, "Error getting sensor list for walking activity detector");
75 Interop.Libc.Free(list);
80 /// Event Handler for storing the callback functions for event corresponding to change in walking activity gesture detector data.
82 public event EventHandler<WalkingActivityDetectorDataUpdatedEventArgs> DataUpdated;
84 protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
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;
91 DataUpdated?.Invoke(this, new WalkingActivityDetectorDataUpdatedEventArgs(sensorData.values[0]));
94 internal override SensorType GetSensorType()
96 return SensorType.WalkingActivityDetector;