コード例 #1
0
 public AnimatedLedBase(Led led)
 {
     if(led == null)
     {
         throw new Exception("You must supply a LED object for this constructor!");
     }
     m_led = led;
     InitValues();
     ToggleResigerForAnimationTicks(true);
 }
コード例 #2
0
        //
        // Public functions
        //
        // Binds an LED object to a controller.
        public void AssociateLed(int startingSlot, Led assoicateLed)
        {
            if (assoicateLed == null)
            {
                throw new ArgumentNullException("Led can't be null!");
            }
            if(startingSlot < 0)
            {
                throw new ArgumentOutOfRangeException("The LED slot can't be < 0!");
            }

            // Get how many slots are needed
            int slotsNeeded = assoicateLed.GetBase().SlotsRequired;

            lock (m_ledMap)
            {
                // Make sure there is enough room in the position requested to
                // hold the new LED
                for (int i = 0; i < slotsNeeded; i++)
                {
                    // Check if something exists at that key
                    if (m_ledMap.ContainsKey(i + startingSlot))
                    {
                        // If it does, see if it is still valid
                        Led tempLed;
                        if (m_ledMap[i + startingSlot].TryGetTarget(out tempLed))
                        {
                            // The LED actually exists, we can't add the LED here
                            throw new ArgumentException("The requested position is already occupied by a LED. Remember RBG LEDs take 3 slots!");
                        }
                        else
                        {
                            // If we get here we have an entry for a LED that is gone. Remove it
                            m_ledMap.Remove(startingSlot + i);
                        }
                    }
                }
            }

            // Inform the listener that slots need to be added. The listener should throw if
            // this fails.
            m_controllerExtener.NotifiySlotsAdded(startingSlot, slotsNeeded);

            // Now actually add the LEDs to the map.
            lock(m_ledMap)
            {
                for (int i = 0; i < slotsNeeded; i++)
                {
                    m_ledMap.Add(startingSlot + i, new WeakReference<Led>(assoicateLed));
                }
            }

            // Inform the LED of the association
            assoicateLed.GetBase().SetNotificationCallback(startingSlot, this);
        }
コード例 #3
0
        private void SimpleSample_Loaded(object sender, RoutedEventArgs e)
        {
            // First we need to create the controller. This is the object that is responsible for controlling the
            // output of the system. The visual controller is an extension of the controller that feeds data back to 
            // a UI. Two controller are provided in the SDK, a software PWM controller, and a SPI bus controller.
            m_controller = new VisualLedController();

            // This is only needed for the VisualController
            m_controller.AddVisualListener(this);

            // Now create the LEDs. All we need to do is tell the system if they are multi color or single colored.
            m_led1 = new Led(LedType.RBG);
            m_led2 = new Led(LedType.RBG);
            m_led3 = new Led(LedType.RBG);
            m_led4 = new Led(LedType.RBG);
            m_led5 = new Led(LedType.RBG);

            // Next wrap the LEDs in an animated LED object so we can make them animated nicely.
            m_animatedLed1 = new AnimatedLed(m_led1);
            m_animatedLed2 = new AnimatedLed(m_led2);
            m_animatedLed3 = new AnimatedLed(m_led3);
            m_animatedLed4 = new AnimatedLed(m_led4);
            m_animatedLed5 = new AnimatedLed(m_led5);

            // Last, associate the LEDs with the controller. This actually binds the LED objects to a given controller.
            // The only thing we must specify here is what slot the LED is in. What a slot means is defined by whatever
            // controller you're using, for example in PWM a slot is the same as a pin; for SPI the slot is the same as the output
            // For RGB LEDs the slot passed is for the first pin (red), blue and green are assumed to be slot + 1 and slot + 2.
            m_controller.AssociateLed(0, m_led1);
            m_controller.AssociateLed(3, m_led2);
            m_controller.AssociateLed(6, m_led3);
            m_controller.AssociateLed(9, m_led4);
            m_controller.AssociateLed(12, m_led5);

            // Now set the intensity on the LEDs to match the UI.
            m_led1.Intensity = 1.0;
            m_led2.Intensity = 1.0;
            m_led3.Intensity = 1.0;
            m_led4.Intensity = 1.0;
            m_led5.Intensity = 1.0;

            // Setup the animation thread.
            m_timer = new DispatcherTimer();
            m_timer.Tick += AnimationTimer_Tick;
            m_timer.Interval = new TimeSpan(0, 0, 1);
            m_timer.Start();

            // Done.
            isSetup = true;
        }
コード例 #4
0
 public void AssoicateLed(int startingPosition, Led assoicateLed)
 {
     m_controller.AssociateLed(startingPosition, assoicateLed);
 }
コード例 #5
0
 public void DissociateLed(Led dissociateLed)
 {
     m_controller.DissociateLed(dissociateLed);
 }
コード例 #6
0
 // Called by the consumer when a new LED is associated to the controller
 public void AssociateLed(int startingSlot, Led assoicateLed)
 {
     // Call through to the base
     m_baseController.AssociateLed(startingSlot, assoicateLed);
 }
コード例 #7
0
        // Breaks the association with a LED and the controller
        public void DissociateLed(Led dissociateLed)
        {
            if(dissociateLed == null)
            {
                throw new ArgumentNullException("The LED can't be null!");
            }

            int startingPosition = dissociateLed.GetBase().FirstSlot;
            int slotsFilled = dissociateLed.GetBase().SlotsRequired;

            // Remove the LED from the map
            lock (m_ledMap)
            {
                for (int i = 0; i < slotsFilled; i++)
                {
                    m_ledMap.Remove(startingPosition + i);
                }
            }

            // Remove the association with the LED
            dissociateLed.GetBase().RemoveNotificationCallback();

            // Tell the listener last, if they fail we still want to do our logic
            m_controllerExtener.NotifiySlotsRevmoed(startingPosition, slotsFilled);
        }
コード例 #8
0
 /// <summary>
 /// Removes an LED from the controller. This will clean up the slots allocated for it.
 /// </summary>
 /// <param name="dissociateLed">The LED that should be removed</param>
 public void DissociateLed(Led dissociateLed)
 {
     m_base.DissociateLed(dissociateLed);
 }
コード例 #9
0
 /// <summary>
 /// Bind a LED to the controller and specifies where it should be bound.
 //  For single color LEDs they will bind to the number given, for multi color
 //  LEDs they will bind to the given number with an additional 2 slots added linearly.
 /// </summary>
 /// <param name="startingPosition">The first slot the LED should be bound to</param>
 /// <param name="assoicateLed">The LED to bind to the controller</param>
 public void AssociateLed(int startingPosition, Led assoicateLed)
 {
     m_base.AssociateLed(startingPosition, assoicateLed);
 }
コード例 #10
0
 /// <summary>
 /// Creates a new animated LED given an existing LED class
 /// </summary>
 /// <param name="led">An instance of the LED class.</param>
 public AnimatedLed(Led led)
 {
     m_base = new AnimatedLedBase(led);
 }
コード例 #11
0
 //
 // Constructor
 //
 public AnimatedLedBase(LedType type)
 {
     m_led = new Led(type);
     InitValues();
     ToggleResigerForAnimationTicks(true);
 }