6 /// The Led class provides properties and methods to control the attached led device.
8 public static class Led
11 /// Gets the max brightness value of a LED that is located next to the camera.
13 public static int MaxBrightness
18 DeviceError res = (DeviceError) Interop.Device.DeviceFlashGetMaxBrightness(out max);
19 if (res != DeviceError.None)
21 Log.Warn(DeviceExceptionFactory.LogTag, "unable to get max brightness value.");
27 private static readonly object s_lock = new object();
30 /// Gets the brightness value of a LED that is located next to the camera.
32 public static int Brightness
37 DeviceError res = (DeviceError) Interop.Device.DeviceFlashGetBrightness(out brightness);
38 if (res != DeviceError.None)
40 Log.Warn(DeviceExceptionFactory.LogTag, "unable to get brightness value.");
46 Interop.Device.DeviceFlashSetBrightness(value);
51 /// Plays the LED that is located to the front of a device.
53 /// <param name="on">Turn on time in milliseconds </param>
54 /// <param name="off">Turn off time in milliseconds </param>
55 /// <param name="color">
57 /// The first byte means opaque and the other 3 bytes are RGB values.
59 public static void Play(int on, int off, uint color)
61 //looks like only blink option is supported. So hard coded to default blink option.
62 DeviceError res = (DeviceError)Interop.Device.DeviceLedPlayCustom(on, off, color, 1);
63 if (res != DeviceError.None)
65 throw DeviceExceptionFactory.CreateException(DeviceError.InvalidParameter, "failed to play Led.");
70 /// Stops the LED that is located to the front of a device.
72 public static void Stop()
74 DeviceError res = (DeviceError) Interop.Device.DeviceLedStopCustom();
75 if(res != DeviceError.None)
77 throw DeviceExceptionFactory.CreateException(DeviceError.InvalidParameter, "failed to stop Led.");
82 private static EventHandler<LedBrightnessChangedEventArgs> s_brightnessChanged;
84 /// StateChanged is raised when the LED state is changed
86 /// <param name="sender">The source of the event.</param>
87 /// <param name="e">An LedBrightnessChangedEventArgs object that contains the changed brightness.</param>
88 public static event EventHandler<LedBrightnessChangedEventArgs> BrightnessChanged
94 if (s_brightnessChanged == null)
98 s_brightnessChanged += value;
105 s_brightnessChanged -= value;
106 if (s_brightnessChanged == null)
114 private static Interop.Device.deviceCallback s_handler;
115 private static void EventListenerStart()
117 s_handler = (int type, IntPtr value, IntPtr data) =>
119 int val = value.ToInt32();
120 LedBrightnessChangedEventArgs e = new LedBrightnessChangedEventArgs()
124 s_brightnessChanged?.Invoke(null, e);
127 Interop.Device.DeviceAddCallback(EventType.FlashBrightness, s_handler, IntPtr.Zero);
130 private static void EventListenerStop()
132 Interop.Device.DeviceRemoveCallback(EventType.FlashBrightness, s_handler);