namespace Tizen.Sensor
{
/// <summary>
- /// WalkingActivityDetector Class. Used for registering callbacks for walking activity detector and getting the walking state
+ /// The WalkingActivityDetector class is used for registering callbacks for the walking activity detector and getting the walking state.
/// </summary>
public sealed class WalkingActivityDetector : ActivityDetector
{
private static string ActivityDetectorKey = "http://tizen.org/feature/sensor.activity_recognition";
/// <summary>
- /// Gets the state of walking activity detector
+ /// Gets the state of the walking activity detector.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value> The walking state. </value>
public DetectorState Walking { get; private set; } = DetectorState.Unknown;
/// <summary>
- /// Returns true or false based on whether walking activity detector is supported by device.
+ /// Returns true or false based on whether the walking activity detector is supported by the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value><c>true</c> if supported; otherwise <c>false</c>.</value>
public static bool IsSupported
{
get
}
/// <summary>
- /// Returns the number of walking activity detector available on the device.
+ /// Returns the number of walking activity detectors available on the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value> The count of walking activity detectors. </value>
public static int Count
{
get
}
/// <summary>
- /// Initializes a new instance of the <see cref="Tizen.Sensor.walkingActivityDetector"/> class.
+ /// Initializes a new instance of the <see cref="Tizen.Sensor.WalkingActivityDetector"/> class.
/// </summary>
- /// <exception cref="ArgumentException">Thrown when an invalid argument is used</exception>
- /// <exception cref="NotSupportedException">Thrown when the sensor is not supported</exception>
- /// <exception cref="InvalidOperationException">Thrown when the operation is invalid for the current state</exception>
+ /// <since_tizen> 3 </since_tizen>
+ /// <feature>http://tizen.org/feature/sensor.activity_recognition</feature>
+ /// <exception cref="ArgumentException">Thrown when an invalid argument is used.</exception>
+ /// <exception cref="NotSupportedException">Thrown when the sensor is not supported.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when the operation is invalid for the current state.</exception>
/// <param name='index'>
/// Index. Default value for this is 0. Index refers to a particular walking activity detector in case of multiple sensors.
/// </param>
}
/// <summary>
- /// Event Handler for storing the callback functions for event corresponding to change in walking activity gesture detector data.
+ /// An event handler for storing the callback functions for the event corresponding to the change in the walking activity gesture detector data.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public event EventHandler<WalkingActivityDetectorDataUpdatedEventArgs> DataUpdated;
- internal override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
+ internal static Interop.SensorListener.SensorEventCallback _callback;
+
+ internal override void EventListenStart()
{
- Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
- TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
- Walking = (DetectorState)sensorData.values[0];
- ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy;
+ _callback = (IntPtr sensorHandle, IntPtr eventPtr, IntPtr data) => {
+ Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(eventPtr);
+
+ TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
+ Walking = (DetectorState)sensorData.values[0];
+ ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy;
+
+ DataUpdated?.Invoke(this, new WalkingActivityDetectorDataUpdatedEventArgs(sensorData.values[0]));
+ };
+
+ int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, _callback, IntPtr.Zero);
+ if (error != (int)SensorError.None)
+ {
+ Log.Error(Globals.LogTag, "Error setting event callback for walking activity detector");
+ throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for walking activity detector");
+ }
+ }
- DataUpdated?.Invoke(this, new WalkingActivityDetectorDataUpdatedEventArgs(sensorData.values[0]));
+ internal override void EventListenStop()
+ {
+ int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
+ if (error != (int)SensorError.None)
+ {
+ Log.Error(Globals.LogTag, "Error unsetting event callback for walking activity detector");
+ throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for walking activity detector");
+ }
}
internal override SensorType GetSensorType()