From 04055aa97aaf990364cbd98e82db53ddd1a599cb Mon Sep 17 00:00:00 2001 From: David Khachaturov Date: Fri, 22 May 2020 16:44:43 +0100 Subject: [PATCH] - implemented inactivity timeout poweroff setting - updated version --- BetterJoyForCemu/App.config | 179 +++++++++++++------------- BetterJoyForCemu/Joycon.cs | 23 +++- BetterJoyForCemu/MainForm.Designer.cs | 2 +- README.md | 2 +- 4 files changed, 113 insertions(+), 93 deletions(-) diff --git a/BetterJoyForCemu/App.config b/BetterJoyForCemu/App.config index c2a5cb8c..ae3a695a 100644 --- a/BetterJoyForCemu/App.config +++ b/BetterJoyForCemu/App.config @@ -1,97 +1,100 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BetterJoyForCemu/Joycon.cs b/BetterJoyForCemu/Joycon.cs index 4dae7990..720c0692 100644 --- a/BetterJoyForCemu/Joycon.cs +++ b/BetterJoyForCemu/Joycon.cs @@ -22,6 +22,8 @@ public class Joycon { public Joycon other; public bool active_gyro = false; + private long inactivity = Stopwatch.GetTimestamp(); + public bool send = true; public enum DebugType : int { @@ -601,6 +603,7 @@ private void SimulateContinous(int origin, string s) { string extraGyroFeature = ConfigurationManager.AppSettings["GyroToJoyOrMouse"]; int GyroMouseSensitivity = Int32.Parse(ConfigurationManager.AppSettings["GyroMouseSensitivity"]); bool HomeLongPowerOff = Boolean.Parse(ConfigurationManager.AppSettings["HomeLongPowerOff"]); + long PowerOffInactivityMins = Int32.Parse(ConfigurationManager.AppSettings["PowerOffInactivity"]); bool GyroAnalogSliders = Boolean.Parse(ConfigurationManager.AppSettings["GyroAnalogSliders"]); int GyroAnalogSensitivity = Int32.Parse(ConfigurationManager.AppSettings["GyroAnalogSensitivity"]); @@ -608,8 +611,8 @@ private void SimulateContinous(int origin, string s) { private void DoThingsWithButtons() { int powerOffButton = (int)((isPro || !isLeft || other != null) ? Button.HOME : Button.CAPTURE); + long timestamp = Stopwatch.GetTimestamp(); if (HomeLongPowerOff && buttons[powerOffButton]) { - long timestamp = Stopwatch.GetTimestamp(); if ((timestamp - buttons_down_timestamp[powerOffButton]) / 10000 > 2000.0) { if (other != null) other.PowerOff(); @@ -619,6 +622,16 @@ private void DoThingsWithButtons() { } } + if (PowerOffInactivityMins > 0) { + if ((timestamp - inactivity) / 10000 > PowerOffInactivityMins * 60 * 1000) { + if (other != null) + other.PowerOff(); + + PowerOff(); + return; + } + } + if (buttons_down[(int)Button.CAPTURE]) Simulate(Config.Value("capture")); if (buttons_down[(int)Button.HOME]) @@ -709,8 +722,7 @@ private void DoThingsWithButtons() { private Thread PollThreadObj; // pro times out over time randomly if it was USB and then bluetooth?? private void Poll() { int attempts = 0; - Stopwatch watch = new Stopwatch(); - watch.Start(); + while (!stop_polling & state > state_.NO_JOYCONS) { if (!isSnes && (rumble_obj.t > 0)) SendRumble(rumble_obj.GetData()); @@ -856,12 +868,17 @@ private int ProcessButtonsAndStick(byte[] report_buf) { lock (buttons_up) { lock (buttons_down) { + bool changed = false; for (int i = 0; i < buttons.Length; ++i) { buttons_up[i] = (down_[i] & !buttons[i]); buttons_down[i] = (!down_[i] & buttons[i]); if (down_[i] != buttons[i]) buttons_down_timestamp[i] = (buttons[i] ? timestamp : -1); + if (buttons_up[i] || buttons_down[i]) + changed = true; } + + inactivity = (changed) ? timestamp : inactivity; } } } diff --git a/BetterJoyForCemu/MainForm.Designer.cs b/BetterJoyForCemu/MainForm.Designer.cs index dc1e0cfc..b68a088c 100644 --- a/BetterJoyForCemu/MainForm.Designer.cs +++ b/BetterJoyForCemu/MainForm.Designer.cs @@ -109,7 +109,7 @@ private void InitializeComponent() { this.version_lbl.Name = "version_lbl"; this.version_lbl.Size = new System.Drawing.Size(28, 13); this.version_lbl.TabIndex = 2; - this.version_lbl.Text = "v6.2"; + this.version_lbl.Text = "v6.3"; // // passiveScanBox // diff --git a/README.md b/README.md index 3e1517a1..b98ca74f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

-# BetterJoy v6.2 +# BetterJoy v6.3 Allows the Nintendo Switch Pro Controller, Joycons, and Switch SNES controller to be used with [Cemu](http://cemu.info/) using [Cemuhook](https://sshnuke.net/cemuhook/), [Citra](https://citra-emu.org/), [Dolphin](https://dolphin-emu.org/), and system-wide with generic XInput support. It also allows using the gyro to control your mouse and remap the special buttons (SL, SR, Capture) to key bindings of your choice.