public void Stop() { Console.WriteLine("DS4 disconnecting"); if (_controller == null) { return; } _controller.LightBarColor = new DS4Color(0, 0, 0); _controller.LightBarOnDuration = 0; _controller.LightBarOffDuration = 0; _controller.FlushHID(); if (_controller.ConnectionType == DS4Windows.ConnectionType.BT) { _controller.DisconnectBT(); } _controller = null; }
//Called every time the new input report has arrived protected virtual void On_Report(object sender, EventArgs e) { DS4Device device = (DS4Device)sender; int ind = -1; for (int i = 0; i < DS4Controllers.Length; i++) { if (device == DS4Controllers[i]) { ind = i; } } if (ind != -1) { if (Global.getFlushHIDQueue(ind)) { device.FlushHID(); } if (!string.IsNullOrEmpty(device.error)) { LogDebug(device.error); } device.getExposedState(ExposedState[ind], CurrentState[ind]); DS4State cState = CurrentState[ind]; device.getPreviousState(PreviousState[ind]); DS4State pState = PreviousState[ind]; if (pState.Battery != cState.Battery) { Global.ControllerStatusChanged(this); } CheckForHotkeys(ind, cState, pState); GetInputkeys(ind); if (Global.getLSCurve(ind) + Global.getRSCurve(ind) + Global.getLSDeadzone(ind) + Global.getRSDeadzone(ind) + Global.getL2Deadzone(ind) + Global.getR2Deadzone(ind) > 0) //if a curve or deadzone is in place { cState = Mapping.SetCurveAndDeadzone(ind, cState); } if (!recordingMacro && (!string.IsNullOrEmpty(Global.tempprofilename[ind]) || Global.getHasCustomKeysorButtons(ind) || Global.getHasShiftCustomKeysorButtons(ind))) { Mapping.MapCustom(ind, cState, MappedState[ind], ExposedState[ind], touchPad[ind], this); cState = MappedState[ind]; } if (Global.getHasCustomExtras(ind)) { DoExtras(ind); } // Update the GUI/whatever. DS4LightBar.updateLightBar(device, ind, cState, ExposedState[ind], touchPad[ind]); x360Bus.Parse(cState, processingData[ind].Report, ind); // We push the translated Xinput state, and simultaneously we // pull back any possible rumble data coming from Xinput consumers. if (x360Bus.Report(processingData[ind].Report, processingData[ind].Rumble)) { Byte Big = (Byte)(processingData[ind].Rumble[3]); Byte Small = (Byte)(processingData[ind].Rumble[4]); if (processingData[ind].Rumble[1] == 0x08) { setRumble(Big, Small, ind); } } // Output any synthetic events. Mapping.Commit(ind); // Pull settings updates. device.IdleTimeout = Global.getIdleDisconnectTimeout(ind); } }