Exemplo n.º 1
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");
            }
        }
Exemplo n.º 2
0
 private bool SaveDevicesInsertionSounds()
 {
     try
     {
         DebugLog.write("Saving device connect/disconnect sounds");
         insertSound = RegUtils.GetDevConnectedSound();
         removeSound = RegUtils.GetDevDisconnectedSound();
         return(true);
     }
     catch
     {
         if (DebugLog.isLogging)
         {
             DebugLog.write("Unable to save device connect/disconnect sounds");
         }
         return(false);
     }
 }
Exemplo n.º 3
0
 private void RestoreDevicesInsertionSounds()
 {
     try
     {
         DebugLog.write("Restoring device connect/disconnect sounds");
         if (insertSound.Length > 0)
         {
             RegUtils.SetDevConnectedSound(insertSound);
         }
         if (removeSound.Length > 0)
         {
             RegUtils.SetDevDisconnectedSound(removeSound);
         }
     }
     catch
     {
         DebugLog.write("Unable to restore device connect/disconnect sounds");
     }
 }
Exemplo n.º 4
0
        public SettingsForm()
        {
            for (int i = 0; i < buttonMappings.Length; i++)
            {
                buttonMappings[i] = new ButtonMapping();
            }

            InitializeComponent();

            ListViewItem lvItem;

            foreach (PS3Remote.Button button in Enum.GetValues(typeof(PS3Remote.Button)))
            {
                lvItem = new ListViewItem();
                lvItem.SubItems.Add(button.ToString());
                lvItem.SubItems.Add("");
                lvButtons.Items.Add(lvItem);
            }

            foreach (SendInputAPI.Keyboard.KeyCode key in Enum.GetValues(typeof(SendInputAPI.Keyboard.KeyCode)))
            {
                lvKeys.Items.Add(new ListViewItem(key.ToString()));
            }

            if (!loadSettings())
            {
                saveSettings();
            }
            timerRepeat          = new System.Timers.Timer();
            timerRepeat.Interval = int.Parse(txtRepeatInterval.Text);
            timerRepeat.Elapsed += new System.Timers.ElapsedEventHandler(timerRepeat_Elapsed);



            buttonDump.Visible = DebugLog.isLogging;

            // Finding BT Address of the remote for Hibernation
            if (comboBtAddr.Text.Length != 12 && comboBtAddr.Text.Length != 17)
            {
                UpdateBtAddrList(1000);
            }
            else
            {
                comboBtAddr.Items.Clear();
                comboBtAddr.Items.Add(comboBtAddr.Text);
                comboBtAddr.Items.Add("Search again");
                comboBtAddr.Enabled = true;
            }

            // Saving Device Insertion sounds
            try
            {
                string s;
                bool   save = false;
                s = RegUtils.GetDevConnectedSound();
                if (insertSound.Length == 0 || (insertSound != s && s.Length > 0))
                {
                    insertSound = s;
                    save        = true;
                }
                s = RegUtils.GetDevDisconnectedSound();
                if (removeSound.Length == 0 || (removeSound != s && s.Length > 0))
                {
                    removeSound = s;
                    save        = true;
                }
                if (save)
                {
                    saveSettings();
                }
            }
            catch
            {
                if (DebugLog.isLogging)
                {
                    DebugLog.write("Unexpected error while trying to save Devices insertion/remove sounds.");
                }
            }

            // Restoring Device Insertion sounds in case they have been left blank
            try
            {
                string s;
                s = RegUtils.GetDevConnectedSound();
                if (s.Length == 0 && insertSound.Length > 0)
                {
                    RegUtils.SetDevConnectedSound(insertSound);
                }
                s = RegUtils.GetDevDisconnectedSound();
                if (s.Length == 0 && removeSound.Length > 0)
                {
                    RegUtils.SetDevDisconnectedSound(removeSound);
                }
            }
            catch
            {
                if (DebugLog.isLogging)
                {
                    DebugLog.write("Unexpected error while trying to restore Devices insertion/remove sounds.");
                }
            }

            try
            {
                int hibMs;
                try
                {
                    hibMs = System.Convert.ToInt32(txtMinutes.Text) * 60 * 1000;
                }
                catch
                {
                    if (DebugLog.isLogging)
                    {
                        DebugLog.write("Error while parsing Hibernation Interval, taking Default 3 Minutes");
                    }
                    txtMinutes.Text = "3";
                    hibMs           = 180000;
                }
                remote = new PS3Remote(int.Parse(txtVendorId.Text.Remove(0, 2), System.Globalization.NumberStyles.HexNumber), int.Parse(txtProductId.Text.Remove(0, 2), System.Globalization.NumberStyles.HexNumber));

                remote.BatteryLifeChanged += new EventHandler <EventArgs>(remote_BatteryLifeChanged);
                remote.ButtonDown         += new EventHandler <PS3Remote.ButtonData>(remote_ButtonDown);
                remote.ButtonReleased     += new EventHandler <PS3Remote.ButtonData>(remote_ButtonReleased);

                remote.Connected    += new EventHandler <EventArgs>(remote_Connected);
                remote.Disconnected += new EventHandler <EventArgs>(remote_Disconnected);
                remote.Hibernated   += new EventHandler <EventArgs>(remote_Hibernated);
                remote.Awake        += new EventHandler <EventArgs>(remote_Connected);

                remote.connect();

                remote.btAddress           = comboBtAddr.Text;
                remote.hibernationInterval = hibMs;
                remote.hibernationEnabled  = cbHibernation.Enabled && cbHibernation.Checked;
            }
            catch
            {
                MessageBox.Show("An error occured whilst attempting to load the remote.", "PS3BluMote: Remote error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            keyboard = new SendInputAPI.Keyboard(cbSms.Checked);
        }
Exemplo n.º 5
0
        private static List <string> FromReg(string pid, string vid)
        {
            List <string>      result = new List <string>();
            List <RegistryKey> regResult;

            try
            {
                string regFilter;
                if (vid.ToLower().Contains("x"))
                {
                    regFilter = vid.Substring(2);
                }
                else
                {
                    regFilter = vid;
                }
                if (pid.ToLower().Contains("x"))
                {
                    regFilter += "_PID&" + pid.Substring(2);
                }
                else
                {
                    regFilter += "_PID&" + pid;
                }

                regResult = RegUtils.GetKeys(Registry.LocalMachine, regFilter, "Bluetooth_UniqueID");
                foreach (RegistryKey k in regResult)
                {
                    try
                    {
                        string v = (string)k.GetValue("Bluetooth_UniqueID");
                        if (v.Length != 0 && v.Contains("#") && v.Contains("_") && (v.IndexOf("_") - v.IndexOf("#")) == 13)
                        {
                            v = v.Substring(v.IndexOf("#") + 1, 12);
                            v = BTUtils.FormatBtAddress(v, null, "N");
                            if (v != "")
                            {
                                if (!result.Contains(v))
                                {
                                    DebugLog.write("FindBTAddress.FromReg will return " + v);
                                    result.Add(v);
                                }
                            }
                            else
                            {
                                DebugLog.write("FindBTAddress.FromReg parsing returned the empty String (" + (string)k.GetValue("Bluetooth_UniqueID") + ")");
                            }
                        }
                    }
                    catch
                    {
                        try
                        {
                            DebugLog.write("FindBTAddress.FromReg Failed while parsing" + k.Name);
                        }
                        catch
                        {
                            DebugLog.write("FindBTAddress.FromReg Failed while parsing some key ..");
                        }
                    }
                }
                return(result);
            }
            catch
            {
                DebugLog.write("FindBTAddress.FromReg Failed");
                return(result);
            }
        }