- Fixed USB high CPU usage (d'oh!)
- Another attempt at fixing USB lag - Moved to WindowsInput for mouse movement - Linked "Capture" button to Print Screen
This commit is contained in:
parent
5e11617fa9
commit
45baa6360f
5 changed files with 32 additions and 19 deletions
BIN
BetterJoyForCemu/.nuget/mouse-keyboard-hook-logo.png
Normal file
BIN
BetterJoyForCemu/.nuget/mouse-keyboard-hook-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -143,6 +143,9 @@
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Net.Http" />
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="WindowsInput, Version=6.1.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\WindowsInput.6.1.1\lib\net461\WindowsInput.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="3rdPartyControllers.cs">
|
<Compile Include="3rdPartyControllers.cs">
|
||||||
|
@ -170,10 +173,13 @@
|
||||||
<Compile Include="UpdServer.cs" />
|
<Compile Include="UpdServer.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</None>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Content Include=".nuget\mouse-keyboard-hook-logo.png" />
|
||||||
<Content Include="Icons\snes.png" />
|
<Content Include="Icons\snes.png" />
|
||||||
<None Include="Properties\app.manifest" />
|
<None Include="Properties\app.manifest" />
|
||||||
<Content Include="Icons\betterjoyforcemu_icon.ico" />
|
<Content Include="Icons\betterjoyforcemu_icon.ico" />
|
||||||
|
|
|
@ -13,6 +13,7 @@ using Nefarius.ViGEm.Client.Targets;
|
||||||
using Nefarius.ViGEm.Client.Targets.Xbox360;
|
using Nefarius.ViGEm.Client.Targets.Xbox360;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using WindowsInput;
|
||||||
|
|
||||||
namespace BetterJoyForCemu {
|
namespace BetterJoyForCemu {
|
||||||
// For mouse movement
|
// For mouse movement
|
||||||
|
@ -364,7 +365,7 @@ namespace BetterJoyForCemu {
|
||||||
HIDapi.hid_write(handle, a, new UIntPtr(2));
|
HIDapi.hid_write(handle, a, new UIntPtr(2));
|
||||||
|
|
||||||
a[0] = 0x80; a[1] = 0x4; // Prevent HID timeout
|
a[0] = 0x80; a[1] = 0x4; // Prevent HID timeout
|
||||||
HIDapi.hid_write(handle, a, new UIntPtr(2));
|
HIDapi.hid_write(handle, a, new UIntPtr(2)); // doesn't actually prevent timout...
|
||||||
|
|
||||||
dump_calibration_data();
|
dump_calibration_data();
|
||||||
}
|
}
|
||||||
|
@ -383,6 +384,10 @@ namespace BetterJoyForCemu {
|
||||||
|
|
||||||
HIDapi.hid_set_nonblocking(handle, 1);
|
HIDapi.hid_set_nonblocking(handle, 1);
|
||||||
|
|
||||||
|
// send ping to USB to not time out instantly
|
||||||
|
if (isUSB)
|
||||||
|
SendRumble(rumble_obj.GetData());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,23 +504,24 @@ namespace BetterJoyForCemu {
|
||||||
xin.SendReport(report);
|
xin.SendReport(report);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Link capture button to print screen
|
||||||
|
if (buttons[(int)Button.CAPTURE])
|
||||||
|
WindowsInput.Simulate.Events().Click(WindowsInput.Events.KeyCode.PrintScreen).Invoke();
|
||||||
|
|
||||||
if (extraGyroFeature == "joy") {
|
if (extraGyroFeature == "joy") {
|
||||||
// TODO
|
// TODO
|
||||||
} else if (extraGyroFeature == "mouse" && (isPro || (other == null) || (other != null && (Boolean.Parse(ConfigurationManager.AppSettings["GyroMouseLeftHanded"]) ? isLeft : !isLeft)))) {
|
} else if (extraGyroFeature == "mouse" && (isPro || (other == null) || (other != null && (Boolean.Parse(ConfigurationManager.AppSettings["GyroMouseLeftHanded"]) ? isLeft : !isLeft)))) {
|
||||||
Win32.POINT p;
|
|
||||||
Win32.GetCursorPos(out p);
|
|
||||||
|
|
||||||
float dt = 0.015f; // 15ms
|
float dt = 0.015f; // 15ms
|
||||||
|
|
||||||
// gyro data is in degrees/s
|
// gyro data is in degrees/s
|
||||||
int dx = (int)(GyroMouseSensitivity * (gyr_g.Z * dt) * (Math.Abs(gyr_g.Z) < 1 ? 0 : 1));
|
int dx = (int)(GyroMouseSensitivity * (gyr_g.Z * dt) * (Math.Abs(gyr_g.Z) < 1 ? 0 : 1));
|
||||||
int dy = (int)-(GyroMouseSensitivity * (gyr_g.Y * dt) * (Math.Abs(gyr_g.Y) < 1 ? 0 : 1));
|
int dy = (int)-(GyroMouseSensitivity * (gyr_g.Y * dt) * (Math.Abs(gyr_g.Y) < 1 ? 0 : 1));
|
||||||
|
|
||||||
Win32.SetCursorPos(p.x + dx, p.y + dy);
|
WindowsInput.Simulate.Events().MoveBy(dx, dy).Invoke();
|
||||||
|
|
||||||
// reset mouse position to centre of primary monitor
|
// reset mouse position to centre of primary monitor
|
||||||
if (buttons[(int) Button.STICK] || buttons[(int) Button.STICK2])
|
if (buttons[(int)Button.STICK] || buttons[(int)Button.STICK2])
|
||||||
Win32.SetCursorPos(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2);
|
WindowsInput.Simulate.Events().MoveTo(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2).Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ts_en == raw_buf[1] && !isSnes) {
|
if (ts_en == raw_buf[1] && !isSnes) {
|
||||||
|
@ -535,21 +541,18 @@ namespace BetterJoyForCemu {
|
||||||
Stopwatch watch = new Stopwatch();
|
Stopwatch watch = new Stopwatch();
|
||||||
watch.Start();
|
watch.Start();
|
||||||
while (!stop_polling & state > state_.NO_JOYCONS) {
|
while (!stop_polling & state > state_.NO_JOYCONS) {
|
||||||
if (!isSnes && (isUSB || rumble_obj.t > 0))
|
if (!isSnes && (rumble_obj.t > 0))
|
||||||
SendRumble(rumble_obj.GetData());
|
SendRumble(rumble_obj.GetData());
|
||||||
else if (watch.ElapsedMilliseconds >= 1000) {
|
|
||||||
// Send a no-op operation as heartbeat to keep connection alive.
|
|
||||||
// Do not send this too frequently, otherwise I/O would be too heavy and cause lag.
|
|
||||||
// Needed for both BLUETOOTH and USB to not time out. Never remove pls
|
|
||||||
//SendRumble(rumble_obj.GetData());
|
|
||||||
// TODO: Investigate if this really is safe to remove now?
|
|
||||||
watch.Restart();
|
|
||||||
}
|
|
||||||
int a = ReceiveRaw();
|
int a = ReceiveRaw();
|
||||||
|
|
||||||
if (a > 0) {
|
if (a > 0) {
|
||||||
state = state_.IMU_DATA_OK;
|
state = state_.IMU_DATA_OK;
|
||||||
attempts = 0;
|
attempts = 0;
|
||||||
|
|
||||||
|
// Needed for USB to not time out; I think USB requires a reply message after every packet sent
|
||||||
|
if (isUSB)
|
||||||
|
SendRumble(rumble_obj.GetData());
|
||||||
} else if (attempts > 240) {
|
} else if (attempts > 240) {
|
||||||
state = state_.DROPPED;
|
state = state_.DROPPED;
|
||||||
form.AppendTextBox("Dropped.\r\n");
|
form.AppendTextBox("Dropped.\r\n");
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace BetterJoyForCemu {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start() {
|
public void Start() {
|
||||||
controllerCheck = new System.Timers.Timer(5000); // check for new controllers every 5 seconds
|
controllerCheck = new System.Timers.Timer(2000); // check for new controllers every 2 seconds
|
||||||
controllerCheck.Elapsed += CheckForNewControllersTime;
|
controllerCheck.Elapsed += CheckForNewControllersTime;
|
||||||
controllerCheck.Start();
|
controllerCheck.Start();
|
||||||
}
|
}
|
||||||
|
@ -113,8 +113,11 @@ namespace BetterJoyForCemu {
|
||||||
while (ptr != IntPtr.Zero) {
|
while (ptr != IntPtr.Zero) {
|
||||||
enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info));
|
enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info));
|
||||||
|
|
||||||
if (enumerate.serial_number == null)
|
if (enumerate.serial_number == null) {
|
||||||
|
ptr = enumerate.next; // can't believe it took me this long to figure out why USB connections used up so much CPU.
|
||||||
|
// it was getting stuck in an inf loop here!
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (form.nonOriginal) {
|
if (form.nonOriginal) {
|
||||||
enumerate.product_id = product_pro;
|
enumerate.product_id = product_pro;
|
||||||
|
|
|
@ -5,4 +5,5 @@
|
||||||
<package id="Fielder.Fody" version="1.2.3" targetFramework="net461" />
|
<package id="Fielder.Fody" version="1.2.3" targetFramework="net461" />
|
||||||
<package id="Fody" version="4.2.1" targetFramework="net461" developmentDependency="true" />
|
<package id="Fody" version="4.2.1" targetFramework="net461" developmentDependency="true" />
|
||||||
<package id="Nefarius.ViGEmClient" version="1.15.16" targetFramework="net461" />
|
<package id="Nefarius.ViGEmClient" version="1.15.16" targetFramework="net461" />
|
||||||
|
<package id="WindowsInput" version="6.1.1" targetFramework="net461" />
|
||||||
</packages>
|
</packages>
|
Loading…
Add table
Reference in a new issue