Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 8b7219e

Browse files
committed
- no-longer relying on application settings to define default behaviors. Using profiles\default.json instead.
- renamed all profile variables. - moved MonitorRatio to profile variables. - moved padMeta to UDP server. - reports sent to UDP server are no longer paused when no new inputs from gyroscope or accelerometer has been received. - UDP server now receive and send AYA battery status.
1 parent 2cc6f76 commit 8b7219e

16 files changed

+177
-339
lines changed

AyaGyroAiming/AyaGyroAiming.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<None Update="profiles\cemu.json">
4949
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5050
</None>
51-
<None Update="profiles\example.json">
51+
<None Update="profiles\default.json">
5252
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
5353
</None>
5454
<None Update="profiles\Kena-Win64-Shipping.json">

AyaGyroAiming/FlagsHelper.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

AyaGyroAiming/Program.cs

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Nefarius.ViGEm.Client;
22
using Nefarius.ViGEm.Client.Targets;
3+
using Nefarius.ViGEm.Client.Targets.Xbox360;
34
using System;
45
using System.Collections.Specialized;
56
using System.Configuration;
@@ -38,20 +39,20 @@ class Program
3839
static IXbox360Controller VirtualXBOX;
3940
static XInputGirometer Gyrometer;
4041
static XInputAccelerometer Accelerometer;
42+
static UdpServer UDPServer;
4143

4244
private delegate bool ConsoleEventDelegate(int eventType);
4345
static ConsoleEventDelegate CurrentHandler;
4446
static int CurrenthWnd;
4547

4648
static bool IsRunning = true;
47-
static string CurrentPath, CurrentPathIni, CurrentPathCli;
49+
static string CurrentPath, CurrentProfilePath, CurrentPathCli;
4850
static PhysicalAddress PadMacAddress = new PhysicalAddress(new byte[] { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 });
4951

5052
// settings vars
5153
static Settings settings = new Settings();
5254
static int UdpPort;
5355
static StringCollection HidHideDevices;
54-
static bool EnableScreenRatio;
5556

5657
static HidHide hidder;
5758

@@ -67,16 +68,12 @@ static void Main()
6768

6869
// paths
6970
CurrentPath = Directory.GetCurrentDirectory();
70-
CurrentPathIni = Path.Combine(CurrentPath, "profiles");
71+
CurrentProfilePath = Path.Combine(CurrentPath, "profiles");
7172
CurrentPathCli = @"C:\Program Files\Nefarius Software Solutions e.U\HidHideCLI\HidHideCLI.exe";
7273

7374
// settings
7475
UpdateSettings();
7576

76-
// resolution settings
77-
Rectangle resolution = Screen.PrimaryScreen.Bounds;
78-
float ratio = EnableScreenRatio ? ((float)resolution.Width / (float)resolution.Height) : 1.0f;
79-
8077
if (!File.Exists(CurrentPathCli))
8178
{
8279
Console.WriteLine("HidHide is missing. Please get it from: https://github.com/ViGEm/HidHide/releases");
@@ -153,7 +150,7 @@ static void Main()
153150
}
154151

155152
// default is 10ms rating and 10 samples
156-
Gyrometer = new XInputGirometer(settings, ratio);
153+
Gyrometer = new XInputGirometer(settings);
157154
if (Gyrometer.sensor == null)
158155
{
159156
Console.WriteLine("No Gyrometer detected. Application will stop.");
@@ -170,15 +167,15 @@ static void Main()
170167
Environment.Exit(0);
171168
}
172169

173-
// start UDP server (temp)
174-
UdpServer _udpServer = new UdpServer(PadMacAddress);
175-
_udpServer.Start(UdpPort);
170+
// start UDP server
171+
UDPServer = new UdpServer(PadMacAddress);
172+
UDPServer.Start(UdpPort);
176173

177-
if (_udpServer != null)
174+
if (UDPServer != null)
178175
{
179176
Console.WriteLine($"UDP server has started. Listening to port: {UdpPort}");
180177
Console.WriteLine();
181-
PhysicalController.SetUdpServer(_udpServer);
178+
PhysicalController.SetUdpServer(UDPServer);
182179
}
183180

184181
VirtualXBOX.Connect();
@@ -195,6 +192,10 @@ static void Main()
195192
// listen to user inputs (a bit too rigid, improve me)
196193
Thread MonitorConsole = new Thread(ConsoleListener);
197194
MonitorConsole.Start();
195+
196+
// monitor device battery status and notify UDP server
197+
Thread MonitorBattery = new Thread(MonitorBatteryLife);
198+
MonitorBattery.Start();
198199
}
199200

200201
static string Between(string STR, string FirstString, string LastString)
@@ -206,6 +207,30 @@ static string Between(string STR, string FirstString, string LastString)
206207
return FinalString;
207208
}
208209

210+
static void MonitorBatteryLife()
211+
{
212+
while (IsRunning)
213+
{
214+
BatteryChargeStatus ChargeStatus = SystemInformation.PowerStatus.BatteryChargeStatus;
215+
// float ChargePercent = SystemInformation.PowerStatus.BatteryLifePercent;
216+
217+
if (ChargeStatus.HasFlag(BatteryChargeStatus.Charging))
218+
UDPServer.padMeta.BatteryStatus = DsBattery.Charging;
219+
else if (ChargeStatus.HasFlag(BatteryChargeStatus.NoSystemBattery))
220+
UDPServer.padMeta.BatteryStatus = DsBattery.None;
221+
else if(ChargeStatus.HasFlag(BatteryChargeStatus.High))
222+
UDPServer.padMeta.BatteryStatus = DsBattery.High;
223+
else if (ChargeStatus.HasFlag(BatteryChargeStatus.Low))
224+
UDPServer.padMeta.BatteryStatus = DsBattery.Low;
225+
else if (ChargeStatus.HasFlag(BatteryChargeStatus.Critical))
226+
UDPServer.padMeta.BatteryStatus = DsBattery.Dying;
227+
else
228+
UDPServer.padMeta.BatteryStatus = DsBattery.Medium;
229+
230+
Thread.Sleep(1000);
231+
}
232+
}
233+
209234
static void ConsoleListener()
210235
{
211236
while (IsRunning)
@@ -280,22 +305,35 @@ static void ConsoleListener()
280305

281306
static void UpdateSettings()
282307
{
283-
settings.EnableGyroAiming = Properties.Settings.Default.EnableGyroAiming;
284-
settings.GyroPullRate = Properties.Settings.Default.GyroPullRate;
285-
settings.GyroMaxSample = Properties.Settings.Default.GyroMaxSample;
286-
settings.GyroStickAggressivity = Properties.Settings.Default.GyroStickAggressivity;
287-
settings.GyroStickRange = Properties.Settings.Default.GyroStickRange;
288-
settings.GyroStickInvertAxisX = Properties.Settings.Default.GyroStickInvertAxisX;
289-
settings.GyroStickInvertAxisY = Properties.Settings.Default.GyroStickInvertAxisY;
290-
settings.GyroStickInvertAxisZ = Properties.Settings.Default.GyroStickInvertAxisZ;
291-
settings.TriggerString = Properties.Settings.Default.TriggerString;
308+
string filename = $"{CurrentProfilePath}\\default.json";
309+
if (File.Exists(filename))
310+
{
311+
string jsonString = File.ReadAllText(filename);
312+
settings = JsonSerializer.Deserialize<Settings>(jsonString);
313+
}
314+
else
315+
{
316+
Console.WriteLine("Missing default.json profile.");
317+
settings = new Settings
318+
{
319+
GyroAiming = true,
320+
PullRate = 10,
321+
MaxSample = 1,
322+
Aggressivity = 0.5f,
323+
Range = 10000.0f,
324+
InvertAxisX = false,
325+
InvertAxisY = false,
326+
InvertAxisZ = false,
327+
Trigger = "",
328+
MonitorRatio = false
329+
};
330+
}
292331

293332
UdpPort = Properties.Settings.Default.UdpPort; // 26760
294333
HidHideDevices = Properties.Settings.Default.HidHideDevices; // not yet implemented
295-
EnableScreenRatio = Properties.Settings.Default.EnableScreenRatio;
296334

297335
// update controller settings
298-
if (PhysicalController != null)
336+
if (PhysicalController != null && settings != null)
299337
PhysicalController.UpdateSettings(settings);
300338
}
301339

@@ -316,7 +354,7 @@ static void MonitorProcess()
316354
Process CurrentProcess = Process.GetProcessById((int)processId);
317355

318356
// check if a specific profile exists for the foreground executable
319-
string filename = $"{CurrentPathIni}\\{CurrentProcess.ProcessName}.json";
357+
string filename = $"{CurrentProfilePath}\\{CurrentProcess.ProcessName}.json";
320358
if (File.Exists(filename))
321359
{
322360
string jsonString = File.ReadAllText(filename);

AyaGyroAiming/Properties/Settings.Designer.cs

Lines changed: 4 additions & 124 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)