From 0c24c025b2603f585c52da4700e4c1b9d25ee7a8 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 26 Jul 2016 22:29:19 +0900 Subject: [PATCH] Add activity/gesture detectors as new sensor Change-Id: If2451f4d07264bdddf604c9874daf49861432955 Signed-off-by: kibak.yoon --- Tizen.System.Sensor/Tizen.System.Sensor.csproj | 257 +++++++++++---------- .../FaceDownGestureDetectorDataUpdatedEventArgs.cs | 28 +++ ...nVehicleActivityDetectorDataUpdatedEventArgs.cs | 28 +++ .../PickUpGestureDetectorDataUpdatedEventArgs.cs | 28 +++ .../RunningActivityDetectorDataUpdatedEventArgs.cs | 28 +++ ...ationaryActivityDetectorDataUpdatedEventArgs.cs | 28 +++ .../WalkingActivityDetectorDataUpdatedEventArgs.cs | 28 +++ .../WristUpGestureDetectorDataUpdatedEventArgs.cs | 28 +++ .../Plugins/ActivityDetector.cs | 46 ++++ .../Plugins/FaceDownGestureDetector.cs | 121 ++++++++++ .../Plugins/InVehicleActivityDetector.cs | 102 ++++++++ .../Tizen.System.Sensor/Plugins/Pedometer.cs | 6 +- .../Plugins/PickUpGestureDetector.cs | 121 ++++++++++ .../Plugins/RunningActivityDetector.cs | 102 ++++++++ .../Tizen.System.Sensor/Plugins/SleepMonitor.cs | 6 +- .../Plugins/StationaryActivityDetector.cs | 102 ++++++++ .../Plugins/WalkingActivityDetector.cs | 102 ++++++++ .../Plugins/WristUpGestureDetector.cs | 121 ++++++++++ .../Tizen.System.Sensor/SensorEnumerations.cs | 50 +++- 19 files changed, 1202 insertions(+), 130 deletions(-) mode change 100644 => 100755 Tizen.System.Sensor/Tizen.System.Sensor.csproj create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/FaceDownGestureDetectorDataUpdatedEventArgs.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/InVehicleActivityDetectorDataUpdatedEventArgs.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/PickUpGestureDetectorDataUpdatedEventArgs.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/RunningActivityDetectorDataUpdatedEventArgs.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/StationaryActivityDetectorDataUpdatedEventArgs.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/WalkingActivityDetectorDataUpdatedEventArgs.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/WristUpGestureDetectorDataUpdatedEventArgs.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/Plugins/ActivityDetector.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/Plugins/FaceDownGestureDetector.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/Plugins/InVehicleActivityDetector.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/Plugins/PickUpGestureDetector.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/Plugins/RunningActivityDetector.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/Plugins/StationaryActivityDetector.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WalkingActivityDetector.cs create mode 100644 Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WristUpGestureDetector.cs diff --git a/Tizen.System.Sensor/Tizen.System.Sensor.csproj b/Tizen.System.Sensor/Tizen.System.Sensor.csproj old mode 100644 new mode 100755 index d1a78aa..db06165 --- a/Tizen.System.Sensor/Tizen.System.Sensor.csproj +++ b/Tizen.System.Sensor/Tizen.System.Sensor.csproj @@ -1,121 +1,136 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {CB655C6A-F73B-448E-913C-CA4DCBC5E401} - Library - Tizen.System.Sensor - Tizen.System.Sensor - v4.5 - - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - false - - - none - false - bin\Release - prompt - 4 - false - false - - - true - - - Tizen.System.Sensor.snk - - - - - - - - ..\..\tizen\Tizen.Internals\bin\Debug\Tizen.Internals.dll - - - ..\..\tizen\Tizen\bin\Debug\Tizen.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {CB655C6A-F73B-448E-913C-CA4DCBC5E401} + Library + Tizen.System.Sensor + Tizen.System.Sensor + v4.5 + + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + false + + + none + false + bin\Release + prompt + 4 + false + false + + + true + + + Tizen.System.Sensor.snk + + + + + + + + ..\..\tizen\Tizen.Internals\bin\Debug\Tizen.Internals.dll + + + ..\..\tizen\Tizen\bin\Debug\Tizen.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/FaceDownGestureDetectorDataUpdatedEventArgs.cs b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/FaceDownGestureDetectorDataUpdatedEventArgs.cs new file mode 100644 index 0000000..7869fa4 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/FaceDownGestureDetectorDataUpdatedEventArgs.cs @@ -0,0 +1,28 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + /// + /// FaceDownGestureDetector changed event arguments. Class for storing the data returned by face down gesture detector. + /// + public class FaceDownGestureDetectorDataUpdatedEventArgs : EventArgs + { + internal FaceDownGestureDetectorDataUpdatedEventArgs(float state) + { + FaceDown = (DetectorState) state; + } + + /// + /// Gets the face down state. + /// + public DetectorState FaceDown { get; private set; } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/InVehicleActivityDetectorDataUpdatedEventArgs.cs b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/InVehicleActivityDetectorDataUpdatedEventArgs.cs new file mode 100644 index 0000000..df7fa04 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/InVehicleActivityDetectorDataUpdatedEventArgs.cs @@ -0,0 +1,28 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + /// + /// InVehicleActivityDetector changed event arguments. Class for storing the data returned by in-vehicle activity detector + /// + public class InVehicleActivityDetectorDataUpdatedEventArgs : EventArgs + { + internal InVehicleActivityDetectorDataUpdatedEventArgs(float state) + { + InVehicle = (DetectorState) state; + } + + /// + /// Gets the in-vehicle state. + /// + public DetectorState InVehicle { get; private set; } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/PickUpGestureDetectorDataUpdatedEventArgs.cs b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/PickUpGestureDetectorDataUpdatedEventArgs.cs new file mode 100644 index 0000000..17a2552 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/PickUpGestureDetectorDataUpdatedEventArgs.cs @@ -0,0 +1,28 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + /// + /// PickUpGestureDetector changed event arguments. Class for storing the data returned by pick up gesture detector + /// + public class PickUpGestureDetectorDataUpdatedEventArgs : EventArgs + { + internal PickUpGestureDetectorDataUpdatedEventArgs(float state) + { + PickUp = (DetectorState) state; + } + + /// + /// Gets the pick up state. + /// + public DetectorState PickUp { get; private set; } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/RunningActivityDetectorDataUpdatedEventArgs.cs b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/RunningActivityDetectorDataUpdatedEventArgs.cs new file mode 100644 index 0000000..ccb8b27 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/RunningActivityDetectorDataUpdatedEventArgs.cs @@ -0,0 +1,28 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + /// + /// RunningActivityDetector changed event arguments. Class for storing the data returned by running activity detector + /// + public class RunningActivityDetectorDataUpdatedEventArgs : EventArgs + { + internal RunningActivityDetectorDataUpdatedEventArgs(float state) + { + Running = (DetectorState) state; + } + + /// + /// Gets the running state. + /// + public DetectorState Running { get; private set; } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/StationaryActivityDetectorDataUpdatedEventArgs.cs b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/StationaryActivityDetectorDataUpdatedEventArgs.cs new file mode 100644 index 0000000..6e13641 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/StationaryActivityDetectorDataUpdatedEventArgs.cs @@ -0,0 +1,28 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + /// + /// StationaryActivityDetector changed event arguments. Class for storing the data returned by stationary activity detector + /// + public class StationaryActivityDetectorDataUpdatedEventArgs : EventArgs + { + internal StationaryActivityDetectorDataUpdatedEventArgs(float state) + { + Stationary = (DetectorState) state; + } + + /// + /// Gets the stationary state. + /// + public DetectorState Stationary { get; private set; } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/WalkingActivityDetectorDataUpdatedEventArgs.cs b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/WalkingActivityDetectorDataUpdatedEventArgs.cs new file mode 100644 index 0000000..aa309d0 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/WalkingActivityDetectorDataUpdatedEventArgs.cs @@ -0,0 +1,28 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + /// + /// WalkingActivityDetector changed event arguments. Class for storing the data returned by walking activity detector + /// + public class WalkingActivityDetectorDataUpdatedEventArgs : EventArgs + { + internal WalkingActivityDetectorDataUpdatedEventArgs(float state) + { + Walking = (DetectorState) state; + } + + /// + /// Gets the walking state. + /// + public DetectorState Walking { get; private set; } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/WristUpGestureDetectorDataUpdatedEventArgs.cs b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/WristUpGestureDetectorDataUpdatedEventArgs.cs new file mode 100644 index 0000000..69d6f4a --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/EventArgs/WristUpGestureDetectorDataUpdatedEventArgs.cs @@ -0,0 +1,28 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + /// + /// WristUpGestureDetector changed event arguments. Class for storing the data returned by wrist up gesture detector + /// + public class WristUpGestureDetectorDataUpdatedEventArgs : EventArgs + { + internal WristUpGestureDetectorDataUpdatedEventArgs(float state) + { + WristUp = (DetectorState) state; + } + + /// + /// Gets the wrist up state. + /// + public DetectorState WristUp { get; private set; } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/ActivityDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/ActivityDetector.cs new file mode 100644 index 0000000..41e5e2d --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/ActivityDetector.cs @@ -0,0 +1,46 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + public abstract class ActivityDetector : Sensor + { + /// + /// Gets the activity accuracy of activity detector + /// + public SensorDataAccuracy ActivityAccuracy { get; protected set; } + + protected abstract void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data); + + internal ActivityDetector(int index) : base(index) + { + } + + protected override void EventListenStart() + { + int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, SensorEventCallback, IntPtr.Zero); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error setting event callback for activity detector"); + throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for activity detector"); + } + } + + protected override void EventListenStop() + { + int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error unsetting event callback for activity detector"); + throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for activity detector"); + } + } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/FaceDownGestureDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/FaceDownGestureDetector.cs new file mode 100644 index 0000000..e3cc4a2 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/FaceDownGestureDetector.cs @@ -0,0 +1,121 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + public class FaceDownGestureDetector : Sensor + { + /// + /// Gets the state of the face down gesture. + /// + public DetectorState FaceDown { get; private set; } + + /// + /// Returns true or false based on whether face down gesture detector is supported by device. + /// + public static bool IsSupported + { + get + { + Log.Info(Globals.LogTag, "Checking if the face down gesture detector is supported"); + return CheckIfSupported(); + } + } + + /// + /// Returns the number of face down gesture detector available on the device. + /// + public static int Count + { + get + { + Log.Info(Globals.LogTag, "Getting the count of face down gesture detectors"); + return GetCount(); + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// Index. Default value for this is 0. Index refers to a particular face down gesture detector in case of multiple sensors. + /// + public FaceDownGestureDetector(int index = 0) : base(index) + { + Log.Info(Globals.LogTag, "Creating face down gesture detector object"); + } + + internal override SensorType GetSensorType() + { + return SensorType.FaceDownGestureDetector; + } + + private static bool CheckIfSupported() + { + bool isSupported; + int error = Interop.SensorManager.SensorIsSupported(SensorType.FaceDownGestureDetector, out isSupported); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error checking if face down gesture detector is supported"); + isSupported = false; + } + return isSupported; + } + + private static int GetCount() + { + IntPtr list; + int count; + int error = Interop.SensorManager.GetSensorList(SensorType.FaceDownGestureDetector, out list, out count); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error getting sensor list for face down gesture detector"); + count = 0; + } + else + Interop.Libc.Free(list); + return count; + } + + /// + /// Event Handler for storing the callback functions for event corresponding to change in face down gesture detector data. + /// + public event EventHandler DataUpdated; + + protected override void EventListenStart() + { + int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, SensorEventCallback, IntPtr.Zero); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error setting event callback for face down gesture detector"); + throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for face down gesture detector"); + } + } + + protected override void EventListenStop() + { + int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error unsetting event callback for face down gesture detector"); + throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for face down gesture detector"); + } + } + + private void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data) + { + Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr); + TimeSpan = new TimeSpan((Int64)sensorData.timestamp); + FaceDown = (DetectorState) sensorData.values[0]; + + DataUpdated?.Invoke(this, new FaceDownGestureDetectorDataUpdatedEventArgs(sensorData.values[0])); + } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/InVehicleActivityDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/InVehicleActivityDetector.cs new file mode 100644 index 0000000..21b5382 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/InVehicleActivityDetector.cs @@ -0,0 +1,102 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + public class InVehicleActivityDetector : ActivityDetector + { + /// + /// Gets the state of in-vehicle activity detector + /// + public DetectorState InVehicle { get; private set; } + + /// + /// Returns true or false based on whether in-vehicle activity detector is supported by device. + /// + public static bool IsSupported + { + get + { + Log.Info(Globals.LogTag, "Checking if the in-vehicle activity detector is supported"); + return CheckIfSupported(); + } + } + + /// + /// Returns the number of in-vehicle activity detector available on the device. + /// + public static int Count + { + get + { + Log.Info(Globals.LogTag, "Getting the count of in-vehicle activity detectors"); + return GetCount(); + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// Index. Default value for this is 0. Index refers to a particular in-vehicle activity detector in case of multiple sensors. + /// + public InVehicleActivityDetector(int index) : base(index) + { + Log.Info(Globals.LogTag, "Creating in-vehicle activity detector object"); + } + + private static bool CheckIfSupported() + { + bool isSupported; + int error = Interop.SensorManager.SensorIsSupported(SensorType.InVehicleActivityDetector, out isSupported); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error checking if in-vehicle activity detector is supported"); + isSupported = false; + } + return isSupported; + } + + private static int GetCount() + { + IntPtr list; + int count; + int error = Interop.SensorManager.GetSensorList(SensorType.InVehicleActivityDetector, out list, out count); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error getting sensor list for in-vehicle activity detector"); + count = 0; + } + else + Interop.Libc.Free(list); + return count; + } + + /// + /// Event Handler for storing the callback functions for event corresponding to change in in-vehicle activity detector data. + /// + public event EventHandler DataUpdated; + + protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data) + { + Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr); + TimeSpan = new TimeSpan((Int64)sensorData.timestamp); + InVehicle = (DetectorState)sensorData.values[0]; + ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy; + + DataUpdated?.Invoke(this, new InVehicleActivityDetectorDataUpdatedEventArgs(sensorData.values[0])); + } + + internal override SensorType GetSensorType() + { + return SensorType.InVehicleActivityDetector; + } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/Pedometer.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/Pedometer.cs index 3ad8baa..d399f2c 100644 --- a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/Pedometer.cs +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/Pedometer.cs @@ -92,7 +92,7 @@ namespace Tizen.System.Sensor internal override SensorType GetSensorType() { - return SensorType.HumanPedometer; + return SensorType.Pedometer; } /// @@ -104,7 +104,7 @@ namespace Tizen.System.Sensor private static bool CheckIfSupported() { bool isSupported; - int error = Interop.SensorManager.SensorIsSupported(SensorType.HumanPedometer, out isSupported); + int error = Interop.SensorManager.SensorIsSupported(SensorType.Pedometer, out isSupported); if (error != (int)SensorError.None) { Log.Error(Globals.LogTag, "Error checking if pedometer sensor is supported"); @@ -117,7 +117,7 @@ namespace Tizen.System.Sensor { IntPtr list; int count; - int error = Interop.SensorManager.GetSensorList(SensorType.HumanPedometer, out list, out count); + int error = Interop.SensorManager.GetSensorList(SensorType.Pedometer, out list, out count); if (error != (int)SensorError.None) { Log.Error(Globals.LogTag, "Error getting sensor list for pedometer"); diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/PickUpGestureDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/PickUpGestureDetector.cs new file mode 100644 index 0000000..90a3288 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/PickUpGestureDetector.cs @@ -0,0 +1,121 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + public class PickUpGestureDetector : Sensor + { + /// + /// Gets the state of the pick up gesture. + /// + public DetectorState PickUp { get; private set; } + + /// + /// Returns true or false based on whether pick up gesture detector is supported by device. + /// + public static bool IsSupported + { + get + { + Log.Info(Globals.LogTag, "Checking if the pick up gesture detector is supported"); + return CheckIfSupported(); + } + } + + /// + /// Returns the number of pick up gesture detector available on the device. + /// + public static int Count + { + get + { + Log.Info(Globals.LogTag, "Getting the count of pick up gesture detectors"); + return GetCount(); + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// Index. Default value for this is 0. Index refers to a particular pick up gesture detector in case of multiple sensors. + /// + public PickUpGestureDetector(int index = 0) : base(index) + { + Log.Info(Globals.LogTag, "Creating pick up gesture detector object"); + } + + internal override SensorType GetSensorType() + { + return SensorType.PickUpGestureDetector; + } + + private static bool CheckIfSupported() + { + bool isSupported; + int error = Interop.SensorManager.SensorIsSupported(SensorType.PickUpGestureDetector, out isSupported); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error checking if pick up gesture detector is supported"); + isSupported = false; + } + return isSupported; + } + + private static int GetCount() + { + IntPtr list; + int count; + int error = Interop.SensorManager.GetSensorList(SensorType.PickUpGestureDetector, out list, out count); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error getting sensor list for pick up gesture detector"); + count = 0; + } + else + Interop.Libc.Free(list); + return count; + } + + /// + /// Event Handler for storing the callback functions for event corresponding to change in pick up gesture detector data. + /// + public event EventHandler DataUpdated; + + protected override void EventListenStart() + { + int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, SensorEventCallback, IntPtr.Zero); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error setting event callback for pick up gesture detector"); + throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for pick up gesture detector"); + } + } + + protected override void EventListenStop() + { + int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error unsetting event callback for pick up gesture detector"); + throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for pick up gesture detector"); + } + } + + private void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data) + { + Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr); + TimeSpan = new TimeSpan((Int64)sensorData.timestamp); + PickUp = (DetectorState) sensorData.values[0]; + + DataUpdated?.Invoke(this, new PickUpGestureDetectorDataUpdatedEventArgs(sensorData.values[0])); + } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/RunningActivityDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/RunningActivityDetector.cs new file mode 100644 index 0000000..d604bc5 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/RunningActivityDetector.cs @@ -0,0 +1,102 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + public class RunningActivityDetector : ActivityDetector + { + /// + /// Gets the state of running activity detector + /// + public DetectorState Running { get; private set; } + + /// + /// Returns true or false based on whether running activity detector is supported by device. + /// + public static bool IsSupported + { + get + { + Log.Info(Globals.LogTag, "Checking if the running activity detector is supported"); + return CheckIfSupported(); + } + } + + /// + /// Returns the number of running activity detector available on the device. + /// + public static int Count + { + get + { + Log.Info(Globals.LogTag, "Getting the count of running activity detectors"); + return GetCount(); + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// Index. Default value for this is 0. Index refers to a particular running activity detector in case of multiple sensors. + /// + public RunningActivityDetector(int index) : base(index) + { + Log.Info(Globals.LogTag, "Creating running activity detector object"); + } + + private static bool CheckIfSupported() + { + bool isSupported; + int error = Interop.SensorManager.SensorIsSupported(SensorType.RunningActivityDetector, out isSupported); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error checking if running activity detector is supported"); + isSupported = false; + } + return isSupported; + } + + private static int GetCount() + { + IntPtr list; + int count; + int error = Interop.SensorManager.GetSensorList(SensorType.RunningActivityDetector, out list, out count); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error getting sensor list for running activity detector"); + count = 0; + } + else + Interop.Libc.Free(list); + return count; + } + + /// + /// Event Handler for storing the callback functions for event corresponding to change in running activity detector data. + /// + public event EventHandler DataUpdated; + + protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data) + { + Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr); + TimeSpan = new TimeSpan((Int64)sensorData.timestamp); + Running = (DetectorState)sensorData.values[0]; + ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy; + + DataUpdated?.Invoke(this, new RunningActivityDetectorDataUpdatedEventArgs(sensorData.values[0])); + } + + internal override SensorType GetSensorType() + { + return SensorType.RunningActivityDetector; + } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/SleepMonitor.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/SleepMonitor.cs index f7b6c69..cdb2d5c 100644 --- a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/SleepMonitor.cs +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/SleepMonitor.cs @@ -57,7 +57,7 @@ namespace Tizen.System.Sensor internal override SensorType GetSensorType() { - return SensorType.HumanSleepMonitor; + return SensorType.SleepMonitor; } /// @@ -69,7 +69,7 @@ namespace Tizen.System.Sensor private static bool CheckIfSupported() { bool isSupported; - int error = Interop.SensorManager.SensorIsSupported(SensorType.HumanSleepMonitor, out isSupported); + int error = Interop.SensorManager.SensorIsSupported(SensorType.SleepMonitor, out isSupported); if (error != (int)SensorError.None) { Log.Error(Globals.LogTag, "Error checking if sleep monitor is supported"); @@ -82,7 +82,7 @@ namespace Tizen.System.Sensor { IntPtr list; int count; - int error = Interop.SensorManager.GetSensorList(SensorType.HumanSleepMonitor, out list, out count); + int error = Interop.SensorManager.GetSensorList(SensorType.SleepMonitor, out list, out count); if (error != (int)SensorError.None) { Log.Error(Globals.LogTag, "Error getting sensor list for sleep"); diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/StationaryActivityDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/StationaryActivityDetector.cs new file mode 100644 index 0000000..5684b75 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/StationaryActivityDetector.cs @@ -0,0 +1,102 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + public class StationaryActivityDetector : ActivityDetector + { + /// + /// Gets the state of stationary activity detector + /// + public DetectorState Stationary { get; private set; } + + /// + /// Returns true or false based on whether stationary activity detector is supported by device. + /// + public static bool IsSupported + { + get + { + Log.Info(Globals.LogTag, "Checking if the stationary activity detector is supported"); + return CheckIfSupported(); + } + } + + /// + /// Returns the number of stationary activity detector available on the device. + /// + public static int Count + { + get + { + Log.Info(Globals.LogTag, "Getting the count of stationary activity detectors"); + return GetCount(); + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// Index. Default value for this is 0. Index refers to a particular stationary activity detector in case of multiple sensors. + /// + public StationaryActivityDetector(int index) : base(index) + { + Log.Info(Globals.LogTag, "Creating stationary activity detector object"); + } + + private static bool CheckIfSupported() + { + bool isSupported; + int error = Interop.SensorManager.SensorIsSupported(SensorType.StationaryActivityDetector, out isSupported); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error checking if stationary activity detector is supported"); + isSupported = false; + } + return isSupported; + } + + private static int GetCount() + { + IntPtr list; + int count; + int error = Interop.SensorManager.GetSensorList(SensorType.StationaryActivityDetector, out list, out count); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error getting sensor list for stationary activity detector"); + count = 0; + } + else + Interop.Libc.Free(list); + return count; + } + + /// + /// Event Handler for storing the callback functions for event corresponding to change in stationary activity detector data. + /// + public event EventHandler DataUpdated; + + protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data) + { + Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr); + TimeSpan = new TimeSpan((Int64)sensorData.timestamp); + Stationary = (DetectorState)sensorData.values[0]; + ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy; + + DataUpdated?.Invoke(this, new StationaryActivityDetectorDataUpdatedEventArgs(sensorData.values[0])); + } + + internal override SensorType GetSensorType() + { + return SensorType.StationaryActivityDetector; + } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WalkingActivityDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WalkingActivityDetector.cs new file mode 100644 index 0000000..24693b1 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WalkingActivityDetector.cs @@ -0,0 +1,102 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + public class WalkingActivityDetector : ActivityDetector + { + /// + /// Gets the state of walking activity detector + /// + public DetectorState Walking { get; private set; } + + /// + /// Returns true or false based on whether walking activity detector is supported by device. + /// + public static bool IsSupported + { + get + { + Log.Info(Globals.LogTag, "Checking if the walking activity detector is supported"); + return CheckIfSupported(); + } + } + + /// + /// Returns the number of walking activity detector available on the device. + /// + public static int Count + { + get + { + Log.Info(Globals.LogTag, "Getting the count of walking activity detectors"); + return GetCount(); + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// Index. Default value for this is 0. Index refers to a particular walking activity detector in case of multiple sensors. + /// + public WalkingActivityDetector(int index) : base(index) + { + Log.Info(Globals.LogTag, "Creating walking activity gesture detector object"); + } + + private static bool CheckIfSupported() + { + bool isSupported; + int error = Interop.SensorManager.SensorIsSupported(SensorType.WalkingActivityDetector, out isSupported); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error checking if walking activity detector is supported"); + isSupported = false; + } + return isSupported; + } + + private static int GetCount() + { + IntPtr list; + int count; + int error = Interop.SensorManager.GetSensorList(SensorType.WalkingActivityDetector, out list, out count); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error getting sensor list for walking activity detector"); + count = 0; + } + else + Interop.Libc.Free(list); + return count; + } + + /// + /// Event Handler for storing the callback functions for event corresponding to change in walking activity gesture detector data. + /// + public event EventHandler DataUpdated; + + protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data) + { + Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr); + TimeSpan = new TimeSpan((Int64)sensorData.timestamp); + Walking = (DetectorState)sensorData.values[0]; + ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy; + + DataUpdated?.Invoke(this, new WalkingActivityDetectorDataUpdatedEventArgs(sensorData.values[0])); + } + + internal override SensorType GetSensorType() + { + return SensorType.WalkingActivityDetector; + } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WristUpGestureDetector.cs b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WristUpGestureDetector.cs new file mode 100644 index 0000000..9c79955 --- /dev/null +++ b/Tizen.System.Sensor/Tizen.System.Sensor/Plugins/WristUpGestureDetector.cs @@ -0,0 +1,121 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.Sensor +{ + public class WristUpGestureDetector : Sensor + { + /// + /// Gets the state of the wrist up gesture. + /// + public DetectorState WristUp { get; private set; } + + /// + /// Returns true or false based on whether wrist up gesture detector is supported by device. + /// + public static bool IsSupported + { + get + { + Log.Info(Globals.LogTag, "Checking if the wrist up gesture detector is supported"); + return CheckIfSupported(); + } + } + + /// + /// Returns the number of wrist up gesture detector available on the device. + /// + public static int Count + { + get + { + Log.Info(Globals.LogTag, "Getting the count of wrist up gesture detectors"); + return GetCount(); + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// Index. Default value for this is 0. Index refers to a particular wrist up gesture detector in case of multiple sensors. + /// + public WristUpGestureDetector(int index = 0) : base(index) + { + Log.Info(Globals.LogTag, "Creating wrist up gesture detector object"); + } + + internal override SensorType GetSensorType() + { + return SensorType.WristUpGestureDetector; + } + + private static bool CheckIfSupported() + { + bool isSupported; + int error = Interop.SensorManager.SensorIsSupported(SensorType.WristUpGestureDetector, out isSupported); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error checking if wrist up gesture detector is supported"); + isSupported = false; + } + return isSupported; + } + + private static int GetCount() + { + IntPtr list; + int count; + int error = Interop.SensorManager.GetSensorList(SensorType.WristUpGestureDetector, out list, out count); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error getting sensor list for wrist up gesture detector"); + count = 0; + } + else + Interop.Libc.Free(list); + return count; + } + + /// + /// Event Handler for storing the callback functions for event corresponding to change in wrist up gesture detector data. + /// + public event EventHandler DataUpdated; + + protected override void EventListenStart() + { + int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, SensorEventCallback, IntPtr.Zero); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error setting event callback for wrist up gesture detector"); + throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for wrist up gesture detector"); + } + } + + protected override void EventListenStop() + { + int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle); + if (error != (int)SensorError.None) + { + Log.Error(Globals.LogTag, "Error unsetting event callback for wrist up gesture detector"); + throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for wrist up gesture detector"); + } + } + + private void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data) + { + Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr); + TimeSpan = new TimeSpan((Int64)sensorData.timestamp); + WristUp = (DetectorState) sensorData.values[0]; + + DataUpdated?.Invoke(this, new WristUpGestureDetectorDataUpdatedEventArgs(sensorData.values[0])); + } + } +} diff --git a/Tizen.System.Sensor/Tizen.System.Sensor/SensorEnumerations.cs b/Tizen.System.Sensor/Tizen.System.Sensor/SensorEnumerations.cs index c711152..29e8fd7 100644 --- a/Tizen.System.Sensor/Tizen.System.Sensor/SensorEnumerations.cs +++ b/Tizen.System.Sensor/Tizen.System.Sensor/SensorEnumerations.cs @@ -94,11 +94,39 @@ namespace Tizen.System.Sensor /// /// Pedometer sensor. /// - HumanPedometer = 0x300, + Pedometer = 0x300, /// /// Sleep monitor sensor. /// - HumanSleepMonitor = 22 + SleepMonitor = 0x301, + /// + /// Walking activity detector. + /// + WalkingActivityDetector = 0x401, + /// + /// Running activity detector. + /// + RunningActivityDetector = 0x402, + /// + /// Stationary activity detector. + /// + StationaryActivityDetector = 0x408, + /// + /// InVehicle activity detector. + /// + InVehicleActivityDetector = 0x409, + /// + /// Wrist up gesture detector. + /// + WristUpGestureDetector = 0x1201, + /// + /// Pick up gesture detector. + /// + PickUpGestureDetector = 0x1204, + /// + /// Face down gesture detector. + /// + FaceDownGestureDetector = 0x1205 } /// @@ -206,8 +234,8 @@ namespace Tizen.System.Sensor /// /// The wake state. /// - Wake, + /// /// The sleeping state. /// @@ -229,4 +257,20 @@ namespace Tizen.System.Sensor /// Far = 5 } + + /// + /// Detector sensor state. + /// + public enum DetectorState + { + /// + /// None sate. + /// + NotDetected = 0, + + /// + /// Detected state. + /// + Detected = 1 + } } -- 2.7.4