- implemented inactivity timeout poweroff setting

- updated version
This commit is contained in:
David Khachaturov 2020-05-22 16:44:43 +01:00
parent d539425b7b
commit 04055aa97a
4 changed files with 113 additions and 93 deletions

View file

@ -1,97 +1,100 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup> </startup>
<appSettings> <appSettings>
<!--Motion Server IP: the default is localhost; you can change it to 0.0.0.0 (all interfaces) or a specific LAN IP <!--Motion Server IP: the default is localhost; you can change it to 0.0.0.0 (all interfaces) or a specific LAN IP
which is **useful if you want to access the server from another computer in a network.** Default: 127.0.0.1--> which is **useful if you want to access the server from another computer in a network.** Default: 127.0.0.1-->
<add key="IP" value="127.0.0.1" /> <add key="IP" value="127.0.0.1" />
<!--Motion Server port: the default is 26760; if it conflicts with another server set it to anything valid <!--Motion Server port: the default is 26760; if it conflicts with another server set it to anything valid
but in that case also change the port in PadTest and cemuhook.ini accordingly. Default: 26760 --> but in that case also change the port in PadTest and cemuhook.ini accordingly. Default: 26760 -->
<add key="Port" value="26760" /> <add key="Port" value="26760" />
<!--Whether the Motion Server is enabled or not. Default: true --> <!--Whether the Motion Server is enabled or not. Default: true -->
<add key="MotionServer" value="true" /> <add key="MotionServer" value="true" />
<!--Rumble motor period in millisec. Lower means more granular vibration, higher is more stable.-->
<!--The response of rumble does not only depend on this setting and it's always high. Default: 300 -->
<add key="RumblePeriod" value="300" />
<!--The controller's HD rumble settings for the low/high frequency rumble. Change to change the pitch of the rumble.-->
<!--Don't set above ~1200. Default: 20 and 400 -->
<add key="LowFreqRumble" value="20" />
<add key="HighFreqRumble" value="400" />
<!--Rumble Setting. Turns rumble on or off.-->
<!--On is "true"; off is "false". Default: true -->
<add key="EnableRumble" value="true" />
<!--Swap A-B buttons; if on, this mimicks the (half of) Xbox layout by the button name, rather than by the physical layout.-->
<!--Also swaps buttons when using "Also use for buttons/axes"-->
<!--On is "true"; off is "false". Default: false -->
<add key="SwapAB" value="false" />
<!--Swap X-Y buttons; if on, this mimicks the (other half of) Xbox layout by the button name, rather than by the physical layout.-->
<!--Also swaps buttons when using "Also use for buttons/axes"-->
<!--On is "true"; off is "false". Default: false -->
<add key="SwapXY" value="false" />
<!--Allows use of gyroscope tilting to get full control of the slider values (big triggers)-->
<!--Works on pro controller and joined joycons (pro controller case - triggers combined, joycons case - separate tilt)-->
<!--Default: false -->
<add key="GyroAnalogSliders" value="true" />
<!--Change to -20 to change direction of tilt needed. Positive is ramp up if pointing up-->
<!--Default: 20 -->
<add key="GyroAnalogSensitivity" value="20" />
<!-- Determines whether or not the program should purge the affected devices list upon exit --> <!--Rumble motor period in millisec. Lower means more granular vibration, higher is more stable.-->
<!-- Should prevent any more issues of the controller being unusable after the program (even though this can be fixed if you read the README) --> <!--The response of rumble does not only depend on this setting and it's always high. Default: 300 -->
<!-- Default: true --> <add key="RumblePeriod" value="300" />
<add key="PurgeAffectedDevices" value="false" /> <!--The controller's HD rumble settings for the low/high frequency rumble. Change to change the pitch of the rumble.-->
<!-- Determines whether or not HidGuardian's process whitelist is purged on start-up --> <!--Don't set above ~1200. Default: 20 and 400 -->
<!-- Can interfere with other programs using HidGuardian, but prevents whitelist from being clogged from crashed instances --> <add key="LowFreqRumble" value="20" />
<!-- Default: true --> <add key="HighFreqRumble" value="400" />
<add key="PurgeWhitelist" value="false" /> <!--Rumble Setting. Turns rumble on or off.-->
<!-- Determines whether or not to use HidGuardian (improves compatibility with other programs, like Steam, when set to "false") --> <!--On is "true"; off is "false". Default: true -->
<!-- When "true", BetterJoyForCemu will hide the Pro/Joycons from other programs to prevent glitching out on exit and to prevent DI/XI clashes in certain programs --> <add key="EnableRumble" value="true" />
<!-- Default: false -->
<add key="UseHIDG" value="true" />
<!-- Determines whether or not to enable (experimental - currently default controller to pro) support for 3rd-party controllers. Adds a "Calibrate" button. --> <!--Swap A-B buttons; if on, this mimicks the (half of) Xbox layout by the button name, rather than by the physical layout.-->
<!-- When "true", click "Calibrate" button once to get gyro calibrate data. --> <!--Also swaps buttons when using "Also use for buttons/axes"-->
<!-- When enabled, can only calibrate one controller at a time. --> <!--On is "true"; off is "false". Default: false -->
<!-- Default: false --> <add key="SwapAB" value="false" />
<add key="NonOriginalController" value="false" /> <!--Swap X-Y buttons; if on, this mimicks the (other half of) Xbox layout by the button name, rather than by the physical layout.-->
<!-- The program will keep the HOME button LED ring light on at all times. --> <!--Also swaps buttons when using "Also use for buttons/axes"-->
<!-- Default: true --> <!--On is "true"; off is "false". Default: false -->
<add key="HomeLEDOn" value="true"/> <add key="SwapXY" value="false" />
<!-- Determines whether or not to translate gyro movements into joystick ("joy") or mouse movement ("mouse"), or have no effect ("none") --> <!--Allows use of gyroscope tilting to get full control of the slider values (big triggers)-->
<!-- When "joy", turn gyro movements into joystick movement (left/right depends on setting) [not yet implemented]--> <!--Works on pro controller and joined joycons (pro controller case - triggers combined, joycons case - separate tilt)-->
<!-- When "mouse", turn gyro movements into mouse movement. Press either stick-button to reset to middle of primary display --> <!--Default: false -->
<!-- Default: none --> <add key="GyroAnalogSliders" value="false" />
<add key="GyroToJoyOrMouse" value="none"/> <!--Change to -20 to change direction of tilt needed. Positive is ramp up if pointing up-->
<!-- Sensitivity of gyro-to-mouse movements --> <!--Default: 20 -->
<!-- Default: 50 --> <add key="GyroAnalogSensitivity" value="20" />
<add key="GyroMouseSensitivity" value="50"/>
<!-- When two joycons are connected, it would take the gyro movement of the right joycon for mouse movement. This swaps that -->
<!-- Default: false -->
<add key="GyroMouseLeftHanded" value="false"/>
<!-- Changes drag behaviour. -->
<!-- Will only apply to mouse buttons being mapped -->
<!-- Default: false -->
<add key="DragToggle" value="false"/>
<!-- Determines whether or not the program will expose detected controllers as Xbox 360 controllers --> <!-- Determines whether or not the program should purge the affected devices list upon exit -->
<!-- When "false", BetterJoyForCemu is only usable with CEMU. --> <!-- Should prevent any more issues of the controller being unusable after the program (even though this can be fixed if you read the README) -->
<!-- Default: true --> <!-- Default: true -->
<add key="ShowAsXInput" value="true" /> <add key="PurgeAffectedDevices" value="false" />
<!-- Have ShowAsXInput as false if using this --> <!-- Determines whether or not HidGuardian's process whitelist is purged on start-up -->
<!-- Default: false --> <!-- Can interfere with other programs using HidGuardian, but prevents whitelist from being clogged from crashed instances -->
<add key="ShowAsDS4" value="false"/> <!-- Default: true -->
<add key="PurgeWhitelist" value="false" />
<!-- Automatically power off joycons at program exit --> <!-- Determines whether or not to use HidGuardian (improves compatibility with other programs, like Steam, when set to "false") -->
<!-- Default: false --> <!-- When "true", BetterJoyForCemu will hide the Pro/Joycons from other programs to prevent glitching out on exit and to prevent DI/XI clashes in certain programs -->
<add key="AutoPowerOff" value="false" /> <!-- Default: false -->
<!-- Power off joycons when Capture (left only) or Home (right only or combined) buttons are pressed for a long interval (2s) --> <add key="UseHIDG" value="true" />
<!-- Default: true -->
<add key="HomeLongPowerOff" value="true" /> <!-- Determines whether or not to enable (experimental - currently default controller to pro) support for 3rd-party controllers. Adds a "Calibrate" button. -->
</appSettings> <!-- When "true", click "Calibrate" button once to get gyro calibrate data. -->
<!-- When enabled, can only calibrate one controller at a time. -->
<!-- Default: false -->
<add key="NonOriginalController" value="false" />
<!-- The program will keep the HOME button LED ring light on at all times. -->
<!-- Default: true -->
<add key="HomeLEDOn" 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]-->
<!-- When "mouse", turn gyro movements into mouse movement. Press either stick-button to reset to middle of primary display -->
<!-- Default: none -->
<add key="GyroToJoyOrMouse" value="none"/>
<!-- Sensitivity of gyro-to-mouse movements -->
<!-- Default: 50 -->
<add key="GyroMouseSensitivity" value="50"/>
<!-- When two joycons are connected, it would take the gyro movement of the right joycon for mouse movement. This swaps that -->
<!-- Default: false -->
<add key="GyroMouseLeftHanded" value="false"/>
<!-- Changes drag behaviour. -->
<!-- Will only apply to mouse buttons being mapped -->
<!-- Default: false -->
<add key="DragToggle" value="false"/>
<!-- Determines whether or not the program will expose detected controllers as Xbox 360 controllers -->
<!-- When "false", BetterJoyForCemu is only usable with CEMU. -->
<!-- Default: true -->
<add key="ShowAsXInput" value="true" />
<!-- Have ShowAsXInput as false if using this -->
<!-- Default: false -->
<add key="ShowAsDS4" value="false"/>
<!-- Automatically power off controllers at program exit -->
<!-- Default: false -->
<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" />
<!-- 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" />
</appSettings>
</configuration> </configuration>

View file

@ -22,6 +22,8 @@ namespace BetterJoyForCemu {
public Joycon other; public Joycon other;
public bool active_gyro = false; public bool active_gyro = false;
private long inactivity = Stopwatch.GetTimestamp();
public bool send = true; public bool send = true;
public enum DebugType : int { public enum DebugType : int {
@ -601,6 +603,7 @@ namespace BetterJoyForCemu {
string extraGyroFeature = ConfigurationManager.AppSettings["GyroToJoyOrMouse"]; string extraGyroFeature = ConfigurationManager.AppSettings["GyroToJoyOrMouse"];
int GyroMouseSensitivity = Int32.Parse(ConfigurationManager.AppSettings["GyroMouseSensitivity"]); int GyroMouseSensitivity = Int32.Parse(ConfigurationManager.AppSettings["GyroMouseSensitivity"]);
bool HomeLongPowerOff = Boolean.Parse(ConfigurationManager.AppSettings["HomeLongPowerOff"]); bool HomeLongPowerOff = Boolean.Parse(ConfigurationManager.AppSettings["HomeLongPowerOff"]);
long PowerOffInactivityMins = Int32.Parse(ConfigurationManager.AppSettings["PowerOffInactivity"]);
bool GyroAnalogSliders = Boolean.Parse(ConfigurationManager.AppSettings["GyroAnalogSliders"]); bool GyroAnalogSliders = Boolean.Parse(ConfigurationManager.AppSettings["GyroAnalogSliders"]);
int GyroAnalogSensitivity = Int32.Parse(ConfigurationManager.AppSettings["GyroAnalogSensitivity"]); int GyroAnalogSensitivity = Int32.Parse(ConfigurationManager.AppSettings["GyroAnalogSensitivity"]);
@ -608,8 +611,8 @@ namespace BetterJoyForCemu {
private void DoThingsWithButtons() { private void DoThingsWithButtons() {
int powerOffButton = (int)((isPro || !isLeft || other != null) ? Button.HOME : Button.CAPTURE); int powerOffButton = (int)((isPro || !isLeft || other != null) ? Button.HOME : Button.CAPTURE);
long timestamp = Stopwatch.GetTimestamp();
if (HomeLongPowerOff && buttons[powerOffButton]) { if (HomeLongPowerOff && buttons[powerOffButton]) {
long timestamp = Stopwatch.GetTimestamp();
if ((timestamp - buttons_down_timestamp[powerOffButton]) / 10000 > 2000.0) { if ((timestamp - buttons_down_timestamp[powerOffButton]) / 10000 > 2000.0) {
if (other != null) if (other != null)
other.PowerOff(); other.PowerOff();
@ -619,6 +622,16 @@ namespace BetterJoyForCemu {
} }
} }
if (PowerOffInactivityMins > 0) {
if ((timestamp - inactivity) / 10000 > PowerOffInactivityMins * 60 * 1000) {
if (other != null)
other.PowerOff();
PowerOff();
return;
}
}
if (buttons_down[(int)Button.CAPTURE]) if (buttons_down[(int)Button.CAPTURE])
Simulate(Config.Value("capture")); Simulate(Config.Value("capture"));
if (buttons_down[(int)Button.HOME]) if (buttons_down[(int)Button.HOME])
@ -709,8 +722,7 @@ namespace BetterJoyForCemu {
private Thread PollThreadObj; // pro times out over time randomly if it was USB and then bluetooth?? private Thread PollThreadObj; // pro times out over time randomly if it was USB and then bluetooth??
private void Poll() { private void Poll() {
int attempts = 0; int attempts = 0;
Stopwatch watch = new Stopwatch();
watch.Start();
while (!stop_polling & state > state_.NO_JOYCONS) { while (!stop_polling & state > state_.NO_JOYCONS) {
if (!isSnes && (rumble_obj.t > 0)) if (!isSnes && (rumble_obj.t > 0))
SendRumble(rumble_obj.GetData()); SendRumble(rumble_obj.GetData());
@ -856,12 +868,17 @@ namespace BetterJoyForCemu {
lock (buttons_up) { lock (buttons_up) {
lock (buttons_down) { lock (buttons_down) {
bool changed = false;
for (int i = 0; i < buttons.Length; ++i) { for (int i = 0; i < buttons.Length; ++i) {
buttons_up[i] = (down_[i] & !buttons[i]); buttons_up[i] = (down_[i] & !buttons[i]);
buttons_down[i] = (!down_[i] & buttons[i]); buttons_down[i] = (!down_[i] & buttons[i]);
if (down_[i] != buttons[i]) if (down_[i] != buttons[i])
buttons_down_timestamp[i] = (buttons[i] ? timestamp : -1); buttons_down_timestamp[i] = (buttons[i] ? timestamp : -1);
if (buttons_up[i] || buttons_down[i])
changed = true;
} }
inactivity = (changed) ? timestamp : inactivity;
} }
} }
} }

View file

@ -109,7 +109,7 @@
this.version_lbl.Name = "version_lbl"; this.version_lbl.Name = "version_lbl";
this.version_lbl.Size = new System.Drawing.Size(28, 13); this.version_lbl.Size = new System.Drawing.Size(28, 13);
this.version_lbl.TabIndex = 2; this.version_lbl.TabIndex = 2;
this.version_lbl.Text = "v6.2"; this.version_lbl.Text = "v6.3";
// //
// passiveScanBox // passiveScanBox
// //

View file

@ -2,7 +2,7 @@
<img src="title.png"> <img src="title.png">
</p> </p>
# 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. 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. It also allows using the gyro to control your mouse and remap the special buttons (SL, SR, Capture) to key bindings of your choice.