Adding IR Module.Fixed device not supported error.
authorPraveen Gattu <gattu.p@samsung.com>
Wed, 11 May 2016 05:49:28 +0000 (11:19 +0530)
committerPraveen Gattu <gattu.p@samsung.com>
Mon, 16 May 2016 04:34:14 +0000 (10:04 +0530)
Change-Id: I769b19c8ff7de6cd180b7fe227a7721a2f98e29f
Signed-off-by: Praveen Gattu <gattu.p@samsung.com>
Tizen.System/Device/DeviceExceptionFactory.cs
Tizen.System/Device/IR.cs [new file with mode: 0644]
Tizen.System/Device/Led.cs
Tizen.System/Interop/Interop.Device.cs
Tizen.System/Tizen.System.csproj

index 3512432..c30d004 100644 (file)
@@ -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/Tizen.System/Device/IR.cs b/Tizen.System/Device/IR.cs
new file mode 100644 (file)
index 0000000..ff9478a
--- /dev/null
@@ -0,0 +1,47 @@
+using System;
+
+namespace Tizen.System
+{
+    /// <summary>
+    /// 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.
+    /// </summary>
+    public static class IR
+    {
+        /// <summary>
+        /// Gets the information whether IR module is available.
+        /// </summary>
+        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;
+            }
+        }
+
+        /// <summary>
+        /// Transmits IR command.
+        /// </summary>
+        /// <param name="carrierFreequency">
+        /// Carrier frequency to transmit IR command (Hertz).
+        /// </param>
+        /// <param name="pattern">
+        /// IR command list of type interger.
+        /// </param>
+        public void Transmit(int carrierFreequency, IList<int> 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.");
+            }
+        }
+    }
+}
index d0b18bd..d17044e 100644 (file)
@@ -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.");
             }
         }
 
index e9b8f89..31c2ea3 100644 (file)
@@ -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);
index 1811f03..6c61840 100644 (file)
@@ -61,6 +61,7 @@
     <Compile Include="Device\Haptic.cs" />
     <Compile Include="Device\Led.cs" />
     <Compile Include="Device\Power.cs" />
+    <Compile Include="Device\IR.cs" />
     <Compile Include="Device\DeviceEventArgs.cs" />
     <Compile Include="Interop\Interop.Device.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />