Release 4.0.0-preview1-00301
[platform/core/csapi/tizenfx.git] / src / Tizen.System / Device / IR.cs
1 /*
2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20
21 namespace Tizen.System
22 {
23     /// <summary>
24     /// The IR API provides the functions to control the IR transmitter.
25     /// The IR API provides the way to get the information if IR is available and then transmit the IR command.
26     /// </summary>
27     /// <privilege>
28     /// http://tizen.org/privilege/use_ir
29     /// </privilege>
30     /// <code>
31     ///     Console.WriteLine("IR availability for this device is: {0}", IR.IsAvailable);
32     /// </code>
33     public static class IR
34     {
35         /// <summary>
36         /// Gets the information whether the IR module is available.
37         /// </summary>
38         /// <since_tizen> 3 </since_tizen>
39         public static bool IsAvailable
40         {
41             get
42             {
43                 bool available = false;
44                 DeviceError res = (DeviceError)Interop.Device.DeviceIRIsAvailable(out available);
45                 if (res != DeviceError.None)
46                 {
47                     Log.Warn(DeviceExceptionFactory.LogTag, "unable to get ir status.");
48                 }
49                 return available;
50             }
51         }
52
53         /// <summary>
54         /// Transmits the IR command.
55         /// </summary>
56         /// <since_tizen> 3 </since_tizen>
57         /// <param name="carrierFreequency">
58         /// The carrier frequency to transmit the IR command (Hertz).
59         /// </param>
60         /// <param name="pattern">
61         /// The IR command list of type integer.
62         /// </param>
63         /// <exception cref="ArgumentException"> When an invalid parameter value is set.</exception>
64         /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
65         /// <exception cref="InvalidOperationException">In case of any system error.</exception>
66         /// <exception cref="NotSupportedException">In case the device does not support this behavior.</exception>
67         /// <code>
68         ///    try
69         ///    {
70         ///       List&lt;int&gt; pattern = new List&lt;int&gt;();
71         ///       pattern.Add(10);
72         ///       pattern.Add(50);
73         ///       IR.Transmit(60657, pattern);
74         ///    }
75         ///    catch(Exception e)
76         ///    {
77         ///    }
78         /// </code>
79         public static void Transmit(int carrierFreequency, IList<int> pattern)
80         {
81             int[] patternArray = pattern.ToArray();
82             DeviceError res = (DeviceError)Interop.Device.DeviceIRTransmit(carrierFreequency, patternArray, pattern.Count());
83             if (res != DeviceError.None)
84             {
85                 throw DeviceExceptionFactory.CreateException(res, "unable to trasmit IR command.");
86             }
87         }
88     }
89 }