Ejemplo n.º 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;
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 4
0
 internal override void LedBrightnessChanged(Led led)
 {
     values[led.Channel] = (byte)Math.Round(led.Brightness * 255);
     if (AutoFlush)
     {
         FlushAsync().Wait();
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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();
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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);
Ejemplo n.º 12
0
 void ILedDriver.LedStateChanged(Led led)
 {
     LedStateChanged(led);
 }
Ejemplo n.º 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); }
Ejemplo n.º 18
0
        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();
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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) { }
Ejemplo n.º 23
0
 void ILedDriver.LedBrightnessChanged(Led led)
 {
 }
Ejemplo n.º 24
0
 void ILedDriver.LedStateChanged(Led led)
 {
     update(led);
 }
Ejemplo n.º 25
0
 void ILedDriver.LedStateChanged(Led led)
 {
     currentValue.Set(led.Channel, led.State);
     CurrentValue = currentValue.GetBytes();
     FlushIfAutoFlushEnabled().Wait();
 }
Ejemplo n.º 26
0
 void ILedDriver.LedBrightnessChanged(Led led)
 {
     update(led);
 }
Ejemplo n.º 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();
        }