JoyCons power-off feature (#334)
* Tracking button down timestamps (for long press detection) * Added joycons power-off functionality
This commit is contained in:
parent
fb9240d568
commit
3b10bb609f
4 changed files with 42 additions and 1 deletions
|
@ -79,5 +79,11 @@
|
||||||
<!-- Have ShowAsXInput as false if using this -->
|
<!-- Have ShowAsXInput as false if using this -->
|
||||||
<!-- Default: false -->
|
<!-- Default: false -->
|
||||||
<add key="ShowAsDS4" value="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: false -->
|
||||||
|
<add key="HomeLongPowerOff" value="false" />
|
||||||
</appSettings>
|
</appSettings>
|
||||||
</configuration>
|
</configuration>
|
|
@ -76,6 +76,7 @@ namespace BetterJoyForCemu {
|
||||||
private bool[] buttons_up = new bool[20];
|
private bool[] buttons_up = new bool[20];
|
||||||
private bool[] buttons = new bool[20];
|
private bool[] buttons = new bool[20];
|
||||||
private bool[] down_ = new bool[20];
|
private bool[] down_ = new bool[20];
|
||||||
|
private long[] buttons_down_timestamp = new long[20];
|
||||||
|
|
||||||
private float[] stick = { 0, 0 };
|
private float[] stick = { 0, 0 };
|
||||||
private float[] stick2 = { 0, 0 };
|
private float[] stick2 = { 0, 0 };
|
||||||
|
@ -250,6 +251,8 @@ namespace BetterJoyForCemu {
|
||||||
imu_enabled = imu;
|
imu_enabled = imu;
|
||||||
do_localize = localize;
|
do_localize = localize;
|
||||||
rumble_obj = new Rumble(160, 320, 0);
|
rumble_obj = new Rumble(160, 320, 0);
|
||||||
|
for (int i = 0; i < buttons_down_timestamp.Length; i++)
|
||||||
|
buttons_down_timestamp[i] = -1;
|
||||||
filterweight = alpha;
|
filterweight = alpha;
|
||||||
isLeft = left;
|
isLeft = left;
|
||||||
|
|
||||||
|
@ -417,6 +420,18 @@ namespace BetterJoyForCemu {
|
||||||
Subcommand(0x38, a, 25, false);
|
Subcommand(0x38, a, 25, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetHCIState(byte state) {
|
||||||
|
byte[] a = { state };
|
||||||
|
Subcommand(0x06, a, 1, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PowerOff() {
|
||||||
|
if (state > state_.DROPPED) {
|
||||||
|
SetHCIState(0x00);
|
||||||
|
state = state_.DROPPED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void BatteryChanged() { // battery changed level
|
private void BatteryChanged() { // battery changed level
|
||||||
foreach (var v in form.con) {
|
foreach (var v in form.con) {
|
||||||
if (v.Tag == this) {
|
if (v.Tag == this) {
|
||||||
|
@ -590,6 +605,18 @@ 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"]);
|
||||||
private void DoThingsWithButtons() {
|
private void DoThingsWithButtons() {
|
||||||
|
int powerOffButton = (int)((!isLeft || other != null) ? Button.HOME : Button.CAPTURE);
|
||||||
|
|
||||||
|
if (buttons[powerOffButton]) {
|
||||||
|
long timestamp = Stopwatch.GetTimestamp();
|
||||||
|
if ((timestamp - buttons_down_timestamp[powerOffButton]) / 10000 > 2000.0) {
|
||||||
|
PowerOff();
|
||||||
|
if (other != null)
|
||||||
|
other.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])
|
||||||
|
@ -802,11 +829,15 @@ namespace BetterJoyForCemu {
|
||||||
buttons[(int)Button.MINUS] = other.buttons[(int)Button.MINUS];
|
buttons[(int)Button.MINUS] = other.buttons[(int)Button.MINUS];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long timestamp = Stopwatch.GetTimestamp();
|
||||||
|
|
||||||
lock (buttons_up) {
|
lock (buttons_up) {
|
||||||
lock (buttons_down) {
|
lock (buttons_down) {
|
||||||
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])
|
||||||
|
buttons_down_timestamp[i] = (buttons[i] ? timestamp : -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,6 +255,7 @@ namespace BetterJoyForCemu {
|
||||||
AppendTextBox("Error writing app settings.\r\n");
|
AppendTextBox("Error writing app settings.\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigurationManager.AppSettings["AutoPowerOff"] = "false"; // Prevent joycons poweroff when applying settings
|
||||||
Application.Restart();
|
Application.Restart();
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,7 +300,10 @@ namespace BetterJoyForCemu {
|
||||||
|
|
||||||
public void OnApplicationQuit() {
|
public void OnApplicationQuit() {
|
||||||
foreach (Joycon v in j) {
|
foreach (Joycon v in j) {
|
||||||
v.Detach();
|
if (Boolean.Parse(ConfigurationManager.AppSettings["AutoPowerOff"]))
|
||||||
|
v.PowerOff();
|
||||||
|
else
|
||||||
|
v.Detach();
|
||||||
|
|
||||||
if (v.xin != null) {
|
if (v.xin != null) {
|
||||||
v.xin.Disconnect();
|
v.xin.Disconnect();
|
||||||
|
|
Loading…
Add table
Reference in a new issue