From f8e3fa6e30d72e789eeb9d9d97e8333a4103384d Mon Sep 17 00:00:00 2001 From: Praveen Gattu Date: Wed, 11 May 2016 11:19:28 +0530 Subject: [PATCH] Adding IR Module.Fixed device not supported error. Change-Id: I769b19c8ff7de6cd180b7fe227a7721a2f98e29f Signed-off-by: Praveen Gattu --- src/Tizen.System/Device/DeviceExceptionFactory.cs | 5 ++- src/Tizen.System/Device/IR.cs | 47 +++++++++++++++++++++++ src/Tizen.System/Device/Led.cs | 4 +- src/Tizen.System/Interop/Interop.Device.cs | 7 +++- src/Tizen.System/Tizen.System.csproj | 1 + 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 src/Tizen.System/Device/IR.cs diff --git a/src/Tizen.System/Device/DeviceExceptionFactory.cs b/src/Tizen.System/Device/DeviceExceptionFactory.cs index 3512432..c30d004 100644 --- a/src/Tizen.System/Device/DeviceExceptionFactory.cs +++ b/src/Tizen.System/Device/DeviceExceptionFactory.cs @@ -30,9 +30,10 @@ namespace Tizen.System case DeviceError.InvalidParameter: exp = new ArgumentException(msg); break; - case DeviceError.AlreadyInProgress: - //fall through case DeviceError.NotSupported: + exp = new InvalidOperationException(msg +" : Device does not support the Operation."); + break; + case DeviceError.AlreadyInProgress: //fall through case DeviceError.ResourceBusy: //fall through diff --git a/src/Tizen.System/Device/IR.cs b/src/Tizen.System/Device/IR.cs new file mode 100644 index 0000000..ff9478a --- /dev/null +++ b/src/Tizen.System/Device/IR.cs @@ -0,0 +1,47 @@ +using System; + +namespace Tizen.System +{ + /// + /// The IR API provides functions to control a IR transmitter. + /// The IR API provides the way to get the information whether IR is available and transmit IR command. + /// + public static class IR + { + /// + /// Gets the information whether IR module is available. + /// + public bool IsAvailable + { + get + { + bool available = false; + DeviceError res = (DeviceError) Interop.Device.DeviceIRIsAvailable(out available); + if (res != DeviceError.None) + { + Log.Warn(DeviceExceptionFactory.LogTag, "unable to get ir status."); + } + return available; + } + } + + /// + /// Transmits IR command. + /// + /// + /// Carrier frequency to transmit IR command (Hertz). + /// + /// + /// IR command list of type interger. + /// + public void Transmit(int carrierFreequency, IList pattern) + { + int[] patternArray = pattern.toArray(); + DeviceError res = (DeviceError) Interop.Device.DeviceIRTransmit(carrierFreequency, patternArray, pattern.Count()); + if (res != DeviceError.None) + { + throw DeviceExceptionFactory.CreateException(res, "unable to trasmit IR command."); + } + } + } +} diff --git a/src/Tizen.System/Device/Led.cs b/src/Tizen.System/Device/Led.cs index d0b18bd..d17044e 100644 --- a/src/Tizen.System/Device/Led.cs +++ b/src/Tizen.System/Device/Led.cs @@ -62,7 +62,7 @@ namespace Tizen.System DeviceError res = (DeviceError)Interop.Device.DeviceLedPlayCustom(on, off, color, 1); if (res != DeviceError.None) { - throw DeviceExceptionFactory.CreateException(DeviceError.InvalidParameter, "failed to play Led."); + throw DeviceExceptionFactory.CreateException(res, "failed to play Led."); } } @@ -74,7 +74,7 @@ namespace Tizen.System DeviceError res = (DeviceError) Interop.Device.DeviceLedStopCustom(); if(res != DeviceError.None) { - throw DeviceExceptionFactory.CreateException(DeviceError.InvalidParameter, "failed to stop Led."); + throw DeviceExceptionFactory.CreateException(res, "failed to stop Led."); } } diff --git a/src/Tizen.System/Interop/Interop.Device.cs b/src/Tizen.System/Interop/Interop.Device.cs index e9b8f89..31c2ea3 100644 --- a/src/Tizen.System/Interop/Interop.Device.cs +++ b/src/Tizen.System/Interop/Interop.Device.cs @@ -21,7 +21,6 @@ namespace Tizen.System FlashBrightness } } - internal static class Interop { internal static partial class Device @@ -78,6 +77,12 @@ internal static class Interop [DllImport("libcapi-system-device.so.0", EntryPoint = "device_power_release_lock", CallingConvention = CallingConvention.Cdecl)] internal static extern int DevicePowerReleaseLock(int type); + //IR + [DllImport("libcapi-system-device.so.0", EntryPoint = "device_ir_is_available", CallingConvention = CallingConvention.Cdecl)] + internal static extern int DeviceIRIsAvailable(out bool available); + [DllImport("libcapi-system-device.so.0", EntryPoint = "device_ir_transmit", CallingConvention = CallingConvention.Cdecl)] + internal static extern int DeviceIRTransmit(int carrierFreequency, int[] pattern, int size); + // Callback [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate bool deviceCallback(int type, IntPtr value, IntPtr data); diff --git a/src/Tizen.System/Tizen.System.csproj b/src/Tizen.System/Tizen.System.csproj index 1811f03..6c61840 100644 --- a/src/Tizen.System/Tizen.System.csproj +++ b/src/Tizen.System/Tizen.System.csproj @@ -61,6 +61,7 @@ + -- 2.7.4