Skip to content

Commit

Permalink
port from EA
Browse files Browse the repository at this point in the history
- Add support for ONEXPLAYER 2 PRO ARP23P (non eva)
- Add support for GPD Win 4 2023
- Improve bluetooth controllers stability and UI experience
- Implement power cycling logic for bluetooth controllers
- Implement fan control over Rog Ally
- Migrated to more reliable and faster HidLibrary
- Fixed an issue with broken first start check
- Fixed an issue with infinite rumble on start
- DualSense and DualShock 4 LED will now be equal to Windows Accent Color
  • Loading branch information
Valkirie committed Oct 25, 2023
1 parent ab82a64 commit 64f5a0d
Show file tree
Hide file tree
Showing 42 changed files with 1,602 additions and 433 deletions.
2 changes: 1 addition & 1 deletion HandheldCompanion.iss
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ end;

#define MyAppSetupName 'Handheld Companion'
#define MyBuildId 'HandheldCompanion'
#define MyAppVersion '0.18.0.3'
#define MyAppVersion '0.18.0.4'
#define MyAppPublisher 'BenjaminLSR'
#define MyAppCopyright 'Copyright @ BenjaminLSR'
#define MyAppURL 'https://github.com/Valkirie/HandheldCompanion'
Expand Down
11 changes: 11 additions & 0 deletions HandheldCompanion/Controllers/DS4Controller.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Utils;
using Inkore.UI.WPF.Modern;
using System.Windows;
using System.Windows.Media;
using static JSL;

Expand Down Expand Up @@ -97,6 +99,15 @@ public override void Unplug()
base.Unplug();
}

public override void SetLightColor(byte R, byte G, byte B)
{
// UI thread
Application.Current.Dispatcher.Invoke(() =>
{
JslSetLightColour(UserIndex, CommonUtils.rgb_to_int(R, G, B));
});
}

public override void Cleanup()
{
TimerManager.Tick -= UpdateInputs;
Expand Down
10 changes: 10 additions & 0 deletions HandheldCompanion/Controllers/DualSenseController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Utils;
using System.Windows;
using static JSL;

namespace HandheldCompanion.Controllers;
Expand Down Expand Up @@ -90,6 +91,15 @@ public override void Unplug()
base.Unplug();
}

public override void SetLightColor(byte R, byte G, byte B)
{
// UI thread
Application.Current.Dispatcher.Invoke(() =>
{
JslSetLightColour(UserIndex, CommonUtils.rgb_to_int(R, G, B));
});
}

public override void Cleanup()
{
TimerManager.Tick -= UpdateInputs;
Expand Down
16 changes: 12 additions & 4 deletions HandheldCompanion/Controllers/IController.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,19 @@
</DockPanel>
</Grid>

<ui:ProgressBar
Name="ProgressBarUpdate"
<ui:SimpleStackPanel
Name="ProgressBarPanel"
d:Visibility="Visible"
IsIndeterminate="True"
Visibility="Collapsed" />
Spacing="6"
Visibility="Collapsed">
<ui:ProgressBar Name="ProgressBarUpdate" IsIndeterminate="True" />
<TextBlock
Name="ProgressBarWarning"
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
TextAlignment="Center"
TextWrapping="Wrap" />
</ui:SimpleStackPanel>
</StackPanel>
</Border>
</UserControl>
50 changes: 31 additions & 19 deletions HandheldCompanion/Controllers/IController.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ public void InjectButton(ButtonFlags button, bool IsKeyDown, bool IsKeyUp)
public virtual void SetVibrationStrength(uint value, bool rumble = false)
{
VibrationStrength = value / 100.0d;
if (rumble)
Rumble();
if (rumble) Rumble();
}

public virtual void SetVibration(byte LargeMotor, byte SmallMotor)
Expand All @@ -223,11 +222,14 @@ public virtual bool IsConnected()
return false;
}

public virtual async void Rumble(int delay = 125)
public virtual void Rumble(int delay = 125)
{
SetVibration(byte.MaxValue, byte.MaxValue);
await Task.Delay(delay);
SetVibration(0, 0);
Task.Run(async () =>
{
SetVibration(byte.MaxValue, byte.MaxValue);
await Task.Delay(delay);
SetVibration(0, 0);
});
}

public virtual bool IsPlugged()
Expand Down Expand Up @@ -262,59 +264,64 @@ public virtual void Cleanup()

public bool IsHidden()
{
var hide_device = HidHide.IsRegistered(Details.deviceInstanceId);
// var hide_device = HidHide.IsRegistered(Details.deviceInstanceId);
var hide_base = HidHide.IsRegistered(Details.baseContainerDeviceInstanceId);
return /* hide_device || */ hide_base;
}

public void Hide(bool powerCycle = true)
public virtual void Hide(bool powerCycle = true)
{
HideHID();

// set flag
powerCycle = powerCycle && this is not SteamController;

if (powerCycle)
{
// UI thread (async)
Application.Current.Dispatcher.BeginInvoke(() =>
{
IsEnabled = false;
ProgressBarUpdate.Visibility = Visibility.Visible;
ProgressBarPanel.Visibility = Visibility.Visible;
});

ControllerManager.PowerCyclers[Details.baseContainerDeviceInstanceId] = true;
Details.CyclePort();

CyclePort();
return;
}

RefreshControls();
}

public void Unhide(bool powerCycle = true)
public virtual void Unhide(bool powerCycle = true)
{
UnhideHID();

// set flag
powerCycle = powerCycle && this is not SteamController;

if (powerCycle)
{
// UI thread (async)
Application.Current.Dispatcher.BeginInvoke(() =>
{
IsEnabled = false;
ProgressBarUpdate.Visibility = Visibility.Visible;
ProgressBarPanel.Visibility = Visibility.Visible;
});

ControllerManager.PowerCyclers[Details.baseContainerDeviceInstanceId] = true;
Details.CyclePort();

CyclePort();
return;
}

RefreshControls();
}

public virtual void CyclePort()
{
Details.CyclePort();
}

public virtual void SetLightColor(byte R, byte G, byte B)
{
}

public void HideHID()
{
HidHide.HidePath(Details.baseContainerDeviceInstanceId);
Expand Down Expand Up @@ -343,6 +350,11 @@ public void UnhideHID()
*/
}

public virtual bool RestoreDrivers()
{
return true;
}

protected virtual void Calibrate()
{
}
Expand Down
26 changes: 26 additions & 0 deletions HandheldCompanion/Controllers/JSController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Utils;
using Nefarius.Utilities.DeviceManagement.PnP;
using System.Threading.Tasks;
using System.Windows;
using static JSL;
using Timer = System.Timers.Timer;
Expand Down Expand Up @@ -177,6 +179,30 @@ protected override void Calibrate()
});
}

public override void CyclePort()
{
string enumerator = Details.GetEnumerator();
switch (enumerator)
{
default:
case "BTHENUM":
Task.Run(async () =>
{
// Details.InstallNullDrivers();
// await Task.Delay(1000);
// Details.InstallCustomDriver("hidbth.inf");

Details.Uninstall(false);
await Task.Delay(1000);
Devcon.Refresh();
});
break;
case "USB":
base.CyclePort();
break;
}
}

protected override void ui_button_calibrate_Click(object sender, RoutedEventArgs e)
{
// start calibration
Expand Down
14 changes: 14 additions & 0 deletions HandheldCompanion/Controllers/SteamController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ public virtual void SetVirtualMuted(bool mute)
isVirtualMuted = mute;
}

public override void Hide(bool powerCycle = true)
{
HideHID();

RefreshControls();
}

public override void Unhide(bool powerCycle = true)
{
UnhideHID();

RefreshControls();
}

public override string GetGlyph(ButtonFlags button)
{
switch (button)
Expand Down
76 changes: 64 additions & 12 deletions HandheldCompanion/Controllers/XInputController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using Nefarius.Utilities.DeviceManagement.PnP;
using SharpDX.XInput;
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace HandheldCompanion.Controllers;
Expand All @@ -13,9 +16,6 @@ public class XInputController : IController
private Controller Controller;
private Gamepad Gamepad;

private GamepadButtonFlags prevButtons;
private XInputStateSecret prevState;

private XInputStateSecret State;

public XInputController()
Expand Down Expand Up @@ -75,11 +75,6 @@ public override void UpdateInputs(long ticks)
// update secret state
XInputGetStateSecret14(UserIndex, out State);

/*
if (prevButtons.Equals(Gamepad.Buttons) && State.wButtons.Equals(prevState.wButtons) && prevInjectedButtons.Equals(InjectedButtons))
return;
*/

Inputs.ButtonState = InjectedButtons.Clone() as ButtonState;

Inputs.ButtonState[ButtonFlags.B1] = Gamepad.Buttons.HasFlag(GamepadButtonFlags.A);
Expand Down Expand Up @@ -129,10 +124,6 @@ public override void UpdateInputs(long ticks)

Inputs.AxisState[AxisFlags.L2] = Gamepad.LeftTrigger;
Inputs.AxisState[AxisFlags.R2] = Gamepad.RightTrigger;

// update states
prevButtons = Gamepad.Buttons;
prevState = State;
}
catch { }

Expand Down Expand Up @@ -195,6 +186,67 @@ public static UserIndex TryGetUserIndex(PnPDetails details)
return SharpDX.XInput.UserIndex.Any;
}

public override void Hide(bool powerCycle = true)
{
if (powerCycle)
{
// UI thread (async)
Application.Current.Dispatcher.BeginInvoke(() =>
{
ProgressBarWarning.Text = Properties.Resources.ControllerPage_XInputControllerWarning;
});
}

base.Hide(powerCycle);
}

public override void Unhide(bool powerCycle = true)
{
if (powerCycle)
{
// UI thread (async)
Application.Current.Dispatcher.BeginInvoke(() =>
{
ProgressBarWarning.Text = Properties.Resources.ControllerPage_XInputControllerWarning;
});
}

base.Unhide(powerCycle);
}

public override void CyclePort()
{
string enumerator = Details.GetEnumerator();
switch (enumerator)
{
default:
case "BTHENUM":
Task.Run(async () =>
{
/*
// Bluetooth HID Device
Details.InstallNullDrivers(false);
Details.InstallCustomDriver("hidbth.inf", false);
// Bluetooth XINPUT compatible input device
Details.InstallNullDrivers(true);
Details.InstallCustomDriver("xinputhid.inf", true);
*/

/*
Details.Uninstall(false); // Bluetooth HID Device
Details.Uninstall(true); // Bluetooth XINPUT compatible input device
await Task.Delay(1000);
Devcon.Refresh();
*/
});
break;
case "USB":
base.CyclePort();
break;
}
}

public override string GetGlyph(ButtonFlags button)
{
switch (button)
Expand Down
Loading

0 comments on commit 64f5a0d

Please sign in to comment.