示例#1
0
        /// <summary>
        /// Task that periodically updates the health bar.
        /// </summary>
        private async Task FrameTimer()
        {
            while (true)
            {
                if (masterCancelToken.IsCancellationRequested)
                {
                    return;
                }
                if (msSinceLastExternalFrameReceived >= msAnimationTimerThreshold)
                {
                    // Get the screen frame
                    using (Bitmap screenCaptureFrame = ScreenCaptureModule.GetNextFrame())
                    {
                        if (screenCaptureFrame != null)
                        {
                            CheckIfNotIngame(screenCaptureFrame);
                            goalModule.DoFrame(screenCaptureFrame);
                            if (!goalModule.IsPlayingAnimation)
                            {
                                LEDFrame frame = boostModule.DoFrame(screenCaptureFrame); // TODO: Idle animation after goal or when not ingame
                                if (frame != null)
                                {
                                    InvokeNewFrameReady(frame);
                                }
                            }
                        }
                    }
                }
                await Task.Delay(30);

                msSinceLastExternalFrameReceived += 30;
            }
        }
示例#2
0
        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");
            }
        }
示例#3
0
 /// <summary>
 /// Called by a <see cref="LEDModule"/> when a new frame is available to be processed.
 /// </summary>
 /// <param name="s">Module that sent the message</param>
 /// <param name="data">LED data</param>
 protected override void NewFrameReadyHandler(LEDFrame frame)
 {
     /*if (frame.LastSender != Animator && frame.LastSender != CurrentLEDSource)
      *  return; // If it's from a different source that what we're listening to, ignore it*/
     InvokeNewFrameReady(frame);
     msSinceLastExternalFrameReceived = 0;
 }
示例#4
0
 //bool updatingDisplay = false;
 /// <summary>
 /// Updates the LED display
 /// </summary>
 /// <param name="s">Module that sent the update command</param>
 /// <param name="ls">Array containing values for each LED in the strip</param>
 public void UpdateLEDDisplay(LEDFrame frame)
 {
     CheckFrame(frame);
     if (frame.Priority)
     {
         FrameQueue.Clear();
     }
     FrameQueue.Enqueue(frame);
     //Debug.WriteLine("Frame received. " + frame.LastSender.GetType().Name + " Queue=" + FrameQueue.Count);
 }
示例#5
0
        /// <summary>
        /// Starts the LED Manager in keyboard mode by default. Use <seealso cref="SetController"/> to further customize settings, especially for LED strips
        /// </summary>
        public LedManager() // by default starts in keyboard mode
        {
            InitLeds();

            ProcessListenerService.ProcessInFocusChanged += OnProcessChanged;
            ProcessListenerService.Start();
            ProcessListenerService.Register("League of Legends"); // Listen when league of legends is opened
            ProcessListenerService.Register("RocketLeague");

            UpdateLEDDisplay(LEDFrame.CreateEmpty(this));
            Task.Run(UpdateLoop).CatchExceptions();
        }
示例#6
0
        private async Task UpdateLoop()
        {
            while (true)
            {
                if (updateLoopCancelToken.IsCancellationRequested)
                {
                    return;
                }
                if (FrameQueue.Count > 0)
                {
                    LEDFrame next = FrameQueue.Dequeue();
                    //this.leds = next.Leds;
                    if (next != null)
                    {
                        SendLedData(next);
                    }
                }
                await Task.Delay(30); // 33 fps

                // await Task.Delay(15);
            }
        }
        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));
        }
 /// <summary>
 /// Dispatches a frame with the given LED data, raising the NewFrameReady event.
 /// </summary>
 protected override void NewFrameReadyHandler(LEDFrame frame)
 {
     //frame.SenderChain.Add(this);
     InvokeNewFrameReady(frame);
 }
示例#9
0
 private void FrameReceived(LEDFrame frame)
 {
     NewFrameReady.Invoke(frame);
 }
示例#10
0
        /// <summary>
        /// Update the virtual LED strip with the given LED color data.
        /// </summary>
        public void UpdateUI(LEDFrame frame)
        {
            if (updatingUI)
            {
                return;
            }
            updatingUI = true;
            updatingUI = false; // TODO: implement UI

            /*Task.Run(() => // HACK This is done asynchronously but it's still very slow. 10ms to draw stuff...
             * {
             *  if (currentLightingMode == LightingMode.Keyboard)
             *  {
             *      if (mode == LightingMode.Keyboard)
             *      {
             *          if (lastDrawnMode != LightingMode.Keyboard)
             *          {
             *              canvas.Clear(Color.White);
             *          }
             *          int i = 0;
             *          foreach (var led in leds)
             *          {
             *              byte[] col = led.color.ToRGB();
             *              SolidBrush colBrush = new SolidBrush(Color.FromArgb(col[0], col[1], col[2]));
             *              KeyboardKey key = keyboardLayout[i];
             *              canvas.FillRectangle(colBrush, new Rectangle(key.X, key.Y, (key.Width ?? 20) - 2, (key.Height ?? 20) - 2));
             *              i++;
             *          }
             *          lastDrawnMode = LightingMode.Keyboard;
             *      }
             *      else
             *      {
             *          SolidBrush blackBrush = new SolidBrush(Color.Black);
             *          if (lastDrawnMode != LightingMode.Line)
             *          {
             *              for (int i = 0; i < 88; i++)
             *              {
             *                  KeyboardKey key = keyboardLayout[i];
             *                  canvas.FillRectangle(blackBrush, new Rectangle(key.X, key.Y, (key.Width ?? 20) - 2, (key.Height ?? 20) - 2));
             *                  i++;
             *              }
             *          }
             *          for (int i = 0; i < leds.Length; i++)
             *          {
             *              byte[] col = leds[i].color.ToRGB();
             *              // SolidBrush colBrush = new SolidBrush(Color.FromArgb((int)(leds[i].color.v*255), col[0], col[1], col[2]));
             *              SolidBrush colBrush = new SolidBrush(Color.FromArgb(col[0], col[1], col[2]));
             *              int x = (int)Utils.Scale(i, 0, leds.Length, 0, 22);
             *              for (int j = 0; j < 6; j++)
             *              {
             *                  canvas.FillRectangle(colBrush, new Rectangle(x * 20, j * 20, 18, 18));
             *              }
             *
             *          }
             *          lastDrawnMode = LightingMode.Line;
             *      }
             *
             *  }
             *  else if (currentLightingMode == LightingMode.Line)
             *  {
             *
             *      Led[] ledsToDraw = null;
             *      if (mode == LightingMode.Line) ledsToDraw = leds;
             *      else if (mode == LightingMode.Keyboard) ledsToDraw = SACNController.GetKeyboardToLedStripArray(leds.ToByteArray());
             *      else if (mode == LightingMode.Point) throw new NotImplementedException();
             *      int i = 0;
             *      foreach (var led in ledsToDraw)
             *      {
             *          byte[] col = led.color.ToRGB();
             *          SolidBrush colBrush = new SolidBrush(Color.FromArgb(col[0], col[1], col[2]));
             *          canvas.FillRectangle(colBrush, new Rectangle(0 + i * 10, 0, 10, 10));
             *          i++;
             *      }
             *      lastDrawnMode = LightingMode.Line;
             *  }
             *
             *  updatingUI = false;
             * });*/
        }
示例#11
0
 private void SendLedData(LEDFrame frame)
 {
     lightControllers.ForEach(controller => controller.SendData(frame));
     DisplayUpdated?.Invoke(frame);
 }
示例#12
0
 private void NewFrameReadyHandler(LEDFrame frame)
 {
     frame.SenderChain.Add(this);
     NewFrameReady?.Invoke(frame);
 }
示例#13
0
 protected void InvokeNewFrameReady(LEDFrame frame)
 {
     frame.SenderChain.Add(this);
     NewFrameReady?.Invoke(frame);
 }
示例#14
0
 protected abstract void NewFrameReadyHandler(LEDFrame frame);