protected override void Process()

in ScpControl/Bluetooth/Ds4/BthDs4.cs [289:380]


        protected override void Process(DateTime now)
        {
            if (!Monitor.TryEnter(_hidReport) || State != DsState.Connected) return;

            try
            {
                #region Light bar manipulation

                if (!GlobalConfiguration.Instance.IsLightBarDisabled)
                {
                    if (Battery == DsBattery.Dying)
                    {
                        if (!_flash)
                        {
                            _hidReport[12] = _hidReport[13] = 0x40;

                            _flash = true;
                            m_Queued = 1;
                        }
                    }
                    else
                    {
                        if (_flash)
                        {
                            _hidReport[12] = _hidReport[13] = 0x00;

                            _flash = false;
                            m_Queued = 1;
                        }
                    }
                }

                if (GlobalConfiguration.Instance.Brightness != _brightness)
                {
                    _brightness = GlobalConfiguration.Instance.Brightness;
                }

                if (GlobalConfiguration.Instance.Ds4ShowBatteryInfo)
                {
                    switch (Battery)
                    {
                        case DsBattery.Dying:
                            SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorDying);
                            break;
                        case DsBattery.Low:
                            SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorLow);
                            break;
                        case DsBattery.Medium:
                            SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorMedium);
                            break;
                        case DsBattery.High:
                        case DsBattery.Charging:
                            SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorHigh);
                            break;
                        case DsBattery.Full:
                        case DsBattery.Charged:
                            SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorFull);
                            break;
                        default:
                            SetLightBarColorUInt(GlobalConfiguration.Instance.Ds4ColorDying);
                            break;
                    }
                }
                else if (XInputSlot.HasValue)
                {
                    SetLightBarColor((DsPadId) XInputSlot);
                }

                #endregion

                if ((now - m_Last).TotalMilliseconds >= 500)
                {
                    if (_hidReport[7] > 0x00 || _hidReport[8] > 0x00)
                    {
                        m_Queued = 1;
                    }
                }

                if (!m_Blocked && m_Queued > 0)
                {
                    m_Last = now;
                    m_Blocked = true;
                    m_Queued--;

                    BluetoothDevice.HID_Command(HciHandle.Bytes, Get_SCID(L2CAP.PSM.HID_Command), _hidReport);
                }
            }
            finally
            {
                Monitor.Exit(_hidReport);
            }
        }