8 /// The Led class provides properties and methods to control the attached led device.
11 /// The Led API provides the way to control the attached LED device such as the camera flash and service LED.It supports to turn on the camera flash and set the pattern to the service LED which is located to the front of a device.
13 /// http://tizen.org/feature/led
14 /// http://tizen.org/feature/camera.back.flash
15 /// It is recommended to design feature related codes in your application for reliability.
16 /// You can check if a device supports the related features for this API by using System Information, thereby controlling the procedure of your application.
19 /// http://tizen.org/privilege/led
22 /// Console.WriteLine("Led MaxBrightness is: {0}", Tizen.System.Led.MaxBrightness);
23 /// Console.WriteLine("Led current Brightness is: {0}", Tizen.System.Led.Brightness);
25 public static class Led
28 /// Gets the max brightness value of a LED that is located next to the camera.
30 public static int MaxBrightness
35 DeviceError res = (DeviceError)Interop.Device.DeviceFlashGetMaxBrightness(out max);
36 if (res != DeviceError.None)
38 Log.Warn(DeviceExceptionFactory.LogTag, "unable to get max brightness value.");
44 private static readonly object s_lock = new object();
47 /// Gets the brightness value of a LED that is located next to the camera.
49 /// <remarks>The brightness value range of LED is 0 to Tizen.System.Led.MaxBrightness value.
50 /// Changing the brightness value will invoke the registered EventHandler for led BrightnessChanged (If any).
52 /// <exception cref="ArgumentException"> When the invalid parameter value is set.</exception>
53 /// <exception cref = "UnauthorizedAccessException"> If the privilege is not set.</exception>
55 /// Console.WriteLine("Led current Brightness is: {0}", Tizen.System.Led.Brightness);
56 /// Tizen.System.Led.Brightness = 50;
57 /// Console.WriteLine("Led current Brightness is: {0}", Tizen.System.Led.Brightness);
60 public static int Brightness
65 DeviceError res = (DeviceError)Interop.Device.DeviceFlashGetBrightness(out brightness);
66 if (res != DeviceError.None)
68 Log.Warn(DeviceExceptionFactory.LogTag, "unable to get brightness value.");
74 DeviceError res = (DeviceError) Interop.Device.DeviceFlashSetBrightness(value);
75 if (res != DeviceError.None)
77 throw DeviceExceptionFactory.CreateException(res, "unable to set brightness value");
83 /// Plays the LED that is located to the front of a device.
85 /// <param name="on">Turn on time in milliseconds </param>
86 /// <param name="off">Turn off time in milliseconds </param>
87 /// <param name="color">
89 /// The first byte means opaque and the other 3 bytes are RGB values.
91 /// <exception cref="ArgumentException"> When the invalid parameter value is set.</exception>
92 /// <exception cref = "UnauthorizedAccessException"> If the privilege is not set.</exception>
93 /// <exception cref = "InvalidOperationException"> In case of any system error.</exception>
94 /// <exception cref = "NotSupportedException"> In case of device does not support this behavior.</exception>
98 /// Led.Play(500, 200, Color.FromRgba(255, 255, 255, 1));
100 /// Catch(Exception e)
104 public static void Play(int on, int off, Color color)
106 //looks like only blink option is supported. So hard coded to default blink option.
107 DeviceError res = (DeviceError)Interop.Device.DeviceLedPlayCustom(on, off, Convert.ToUInt32(color.GetArgb()), 1);
108 if (res != DeviceError.None)
110 throw DeviceExceptionFactory.CreateException(res, "failed to play Led.");
115 /// Stops the LED that is located to the front of a device.
117 /// <exception cref = "UnauthorizedAccessException"> If the privilege is not set.</exception>
118 /// <exception cref = "InvalidOperationException"> In case of any system error.</exception>
119 /// <exception cref = "NotSupportedException"> In case of device does not support this behavior.</exception>
123 /// Led.Play(500, 200, Color.FromRgba(255, 255, 255, 1));
124 /// //wait for a while and stop...
127 /// Catch(Exception e)
132 public static void Stop()
134 DeviceError res = (DeviceError)Interop.Device.DeviceLedStopCustom();
135 if (res != DeviceError.None)
137 throw DeviceExceptionFactory.CreateException(res, "failed to stop Led.");
142 private static EventHandler<LedBrightnessChangedEventArgs> s_brightnessChanged;
144 /// StateChanged is raised when the LED state is changed
146 /// <param name="sender">The source of the event.</param>
147 /// <param name="e">An LedBrightnessChangedEventArgs object that contains the changed brightness.</param>
148 public static event EventHandler<LedBrightnessChangedEventArgs> BrightnessChanged
154 if (s_brightnessChanged == null)
156 EventListenerStart();
158 s_brightnessChanged += value;
165 s_brightnessChanged -= value;
166 if (s_brightnessChanged == null)
174 private static Interop.Device.deviceCallback s_handler;
175 private static void EventListenerStart()
177 s_handler = (int type, IntPtr value, IntPtr data) =>
179 int val = value.ToInt32();
180 LedBrightnessChangedEventArgs e = new LedBrightnessChangedEventArgs()
184 s_brightnessChanged?.Invoke(null, e);
187 Interop.Device.DeviceAddCallback(EventType.FlashBrightness, s_handler, IntPtr.Zero);
190 private static void EventListenerStop()
192 Interop.Device.DeviceRemoveCallback(EventType.FlashBrightness, s_handler);