From 68f1c476c61854fd99fd4a72c2450221e5da0d2f Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 19 Nov 2020 16:54:00 +0800 Subject: [PATCH] Use incremental lighting to indicate players on Joycons. (#617) Consolidates LED and other/attached Joycon handling. --- BetterJoyForCemu/App.config | 6 +++-- BetterJoyForCemu/Joycon.cs | 42 +++++++++++++++++++++++++++++++++-- BetterJoyForCemu/MainForm.cs | 13 ----------- BetterJoyForCemu/Program.cs | 9 +------- BetterJoyForCemu/UpdServer.cs | 2 +- 5 files changed, 46 insertions(+), 26 deletions(-) diff --git a/BetterJoyForCemu/App.config b/BetterJoyForCemu/App.config index 27538f9..2546c10 100644 --- a/BetterJoyForCemu/App.config +++ b/BetterJoyForCemu/App.config @@ -1,7 +1,7 @@ - + - + + + diff --git a/BetterJoyForCemu/Joycon.cs b/BetterJoyForCemu/Joycon.cs index 684370d..fe6d054 100644 --- a/BetterJoyForCemu/Joycon.cs +++ b/BetterJoyForCemu/Joycon.cs @@ -17,7 +17,26 @@ namespace BetterJoyForCemu { public bool isPro = false; public bool isSnes = false; bool isUSB = false; - public Joycon other = null; + private Joycon _other = null; + public Joycon other { + get { + return _other; + } + set { + _other = value; + + // If the other Joycon is itself, the Joycon is sideways + if (_other == null || _other == this) { + // Set LED to current Pad ID + SetLEDByPlayerNum(PadId); + } + else { + // Set LED to current Joycon Pair + int lowestPadId = Math.Min(_other.PadId, PadId); + SetLEDByPlayerNum(lowestPadId); + } + } + } public bool active_gyro = false; private long inactivity = Stopwatch.GetTimestamp(); @@ -234,7 +253,26 @@ namespace BetterJoyForCemu { public MainForm form; - public byte LED = 0x0; + public byte LED { get; private set; } = 0x0; + public void SetLEDByPlayerNum(int id) { + if (id > 3) { + // No support for any higher than 3 (4 Joycons/Controllers supported in the application normally) + id = 3; + } + + if (ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["UseJoyconIncrementalLights"].Value.ToLower() == "true") { + // Set all LEDs from 0 to the given id to lit + int ledId = id; + LED = 0x0; + do { + LED |= (byte)(0x1 << ledId); + } while (--ledId >= 0); + } else { + LED = (byte)(0x1 << id); + } + + SetPlayerLED(LED); + } public string serial_number; bool thirdParty = false; diff --git a/BetterJoyForCemu/MainForm.cs b/BetterJoyForCemu/MainForm.cs index 492e10a..9f07750 100644 --- a/BetterJoyForCemu/MainForm.cs +++ b/BetterJoyForCemu/MainForm.cs @@ -205,13 +205,6 @@ namespace BetterJoyForCemu { v.other = jc; jc.other = v; - //Set both Joycon LEDs to the one with the lowest ID - byte led = jc.LED <= v.LED ? jc.LED : v.LED; - jc.LED = led; - v.LED = led; - jc.SetPlayerLED(led); - v.SetPlayerLED(led); - if (v.out_xbox != null) { v.out_xbox.Disconnect(); v.out_xbox = null; @@ -247,12 +240,6 @@ namespace BetterJoyForCemu { if (b.Tag == v.other) b.BackgroundImage = v.other.isLeft ? Properties.Resources.jc_left_s : Properties.Resources.jc_right_s; - //Set original Joycon LEDs - v.other.LED = (byte)(0x1 << v.other.PadId); - v.LED = (byte)(0x1 << v.PadId); - v.other.SetPlayerLED(v.other.LED); - v.SetPlayerLED(v.LED); - v.other.other = null; v.other = null; } diff --git a/BetterJoyForCemu/Program.cs b/BetterJoyForCemu/Program.cs index f96faa0..29084dc 100644 --- a/BetterJoyForCemu/Program.cs +++ b/BetterJoyForCemu/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Configuration; using System.Diagnostics; @@ -268,13 +269,6 @@ namespace BetterJoyForCemu { temp.other = v; v.other = temp; - //Set both Joycon LEDs to the one with the lowest ID - byte led = Math.Min(temp.LED, v.LED); - temp.LED = led; - v.LED = led; - temp.SetPlayerLED(led); - v.SetPlayerLED(led); - if (temp.out_xbox != null) { try { temp.out_xbox.Disconnect(); @@ -326,7 +320,6 @@ namespace BetterJoyForCemu { if (form.allowCalibration) { jc.getActiveData(); } - } } } diff --git a/BetterJoyForCemu/UpdServer.cs b/BetterJoyForCemu/UpdServer.cs index 4b27ab8..30f6609 100644 --- a/BetterJoyForCemu/UpdServer.cs +++ b/BetterJoyForCemu/UpdServer.cs @@ -13,7 +13,7 @@ namespace BetterJoyForCemu { private bool running; private byte[] recvBuffer = new byte[1024]; - List controllers; + IList controllers; public MainForm form;