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"); } }
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); } }
private static List <string> FromBT() { List <string> btResult; btResult = BTUtils.GetNearbyRemoteAddresses(TimeSpan.FromSeconds(1)); if (btResult.Count == 0) { btResult = BTUtils.GetNearbyRemoteAddresses(TimeSpan.Zero); } for (int i = 0; i < btResult.Count; i++) { btResult[i] = BTUtils.FormatBtAddress(btResult[i], null, "N"); DebugLog.write("FindBTAddress.FromBT will return " + btResult[i]); } return(btResult); }
void TimerFindBtAddress_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { timerFindBtAddress.Stop(); if (InvokeRequired) { this.comboBtAddr.Invoke((MethodInvoker) delegate { comboBtAddr.Text = "Searching"; comboBtAddr.Enabled = false; }); } List <string> btAddr = FindBtAddress.Find(txtProductId.Text.Remove(0, 2), txtVendorId.Text.Remove(0, 2)); if (InvokeRequired) { this.comboBtAddr.Invoke((MethodInvoker) delegate { comboBtAddr.Items.Clear(); foreach (string addr in btAddr) { comboBtAddr.Items.Add(BTUtils.FormatBtAddress(addr, null, "C")); } comboBtAddr.Items.Add("Search again"); if (comboBtAddr.Text.Length != 12 && comboBtAddr.Text.Length != 17 && btAddr.Count == 1) { comboBtAddr.Text = BTUtils.FormatBtAddress(btAddr[0], null, "C"); } else { comboBtAddr.Text = ""; } comboBtAddr.Enabled = true; }); } }
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); } }