From 381f940d8b752583a95edc2ae9726e6530c397ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Tue, 29 Nov 2022 21:14:14 +0100 Subject: [PATCH] The `X360.Beep()` cycles currently connected device --- RELEASE.md | 1 + SteamController/Devices/Xbox360Controller.cs | 35 +++++++++----------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index a3c7ee8..4731ea7 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -20,3 +20,4 @@ It does help this project on being supported. - Reduce hold for `Toggle desktop mode` to 2s - Fix `Process Kill` action (STEAM+B for 3s) - Go back to `Startup Profile` on `Toggle deskptop mode` +- The `X360.Beep()` cycles currently connected device (fixes Playnite error) diff --git a/SteamController/Devices/Xbox360Controller.cs b/SteamController/Devices/Xbox360Controller.cs index e099ce8..8392a3f 100644 --- a/SteamController/Devices/Xbox360Controller.cs +++ b/SteamController/Devices/Xbox360Controller.cs @@ -63,12 +63,12 @@ namespace SteamController.Devices Connected = false; } - private void UpdateConnected() + private void SetConnected(bool connected) { if (Connected == isConnected) return; - if (Connected) + if (connected) { device?.Connect(); TraceLine("Connected X360 Controller."); @@ -82,31 +82,28 @@ namespace SteamController.Devices isConnected = Connected; } - internal void Disconnect() - { - if (!isConnected) - return; - - device?.Disconnect(); - isConnected = false; - } - internal void Beep() { - var client = this.client; - if (client is null) + if (device is null) return; - // Generate dummy xbox360 controller to generate notification - var device = client.CreateXbox360Controller(); - device.Connect(); - Thread.Sleep(100); - device.Disconnect(); + lock (this) + { + // cycle currently connected device + SetConnected(!isConnected); + Thread.Sleep(100); + } } internal void Update() { - UpdateConnected(); + if (device is not null && Connected != isConnected) + { + lock (this) + { + SetConnected(Connected); + } + } if (isConnected && submitReport) {