- Fix LEDs not always being set
- Code clean-up
This commit is contained in:
parent
f316ade501
commit
6d2b4b3918
2 changed files with 9 additions and 57 deletions
|
@ -382,8 +382,6 @@ namespace BetterJoyForCemu {
|
||||||
|
|
||||||
BlinkHomeLight();
|
BlinkHomeLight();
|
||||||
|
|
||||||
a[0] = leds_;
|
|
||||||
Subcommand(0x30, a, 1);
|
|
||||||
Subcommand(0x40, new byte[] { (imu_enabled ? (byte)0x1 : (byte)0x0) }, 1, true);
|
Subcommand(0x40, new byte[] { (imu_enabled ? (byte)0x1 : (byte)0x0) }, 1, true);
|
||||||
Subcommand(0x48, new byte[] { 0x01 }, 1, true);
|
Subcommand(0x48, new byte[] { 0x01 }, 1, true);
|
||||||
|
|
||||||
|
@ -392,6 +390,8 @@ namespace BetterJoyForCemu {
|
||||||
Subcommand(0x3, new byte[] { 0x30 }, 1, true);
|
Subcommand(0x3, new byte[] { 0x30 }, 1, true);
|
||||||
DebugPrint("Done with init.", DebugType.COMMS);
|
DebugPrint("Done with init.", DebugType.COMMS);
|
||||||
|
|
||||||
|
SetPlayerLED(leds_);
|
||||||
|
|
||||||
HIDapi.hid_set_nonblocking(handle, 1);
|
HIDapi.hid_set_nonblocking(handle, 1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -405,7 +405,7 @@ namespace BetterJoyForCemu {
|
||||||
byte[] a = Enumerable.Repeat((byte)0xFF, 25).ToArray();
|
byte[] a = Enumerable.Repeat((byte)0xFF, 25).ToArray();
|
||||||
a[0] = 0x18;
|
a[0] = 0x18;
|
||||||
a[1] = 0x01;
|
a[1] = 0x01;
|
||||||
Subcommand(0x38, a, 25, false);
|
Subcommand(0x38, a, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetHomeLight(bool on) {
|
public void SetHomeLight(bool on) {
|
||||||
|
@ -417,12 +417,12 @@ namespace BetterJoyForCemu {
|
||||||
a[0] = 0x10;
|
a[0] = 0x10;
|
||||||
a[1] = 0x01;
|
a[1] = 0x01;
|
||||||
}
|
}
|
||||||
Subcommand(0x38, a, 25, true, false);
|
Subcommand(0x38, a, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetHCIState(byte state) {
|
private void SetHCIState(byte state) {
|
||||||
byte[] a = { state };
|
byte[] a = { state };
|
||||||
Subcommand(0x06, a, 1, false);
|
Subcommand(0x06, a, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PowerOff() {
|
public void PowerOff() {
|
||||||
|
@ -492,15 +492,12 @@ namespace BetterJoyForCemu {
|
||||||
state = state_.NOT_ATTACHED;
|
state = state_.NOT_ATTACHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Improve this loop, make USB not laggy
|
|
||||||
private byte ts_en;
|
private byte ts_en;
|
||||||
private int ReceiveRaw() {
|
private int ReceiveRaw() {
|
||||||
if (handle == IntPtr.Zero) return -2;
|
if (handle == IntPtr.Zero) return -2;
|
||||||
byte[] raw_buf = new byte[report_len];
|
byte[] raw_buf = new byte[report_len];
|
||||||
int ret = HIDapi.hid_read_timeout(handle, raw_buf, new UIntPtr(report_len), 5);
|
int ret = HIDapi.hid_read_timeout(handle, raw_buf, new UIntPtr(report_len), 5);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
// Process packets as soon as they come
|
// Process packets as soon as they come
|
||||||
for (int n = 0; n < 3; n++) {
|
for (int n = 0; n < 3; n++) {
|
||||||
|
@ -720,8 +717,7 @@ namespace BetterJoyForCemu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Fix?
|
private Thread PollThreadObj;
|
||||||
private Thread PollThreadObj; // pro times out over time randomly if it was USB and then bluetooth??
|
|
||||||
private void Poll() {
|
private void Poll() {
|
||||||
stop_polling = false;
|
stop_polling = false;
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
|
@ -734,11 +730,8 @@ namespace BetterJoyForCemu {
|
||||||
int a = ReceiveRaw();
|
int a = ReceiveRaw();
|
||||||
|
|
||||||
if (a > 0 && state > state_.DROPPED) {
|
if (a > 0 && state > state_.DROPPED) {
|
||||||
|
|
||||||
|
|
||||||
state = state_.IMU_DATA_OK;
|
state = state_.IMU_DATA_OK;
|
||||||
attempts = 0;
|
attempts = 0;
|
||||||
|
|
||||||
} else if (attempts > 240) {
|
} else if (attempts > 240) {
|
||||||
state = state_.DROPPED;
|
state = state_.DROPPED;
|
||||||
form.AppendTextBox("Dropped.\r\n");
|
form.AppendTextBox("Dropped.\r\n");
|
||||||
|
|
|
@ -89,14 +89,13 @@ namespace BetterJoyForCemu {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckForNewControllersTime(Object source, ElapsedEventArgs e) {
|
void CheckForNewControllersTime(Object source, ElapsedEventArgs e) {
|
||||||
|
CleanUp();
|
||||||
if (Config.IntValue("ProgressiveScan") == 1) {
|
if (Config.IntValue("ProgressiveScan") == 1) {
|
||||||
CheckForNewControllers();
|
CheckForNewControllers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CheckForNewControllers() {
|
public void CheckForNewControllers() {
|
||||||
CleanUp();
|
|
||||||
|
|
||||||
// move all code for initializing devices here and well as the initial code from Start()
|
// move all code for initializing devices here and well as the initial code from Start()
|
||||||
bool isLeft = false;
|
bool isLeft = false;
|
||||||
IntPtr ptr = HIDapi.hid_enumerate(vendor_id, 0x0);
|
IntPtr ptr = HIDapi.hid_enumerate(vendor_id, 0x0);
|
||||||
|
@ -299,8 +298,8 @@ namespace BetterJoyForCemu {
|
||||||
foreach (Joycon v in j) {
|
foreach (Joycon v in j) {
|
||||||
if (Boolean.Parse(ConfigurationManager.AppSettings["AutoPowerOff"]))
|
if (Boolean.Parse(ConfigurationManager.AppSettings["AutoPowerOff"]))
|
||||||
v.PowerOff();
|
v.PowerOff();
|
||||||
else
|
|
||||||
v.Detach();
|
v.Detach();
|
||||||
|
|
||||||
if (v.out_xbox != null) {
|
if (v.out_xbox != null) {
|
||||||
v.out_xbox.Disconnect();
|
v.out_xbox.Disconnect();
|
||||||
|
@ -316,49 +315,9 @@ namespace BetterJoyForCemu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Custom timer class because system timers have a limit of 15.6ms
|
|
||||||
class HighResTimer {
|
|
||||||
double interval = 0;
|
|
||||||
double frequency = 0;
|
|
||||||
|
|
||||||
Thread thread;
|
|
||||||
|
|
||||||
public delegate void ActionDelegate();
|
|
||||||
ActionDelegate func;
|
|
||||||
|
|
||||||
bool run = false;
|
|
||||||
|
|
||||||
public HighResTimer(double f, ActionDelegate a) {
|
|
||||||
frequency = f;
|
|
||||||
interval = 1.0 / f;
|
|
||||||
|
|
||||||
func = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Start() {
|
|
||||||
run = true;
|
|
||||||
thread = new Thread(new ThreadStart(Run));
|
|
||||||
thread.IsBackground = true;
|
|
||||||
thread.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Run() {
|
|
||||||
while (run) {
|
|
||||||
func();
|
|
||||||
int timeToSleep = (int)(interval * 1000);
|
|
||||||
Thread.Sleep(timeToSleep);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Stop() {
|
|
||||||
run = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
public static PhysicalAddress btMAC = new PhysicalAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
|
public static PhysicalAddress btMAC = new PhysicalAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
|
||||||
public static UdpServer server;
|
public static UdpServer server;
|
||||||
static double pollsPerSecond = 120.0;
|
|
||||||
|
|
||||||
public static ViGEmClient emClient;
|
public static ViGEmClient emClient;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue