Skip to content

Commit

Permalink
- implemented inactivity timeout poweroff setting
Browse files Browse the repository at this point in the history
 - updated version
  • Loading branch information
Davidobot committed May 22, 2020
1 parent d539425 commit 04055aa
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 93 deletions.
179 changes: 91 additions & 88 deletions BetterJoyForCemu/App.config
Original file line number Diff line number Diff line change
@@ -1,97 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<appSettings>
<!--Motion Server IP: the default is localhost; you can change it to 0.0.0.0 (all interfaces) or a specific LAN IP
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<appSettings>
<!--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-->
<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
<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
but in that case also change the port in PadTest and cemuhook.ini accordingly. Default: 26760 -->
<add key="Port" value="26760" />
<!--Whether the Motion Server is enabled or not. Default: 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" />
<add key="Port" value="26760" />
<!--Whether the Motion Server is enabled or not. Default: true -->
<add key="MotionServer" value="true" />

<!-- Determines whether or not the program should purge the affected devices list upon exit -->
<!-- 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 -->
<add key="PurgeAffectedDevices" value="false" />
<!-- Determines whether or not HidGuardian's process whitelist is purged on start-up -->
<!-- Can interfere with other programs using HidGuardian, but prevents whitelist from being clogged from crashed instances -->
<!-- Default: true -->
<add key="PurgeWhitelist" value="false" />
<!-- Determines whether or not to use HidGuardian (improves compatibility with other programs, like Steam, when set to "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 -->
<!-- Default: false -->
<add key="UseHIDG" 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" />

<!-- 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. -->
<!-- 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"/>
<!--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" />

<!-- 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"/>
<!--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="false" />
<!--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 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 joycons at program exit -->
<!-- Default: false -->
<add key="AutoPowerOff" value="false" />
<!-- Power off joycons 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>
<!-- Determines whether or not the program should purge the affected devices list upon exit -->
<!-- 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 -->
<add key="PurgeAffectedDevices" value="false" />
<!-- Determines whether or not HidGuardian's process whitelist is purged on start-up -->
<!-- Can interfere with other programs using HidGuardian, but prevents whitelist from being clogged from crashed instances -->
<!-- Default: true -->
<add key="PurgeWhitelist" value="false" />
<!-- Determines whether or not to use HidGuardian (improves compatibility with other programs, like Steam, when set to "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 -->
<!-- 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. -->
<!-- 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>
23 changes: 20 additions & 3 deletions BetterJoyForCemu/Joycon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -601,15 +603,16 @@ 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"]);
byte[] sliderVal = new byte[] { 0, 0 };
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();
Expand All @@ -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])
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion BetterJoyForCemu/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="title.png">
</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.

It also allows using the gyro to control your mouse and remap the special buttons (SL, SR, Capture) to key bindings of your choice.
Expand Down

0 comments on commit 04055aa

Please sign in to comment.