private void DeactivateLogoButton(object state) //State parameter is not used because we want the most recent report { _LogoButtonActive = false; XInputReport.SetButtonState((Xbox360Buttons)0x0400, _LogoButtonActive); _Target.SendReport(XInputReport); }
private void OnReport(IReport rawReportData) { //if (!(reportData is XInputReport)) return; if (rawReportData.ReportTypeCode != REPORT_TYPE.XINP) { return; } XInputReport reportData = (XInputReport)rawReportData; /*if (reportData.Connected != Connected) * { * ConnectedState.Wait(); * try * { * if (reportData.Connected) * { * ControllerTypeCode = _DEVICE_XBOX360; * IsPresent = true; * Connected = true; * } * else * { * ControllerTypeCode = _DEVICE_NONE; * IsPresent = false; * Connected = false; * } * * ControllerMetadataUpdate?.Invoke(this); * } * finally * { * ConnectedState.Release(); * } * }*/ if (Initalized < 1) { return; } if (0 == Interlocked.Exchange(ref reportUsageLock, 1)) { ConnectedState.Wait(); try { State.StartStateChange(); try { if (reportData.sThumbLX.HasValue) { (State.Controls["stick_left"] as IControlStickWithClick).X = reportData.sThumbLX.Value * 1.0f / Int16.MaxValue; } if (reportData.sThumbLY.HasValue) { (State.Controls["stick_left"] as IControlStickWithClick).Y = reportData.sThumbLY.Value * -1.0f / Int16.MaxValue; } if (reportData.sThumbRX.HasValue) { (State.Controls["stick_right"] as IControlStickWithClick).X = reportData.sThumbRX.Value * 1.0f / Int16.MaxValue; } if (reportData.sThumbRY.HasValue) { (State.Controls["stick_right"] as IControlStickWithClick).Y = reportData.sThumbRY.Value * -1.0f / Int16.MaxValue; } if (reportData.wButtons.HasValue) { (State.Controls["cluster_right"] as IControlButtonQuad).ButtonN = (reportData.wButtons.Value & 0x8000) == 0x8000; (State.Controls["cluster_right"] as IControlButtonQuad).ButtonE = (reportData.wButtons.Value & 0x2000) == 0x2000; (State.Controls["cluster_right"] as IControlButtonQuad).ButtonS = (reportData.wButtons.Value & 0x1000) == 0x1000; (State.Controls["cluster_right"] as IControlButtonQuad).ButtonW = (reportData.wButtons.Value & 0x4000) == 0x4000; bool DPadUp = (reportData.wButtons.Value & 0x0001) == 0x0001; bool DPadDown = (reportData.wButtons.Value & 0x0002) == 0x0002; bool DPadLeft = (reportData.wButtons.Value & 0x0004) == 0x0004; bool DPadRight = (reportData.wButtons.Value & 0x0008) == 0x0008; if (DPadUp && DPadDown) { DPadUp = DPadDown = false; } if (DPadLeft && DPadRight) { DPadLeft = DPadRight = false; } if (DPadUp) { if (DPadRight) { (State.Controls["cluster_left"] as IControlDPad).Direction = EDPadDirection.NorthEast; } else if (DPadLeft) { (State.Controls["cluster_left"] as IControlDPad).Direction = EDPadDirection.NorthWest; } else { (State.Controls["cluster_left"] as IControlDPad).Direction = EDPadDirection.North; } } else if (DPadDown) { if (DPadRight) { (State.Controls["cluster_left"] as IControlDPad).Direction = EDPadDirection.SouthEast; } else if (DPadLeft) { (State.Controls["cluster_left"] as IControlDPad).Direction = EDPadDirection.SouthWest; } else { (State.Controls["cluster_left"] as IControlDPad).Direction = EDPadDirection.South; } } else { if (DPadRight) { (State.Controls["cluster_left"] as IControlDPad).Direction = EDPadDirection.East; } else if (DPadLeft) { (State.Controls["cluster_left"] as IControlDPad).Direction = EDPadDirection.West; } else { (State.Controls["cluster_left"] as IControlDPad).Direction = EDPadDirection.None; } } (State.Controls["stick_right"] as IControlStickWithClick).Click = (reportData.wButtons.Value & 0x0080) == 0x0080; (State.Controls["stick_left"] as IControlStickWithClick).Click = (reportData.wButtons.Value & 0x0040) == 0x0040; (State.Controls["menu_right"] as ControlButton).DigitalStage1 = (reportData.wButtons.Value & 0x0010) == 0x0010; (State.Controls["menu_left"] as ControlButton).DigitalStage1 = (reportData.wButtons.Value & 0x0020) == 0x0020; (State.Controls["bumper_right"] as ControlButton).DigitalStage1 = (reportData.wButtons.Value & 0x0200) == 0x0200; (State.Controls["bumper_left"] as ControlButton).DigitalStage1 = (reportData.wButtons.Value & 0x0100) == 0x0100; (State.Controls["home"] as IControlButton).DigitalStage1 = (reportData.wButtons.Value & 0x0400) == 0x0400; } //(State.Controls["home"] as ControlButton).Button0 = (buttons & 0x1) == 0x1; if (reportData.bLeftTrigger.HasValue) { (State.Controls["trigger_left"] as ControlTrigger).AnalogStage1 = (float)reportData.bLeftTrigger.Value / byte.MaxValue; } if (reportData.bRightTrigger.HasValue) { (State.Controls["trigger_right"] as ControlTrigger).AnalogStage1 = (float)reportData.bRightTrigger.Value / byte.MaxValue; } } finally { State.EndStateChange(); } } finally { ConnectedState.Release(); Interlocked.Exchange(ref reportUsageLock, 0); } } }