예제 #1
0
 private void buttonDump_Click(object sender, EventArgs e)
 {
     DebugLog.outputToFile(SETTINGS_DIRECTORY + "log.txt");
 }
예제 #2
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);
        }
예제 #3
0
        private void readButtonData(HidDeviceData InData)
        {
            timerHibernation.Enabled = false;

            if ((InData.Status == HidDeviceData.ReadStatus.Success) && (InData.Data[0] == 1))
            {
                if (DebugLog.isLogging)
                {
                    DebugLog.write("Read button data: " + String.Join(",", InData.Data));
                }
                //Debug.Print("Read button data: " + String.Join(",", InData.Data));

                if ((InData.Data[10] == 0) || (InData.Data[4] == 255)) // button released
                {
                    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));
                        }
                    }
                }

                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.Enabled = true;
                }

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

                return;
            }

            if (DebugLog.isLogging)
            {
                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.
        }
예제 #4
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);
            }
        }
예제 #5
0
 private void timerSleepButton_Elapsed(object sender, ElapsedEventArgs e)
 {
     DebugLog.write("The remote has been hibernated manually");
     timerSleepButton.Stop();
     SleepState = RemoteBtStates.Hibernated;
 }