public static void UpdateSerial(object sender, EventArgs e) { lock (Devices) { DS4Device device = (DS4Device)sender; if (device != null) { string devPath = device.HidDevice.DevicePath; string serial = device.getMacAddress(); if (Devices.ContainsKey(devPath)) { deviceSerials.Remove(serial); device.updateSerial(); serial = device.getMacAddress(); if (DS4Device.isValidSerial(serial)) { deviceSerials.Add(serial); } if (device.ShouldRunCalib()) { device.RefreshCalibration(); } } } } }
public bool HotPlug(SynchronizationContext uiContext) { if (running) { DS4Devices.findControllers(); IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers(); //foreach (DS4Device device in devices) for (int i = 0, devlen = devices.Count(); i < devlen; i++) { DS4Device device = devices.ElementAt(i); if (device.isDisconnectingStatus()) { continue; } if (((Func <bool>) delegate { for (Int32 Index = 0, arlength = DS4Controllers.Length; Index < arlength; Index++) { if (DS4Controllers[Index] != null && DS4Controllers[Index].getMacAddress() == device.getMacAddress()) { return(true); } } return(false); })()) { continue; } for (Int32 Index = 0, arlength = DS4Controllers.Length; Index < arlength; Index++) { if (DS4Controllers[Index] == null) { LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")"); Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); }); task.Start(); DS4Controllers[Index] = device; device.setUiContext(uiContext); device.Removal += this.On_DS4Removal; device.Removal += DS4Devices.On_Removal; device.SyncChange += this.On_SyncChange; device.SyncChange += DS4Devices.UpdateSerial; device.SerialChange += this.On_SerialChange; if (device.isValidSerial() && containsLinkedProfile(device.getMacAddress())) { ProfilePath[Index] = getLinkedProfile(device.getMacAddress()); } else { ProfilePath[Index] = OlderProfilePath[Index]; } LoadProfile(Index, false, this, false, false); touchPad[Index] = new Mouse(Index, device); device.LightBarColor = getMainColor(Index); device.Report += this.On_Report; if (!getDInputOnly(Index) && device.isSynced()) { int xinputIndex = x360Bus.FirstController + Index; LogDebug("Plugging in X360 Controller #" + xinputIndex); bool xinputResult = x360Bus.Plugin(Index); if (xinputResult) { LogDebug("X360 Controller # " + xinputIndex + " connected"); useDInputOnly[Index] = false; } else { LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode"); useDInputOnly[Index] = true; } } TouchPadOn(Index, device); CheckProfileOptions(Index, device); device.StartUpdate(); //string filename = Path.GetFileName(ProfilePath[Index]); if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml")) { string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", ProfilePath[Index]); LogDebug(prolog); Log.LogToTray(prolog); } else { string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (Index + 1).ToString()); LogDebug(prolog); Log.LogToTray(prolog); } break; } } } } return(true); }
public bool Start(object tempui, bool showlog = true) { if (x360Bus.Open() && x360Bus.Start()) { if (showlog) { LogDebug(Properties.Resources.Starting); } LogDebug("Connection to Scp Virtual Bus established"); DS4Devices.isExclusiveMode = getUseExclusiveMode(); if (showlog) { LogDebug(Properties.Resources.SearchingController); LogDebug(DS4Devices.isExclusiveMode ? Properties.Resources.UsingExclusive : Properties.Resources.UsingShared); } try { DS4Devices.findControllers(); IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers(); //int ind = 0; DS4LightBar.defaultLight = false; //foreach (DS4Device device in devices) for (int i = 0, devCount = devices.Count(); i < devCount; i++) { DS4Device device = devices.ElementAt(i); if (showlog) { LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")"); } Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); }); task.Start(); DS4Controllers[i] = device; device.setUiContext(tempui as SynchronizationContext); device.Removal += this.On_DS4Removal; device.Removal += DS4Devices.On_Removal; device.SyncChange += this.On_SyncChange; device.SyncChange += DS4Devices.UpdateSerial; device.SerialChange += this.On_SerialChange; if (device.isValidSerial() && containsLinkedProfile(device.getMacAddress())) { ProfilePath[i] = getLinkedProfile(device.getMacAddress()); } else { ProfilePath[i] = OlderProfilePath[i]; } LoadProfile(i, false, this, false, false); touchPad[i] = new Mouse(i, device); device.LightBarColor = getMainColor(i); if (!getDInputOnly(i) && device.isSynced()) { int xinputIndex = x360Bus.FirstController + i; LogDebug("Plugging in X360 Controller #" + xinputIndex); bool xinputResult = x360Bus.Plugin(i); if (xinputResult) { LogDebug("X360 Controller # " + xinputIndex + " connected"); useDInputOnly[i] = false; } else { LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode"); useDInputOnly[i] = true; } } device.Report += this.On_Report; TouchPadOn(i, device); CheckProfileOptions(i, device, true); device.StartUpdate(); //string filename = ProfilePath[ind]; //ind++; if (showlog) { if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[i] + ".xml")) { string prolog = Properties.Resources.UsingProfile.Replace("*number*", (i + 1).ToString()).Replace("*Profile name*", ProfilePath[i]); LogDebug(prolog); Log.LogToTray(prolog); } else { string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (i + 1).ToString()); LogDebug(prolog); Log.LogToTray(prolog); } } if (i >= 4) // out of Xinput devices! { break; } } } catch (Exception e) { LogDebug(e.Message); Log.LogToTray(e.Message); } running = true; } else { string logMessage = "Could not connect to Scp Virtual Bus Driver. Please check the status of the System device in Device Manager"; LogDebug(logMessage); Log.LogToTray(logMessage); } runHotPlug = true; return(true); }