- Added low battery notification

- Added automatic detection for badly-closed USB connections. Automatically reset the connection in such a case
This commit is contained in:
David Khachaturov 2020-09-12 09:24:07 +01:00
parent 4b181c6aed
commit 99bae0ec2c
5 changed files with 358 additions and 347 deletions

View file

@ -53,7 +53,7 @@
<!-- Determines whether or not to use HidGuardian (improves compatibility with other programs, like Steam, when set to "false") -->
<!-- When "true", BetterJoy will hide the Pro/Joycons from other programs to prevent glitching out on exit and to prevent DI/XI clashes in certain programs -->
<!-- Default: false -->
<add key="UseHIDG" value="true" />
<add key="UseHIDG" value="false" />
<!-- Determines whether or not to enable (experimental - currently default controller to pro) support for 3rd-party controllers. Adds a "Calibrate" button. -->
<!-- When "true", click "Calibrate" button once to get gyro calibrate data. -->
@ -96,7 +96,7 @@
<add key="AutoPowerOff" value="false" />
<!-- Automatically power off controllers after a period of inactivity (in minutes) -->
<!-- Default: 30 (-1 indicates infinite time) -->
<add key="PowerOffInactivity" value="30" />
<add key="PowerOffInactivity" value="-1" />
<!-- Power off controllers when Capture (left only) or Home (right only or combined) buttons are pressed for a long interval (2s) -->
<!-- Default: true -->
<add key="HomeLongPowerOff" value="true" />

View file

@ -359,6 +359,12 @@ namespace BetterJoyForCemu {
HIDapi.hid_write(handle, a, new UIntPtr(2));
HIDapi.hid_read_timeout(handle, a, new UIntPtr(64), 100);
if (a[0] != 0x81) { // can occur when USB connection isn't closed properly
form.AppendTextBox("Resetting USB connection.\r\n");
Subcommand(0x06, new byte[] { 0x01 }, 1);
throw new Exception("reset_usb");
}
if (a[3] == 0x3) {
PadMacAddress = new PhysicalAddress(new byte[] { a[9], a[8], a[7], a[6], a[5], a[4] });
}
@ -466,6 +472,12 @@ namespace BetterJoyForCemu {
}
}
}
if (battery <= 1) {
form.notifyIcon.Visible = true;
form.notifyIcon.BalloonTipText = String.Format("Controller {0} ({1}) - low battery notification!", PadId, isPro ? "Pro Controller" : (isSnes ? "SNES Controller" : (isLeft ? "Joycon Left" : "Joycon Right")));
form.notifyIcon.ShowBalloonTip(0);
}
}
public void SetFilterCoeff(float a) {
@ -1033,7 +1045,6 @@ namespace BetterJoyForCemu {
HIDapi.hid_write(handle, buf_, new UIntPtr(len + 11));
int tries = 0;
do {
int res = HIDapi.hid_read_timeout(handle, response, new UIntPtr(report_len), 100);
if (res < 1) DebugPrint("No response.", DebugType.COMMS);
else if (print) { PrintArray(response, DebugType.COMMS, report_len - 1, 1, "Response ID 0x" + string.Format("{0:X2}", response[0]) + ". Data: 0x{0:S}"); }

View file

@ -69,7 +69,7 @@
//
// notifyIcon
//
this.notifyIcon.BalloonTipText = "Double click the tray icon to maximise";
this.notifyIcon.BalloonTipText = "Double click the tray icon to maximise!";
this.notifyIcon.BalloonTipTitle = "BetterJoy";
this.notifyIcon.ContextMenuStrip = this.contextMenu;
this.notifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon.Icon")));
@ -372,7 +372,7 @@
#endregion
public System.Windows.Forms.TextBox console;
private System.Windows.Forms.NotifyIcon notifyIcon;
public System.Windows.Forms.NotifyIcon notifyIcon;
private System.Windows.Forms.Label version_lbl;
private System.Windows.Forms.ContextMenuStrip contextMenu;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;

View file

@ -61,7 +61,8 @@ namespace BetterJoyForCemu {
private void HideToTray() {
this.WindowState = FormWindowState.Minimized;
notifyIcon.Visible = true;
notifyIcon.ShowBalloonTip(1);
notifyIcon.BalloonTipText = "Double click the tray icon to maximise!";
notifyIcon.ShowBalloonTip(0);
this.ShowInTaskbar = false;
this.Hide();
}

View file

@ -24,7 +24,6 @@ namespace BetterJoyForCemu {
public bool EnableLocalize = false;
private const ushort vendor_id = 0x57e;
private const ushort vendor_id_ = 0x057e;
private const ushort product_l = 0x2006;
private const ushort product_r = 0x2007;
private const ushort product_pro = 0x2009;