Пример #1
0
        public PS3Remote(int vendor, int product)
        {
            vendorId             = vendor;
            productId            = product;
            _hibernationEnabled  = false;
            _hibernationInterval = 180000;
            _btAddress           = "";
            _sleepState          = RemoteBtStates.Unknown;

            timerHibernation          = new Timer();
            timerHibernation.Interval = _hibernationInterval;
            timerHibernation.Elapsed += new ElapsedEventHandler(timerHibernation_Elapsed);

            timerFindRemote          = new Timer();
            timerFindRemote.Interval = 500;
            timerFindRemote.Elapsed += new ElapsedEventHandler(timerFindRemote_Elapsed);

            timerGetSleepState           = new Timer();
            timerGetSleepState.Interval  = 1000;
            timerGetSleepState.AutoReset = false;
            timerGetSleepState.Elapsed  += new ElapsedEventHandler(timerGetSleepState_Elapsed);

            timerSleepButton           = new Timer();
            timerSleepButton.Interval  = 6000;
            timerSleepButton.AutoReset = false;
            timerSleepButton.Elapsed  += new ElapsedEventHandler(timerSleepButton_Elapsed);

            insertSound = "";
            removeSound = "";
        }
Пример #2
0
        private void timerHibernation_Elapsed(object sender, ElapsedEventArgs e)
        {
            timerHibernation.Stop();
            DebugLog.write("Attempting to hibernate remote");

            if (_btAddress.Length > 0)
            {
                try
                {
                    if (SaveDevicesInsertionSounds())
                    {
                        DebugLog.write("Disabling device connect/disconnect sounds");
                        RegUtils.SetDevConnectedSound("");
                        RegUtils.SetDevDisconnectedSound("");
                        // Values are restored in ReadButton Data, because, it seems that this method might end before the device is actually Reconnected
                    }

                    BTUtils.HibernatePS3Remote(false, _btAddress, null);
                    SleepState = RemoteBtStates.Hibernated;
                    timerFindRemote.Interval = 300;

                    DebugLog.write("Hibernating Done");
                }
                catch (Exception ex)
                {
                    DebugLog.write("Unable to hibernate remote" + ex.Message);
                }
            }
            else
            {
                DebugLog.write("Wrong format for BT Address");
            }
        }
Пример #3
0
 private void timerGetSleepState_Elapsed(object sender, ElapsedEventArgs e)
 {
     timerGetSleepState.Stop();
     if (SleepState == RemoteBtStates.Unknown && hibernationEnabled)
     {
         //it might take some time
         DebugLog.write("Reading sleepState from BT");
         SleepState = BTUtils.RemoteBtState(btAddress, null);
     }
 }
Пример #4
0
        public static RemoteBtStates RemoteBtState(string btAddress, BluetoothDeviceInfo dev)
        {
            RemoteBtStates      result = RemoteBtStates.Unknown;
            BluetoothDeviceInfo device = null;

            if (dev == null && btAddress == null)
            {
                return(result);
            }
            else if (dev == null)
            {
                try { device = new BluetoothDeviceInfo(BluetoothAddress.Parse(btAddress)); }
                catch
                {
                    DebugLog.write("BTUtils.RemoteBtState failed while creating BluetoothDeviceInfo");
                }
            }
            else
            {
                device = dev;
            }

            if (device != null)
            {
                try
                {
                    ServiceRecord[] services = device.GetServiceRecords(BluetoothService.HumanInterfaceDevice);
                    result = RemoteBtStates.Awake;
                }
                catch
                {
                    result = RemoteBtStates.Hibernated;
                }
            }
            if (result == RemoteBtStates.Unknown)
            {
                DebugLog.write("BTUtils.RemoteBtState returns Unknown");
            }
            else if (result == RemoteBtStates.Awake)
            {
                DebugLog.write("BTUtils.RemoteBtState returns Awake");
            }
            else if (result == RemoteBtStates.Hibernated)
            {
                DebugLog.write("BTUtils.RemoteBtState returns Hibernated");
            }
            return(result);
        }
Пример #5
0
 private void timerSleepButton_Elapsed(object sender, ElapsedEventArgs e)
 {
     DebugLog.write("The remote has been hibernated manually");
     timerSleepButton.Stop();
     SleepState = RemoteBtStates.Hibernated;
 }
Пример #6
0
        private void readButtonData(HidDeviceData InData)
        {
            timerHibernation.Enabled = false;

            if ((InData.Status == HidDeviceData.ReadStatus.Success) && (InData.Data[0] == 1))
            {
                SleepState = RemoteBtStates.Awake;
                timerFindRemote.Interval = 1500;

                DebugLog.write("Read button data: " + String.Join(",", InData.Data));

                if ((InData.Data[10] == 0) || (InData.Data[4] == 255)) // button released
                {
                    timerSleepButton.Stop();
                    if (ButtonReleased != null && isButtonDown)
                    {
                        ButtonReleased(this, new ButtonData(lastButton));
                    }
                }
                else // button pressed
                {
                    byte[] bCode = { InData.Data[1], InData.Data[2], InData.Data[3], InData.Data[4] };

                    int i, j;

                    for (j = 0; j < 56; j++)
                    {
                        for (i = 0; i < 4; i++)
                        {
                            if (bCode[i] != buttonCodes[j][i])
                            {
                                break;
                            }
                        }

                        if (i == 4)
                        {
                            break;
                        }
                    }

                    if (j != 56)
                    {
                        lastButton   = (Button)j;
                        isButtonDown = true;

                        if (ButtonDown != null)
                        {
                            ButtonDown(this, new ButtonData(lastButton));
                        }
                        if (lastButton == Button.Playstation)
                        {
                            timerSleepButton.Start();
                        }
                        else
                        {
                            timerSleepButton.Stop();
                        }
                    }
                }

                byte batteryReading = (byte)(InData.Data[11] * 20);

                if (batteryReading != _batteryLife) //Check battery life reading.
                {
                    _batteryLife = batteryReading;

                    if (BatteryLifeChanged != null)
                    {
                        BatteryLifeChanged(this, new EventArgs());
                    }
                }

                if (_hibernationEnabled)
                {
                    timerHibernation.Start();
                }

                hidRemote.Read(readButtonData); //Read next button pressed.

                return;
            }

            DebugLog.write("Read remote data: " + String.Join(",", InData.Data));

            if (Disconnected != null)
            {
                Disconnected(this, new EventArgs());
            }

            hidRemote.Dispose(); //Dispose of current remote.

            hidRemote = null;

            timerFindRemote.Enabled = true; //Try to reconnect.
            if (_hibernationEnabled)
            {
                timerHibernation.Enabled = false;
            }
        }
Пример #7
0
 private void timerSleepButton_Elapsed(object sender, ElapsedEventArgs e)
 {
     DebugLog.write("The remote has been hibernated manually");
     timerSleepButton.Stop();
     SleepState = RemoteBtStates.Hibernated;
 }
Пример #8
0
        private void timerHibernation_Elapsed(object sender, ElapsedEventArgs e)
        {
            timerHibernation.Stop();
            DebugLog.write("Attempting to hibernate remote");

            if (_btAddress.Length>0)
            {
                try
                {
                    if (SaveDevicesInsertionSounds())
                    {
                        DebugLog.write("Disabling device connect/disconnect sounds");
                        RegUtils.SetDevConnectedSound("");
                        RegUtils.SetDevDisconnectedSound("");
                        // Values are restored in ReadButton Data, because, it seems that this method might end before the device is actually Reconnected
                    }

                    BTUtils.HibernatePS3Remote(false, _btAddress, null);
                    SleepState = RemoteBtStates.Hibernated;
                    timerFindRemote.Interval = 300;

                    DebugLog.write("Hibernating Done");

                }
                catch (Exception ex)
                {
                    DebugLog.write("Unable to hibernate remote" + ex.Message);
                }

            }
            else DebugLog.write("Wrong format for BT Address");
        }
Пример #9
0
 private void timerGetSleepState_Elapsed(object sender, ElapsedEventArgs e)
 {
     timerGetSleepState.Stop();
     if (SleepState == RemoteBtStates.Unknown && hibernationEnabled)
     {
         //it might take some time
         DebugLog.write("Reading sleepState from BT");
         SleepState = BTUtils.RemoteBtState(btAddress, null);
     }
 }
Пример #10
0
        private void readButtonData(HidDeviceData InData)
        {
            timerHibernation.Enabled = false;

            if ((InData.Status == HidDeviceData.ReadStatus.Success) && (InData.Data[0] == 1))
            {
                SleepState = RemoteBtStates.Awake;
                timerFindRemote.Interval = 1500;

                DebugLog.write("Read button data: " + String.Join(",", InData.Data));

                if ((InData.Data[10] == 0) || (InData.Data[4] == 255)) // button released
                {
                    timerSleepButton.Stop();
                    if (ButtonReleased != null && isButtonDown) ButtonReleased(this, new ButtonData(lastButton));

                }
                else // button pressed
                {
                    byte[] bCode = { InData.Data[1], InData.Data[2], InData.Data[3], InData.Data[4] };

                    int i, j;

                    for (j = 0; j < 56; j++)
                    {
                        for (i = 0; i < 4; i++)
                        {
                            if (bCode[i] != buttonCodes[j][i]) break;
                        }

                        if (i == 4) break;
                    }

                    if (j != 56)
                    {
                        lastButton = (Button)j;
                        isButtonDown = true;

                        if (ButtonDown != null) ButtonDown(this, new ButtonData(lastButton));
                        if (lastButton == Button.Playstation) timerSleepButton.Start();
                        else timerSleepButton.Stop();
                    }
                }

                byte batteryReading = (byte)(InData.Data[11] * 20);

                if (batteryReading != _batteryLife) //Check battery life reading.
                {
                    _batteryLife = batteryReading;

                    if (BatteryLifeChanged != null) BatteryLifeChanged(this, new EventArgs());
                }

                if (_hibernationEnabled) timerHibernation.Start();

                hidRemote.Read(readButtonData); //Read next button pressed.

                return;
            }

            DebugLog.write("Read remote data: " + String.Join(",", InData.Data));

            if (Disconnected != null) Disconnected(this, new EventArgs());

            hidRemote.Dispose(); //Dispose of current remote.

            hidRemote = null;

            timerFindRemote.Enabled = true; //Try to reconnect.
            if (_hibernationEnabled) timerHibernation.Enabled = false;
        }
Пример #11
0
        public PS3Remote(int vendor, int product)
        {
            vendorId = vendor;
            productId = product;
            _hibernationEnabled = false;
            _hibernationInterval = 180000;
            _btAddress = "";
            _sleepState = RemoteBtStates.Unknown;

            timerHibernation = new Timer();
            timerHibernation.Interval = _hibernationInterval;
            timerHibernation.Elapsed += new ElapsedEventHandler(timerHibernation_Elapsed);

            timerFindRemote = new Timer();
            timerFindRemote.Interval = 500;
            timerFindRemote.Elapsed += new ElapsedEventHandler(timerFindRemote_Elapsed);

            timerGetSleepState = new Timer();
            timerGetSleepState.Interval = 1000;
            timerGetSleepState.AutoReset = false;
            timerGetSleepState.Elapsed += new ElapsedEventHandler(timerGetSleepState_Elapsed);

            timerSleepButton = new Timer();
            timerSleepButton.Interval = 6000;
            timerSleepButton.AutoReset = false;
            timerSleepButton.Elapsed += new ElapsedEventHandler(timerSleepButton_Elapsed);

            insertSound = "";
            removeSound = "";
        }