示例#1
0
 private static void FillLights_Color(LED_Queue QueueToModify, byte R, byte G, byte B, bool ApplyNow, bool SkipAnimationQueue)
 {
     for (int i = 0; i < QueueToModify.LightCount; i++) {
         QueueToModify.Lights [i].R = R;
         QueueToModify.Lights [i].G = G;
         QueueToModify.Lights [i].B = B;
     }
     if (ApplyNow) {
         if (SkipAnimationQueue) {
             QueueToModify.PushToQueue ();
         } else {
             AddToAnimQueue (QueueToModify);
         }
     }
 }
示例#2
0
 private static void FillLights_Brightness(LED_Queue QueueToModify, byte Brightness, bool ApplyNow, bool SkipAnimationQueue)
 {
     for (int i = 0; i < QueueToModify.LightCount; i++) {
         QueueToModify.Lights [i].Brightness = Brightness;
     }
     if (ApplyNow) {
         if (SkipAnimationQueue) {
             QueueToModify.PushToQueue ();
         } else {
             AddToAnimQueue (QueueToModify);
         }
     }
 }
示例#3
0
        private static void UpdateAnimationStackForQueue(LED_Queue QueueToModify, long PerfTracking_TimeElapsed, string PerfTracking_QueueName)
        {
            if (QueueToModify.AnimationActive && QueueToModify.QueueEmpty) {
                // Only add an animation frame if enabled, and the queue is empty
                if ((QueueToModify.SelectedAnimation.RequestedAnimationDelay <= Light_Animation_Latency) ||
                    (QueueToModify.QueueIdleTime >= QueueToModify.SelectedAnimation.RequestedAnimationDelay) ||
                    (QueueToModify.AnimationForceFrameRequest == true)) {
                    // Only add an animation frame if less than default delay is requested, or enough time elapsed in idle
            #if DEBUG_PERFORMANCE
                        Console.WriteLine ("{0} ms - queuing frame from active animation ({1})", PerfTracking_TimeElapsed, PerfTracking_QueueName);
            #endif
                    try {
                        // In all of the below, you must set QueueToModify to the new, intended output, otherwise
                        //  animation transitions will contain old values.
                        if (QueueToModify.SelectedAnimation.EnableSmoothing && Animation_Fading_Enabled) {
                            // Get the next frame, apply smoothing
                            ApplySmoothing (QueueToModify.SelectedAnimation.SmoothingAmount, true, QueueToModify.SelectedAnimation.GetNextFrame (), QueueToModify);
                            // ...and insert it into the queue.
                            QueueToModify.PushToQueue ();
                        } else if ((QueueToModify.AnimationForceFrameRequest == true) &&
                            (QueueToModify.SelectedAnimation.RequestSmoothCrossfade)) {
                            // Animation has a potentially-sharp change and requests a smooth cross-fade
                            // Get the next frame...
                            QueueToModify.Lights = QueueToModify.SelectedAnimation.GetNextFrame ();
                            // ...and insert it into the queue with an animated transition.
                            AddToAnimQueue (QueueToModify);
                        } else {
                            // Without smoothing, just directly add to the queue
                            QueueToModify.Lights = QueueToModify.SelectedAnimation.GetNextFrame ();
                            // But ensure that the local QueueToModify list is accurate
                            QueueToModify.PushToQueue ();
                        }
                    } catch (System.InvalidOperationException) {
                        Console.WriteLine ("(error playing animation, invalid operation encountered - setting queue to black)");
                        // System.InvalidOperationException: AudioPlayer not running, can not determine current track position.
                        // TODO: Better method of fixing this?
                        //  For now, just stop the animation, and let it do whatever it was going to do.
                        Animation_Stop (QueueToModify);
                        FillLights_Color (QueueToModify, LightSystem.Color_MIN, LightSystem.Color_MIN, LightSystem.Color_MIN, false, true);
                        FillLights_Brightness (QueueToModify, LightSystem.Brightness_MIN, false, true);
                    }

                    QueueToModify.AnimationForceFrameRequest = false;
                    // Frame has been sent, reset the ForceFrameRequest flag
                }
            }
        }
示例#4
0
        /// <summary>
        /// Add the collection of LEDs to the queue, automatically smoothly transitioning into it.
        /// </summary>
        /// <param name="QueueToModify">Queue to add animation to</param>
        /// <param name="LED_Collection">Desired LED appearance</param>
        private static void AddToAnimQueue(LED_Queue QueueToModify, List<LED> LED_Collection)
        {
            if (QueueToModify.QueueCount > 0 && Command_ConflictsExpected == false)
                Console.WriteLine ("(Warning: interrupting fade, appearance may vary.  If intended, prefix with '!')");
            // Don't warn about clearing the output queue if it's expected by running multiple commands at once

            QueueToModify.ClearQueue ();
            if (Animation_Fading_Enabled) {
                double Avg_OldPercent = Math.Min (Animation_Smoothing_Percentage_DEFAULT, 1);
                double Avg_NewPercent = Math.Max (1 - Animation_Smoothing_Percentage_DEFAULT, 0);
                List<LED> LED_Intermediate = new List<LED> ();
                lock (QueueToModify.LightsLastProcessed) {
                    for (int i = 0; i < LightSystem.LIGHT_COUNT; i++) {
                        LED_Intermediate.Add (new LED (QueueToModify.LightsLastProcessed [i].R, QueueToModify.LightsLastProcessed [i].G, QueueToModify.LightsLastProcessed [i].B, QueueToModify.LightsLastProcessed [i].Brightness));
                    }
                }
                for (int i_fades = 0; i_fades < Animation_Smoothing_Iterations_DEFAULT; i_fades++) {
                    for (int i = 0; i < LightSystem.LIGHT_COUNT; i++) {
                        LED_Intermediate [i].R = (byte)((LED_Collection [i].R * Avg_NewPercent) + (LED_Intermediate [i].R * Avg_OldPercent));
                        LED_Intermediate [i].G = (byte)((LED_Collection [i].G * Avg_NewPercent) + (LED_Intermediate [i].G * Avg_OldPercent));
                        LED_Intermediate [i].B = (byte)((LED_Collection [i].B * Avg_NewPercent) + (LED_Intermediate [i].B * Avg_OldPercent));
                        LED_Intermediate [i].Brightness = (byte)((LED_Collection [i].Brightness * Avg_NewPercent) + (LED_Intermediate [i].Brightness * Avg_OldPercent));
                    }
                    QueueToModify.PushToQueue (LED_Intermediate);
                }
                // Just in case the fade did not finish completely, ensure the desired state is sent, too
                QueueToModify.PushToQueue (LED_Collection);
            } else {
                QueueToModify.PushToQueue (LED_Collection);
            }
        }
示例#5
0
 private static void SetLight_Color(LED_Queue QueueToModify, int Index, byte R, byte G, byte B, bool ApplyNow, bool SkipAnimationQueue)
 {
     if (Index >= 0 & Index < QueueToModify.LightCount) {
         QueueToModify.Lights [Index].R = R;
         QueueToModify.Lights [Index].G = G;
         QueueToModify.Lights [Index].B = B;
     }
     if (ApplyNow) {
         if (SkipAnimationQueue) {
             QueueToModify.PushToQueue ();
         } else {
             AddToAnimQueue (QueueToModify);
         }
     }
 }