Пример #1
0
        /// <summary>
        ///     Construct a new RGB LED from the specified LED driver channels
        /// </summary>
        /// <param name="red">The red LED</param>
        /// <param name="green">The green LED</param>
        /// <param name="blue">The blue LED</param>
        public RgbLed(Led red, Led green, Led blue)
        {
            r = red;
            g = green;
            b = blue;

            if (!drivers.Contains(red.Driver))
            {
                drivers.Add(red.Driver);
            }
            if (!drivers.Contains(green.Driver))
            {
                drivers.Add(green.Driver);
            }
            if (!drivers.Contains(blue.Driver))
            {
                drivers.Add(blue.Driver);
            }

            // if all the drivers have autoflush disabled, we'll disable it, too
            if (drivers.Where(drv => drv.AutoFlush).Count() == 0)
            {
                AutoFlush = false;
            }

            r.Brightness = 0.0;
            r.State      = true;

            g.Brightness = 0.0;
            g.State      = true;

            b.Brightness = 0.0;
            b.State      = true;
        }
Пример #2
0
 internal override void LedStateChanged(Led led)
 {
     states[led.Channel] = led.State;
     if (AutoFlush)
     {
         FlushAsync().Wait();
     }
 }
 /// <summary>
 /// Construct an LedDriver
 /// </summary>
 /// <param name="numLeds">The number of LEDs to construct</param>
 /// <param name="HasGlobalBrightnessControl">Whether the controller can globally adjust the LED brightness</param>
 /// <param name="HasIndividualBrightnessControl">Whether the controller has individual LED brightness control</param>
 public LedDriver(int numLeds, bool HasGlobalBrightnessControl, bool HasIndividualBrightnessControl)
 {
     for (int i = 0; i < numLeds; i++)
     {
         var led = new Led(this, i, HasIndividualBrightnessControl);
         Leds.Add(led);
     }
 }
Пример #4
0
 internal override void LedBrightnessChanged(Led led)
 {
     values[led.Channel] = (byte)Math.Round(led.Brightness * 255);
     if (AutoFlush)
     {
         FlushAsync().Wait();
     }
 }
Пример #5
0
 /// <summary>
 ///     Construct an LedDriver
 /// </summary>
 /// <param name="numLeds">The number of LEDs to construct</param>
 /// <param name="HasGlobalBrightnessControl">Whether the controller can globally adjust the LED brightness.</param>
 /// <param name="HasIndividualBrightnessControl">Whether the controller has individual LED brightness control</param>
 public LedDriver(int numLeds, bool HasGlobalBrightnessControl, bool HasIndividualBrightnessControl)
 {
     this.HasGlobalBrightnessControl     = HasGlobalBrightnessControl;
     this.HasIndividualBrightnessControl = HasIndividualBrightnessControl;
     for (var i = 0; i < numLeds; i++)
     {
         var led = new Led(this, i, HasIndividualBrightnessControl);
         Leds.Add(led);
     }
 }
Пример #6
0
 private void update(Led led)
 {
     if (useActiveLowOutput)
     {
         Pins[led.Channel].DutyCycle = led.State ? 1.0 - Utility.BrightnessToCieLuminance(led.Brightness) : 1.0;
     }
     else
     {
         Pins[led.Channel].DutyCycle = led.State ? Utility.BrightnessToCieLuminance(led.Brightness) : 0.0;
     }
 }
Пример #7
0
        internal override void LedStateChanged(Led led)
        {
            var index = 16 * (led.Channel / ((int)package / 8)) + led.Channel % ((int)package / 8);

            data.Set(index, led.State);
            if (AutoFlush)
            {
                // if we're autoflushing, only send the LED we need to update
                var address = (byte)(index / 8);
                dev.WriteByteDataAsync(address, data.GetBytes()[address]).Wait();
            }
        }
Пример #8
0
        /// <summary>
        ///     Called by an LED when its state has changed
        /// </summary>
        /// <param name="led">The LED whose state has changed</param>
        internal override void LedStateChanged(Led led)
        {
            var idx = led.Channel;

            if (useActiveLowOutput)
            {
                Pins[idx].DigitalValue = !led.State;
            }
            else
            {
                Pins[idx].DigitalValue = led.State;
            }
        }
Пример #9
0
 private void update(Led led)
 {
     if (led.State)
     {
         var brightness = (ushort)Math.Round(
             Utility.BrightnessToCieLuminance(led.Brightness * globalBrightness) * 65535);
         CurrentValue[led.Channel * 2 + 1] = (byte)(brightness >> 8);
         CurrentValue[led.Channel * 2]     = (byte)(brightness & 0xFF);
     }
     else
     {
         CurrentValue[led.Channel * 2]     = 0x00;
         CurrentValue[led.Channel * 2 + 1] = 0x00;
     }
     FlushIfAutoFlushEnabled().Wait();
 }
Пример #10
0
        internal override void LedStateChanged(Led led)
        {
            var digit   = led.Channel / 8;
            var segment = led.Channel % 8;
            var value   = led.State;

            // set or clear the appropriate bit
            if (led.State)
            {
                newValues[digit] |= (byte)(1 << segment);
            }
            else
            {
                newValues[digit] &= (byte)~(1 << segment);
            }

            if (AutoFlush)
            {
                FlushAsync().Wait();
            }
        }
Пример #11
0
 /// <summary>
 ///     Called by the LED when the brightness changed
 /// </summary>
 /// <param name="led">The LED whose brightness changed</param>
 internal abstract void LedBrightnessChanged(Led led);
Пример #12
0
 void ILedDriver.LedStateChanged(Led led)
 {
     LedStateChanged(led);
 }
Пример #13
0
 /// <summary>
 ///     Called by the LED when the state changes
 /// </summary>
 /// <param name="led">The LED whose state changed</param>
 internal abstract void LedStateChanged(Led led);
 /// <summary>
 /// Called by the LED when the brightness changed
 /// </summary>
 /// <param name="led">The LED whose brightness changed</param>
 internal abstract void LedBrightnessChanged(Led led);
 void ILedDriver.LedBrightnessChanged(Led led) { LedBrightnessChanged(led); }
 /// <summary>
 /// Called by the LED when the state changes
 /// </summary>
 /// <param name="led">The LED whose state changed</param>
 internal abstract void LedStateChanged(Led led);
 void ILedDriver.LedStateChanged(Led led) { LedStateChanged(led); }
        internal override void LedStateChanged(Led led)
        {
            int digit = led.Channel / 8;
            int segment = led.Channel % 8;
            bool value = led.State;

            // set or clear the appropriate bit
            if(led.State)
                newValues[digit] |= (byte)(1 << segment);
            else
                newValues[digit] &= (byte)~(1 << segment);

            if (AutoFlush)
                Flush().Wait();
        }
Пример #19
0
 /// <summary>
 ///     Called by an LED when its brightness has changed
 /// </summary>
 /// <param name="led">The LED whose brightness has changed</param>
 internal override void LedBrightnessChanged(Led led)
 {
     update(led);
 }
Пример #20
0
 /// <summary>
 ///     Called by an LED when its state has changed
 /// </summary>
 /// <param name="led">The LED whose state has changed</param>
 internal override void LedStateChanged(Led led)
 {
     update(led);
 }
        internal override void LedStateChanged(Led led)
        {

            int digit = led.Channel / 8;
            int segment = led.Channel % 8;

            if(!UseNativeLedOrder)
            {
                if (segment < 7)
                    segment = 6 - segment;
            }

            if (led.State == true)
                state[digit] |= (byte)(1 << segment);
            else
                state[digit] &= (byte)~(1 << segment);

            if (AutoFlush)
            {
                Send((Opcode)(digit + 1), state[digit]).Wait(); 
            }
        }
 internal override void LedBrightnessChanged(Led led) { }
Пример #23
0
 void ILedDriver.LedBrightnessChanged(Led led)
 {
 }
Пример #24
0
 void ILedDriver.LedStateChanged(Led led)
 {
     update(led);
 }
Пример #25
0
 void ILedDriver.LedStateChanged(Led led)
 {
     currentValue.Set(led.Channel, led.State);
     CurrentValue = currentValue.GetBytes();
     FlushIfAutoFlushEnabled().Wait();
 }
Пример #26
0
 void ILedDriver.LedBrightnessChanged(Led led)
 {
     update(led);
 }
Пример #27
0
 internal override void LedBrightnessChanged(Led led)
 {
 }
        void ILedDriver.LedStateChanged(Led led)
        {
            if (led.State)
                CurrentValue |= (uint)(1 << led.Channel);
            else
                CurrentValue &= (uint)~(1 << led.Channel);

            FlushIfAutoFlushEnabled().Wait();
        }