Skip to content

Instantly share code, notes, and snippets.

@Ryochan7
Last active February 25, 2022 07:36
Show Gist options
  • Save Ryochan7/b3108cd2e4f86df7c5b9fbeb8471cb35 to your computer and use it in GitHub Desktop.
Save Ryochan7/b3108cd2e4f86df7c5b9fbeb8471cb35 to your computer and use it in GitHub Desktop.
JoyCon changes
diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs
index 49f61696..c1cd694c 100644
--- a/DS4Windows/DS4Control/ControlService.cs
+++ b/DS4Windows/DS4Control/ControlService.cs
@@ -2250,6 +2250,33 @@ namespace DS4Windows
if (!device.PrimaryDevice)
{
+ if (device.OutputMapGyro)
+ {
+ GyroOutMode imuOutMode = Global.GetGyroOutMode(device.JointDeviceSlotNumber);
+ if (imuOutMode != GyroOutMode.None)
+ {
+ if (imuOutMode == GyroOutMode.Mouse)
+ {
+ outputKBMHandler.Sync();
+ }
+ else if (imuOutMode == GyroOutMode.MouseJoystick)
+ {
+ // Add new Mapping method and add data to
+ // parent device state
+ int jointInd = device.JointDeviceSlotNumber;
+ if (jointInd >= 0)
+ {
+ DS4State tempMapState = MappedState[jointInd];
+ Mapping.TempMouseJoystick(jointInd, tempMapState);
+ if (!useDInputOnly[jointInd])
+ {
+ outputDevices[jointInd]?.ConvertandSendReport(tempMapState, jointInd);
+ }
+ }
+ }
+ }
+ }
+
// Skip mapping routine if part of a joined device
return;
}
diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs
index 30b7d005..bccd3d43 100644
--- a/DS4Windows/DS4Control/Mapping.cs
+++ b/DS4Windows/DS4Control/Mapping.cs
@@ -2504,6 +2504,74 @@ namespace DS4Windows
}
}
+ public static void TempMouseJoystick(int device, DS4State MappedState)
+ {
+ GyroOutMode imuOutMode = Global.GetGyroOutMode(device);
+ if (imuOutMode == GyroOutMode.MouseJoystick)
+ {
+ GyroMouseStickInfo msinfo = Global.GetGyroMouseStickInfo(device);
+ if (msinfo.outputStick != GyroMouseStickInfo.OutputStick.None)
+ {
+ ref byte gyroTempX = ref gyroStickX[device];
+ if (msinfo.OutputHorizontal() && gyroTempX != 128)
+ {
+ byte outputStickXVal = msinfo.outputStick == GyroMouseStickInfo.OutputStick.RightStick ?
+ MappedState.RX : MappedState.LX;
+ byte tempAxisVal = 128;
+
+ if (outputStickXVal != 128)
+ {
+ tempAxisVal = Math.Abs(gyroTempX - 128) > Math.Abs(outputStickXVal - 128) ?
+ gyroTempX : outputStickXVal;
+ }
+ else
+ {
+ tempAxisVal = gyroTempX;
+ }
+
+ if (msinfo.outputStick ==
+ GyroMouseStickInfo.OutputStick.RightStick)
+ {
+ MappedState.RX = tempAxisVal;
+ }
+ else if (msinfo.outputStick ==
+ GyroMouseStickInfo.OutputStick.LeftStick)
+ {
+ MappedState.LX = tempAxisVal;
+ }
+ }
+
+ ref byte gyroTempY = ref gyroStickY[device];
+ if (msinfo.OutputVertical() && gyroTempY != 128)
+ {
+ byte outputStickYVal = msinfo.outputStick == GyroMouseStickInfo.OutputStick.RightStick ?
+ MappedState.RY : MappedState.LY;
+ byte tempAxisVal = 128;
+
+ if (outputStickYVal != 128)
+ tempAxisVal = Math.Abs(gyroTempY - 128) > Math.Abs(outputStickYVal - 128) ?
+ gyroTempY : outputStickYVal;
+ else
+ tempAxisVal = gyroTempY;
+
+ if (msinfo.outputStick ==
+ GyroMouseStickInfo.OutputStick.RightStick)
+ {
+ MappedState.RY = tempAxisVal;
+ }
+ else if (msinfo.outputStick ==
+ GyroMouseStickInfo.OutputStick.LeftStick)
+ {
+ MappedState.LY = tempAxisVal;
+ }
+ }
+
+ // Don't reset Mouse Joystick output coords here
+ //gyroTempX = gyroTempY = 128;
+ }
+ }
+ }
+
private static void ProcessTwoStageTrigger(int device, DS4State cState, byte triggerValue,
ref DS4ControlSettings inputSoftPull, ref DS4ControlSettings inputFullPull, TriggerOutputSettings outputSettings,
TwoStageTriggerMappingData twoStageData, out DS4ControlSettings outputSoftPull, out DS4ControlSettings outputFullPull)
diff --git a/DS4Windows/DS4Control/Mouse.cs b/DS4Windows/DS4Control/Mouse.cs
index 3dd1562c..b1249b1f 100644
--- a/DS4Windows/DS4Control/Mouse.cs
+++ b/DS4Windows/DS4Control/Mouse.cs
@@ -494,8 +494,8 @@ namespace DS4Windows
{
double maxOutRatio = msinfo.maxOutput / 100.0;
// Expand output a bit. Likely not going to get a straight line with Gyro
- double maxOutXRatio = Math.Min(normX / 0.99, 1.0) * maxOutRatio;
- double maxOutYRatio = Math.Min(normY / 0.99, 1.0) * maxOutRatio;
+ double maxOutXRatio = Math.Min(normX / 0.95, 1.0) * maxOutRatio;
+ double maxOutYRatio = Math.Min(normY / 0.95, 1.0) * maxOutRatio;
xratio = Math.Min(Math.Max(xratio, 0.0), maxOutXRatio);
yratio = Math.Min(Math.Max(yratio, 0.0), maxOutYRatio);
diff --git a/DS4Windows/DS4Library/InputDevices/JoyConDevice.cs b/DS4Windows/DS4Library/InputDevices/JoyConDevice.cs
index 40479877..ea4ba9d7 100644
--- a/DS4Windows/DS4Library/InputDevices/JoyConDevice.cs
+++ b/DS4Windows/DS4Library/InputDevices/JoyConDevice.cs
@@ -454,15 +454,17 @@ namespace DS4Windows.InputDevices
testelapsed = curtime - oldtime;
lastTimeElapsedDouble = testelapsed * (1.0 / Stopwatch.Frequency) * 1000.0;
lastTimeElapsed = (long)lastTimeElapsedDouble;
- oldtime = curtime;
elapsedDeltaTime = lastTimeElapsedDouble * .001;
- combLatency += elapsedDeltaTime;
+ //combLatency += elapsedDeltaTime;
+ combLatency = elapsedDeltaTime;
if (elapsedDeltaTime <= 0.005)
{
continue;
}
+ oldtime = curtime;
+
if (tempLatencyCount >= 20)
{
latencySum -= latencyQueue.Dequeue();
@@ -482,8 +484,8 @@ namespace DS4Windows.InputDevices
cState.FrameCounter = (byte)(cState.PacketCounter % 128);
cState.ReportTimeStamp = utcNow;
- cState.elapsedTime = combLatency;
- cState.totalMicroSec = pState.totalMicroSec + (uint)(combLatency * 1000000);
+ cState.elapsedTime = elapsedDeltaTime;
+ cState.totalMicroSec = pState.totalMicroSec + (uint)(elapsedDeltaTime * 1000000);
combLatency = 0.0;
if ((this.featureSet & VidPidFeatureSet.NoBatteryReading) == 0)
@@ -773,7 +775,8 @@ namespace DS4Windows.InputDevices
Subcommand(0x40, imuEnable, 1, checkResponse: true);
// Enable High Performance Gyro mode
- byte[] gyroModeBuffer = new byte[] { 0x03, 0x00, 0x00, 0x01 };
+ //byte[] gyroModeBuffer = new byte[] { 0x03, 0x00, 0x00, 0x01 };
+ byte[] gyroModeBuffer = new byte[] { 0x03, 0x00, 0x00, 0x00 };
//Thread.Sleep(1000);
Subcommand(0x41, gyroModeBuffer, 4, checkResponse: true);
@@ -787,9 +790,12 @@ namespace DS4Windows.InputDevices
if (sideType == JoyConSide.Right)
{
// Suspend NFC/IR MCU state. Don't know if it will matter
- Console.WriteLine("RESET NFC/IR MCU");
- byte[] shitBuffer = new byte[] { 0x01 };
- Subcommand(0x20, shitBuffer, 0, checkResponse: true);
+ //Console.WriteLine("RESET NFC/IR MCU");
+ //byte[] shitBuffer = new byte[] { 0x01 };
+ //Subcommand(0x20, shitBuffer, 0, checkResponse: true);
+
+ byte[] shitBuffer = new byte[] { 0x00 };
+ Subcommand(0x22, shitBuffer, 0, checkResponse: true);
Thread.Sleep(1000);
}
diff --git a/DS4Windows/DS4Library/InputDevices/SwitchProDevice.cs b/DS4Windows/DS4Library/InputDevices/SwitchProDevice.cs
index a1e885f2..369aea49 100644
--- a/DS4Windows/DS4Library/InputDevices/SwitchProDevice.cs
+++ b/DS4Windows/DS4Library/InputDevices/SwitchProDevice.cs
@@ -410,15 +410,17 @@ namespace DS4Windows.InputDevices
testelapsed = curtime - oldtime;
lastTimeElapsedDouble = testelapsed * (1.0 / Stopwatch.Frequency) * 1000.0;
lastTimeElapsed = (long)lastTimeElapsedDouble;
- oldtime = curtime;
elapsedDeltaTime = lastTimeElapsedDouble * .001;
- combLatency += elapsedDeltaTime;
+ //combLatency += elapsedDeltaTime;
+ combLatency = elapsedDeltaTime;
if (elapsedDeltaTime <= 0.005)
{
continue;
}
+ oldtime = curtime;
+
if (tempLatencyCount >= 20)
{
latencySum -= latencyQueue.Dequeue();
@@ -438,8 +440,8 @@ namespace DS4Windows.InputDevices
cState.FrameCounter = (byte)(cState.PacketCounter % 128);
cState.ReportTimeStamp = utcNow;
- cState.elapsedTime = combLatency;
- cState.totalMicroSec = pState.totalMicroSec + (uint)(combLatency * 1000000);
+ cState.elapsedTime = elapsedDeltaTime;
+ cState.totalMicroSec = pState.totalMicroSec + (uint)(elapsedDeltaTime * 1000000);
combLatency = 0.0;
if ((this.featureSet & VidPidFeatureSet.NoBatteryReading) == 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment