Use incremental lighting to indicate players on Joycons. (#617)

Consolidates LED and other/attached Joycon handling.
This commit is contained in:
Chris 2020-11-19 16:54:00 +08:00 committed by GitHub
parent 40dce4149c
commit 68f1c476c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 26 deletions

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
@ -80,6 +80,8 @@
<!-- The program will keep the HOME button LED ring light on at all times. -->
<!-- Default: true -->
<add key="HomeLEDOn" value="true"/>
<!-- Will use multiple lights to display the current player rather than a single LED-->
<add key="UseJoyconIncrementalLights" value="true" />
<!-- Determines whether or not to translate gyro movements into joystick ("joy") or mouse movement ("mouse"), or have no effect ("none") -->
<!-- When "joy", turn gyro movements into joystick movement (left/right depends on setting) [not yet implemented]-->

View file

@ -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;

View file

@ -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;
}

View file

@ -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();
}
}
}
}

View file

@ -13,7 +13,7 @@ namespace BetterJoyForCemu {
private bool running;
private byte[] recvBuffer = new byte[1024];
List<Joycon> controllers;
IList<Joycon> controllers;
public MainForm form;