Beispiel #1
0
        private void Set_LED()
        {
            IList <LEDData> ledDataList = new List <LEDData>();

            for (int i = 0; i < 1; i++)
            {
                LEDData ledData = new LEDData();
                ledData.CardNum   = 1;
                ledData.ColorFont = false ? EQ2008.EQ2008.GREEN : EQ2008.EQ2008.RED;
                ledData.Content   = "test" + num++.ToString().PadLeft(6, '0');
                ledData.FontName  = "@宋体";
                ledData.SingleText.FontInfo.iFontSize = 9;
                //if (LedCardType == LedCardType.EQ2013)
                //{
                //    ledData.SingleText.MoveSet.iActionType = 2;
                //    ledData.SingleText.MoveSet.iHoldTime = 15;
                //    ledData.SingleText.MoveSet.iActionSpeed = 10;
                //}
                ledData.X          = 0;
                ledData.Y          = 0;
                ledData.Width      = 192;
                ledData.Height     = 32;
                ledData.IsMove     = true;
                ledData.MethodType = MethodType.AddSingleText;

                ledDataList.Add(ledData);
            }
            if (ledDataList.Count() > 0)
            {
                LEDUtil.Sending(ledDataList.ToArray());
            }
        }
        private void CheckFrame(LEDFrame frame)
        {
            LEDData data = frame.Leds;

            if (data.Keyboard.Length != LEDData.NUMLEDS_KEYBOARD)
            {
                Debug.WriteLine("SEVERE: Keyboard frame does not match expected length");
            }
            if (data.Strip.Length != LEDData.NUMLEDS_STRIP)
            {
                Debug.WriteLine("SEVERE: Strip frame does not match expected length");
            }
            if (data.Mouse.Length != LEDData.NUMLEDS_MOUSE)
            {
                Debug.WriteLine("SEVERE: Mouse frame does not match expected length");
            }
            if (data.Mousepad.Length != LEDData.NUMLEDS_MOUSEPAD)
            {
                Debug.WriteLine("SEVERE: Mousepad frame does not match expected length");
            }
            if (data.Headset.Length != LEDData.NUMLEDS_HEADSET)
            {
                Debug.WriteLine("SEVERE: Headset frame does not match expected length");
            }
            if (data.Keypad.Length != LEDData.NUMLEDS_KEYPAD)
            {
                Debug.WriteLine("SEVERE: Keypad frame does not match expected length");
            }
            if (data.General.Length != LEDData.NUMLEDS_GENERAL)
            {
                Debug.WriteLine("SEVERE: General frame does not match expected length");
            }
        }
Beispiel #3
0
        private bool AddSingleTextToProgram(int cardNum, LEDData data)
        {
            if (AddLed(cardNum))
            {
                AddProgram(cardNum);

                User_SingleText singleText = data.SingleText;

                singleText.PartInfo             = data.PartInfo;
                singleText.chContent            = data.Content;
                singleText.FontInfo.colorFont   = data.ColorFont;
                singleText.FontInfo.strFontName = data.FontName;
                if (!data.IsMove)
                {
                    singleText.MoveSet.iHoldTime = -1;
                }

                if (Programs.ContainsKey(cardNum))
                {
                    int m_iProgramIndex = (int)Programs[cardNum];
                    EQ2008.User_AddSingleText(cardNum, ref singleText, m_iProgramIndex);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a color burst, starting at the given color and progressively fading to black.
        /// </summary>
        /// <param name="color">The burst color.</param>
        /// <param name="fadeoutDuration">The burst fade-out duration.</param>
        /// <param name="destinationColor">The color to progressively fade to after the color burst (black by default)</param>
        /// <returns></returns>
        public void ColorBurst(HSVColor color, LightZone zones, float fadeoutDuration = 0.15f, bool priority = true, HSVColor destinationColor = default)
        {
            LEDData data = LEDData.Empty;

            // Set all to color
            ApplyColorToZones(data, zones, color);

            SendFrame(data, zones, priority);

            // Fade to Black

            if (fadeoutDuration > 0)
            {
                if (destinationColor.Equals(HSVColor.Black))
                {
                    FadeOutToBlack(data, zones, fadeoutDuration);
                }
                else
                {
                    FadeOutToColor(data, zones, fadeoutDuration, destinationColor);
                }
            }
            else
            {
                data = LEDData.Empty;
                if (!destinationColor.Equals(HSVColor.Black))
                {
                    ApplyColorToZones(data, zones, destinationColor);
                }
                SendFrame(data, zones);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Plays the specified animation once for <paramref name="loopDuration"/> seconds.
        /// </summary>
        /// <param name="fadeOutAfterRate">Optionally fade out the last animation frame progressively.</param>
        public void RunAnimationInLoop(string animPath, LightZone zones, float loopDuration, float fadeoutDuration = 0, bool priority = true, float timeScale = 1)
        {
            LEDColorData[] anim         = LoadAnimation(animPath).Frames;
            float          animDuration = anim.Length * 0.03f;
            float          loopRatio    = (int)(loopDuration / animDuration);
            float          time         = 0;
            LEDData        data         = null;

            while (time < anim.Length * loopRatio)
            {
                int i = ((int)time) % anim.Length;
                data = LEDData.FromColors(anim[i]);
                if (time == 0)
                {
                    SendFrame(data, zones, priority);
                }
                else
                {
                    SendFrame(data, zones);
                }
                time += 1 * timeScale;
            }
            if (fadeoutDuration > 0)
            {
                // data is last frame
                FadeOutToBlack(data, zones, fadeoutDuration);
            }
            else
            {
                /*LEDData black = LEDData.Empty;
                 * SendFrame(black, zones);*/
            }
        }
Beispiel #6
0
        // fadeoutDuration in seconds
        private void FadeOutToColor(LEDData frameData, LightZone zones, float fadeoutDuration, HSVColor color)
        {
            int          frames           = (int)Math.Round(fadeoutDuration * FPS);
            List <Led[]> frameLightArrays = frameData.GetArraysForZones(zones);

            for (int i = 0; i < frames; i++)
            {
                float        fadeout             = (float)Utils.Scale(i, 0, frames, 0, 1);
                LEDData      newFrame            = LEDData.Empty;
                List <Led[]> newFrameLightArrays = newFrame.GetArraysForZones(zones);

                for (int j = 0; j < frameLightArrays.Count; j++)
                {
                    Led[] arrCurrent = frameLightArrays[j];
                    Led[] arrNew     = newFrameLightArrays[j];
                    for (int k = 0; k < arrCurrent.Length; k++)
                    {
                        Led      l = arrCurrent[k];
                        HSVColor fadedColor;
                        if (color.Equals(HSVColor.Black))
                        {
                            fadedColor = l.color.FadeToBlackBy(fadeout);
                        }
                        else
                        {
                            fadedColor = l.color.FadeToColorBy(color, fadeout);
                        }
                        arrNew[k].Color(fadedColor);
                    }
                }
                SendFrame(newFrame, zones);
            }
        }
        private void AddImageToProgram(int cardNum, LEDData data, Bitmap bitmap)
        {
            if (AddLed(cardNum))
            {
                AddProgram(cardNum);
                int m_iProgramIndex = -1;
                int BmpZoneIndex    = -1;

                User_Bmp bmp = data.Image;

                bmp.PartInfo = data.PartInfo;

                User_MoveSet moveset = data.MoveSet;
                if (!data.IsMove)
                {
                    moveset.iHoldTime = -1;
                }

                if (Programs.ContainsKey(cardNum))
                {
                    m_iProgramIndex = (int)Programs[cardNum];
                    BmpZoneIndex    = EQ2008.User_AddBmpZone(cardNum, ref bmp, m_iProgramIndex);

                    HandleRef hr      = new HandleRef(bitmap, bitmap.GetHicon());
                    IntPtr    hBitmap = bitmap.GetHbitmap();
                    EQ2008.User_AddBmp(cardNum, BmpZoneIndex, hBitmap, ref moveset, m_iProgramIndex);
                }
            }
        }
Beispiel #8
0
        void OnNewAudioData()
        {
            DoFrame();
            LEDData data = LEDData.Empty;

            data.Strip = this.leds.CloneLeds();
            NewFrameReady?.Invoke(new LEDFrame(this, data, LightZone.Strip, true));
            newAudioAvailable = true;
        }
        public LEDFrame DoFrame(GameState gameState)
        {
            LEDData data = LEDData.Empty;

            HealthBar(data, lastFrame, gameState);
            WardView(data, gameState);
            GoldView(data, gameState);
            lastFrame = data;
            data.Mouse[0].Color(HealthColor);
            return(new LEDFrame(this, data, LightZone.All));
        }
Beispiel #10
0
        public void HoldColor(HSVColor color, LightZone zones, float duration, bool priority = false)
        {
            int frames = (int)Math.Round(duration * FPS);

            for (int i = 0; i < frames; i++)
            {
                LEDData data = LEDData.Empty;
                ApplyColorToZones(data, zones, color);
                SendFrame(data, zones, priority);
            }
        }
Beispiel #11
0
 private void SendFrame(LEDData data, LightZone zones, bool priority = false)
 {
     lastFrame = data;
     if (NewFrameReady == null)
     {
         throw new InvalidOperationException("Tried to SendFrame, but no NewFrameReady handler was attached to this AnimationModule.");
     }
     else
     {
         NewFrameReady?.Invoke(new LEDFrame(this, data, zones, priority));
     }
 }
Beispiel #12
0
        private void ApplyColorToZones(LEDData frameData, LightZone zones, HSVColor color)
        {
            List <Led[]> colArrays = frameData.GetArraysForZones(zones);

            foreach (Led[] arr in colArrays)
            {
                foreach (Led l in arr)
                {
                    l.Color(color);
                }
            }
        }
        private void GoldView(LEDData data, GameState gameState)
        {
            HSVColor col = HSVColor.Black;

            if (gameState.ActivePlayer.CurrentGold >= GoldNotificationThreshold)
            {
                col = GoldColor;
            }
            foreach (int k in goldKeys)
            {
                data.Keyboard[k].Color(col);
            }
        }
        private static void WardView(LEDData data, GameState gameState)
        {
            //if (lightMode != LightingMode.Keyboard) return; // TODO: Implement some sort of notification for LED strip perhaps

            Item trinket = gameState.PlayerChampion.Items.FirstOrDefault(x => x.Slot == 6);

            if (trinket == null)
            {
                // if there is no trinket, set to black
                foreach (int k in trinketKeys)
                {
                    data.Keyboard[k].SetBlack();
                }
            }
            else
            {
                HSVColor col = HSVColor.Black;
                if (trinket.ItemID == WardingTotemModule.ITEM_ID)
                {
                    col = YellowTrinketColor;
                }
                else if (trinket.ItemID == OracleLensModule.ITEM_ID)
                {
                    col = RedTrinketColor;
                }
                else if (trinket.ItemID == FarsightAlterationModule.ITEM_ID)
                {
                    col = BlueTrinketColor;
                }
                else if (trinket.ItemID == HeraldEyeModule.ITEM_ID)
                {
                    col = HeraldColor;
                }
                // TODO: HANDLE HERALD EYE
                foreach (int k in trinketKeys)
                {
                    data.Keyboard[k].Color(col);
                }
            }
        }
        public bool AddToProgram(LEDData data)
        {
            switch (data.MethodType)
            {
            case MethodType.AddText:
                AddTextToProgram(data.CardNum, data);
                break;

            case MethodType.AddSingleText:
                AddSingleTextToProgram(data.CardNum, data);
                break;

            case MethodType.AddImage:
                AddImageToProgram(data.CardNum, data, data.Bitmap);
                break;

            default:
                throw new Exception("EQ2008Collection.AddToProgram失败,未实现的节目添加方法!");
            }

            return(true);
        }
Beispiel #16
0
        public void FadeBetweenTwoColors(LightZone zones, HSVColor col1, HSVColor col2, float rate = 0.15f, float duration = 2)
        {
            // TODO: Broken
            int frames = (int)Math.Round(duration * FPS);

            for (int i = 0; i < frames; i++)
            {
                float        currentTime         = i / FPS;
                float        sin                 = (float)Math.Sin(currentTime * rate);
                HSVColor     color               = HSVColor.Lerp(col1, col2, sin);
                LEDData      newFrame            = LEDData.Empty;
                List <Led[]> newFrameLightArrays = newFrame.GetArraysForZones(zones);

                foreach (Led[] arr in newFrameLightArrays)
                {
                    foreach (Led l in arr)
                    {
                        l.Color(color);
                    }
                }
                SendFrame(newFrame, zones);
            }
        }
Beispiel #17
0
        public void Set_LED()
        {
            IList <LEDData> ledDataList = new List <LEDData>();
            LEDData         ledData     = new LEDData();

            ledData.CardNum = 1;
            //ledData.ColorFont = false ? EQ2008.GREEN : EQ2008.RED;
            ledData.Content  = num++.ToString();
            ledData.FontName = "@宋体";
            ledData.SingleText.FontInfo.iFontSize = 9;
            //if (LedCardType == LedCardType.EQ2013)
            //{
            //    ledData.SingleText.MoveSet.iActionType = 2;
            //    ledData.SingleText.MoveSet.iHoldTime = 15;
            //    ledData.SingleText.MoveSet.iActionSpeed = 10;
            //}
            ledData.X          = 0;
            ledData.Y          = 0;
            ledData.Width      = 192;
            ledData.Height     = 32;
            ledData.IsMove     = true;
            ledData.MethodType = MethodType.AddSingleText;
            Console.WriteLine(DateTime.Now.ToString() + "\t" + LEDUtil.Sending(ledData));
        }
        private void AddTextToProgram(int cardNum, LEDData data)
        {
            if (AddLed(cardNum))
            {
                AddProgram(cardNum);

                User_Text text = data.Text;

                text.PartInfo             = data.PartInfo;
                text.chContent            = data.Content;
                text.FontInfo.colorFont   = data.ColorFont;
                text.FontInfo.strFontName = data.FontName;
                if (!data.IsMove)
                {
                    text.MoveSet.iHoldTime = -1;
                }

                if (Programs.ContainsKey(cardNum))
                {
                    int m_iProgramIndex = (int)Programs[cardNum];
                    EQ2008.User_AddText(cardNum, ref text, m_iProgramIndex);
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// Cancels the currently running animation and sets the LEDs to black.
        /// </summary>
        public void StopCurrentAnimation()
        {
            LEDData black = LEDData.Empty;

            SendFrame(black, LightZone.None, true);
        }
Beispiel #20
0
 private void FadeOutToBlack(LEDData frameData, LightZone zones, float fadeoutDuration)
 {
     FadeOutToColor(frameData, zones, fadeoutDuration, HSVColor.Black);
 }
        private LEDFrame GetLEDFrameFromLuminosities(double[] luminosities)
        {
            LEDFrame frame = LEDFrame.Empty;
            LEDData  data  = frame.Leds;

            //Debug.WriteLine(String.Join(",", luminosities));
            int lastLuminositySpot = 0;

            for (int i = 0; i < LUMINOSITY_THRESHOLDS.Length; i++)
            {
                if (luminosities[i] > LUMINOSITY_THRESHOLDS[i])
                {
                    lastLuminositySpot = i;
                }
            }
            // TODO: Detect when it's not a valid frame so lights dont go crazy

            alreadyTouchedLeds.Clear();
            //double lastLuminositySpotNormal = lastLuminositySpot / 20.0;
            //Debug.WriteLine(lastLuminositySpot);
            double boostCurve        = lastLuminositySpot / (double)(LUMINOSITY_THRESHOLDS.Length - 1);
            int    keyboardBoostLeds = Math.Max(boostCurve > 0 ? 1 : 0, (int)Utils.Scale(boostCurve, 0, 1, 0, 18)); // ease in

            // KEYBOARD

            for (int i = 0; i < 16; i++)
            {
                List <int> listLedsToTurnOn = new List <int>(6); // light the whole column
                for (int j = 0; j < 6; j++)
                {
                    listLedsToTurnOn.Add(KeyUtils.PointToKey(new Point(i, j)));
                }

                if (i < keyboardBoostLeds)
                {
                    foreach (int idx in listLedsToTurnOn.Where(x => x != -1))
                    {
                        if (alreadyTouchedLeds.Contains(idx))
                        {
                            continue;
                        }
                        data.Keyboard[idx].Color(BoostColor);
                    }
                }
                else
                {
                    foreach (int idx in listLedsToTurnOn.Where(x => x != -1))
                    {
                        if (alreadyTouchedLeds.Contains(idx))
                        {
                            continue;
                        }
                        if (data.Keyboard[idx].color.AlmostEqual(BoostColor))
                        {
                            data.Keyboard[idx].Color(BoostColor);
                        }
                        else
                        {
                            data.Keyboard[idx].FadeToBlackBy(0.08f);
                        }
                    }
                }
                alreadyTouchedLeds.AddRange(listLedsToTurnOn);
            }

            // MOUSE
            int mouseBoostLeds = (int)Utils.Scale(boostCurve, 0, 1, 0, 8);

            for (int i = 0; i < LEDData.NUMLEDS_MOUSE; i++)
            {
                data.Mouse[i].FadeToBlackBy(0.01f);
            }
            if (boostCurve > 0)
            {
                data.Mouse[0].Color(BoostColor);
                data.Mouse[1].Color(BoostColor);
                for (int i = 0; i < mouseBoostLeds; i++)
                {
                    data.Mouse[2 + 6 - i].Color(BoostColor);
                    data.Mouse[2 + 7 + 6 - i].Color(BoostColor); // both sides of the mouse
                }
            }

            // MOUSEPAD

            int mousepadBoostLeds = (int)Utils.Scale(boostCurve, 0, 1, 0, 17);

            for (int i = 0; i < LEDData.NUMLEDS_MOUSEPAD; i++)
            {
                if (i < mousepadBoostLeds)
                {
                    data.Mousepad[i].Color(BoostColor);
                }
                else
                {
                    if (data.Mousepad[i].color.AlmostEqual(BoostColor))
                    {
                        data.Mousepad[i].Color(BoostColor);
                    }
                    else
                    {
                        data.Mousepad[i].FadeToBlackBy(0.05f);
                    }
                }
            }

            return(new LEDFrame(this, data, LightZone.Desk));
        }
        private static List <int> alreadyTouchedLeds = new List <int>(); // fixes a weird flickering bug
        private static void HealthBar(LEDData data, LEDData lastFrame, GameState gameState)
        {
            if (lastFrame != null)
            {
                data.Keyboard = lastFrame.Keyboard;
            }
            float maxHealth        = gameState.ActivePlayer.Stats.MaxHealth;
            float currentHealth    = gameState.ActivePlayer.Stats.CurrentHealth;
            float healthPercentage = currentHealth / maxHealth;

            alreadyTouchedLeds.Clear();

            // KEYBOARD LIGHTING
            int greenHPLeds = Math.Max((int)Utils.Scale(healthPercentage, 0, 1, 0, 16), 1); // at least one led active when player is alive

            for (int i = 0; i < 16; i++)
            {
                List <int> listLedsToTurnOn = new List <int>(6); // light the whole column
                for (int j = 0; j < 6; j++)
                {
                    listLedsToTurnOn.Add(KeyUtils.PointToKey(new Point(i, j)));
                }

                if (i < greenHPLeds)
                {
                    foreach (int idx in listLedsToTurnOn.Where(x => x != -1))
                    {
                        if (alreadyTouchedLeds.Contains(idx))
                        {
                            continue;
                        }
                        data.Keyboard[idx].MixNewColor(HealthColor, true, 0.2f);
                    }
                }
                else
                {
                    foreach (int idx in listLedsToTurnOn.Where(x => x != -1))
                    {
                        if (alreadyTouchedLeds.Contains(idx))
                        {
                            continue;
                        }
                        if (data.Keyboard[idx].color.AlmostEqual(HealthColor))
                        {
                            data.Keyboard[idx].Color(HurtColor);
                        }
                        else
                        {
                            data.Keyboard[idx].FadeToBlackBy(0.08f);
                        }
                    }
                }
                alreadyTouchedLeds.AddRange(listLedsToTurnOn);
            }

            // LED STRIP LIGHTING
            int ledsToTurnOn = Math.Max((int)(healthPercentage * LEDData.NUMLEDS_STRIP), 1);

            for (int i = 0; i < LEDData.NUMLEDS_STRIP; i++)
            {
                if (i < ledsToTurnOn)
                {
                    data.Strip[i].MixNewColor(HealthColor, true, 0.2f);
                }
                else
                {
                    if (data.Strip[i].color.AlmostEqual(HealthColor))
                    {
                        data.Strip[i].Color(HurtColor);
                    }
                    else
                    {
                        data.Strip[i].FadeToBlackBy(0.05f);
                    }
                }
            }
        }