diff --git a/AyaGyroAiming/AyaGyroAiming.csproj b/AyaGyroAiming/AyaGyroAiming.csproj
index 3300a15..b8051a7 100644
--- a/AyaGyroAiming/AyaGyroAiming.csproj
+++ b/AyaGyroAiming/AyaGyroAiming.csproj
@@ -48,7 +48,7 @@
PreserveNewest
-
+
Always
diff --git a/AyaGyroAiming/FlagsHelper.cs b/AyaGyroAiming/FlagsHelper.cs
deleted file mode 100644
index a41da7b..0000000
--- a/AyaGyroAiming/FlagsHelper.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-namespace AyaGyroAiming
-{
- public static class FlagsHelper
- {
- public static bool IsSet(T flags, T flag) where T : struct
- {
- int flagsValue = (int)(object)flags;
- int flagValue = (int)(object)flag;
-
- return (flagsValue & flagValue) != 0;
- }
-
- public static void Set(ref T flags, T flag) where T : struct
- {
- int flagsValue = (int)(object)flags;
- int flagValue = (int)(object)flag;
-
- flags = (T)(object)(flagsValue | flagValue);
- }
-
- public static void Unset(ref T flags, T flag) where T : struct
- {
- int flagsValue = (int)(object)flags;
- int flagValue = (int)(object)flag;
-
- flags = (T)(object)(flagsValue & (~flagValue));
- }
- }
-}
diff --git a/AyaGyroAiming/Program.cs b/AyaGyroAiming/Program.cs
index 5e311a9..d80718f 100644
--- a/AyaGyroAiming/Program.cs
+++ b/AyaGyroAiming/Program.cs
@@ -1,5 +1,6 @@
using Nefarius.ViGEm.Client;
using Nefarius.ViGEm.Client.Targets;
+using Nefarius.ViGEm.Client.Targets.Xbox360;
using System;
using System.Collections.Specialized;
using System.Configuration;
@@ -38,20 +39,20 @@ class Program
static IXbox360Controller VirtualXBOX;
static XInputGirometer Gyrometer;
static XInputAccelerometer Accelerometer;
+ static UdpServer UDPServer;
private delegate bool ConsoleEventDelegate(int eventType);
static ConsoleEventDelegate CurrentHandler;
static int CurrenthWnd;
static bool IsRunning = true;
- static string CurrentPath, CurrentPathIni, CurrentPathCli;
+ static string CurrentPath, CurrentProfilePath, CurrentPathCli;
static PhysicalAddress PadMacAddress = new PhysicalAddress(new byte[] { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 });
// settings vars
static Settings settings = new Settings();
static int UdpPort;
static StringCollection HidHideDevices;
- static bool EnableScreenRatio;
static HidHide hidder;
@@ -67,16 +68,12 @@ static void Main()
// paths
CurrentPath = Directory.GetCurrentDirectory();
- CurrentPathIni = Path.Combine(CurrentPath, "profiles");
+ CurrentProfilePath = Path.Combine(CurrentPath, "profiles");
CurrentPathCli = @"C:\Program Files\Nefarius Software Solutions e.U\HidHideCLI\HidHideCLI.exe";
// settings
UpdateSettings();
- // resolution settings
- Rectangle resolution = Screen.PrimaryScreen.Bounds;
- float ratio = EnableScreenRatio ? ((float)resolution.Width / (float)resolution.Height) : 1.0f;
-
if (!File.Exists(CurrentPathCli))
{
Console.WriteLine("HidHide is missing. Please get it from: https://github.com/ViGEm/HidHide/releases");
@@ -153,7 +150,7 @@ static void Main()
}
// default is 10ms rating and 10 samples
- Gyrometer = new XInputGirometer(settings, ratio);
+ Gyrometer = new XInputGirometer(settings);
if (Gyrometer.sensor == null)
{
Console.WriteLine("No Gyrometer detected. Application will stop.");
@@ -170,15 +167,15 @@ static void Main()
Environment.Exit(0);
}
- // start UDP server (temp)
- UdpServer _udpServer = new UdpServer(PadMacAddress);
- _udpServer.Start(UdpPort);
+ // start UDP server
+ UDPServer = new UdpServer(PadMacAddress);
+ UDPServer.Start(UdpPort);
- if (_udpServer != null)
+ if (UDPServer != null)
{
Console.WriteLine($"UDP server has started. Listening to port: {UdpPort}");
Console.WriteLine();
- PhysicalController.SetUdpServer(_udpServer);
+ PhysicalController.SetUdpServer(UDPServer);
}
VirtualXBOX.Connect();
@@ -195,6 +192,10 @@ static void Main()
// listen to user inputs (a bit too rigid, improve me)
Thread MonitorConsole = new Thread(ConsoleListener);
MonitorConsole.Start();
+
+ // monitor device battery status and notify UDP server
+ Thread MonitorBattery = new Thread(MonitorBatteryLife);
+ MonitorBattery.Start();
}
static string Between(string STR, string FirstString, string LastString)
@@ -206,6 +207,30 @@ static string Between(string STR, string FirstString, string LastString)
return FinalString;
}
+ static void MonitorBatteryLife()
+ {
+ while (IsRunning)
+ {
+ BatteryChargeStatus ChargeStatus = SystemInformation.PowerStatus.BatteryChargeStatus;
+ // float ChargePercent = SystemInformation.PowerStatus.BatteryLifePercent;
+
+ if (ChargeStatus.HasFlag(BatteryChargeStatus.Charging))
+ UDPServer.padMeta.BatteryStatus = DsBattery.Charging;
+ else if (ChargeStatus.HasFlag(BatteryChargeStatus.NoSystemBattery))
+ UDPServer.padMeta.BatteryStatus = DsBattery.None;
+ else if(ChargeStatus.HasFlag(BatteryChargeStatus.High))
+ UDPServer.padMeta.BatteryStatus = DsBattery.High;
+ else if (ChargeStatus.HasFlag(BatteryChargeStatus.Low))
+ UDPServer.padMeta.BatteryStatus = DsBattery.Low;
+ else if (ChargeStatus.HasFlag(BatteryChargeStatus.Critical))
+ UDPServer.padMeta.BatteryStatus = DsBattery.Dying;
+ else
+ UDPServer.padMeta.BatteryStatus = DsBattery.Medium;
+
+ Thread.Sleep(1000);
+ }
+ }
+
static void ConsoleListener()
{
while (IsRunning)
@@ -280,22 +305,35 @@ static void ConsoleListener()
static void UpdateSettings()
{
- settings.EnableGyroAiming = Properties.Settings.Default.EnableGyroAiming;
- settings.GyroPullRate = Properties.Settings.Default.GyroPullRate;
- settings.GyroMaxSample = Properties.Settings.Default.GyroMaxSample;
- settings.GyroStickAggressivity = Properties.Settings.Default.GyroStickAggressivity;
- settings.GyroStickRange = Properties.Settings.Default.GyroStickRange;
- settings.GyroStickInvertAxisX = Properties.Settings.Default.GyroStickInvertAxisX;
- settings.GyroStickInvertAxisY = Properties.Settings.Default.GyroStickInvertAxisY;
- settings.GyroStickInvertAxisZ = Properties.Settings.Default.GyroStickInvertAxisZ;
- settings.TriggerString = Properties.Settings.Default.TriggerString;
+ string filename = $"{CurrentProfilePath}\\default.json";
+ if (File.Exists(filename))
+ {
+ string jsonString = File.ReadAllText(filename);
+ settings = JsonSerializer.Deserialize(jsonString);
+ }
+ else
+ {
+ Console.WriteLine("Missing default.json profile.");
+ settings = new Settings
+ {
+ GyroAiming = true,
+ PullRate = 10,
+ MaxSample = 1,
+ Aggressivity = 0.5f,
+ Range = 10000.0f,
+ InvertAxisX = false,
+ InvertAxisY = false,
+ InvertAxisZ = false,
+ Trigger = "",
+ MonitorRatio = false
+ };
+ }
UdpPort = Properties.Settings.Default.UdpPort; // 26760
HidHideDevices = Properties.Settings.Default.HidHideDevices; // not yet implemented
- EnableScreenRatio = Properties.Settings.Default.EnableScreenRatio;
// update controller settings
- if (PhysicalController != null)
+ if (PhysicalController != null && settings != null)
PhysicalController.UpdateSettings(settings);
}
@@ -316,7 +354,7 @@ static void MonitorProcess()
Process CurrentProcess = Process.GetProcessById((int)processId);
// check if a specific profile exists for the foreground executable
- string filename = $"{CurrentPathIni}\\{CurrentProcess.ProcessName}.json";
+ string filename = $"{CurrentProfilePath}\\{CurrentProcess.ProcessName}.json";
if (File.Exists(filename))
{
string jsonString = File.ReadAllText(filename);
diff --git a/AyaGyroAiming/Properties/Settings.Designer.cs b/AyaGyroAiming/Properties/Settings.Designer.cs
index a52f756..734c8db 100644
--- a/AyaGyroAiming/Properties/Settings.Designer.cs
+++ b/AyaGyroAiming/Properties/Settings.Designer.cs
@@ -1,10 +1,10 @@
//------------------------------------------------------------------------------
//
-// Ce code a été généré par un outil.
-// Version du runtime :4.0.30319.42000
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
//
-// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
-// le code est régénéré.
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
//
//------------------------------------------------------------------------------
@@ -23,102 +23,6 @@ public static Settings Default {
}
}
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("True")]
- public bool EnableGyroAiming {
- get {
- return ((bool)(this["EnableGyroAiming"]));
- }
- set {
- this["EnableGyroAiming"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("1")]
- public uint GyroMaxSample {
- get {
- return ((uint)(this["GyroMaxSample"]));
- }
- set {
- this["GyroMaxSample"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("10000")]
- public float GyroStickRange {
- get {
- return ((float)(this["GyroStickRange"]));
- }
- set {
- this["GyroStickRange"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
- public bool GyroStickInvertAxisX {
- get {
- return ((bool)(this["GyroStickInvertAxisX"]));
- }
- set {
- this["GyroStickInvertAxisX"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
- public bool GyroStickInvertAxisY {
- get {
- return ((bool)(this["GyroStickInvertAxisY"]));
- }
- set {
- this["GyroStickInvertAxisY"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
- public bool GyroStickInvertAxisZ {
- get {
- return ((bool)(this["GyroStickInvertAxisZ"]));
- }
- set {
- this["GyroStickInvertAxisZ"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("10")]
- public uint GyroPullRate {
- get {
- return ((uint)(this["GyroPullRate"]));
- }
- set {
- this["GyroPullRate"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0.5")]
- public float GyroStickAggressivity {
- get {
- return ((float)(this["GyroStickAggressivity"]));
- }
- set {
- this["GyroStickAggressivity"] = value;
- }
- }
-
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("26760")]
@@ -156,29 +60,5 @@ public string HidHideDeviceID {
this["HidHideDeviceID"] = value;
}
}
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("")]
- public string TriggerString {
- get {
- return ((string)(this["TriggerString"]));
- }
- set {
- this["TriggerString"] = value;
- }
- }
-
- [global::System.Configuration.UserScopedSettingAttribute()]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("True")]
- public bool EnableScreenRatio {
- get {
- return ((bool)(this["EnableScreenRatio"]));
- }
- set {
- this["EnableScreenRatio"] = value;
- }
- }
}
}
diff --git a/AyaGyroAiming/Properties/Settings.settings b/AyaGyroAiming/Properties/Settings.settings
index 8f20617..43d3bc4 100644
--- a/AyaGyroAiming/Properties/Settings.settings
+++ b/AyaGyroAiming/Properties/Settings.settings
@@ -2,30 +2,6 @@
-
- True
-
-
- 1
-
-
- 10000
-
-
- False
-
-
- False
-
-
- False
-
-
- 10
-
-
- 0.5
-
26760
@@ -38,11 +14,5 @@
-
-
-
-
- True
-
\ No newline at end of file
diff --git a/AyaGyroAiming/Settings.cs b/AyaGyroAiming/Settings.cs
index eca6cb4..bdc156f 100644
--- a/AyaGyroAiming/Settings.cs
+++ b/AyaGyroAiming/Settings.cs
@@ -1,15 +1,18 @@
-namespace AyaGyroAiming
+using Nefarius.ViGEm.Client.Targets.Xbox360;
+
+namespace AyaGyroAiming
{
public class Settings
{
- public bool EnableGyroAiming { get; set; }
- public float GyroStickAggressivity { get; set; }
- public float GyroStickRange { get; set; }
- public bool GyroStickInvertAxisX { get; set; }
- public bool GyroStickInvertAxisY { get; set; }
- public bool GyroStickInvertAxisZ { get; set; }
- public string TriggerString { get; set; }
- public uint GyroPullRate { get; set; }
- public uint GyroMaxSample { get; set; }
+ public bool GyroAiming { get; set; }
+ public float Aggressivity { get; set; }
+ public float Range { get; set; }
+ public bool InvertAxisX { get; set; }
+ public bool InvertAxisY { get; set; }
+ public bool InvertAxisZ { get; set; }
+ public string Trigger { get; set; }
+ public uint PullRate { get; set; }
+ public uint MaxSample { get; set; }
+ public bool MonitorRatio { get; set; }
}
}
diff --git a/AyaGyroAiming/UdpServer.cs b/AyaGyroAiming/UdpServer.cs
index 9d68734..611acd5 100644
--- a/AyaGyroAiming/UdpServer.cs
+++ b/AyaGyroAiming/UdpServer.cs
@@ -79,6 +79,7 @@ public class UdpServer
private SemaphoreSlim _pool;
private const int ARG_BUFFER_LEN = 80;
+ public DualShockPadMeta padMeta;
private Stopwatch sw;
private PhysicalAddress PadMacAddress;
private int udpPacketCount = 0;
@@ -89,22 +90,24 @@ public class UdpServer
void GetPadDetailForIdx(int padIdx, ref DualShockPadMeta meta)
{
- meta = new DualShockPadMeta()
+ meta = padMeta;
+ }
+
+ public UdpServer(PhysicalAddress _PadMacAddress)
+ {
+ PadMacAddress = _PadMacAddress;
+ portInfoGet = GetPadDetailForIdx;
+
+ padMeta = new DualShockPadMeta()
{
BatteryStatus = DsBattery.Full,
ConnectionType = DsConnection.Bluetooth,
IsActive = true,
- PadId = (byte)0, //_idx
+ PadId = (byte)0,
PadMacAddress = PadMacAddress,
Model = DsModel.DS4,
PadState = DsState.Connected
};
- }
-
- public UdpServer(PhysicalAddress _PadMacAddress)
- {
- PadMacAddress = _PadMacAddress;
- portInfoGet = GetPadDetailForIdx;
sw = new Stopwatch();
sw.Start();
@@ -510,10 +513,7 @@ private bool ReportToBuffer(XInputController hidReport, byte[] outputData, ref i
//motion timestamp
long microseconds = sw.ElapsedTicks / (Stopwatch.Frequency / (1000L * 1000L));
- if (hidReport.gyrometer?.sensor != null)
- Array.Copy(BitConverter.GetBytes((ulong)microseconds), 0, outputData, outIdx, 8);
- else
- Array.Clear(outputData, outIdx, 8);
+ Array.Copy(BitConverter.GetBytes((ulong)microseconds), 0, outputData, outIdx, 8);
outIdx += 8;
@@ -553,7 +553,7 @@ private bool ReportToBuffer(XInputController hidReport, byte[] outputData, ref i
return true;
}
- public void NewReportIncoming(ref DualShockPadMeta padMeta, XInputController hidReport, byte[] outputData)
+ public void NewReportIncoming(XInputController hidReport)
{
if (!running)
return;
@@ -619,7 +619,7 @@ public void NewReportIncoming(ref DualShockPadMeta padMeta, XInputController hid
unchecked
{
- //byte[] outputData = new byte[100];
+ byte[] outputData = new byte[100];
int outIdx = BeginPacket(outputData, 1001);
Array.Copy(BitConverter.GetBytes((uint)MessageType.DSUS_PadDataRsp), 0, outputData, outIdx, 4);
outIdx += 4;
diff --git a/AyaGyroAiming/XInputAccelerometer.cs b/AyaGyroAiming/XInputAccelerometer.cs
index c26ce2e..1defe35 100644
--- a/AyaGyroAiming/XInputAccelerometer.cs
+++ b/AyaGyroAiming/XInputAccelerometer.cs
@@ -22,7 +22,7 @@ public XInputAccelerometer(Settings settings)
sensor = Accelerometer.GetDefault();
if (sensor != null)
{
- sensor.ReportInterval = settings.GyroPullRate < sensor.MinimumReportInterval ? sensor.MinimumReportInterval : settings.GyroPullRate;
+ sensor.ReportInterval = settings.PullRate < sensor.MinimumReportInterval ? sensor.MinimumReportInterval : settings.PullRate;
Console.WriteLine($"Accelerometer initialised.");
Console.WriteLine($"Accelerometer report interval set to {sensor.ReportInterval}ms");
Console.WriteLine();
diff --git a/AyaGyroAiming/XInputController.cs b/AyaGyroAiming/XInputController.cs
index c42dd35..b431fcc 100644
--- a/AyaGyroAiming/XInputController.cs
+++ b/AyaGyroAiming/XInputController.cs
@@ -14,9 +14,8 @@ public class XInputController
private Gamepad gamepad;
private Settings settings;
- private UdpStatus MotionStatus;
+ private UdpServer server;
private IXbox360Controller vcontroller;
- private DualShockPadMeta meta;
public XInputGirometer gyrometer;
public XInputAccelerometer accelerometer;
@@ -25,23 +24,9 @@ public class XInputController
public Vector3 AngularVelocity;
public Vector3 Acceleration;
- [Flags]
- public enum UdpStatus
- {
- None = 0,
- HasGyroscope = 1,
- HasAccelerometer = 2
- }
-
public UserIndex index;
public bool connected = false;
- private byte[][] udpOutBuffers = new byte[UdpServer.NUMBER_SLOTS][]
- {
- new byte[100], new byte[100],
- new byte[100], new byte[100],
- };
-
public XInputController(UserIndex _idx, Settings _settings, PhysicalAddress PadMacAddress)
{
controller = new Controller(_idx);
@@ -49,18 +34,6 @@ public XInputController(UserIndex _idx, Settings _settings, PhysicalAddress PadM
index = _idx;
- // fake data for initialization
- meta = new DualShockPadMeta()
- {
- BatteryStatus = DsBattery.Full,
- ConnectionType = DsConnection.Bluetooth,
- IsActive = true,
- PadId = (byte)0, //_idx
- PadMacAddress = PadMacAddress,
- Model = DsModel.DS4,
- PadState = DsState.Connected
- };
-
connected = controller.IsConnected;
// initialize vectors
@@ -77,7 +50,6 @@ public void SetVirtualController(IXbox360Controller _vcontroller)
vcontroller = _vcontroller;
}
- UdpServer server;
public void SetUdpServer(UdpServer _server)
{
server = _server;
@@ -101,7 +73,6 @@ private void Accelerometer_ReadingChanged(object sender, XInputAccelerometerRead
Acceleration.X = e.AccelerationX;
Acceleration.Y = e.AccelerationY;
Acceleration.Z = e.AccelerationZ;
- FlagsHelper.Set(ref MotionStatus, UdpStatus.HasAccelerometer);
}
private void Girometer_ReadingChanged(object sender, XInputGirometerReadingChangedEventArgs e)
@@ -115,7 +86,6 @@ private void Girometer_ReadingChanged(object sender, XInputGirometerReadingChang
AngularVelocity.X = e.AngularVelocityX;
AngularVelocity.Y = e.AngularVelocityY;
AngularVelocity.Z = e.AngularVelocityZ;
- FlagsHelper.Set(ref MotionStatus, UdpStatus.HasGyroscope);
}
public void UpdateSettings(Settings _settings)
@@ -126,10 +96,10 @@ public void UpdateSettings(Settings _settings)
private bool HasTriggerPressed()
{
- if (settings.TriggerString == null || settings.TriggerString == "")
+ if (settings.Trigger == null || settings.Trigger == "")
return true;
- switch (settings.TriggerString)
+ switch (settings.Trigger)
{
case "LeftTrigger":
return gamepad.LeftTrigger != 0;
@@ -151,15 +121,10 @@ private void Update()
if (vcontroller == null)
continue;
- State state = controller.GetState();
-
- if (server != null && MotionStatus.HasFlag(UdpStatus.HasGyroscope) && MotionStatus.HasFlag(UdpStatus.HasAccelerometer))
- {
- server.NewReportIncoming(ref meta, this, udpOutBuffers[0]);
- FlagsHelper.Unset(ref MotionStatus, UdpStatus.HasAccelerometer);
- FlagsHelper.Unset(ref MotionStatus, UdpStatus.HasGyroscope);
- }
+ if (server != null)
+ server.NewReportIncoming(this);
+ State state = controller.GetState();
if (previousState.PacketNumber != state.PacketNumber)
{
gamepad = controller.GetState().Gamepad;
@@ -191,13 +156,13 @@ private void Update()
}
bool HasTrigger = HasTriggerPressed();
- short ThumbX = (short)Math.Max(-32767, Math.Min(32767, gamepad.RightThumbX + (settings.EnableGyroAiming && HasTrigger ? AngularStick.X : 0)));
- short ThumbY = (short)Math.Max(-32767, Math.Min(32767, gamepad.RightThumbY + (settings.EnableGyroAiming && HasTrigger ? AngularStick.Y : 0)));
+ short ThumbX = (short)Math.Max(-32767, Math.Min(32767, gamepad.RightThumbX + (settings.GyroAiming && HasTrigger ? AngularStick.X : 0)));
+ short ThumbY = (short)Math.Max(-32767, Math.Min(32767, gamepad.RightThumbY + (settings.GyroAiming && HasTrigger ? AngularStick.Y : 0)));
vcontroller.SetAxisValue(Xbox360Axis.RightThumbX, ThumbX);
vcontroller.SetAxisValue(Xbox360Axis.RightThumbY, ThumbY);
- Thread.Sleep((int)settings.GyroPullRate);
+ Thread.Sleep((int)settings.PullRate);
previousState = state;
}
}
diff --git a/AyaGyroAiming/XInputGirometer.cs b/AyaGyroAiming/XInputGirometer.cs
index 00a7db1..1a90810 100644
--- a/AyaGyroAiming/XInputGirometer.cs
+++ b/AyaGyroAiming/XInputGirometer.cs
@@ -1,7 +1,9 @@
using SharpDX.XInput;
using System;
+using System.Drawing;
using System.Linq;
using System.Numerics;
+using System.Windows.Forms;
using Windows.Devices.Sensors;
namespace AyaGyroAiming
@@ -38,18 +40,13 @@ public class XInputGirometer
public event XInputGirometerReadingChangedEventHandler ReadingChanged;
public delegate void XInputGirometerReadingChangedEventHandler(Object sender, XInputGirometerReadingChangedEventArgs e);
- public XInputGirometer(Settings _settings, float _ratio)
+ public XInputGirometer(Settings _settings)
{
sensor = Gyrometer.GetDefault();
if (sensor != null)
{
- settings = _settings;
- GyroStickRatio = _ratio;
+ UpdateSettings(_settings);
- poolsize = settings.GyroMaxSample;
- gyroPool = new Vector3[poolsize];
-
- sensor.ReportInterval = settings.GyroPullRate < sensor.MinimumReportInterval ? sensor.MinimumReportInterval : settings.GyroPullRate;
Console.WriteLine($"Gyrometer initialised.");
Console.WriteLine($"Gyrometer report interval set to {sensor.ReportInterval}ms");
Console.WriteLine($"Gyrometer sample pool size set to: {poolsize}");
@@ -62,6 +59,15 @@ public XInputGirometer(Settings _settings, float _ratio)
public void UpdateSettings(Settings _settings)
{
settings = _settings;
+
+ // resolution settings
+ Rectangle resolution = Screen.PrimaryScreen.Bounds;
+ GyroStickRatio = settings.MonitorRatio ? ((float)resolution.Width / (float)resolution.Height) : 1.0f;
+
+ poolsize = settings.MaxSample;
+ gyroPool = new Vector3[poolsize];
+
+ sensor.ReportInterval = settings.PullRate < sensor.MinimumReportInterval ? sensor.MinimumReportInterval : settings.PullRate;
}
static Vector3 SmoothReading(Vector3 input, float GyroStickAlpha)
@@ -115,17 +121,17 @@ void GyroReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args)
// scale value
Vector3 posAverage = new Vector3()
{
- X = (float)(settings.GyroStickInvertAxisX ? 1.0f : -1.0f) * (float)gyroPool.Select(a => a.X).Average(),
- Y = (float)(settings.GyroStickInvertAxisY ? 1.0f : -1.0f) * (float)gyroPool.Select(a => a.Y).Average(),
- Z = (float)(settings.GyroStickInvertAxisZ ? 1.0f : -1.0f) * (float)gyroPool.Select(a => a.Z).Average(),
+ X = (float)(settings.InvertAxisX ? 1.0f : -1.0f) * (float)gyroPool.Select(a => a.X).Average(),
+ Y = (float)(settings.InvertAxisY ? 1.0f : -1.0f) * (float)gyroPool.Select(a => a.Y).Average(),
+ Z = (float)(settings.InvertAxisZ ? 1.0f : -1.0f) * (float)gyroPool.Select(a => a.Z).Average(),
};
- posAverage *= settings.GyroStickRange;
+ posAverage *= settings.Range;
posAverage.X *= GyroStickRatio; // take screen ratio in consideration 1.7f (16:9)
- posAverage.X = (float)(Math.Sign(posAverage.X) * Math.Pow(Math.Abs(posAverage.X) / Gamepad.RightThumbDeadZone, settings.GyroStickAggressivity) * Gamepad.RightThumbDeadZone);
- posAverage.Y = (float)(Math.Sign(posAverage.Y) * Math.Pow(Math.Abs(posAverage.Y) / Gamepad.RightThumbDeadZone, settings.GyroStickAggressivity) * Gamepad.RightThumbDeadZone);
- posAverage.Z = (float)(Math.Sign(posAverage.Z) * Math.Pow(Math.Abs(posAverage.Z) / Gamepad.RightThumbDeadZone, settings.GyroStickAggressivity) * Gamepad.RightThumbDeadZone);
+ posAverage.X = (float)(Math.Sign(posAverage.X) * Math.Pow(Math.Abs(posAverage.X) / Gamepad.RightThumbDeadZone, settings.Aggressivity) * Gamepad.RightThumbDeadZone);
+ posAverage.Y = (float)(Math.Sign(posAverage.Y) * Math.Pow(Math.Abs(posAverage.Y) / Gamepad.RightThumbDeadZone, settings.Aggressivity) * Gamepad.RightThumbDeadZone);
+ posAverage.Z = (float)(Math.Sign(posAverage.Z) * Math.Pow(Math.Abs(posAverage.Z) / Gamepad.RightThumbDeadZone, settings.Aggressivity) * Gamepad.RightThumbDeadZone);
// raise event
XInputGirometerReadingChangedEventArgs newargs = new XInputGirometerReadingChangedEventArgs()
diff --git a/AyaGyroAiming/profiles/Kena-Win64-Shipping.json b/AyaGyroAiming/profiles/Kena-Win64-Shipping.json
index 01fcac0..1761ae7 100644
--- a/AyaGyroAiming/profiles/Kena-Win64-Shipping.json
+++ b/AyaGyroAiming/profiles/Kena-Win64-Shipping.json
@@ -1,11 +1,12 @@
{
- "GyroMaxSample" : 1,
- "GyroPullRate" : 10,
- "EnableGyroAiming" : true,
- "GyroStickAggressivity" : 0.5,
- "GyroStickRange" : 15000,
- "GyroStickInvertAxisX" : false,
- "GyroStickInvertAxisY" : false,
- "GyroStickInvertAxisZ" : false,
- "TriggerString" : "LeftTrigger"
+ "GyroAiming": true,
+ "Aggressivity": 0.5,
+ "Range": 15000,
+ "InvertAxisX": false,
+ "InvertAxisY": false,
+ "InvertAxisZ": false,
+ "Trigger": "",
+ "PullRate": 10,
+ "MaxSample": 1,
+ "MonitorRatio": false
}
\ No newline at end of file
diff --git a/AyaGyroAiming/profiles/cemu.json b/AyaGyroAiming/profiles/cemu.json
index 2cc6df4..9d96ea9 100644
--- a/AyaGyroAiming/profiles/cemu.json
+++ b/AyaGyroAiming/profiles/cemu.json
@@ -1,11 +1,12 @@
{
- "GyroMaxSample" : 1,
- "GyroPullRate" : 10,
- "EnableGyroAiming" : false,
- "GyroStickAggressivity" : 0.5,
- "GyroStickRange" : 8689,
- "GyroStickInvertAxisX" : false,
- "GyroStickInvertAxisY" : false,
- "GyroStickInvertAxisZ" : false,
- "TriggerString" : ""
+ "GyroAiming": false,
+ "Aggressivity": 0.5,
+ "Range": 10000,
+ "InvertAxisX": false,
+ "InvertAxisY": false,
+ "InvertAxisZ": false,
+ "Trigger": "",
+ "PullRate": 10,
+ "MaxSample": 1,
+ "MonitorRatio": false
}
\ No newline at end of file
diff --git a/AyaGyroAiming/profiles/default.json b/AyaGyroAiming/profiles/default.json
new file mode 100644
index 0000000..2781d80
--- /dev/null
+++ b/AyaGyroAiming/profiles/default.json
@@ -0,0 +1,12 @@
+{
+ "GyroAiming": true,
+ "Aggressivity": 0.5,
+ "Range": 10000,
+ "InvertAxisX": false,
+ "InvertAxisY": false,
+ "InvertAxisZ": false,
+ "Trigger": "",
+ "PullRate": 10,
+ "MaxSample": 1,
+ "MonitorRatio": false
+}
\ No newline at end of file
diff --git a/AyaGyroAiming/profiles/example.json b/AyaGyroAiming/profiles/example.json
deleted file mode 100644
index 3c3261a..0000000
--- a/AyaGyroAiming/profiles/example.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "GyroMaxSample" : 1,
- "GyroPullRate" : 10,
- "EnableGyroAiming" : true,
- "GyroStickAggressivity" : 0.5,
- "GyroStickRange" : 8689,
- "GyroStickInvertAxisX" : false,
- "GyroStickInvertAxisY" : false,
- "GyroStickInvertAxisZ" : false,
- "TriggerString" : "LeftTrigger"
-}
\ No newline at end of file
diff --git a/AyaGyroAiming/profiles/ryujinx.json b/AyaGyroAiming/profiles/ryujinx.json
index 2cc6df4..9d96ea9 100644
--- a/AyaGyroAiming/profiles/ryujinx.json
+++ b/AyaGyroAiming/profiles/ryujinx.json
@@ -1,11 +1,12 @@
{
- "GyroMaxSample" : 1,
- "GyroPullRate" : 10,
- "EnableGyroAiming" : false,
- "GyroStickAggressivity" : 0.5,
- "GyroStickRange" : 8689,
- "GyroStickInvertAxisX" : false,
- "GyroStickInvertAxisY" : false,
- "GyroStickInvertAxisZ" : false,
- "TriggerString" : ""
+ "GyroAiming": false,
+ "Aggressivity": 0.5,
+ "Range": 10000,
+ "InvertAxisX": false,
+ "InvertAxisY": false,
+ "InvertAxisZ": false,
+ "Trigger": "",
+ "PullRate": 10,
+ "MaxSample": 1,
+ "MonitorRatio": false
}
\ No newline at end of file
diff --git a/AyaGyroAiming/profiles/yuzu.json b/AyaGyroAiming/profiles/yuzu.json
index 2cc6df4..9d96ea9 100644
--- a/AyaGyroAiming/profiles/yuzu.json
+++ b/AyaGyroAiming/profiles/yuzu.json
@@ -1,11 +1,12 @@
{
- "GyroMaxSample" : 1,
- "GyroPullRate" : 10,
- "EnableGyroAiming" : false,
- "GyroStickAggressivity" : 0.5,
- "GyroStickRange" : 8689,
- "GyroStickInvertAxisX" : false,
- "GyroStickInvertAxisY" : false,
- "GyroStickInvertAxisZ" : false,
- "TriggerString" : ""
+ "GyroAiming": false,
+ "Aggressivity": 0.5,
+ "Range": 10000,
+ "InvertAxisX": false,
+ "InvertAxisY": false,
+ "InvertAxisZ": false,
+ "Trigger": "",
+ "PullRate": 10,
+ "MaxSample": 1,
+ "MonitorRatio": false
}
\ No newline at end of file