Skip to content

Commit

Permalink
0.9.10.4 (#170)
Browse files Browse the repository at this point in the history
* implemented service manager exist()

Allows the service manager to check if the targeted service exists.

* remove profile manager from service

Services can't access user level variables like MyDocuments.

* Fix an issue displaying the overlay title and close icon

* implement sensors StartListening

* fix a series of issues casused by device resume

* build 0.9.10.4
  • Loading branch information
Valkirie authored Jun 6, 2022
1 parent 126a359 commit 25d751a
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 52 deletions.
18 changes: 18 additions & 0 deletions ControllerCommon/Managers/ServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ public void Stop()
MonitorTimer = null;
}

public bool Exists()
{
try
{
process.StartInfo.Arguments = $"interrogate {name}";
process.Start();
process.WaitForExit();
string output = process.StandardOutput.ReadToEnd();
return !output.Contains("FAILED 1062");
}
catch (Exception ex)
{
LogManager.LogError("Service manager returned error: {0}", ex.Message);
}

return false;
}

private void MonitorHelper(object sender, ElapsedEventArgs e)
{
lock (updateLock)
Expand Down
4 changes: 2 additions & 2 deletions ControllerService.iss
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,13 @@ end;

#define MyAppSetupName 'Handheld Companion'
#define MyBuildId 'HandheldCompanion'
#define MyAppVersion '0.9.10.3'
#define MyAppVersion '0.9.10.4'
#define MyAppPublisher 'BenjaminLSR'
#define MyAppCopyright 'Copyright © BenjaminLSR'
#define MyAppURL 'https://github.com/Valkirie/ControllerService'
#define MyAppExeName "HandheldCompanion.exe"
#define MySerExeName "ControllerService.exe"
#define MyConfiguration "Release"
#define MyConfiguration "Debug"

AppName={#MyAppSetupName}
AppVersion={#MyAppVersion}
Expand Down
4 changes: 2 additions & 2 deletions ControllerService/AssemblyInfo1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
// Numéro de build
// Révision
//
[assembly: AssemblyVersion("0.9.10.3")]
[assembly: AssemblyFileVersion("0.9.10.3")]
[assembly: AssemblyVersion("0.9.10.4")]
[assembly: AssemblyFileVersion("0.9.10.4")]
77 changes: 47 additions & 30 deletions ControllerService/ControllerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class ControllerService : IHostedService
public XInputController XInputController;

private PipeServer pipeServer;
private ProfileManager profileManager;
private SystemManager systemManager;
private DSUServer DSUServer;
public HidHide Hidder;
Expand Down Expand Up @@ -161,7 +160,6 @@ public ControllerService(IHostApplicationLifetime lifetime)
XInputController.SetVibrationStrength(HIDstrength);
XInputController.SetPollRate(HIDrate);
XInputController.Updated += OnTargetSubmited;
XInputController.StartListening();

// prepare physical controller
SetControllerIdx(HIDidx, deviceInstancePath, baseContainerDeviceInstancePath);
Expand All @@ -170,10 +168,6 @@ public ControllerService(IHostApplicationLifetime lifetime)
DSUServer = new DSUServer(DSUip, DSUport);
DSUServer.Started += OnDSUStarted;
DSUServer.Stopped += OnDSUStopped;

// initialize Profile Manager
profileManager = new ProfileManager();
profileManager.Updated += ProfileUpdated;
}

private SerialUSBIMU sensor;
Expand Down Expand Up @@ -267,7 +261,8 @@ private void SetControllerIdx(UserIndex idx, string deviceInstancePath, string b

private void SetControllerMode(HIDmode mode)
{
HIDmode = mode;
if (HIDmode == mode && VirtualTarget != null)
return;

// disconnect current virtual controller
// todo: do not disconnect if similar to incoming mode
Expand All @@ -277,7 +272,9 @@ private void SetControllerMode(HIDmode mode)
{
default:
case HIDmode.NoController:
VirtualTarget.Dispose();
VirtualTarget = null;
XInputController.DetachTarget();
break;
case HIDmode.DualShock4Controller:
VirtualTarget = new DualShock4Target(XInputController, VirtualClient);
Expand All @@ -287,28 +284,38 @@ private void SetControllerMode(HIDmode mode)
break;
}

if (VirtualTarget == null)
return;

VirtualTarget.Connected += OnTargetConnected;
VirtualTarget.Disconnected += OnTargetDisconnected;
if (VirtualTarget != null)
{
VirtualTarget.Connected += OnTargetConnected;
VirtualTarget.Disconnected += OnTargetDisconnected;
XInputController.AttachTarget(VirtualTarget);
}

XInputController.SetViGEmTarget(VirtualTarget);
// update status
SetControllerStatus(HIDstatus);

// update value
HIDmode = mode;
}

private void SetControllerStatus(HIDstatus status)
{
HIDstatus = status;
if (VirtualTarget == null)
return;

switch (status)
{
default:
case HIDstatus.Connected:
VirtualTarget?.Connect();
VirtualTarget.Connect();
break;
case HIDstatus.Disconnected:
VirtualTarget?.Disconnect();
VirtualTarget.Disconnect();
break;
}

// update value
HIDstatus = status;
}

private void OnTargetDisconnected(ViGEmTarget target)
Expand Down Expand Up @@ -577,6 +584,9 @@ private void ApplySetting(string name, string property)

public Task StartAsync(CancellationToken cancellationToken)
{
// start listening to controller
XInputController.StartListening();

// turn on cloaking
Hidder.SetCloaking(HIDcloaked, XInputController.ProductName);

Expand All @@ -585,18 +595,16 @@ public Task StartAsync(CancellationToken cancellationToken)

// update virtual controller
SetControllerMode(HIDmode);
SetControllerStatus(HIDstatus);

// start Pipe Server
pipeServer.Start();

// start and stop Profile Manager
profileManager.Start("Default.json");
profileManager.Stop();

// listen to system events
SystemEvents.PowerModeChanged += OnPowerChange;

// OnPowerChange(null, new PowerModeChangedEventArgs(PowerModes.Suspend));
// OnPowerChange(null, new PowerModeChangedEventArgs(PowerModes.Resume));

return Task.CompletedTask;
}

Expand All @@ -609,7 +617,7 @@ public Task StopAsync(CancellationToken cancellationToken)
Hidder?.SetCloaking(!HIDuncloakonclose, XInputController.ProductName);

// update virtual controller
SetControllerStatus(HIDstatus.Disconnected);
SetControllerMode(HIDmode.NoController);

// stop listening to system events
SystemEvents.PowerModeChanged -= OnPowerChange;
Expand All @@ -636,18 +644,27 @@ private void OnPowerChange(object s, PowerModeChangedEventArgs e)
case PowerModes.StatusChange:
break;
case PowerModes.Resume:
// (re)initialize sensors
XInputController?.UpdateSensors();
{
// resume delay (arbitrary)

This comment has been minimized.

Copy link
@Valkirie

Valkirie Jun 6, 2022

Author Owner

That was painful !

Thread.Sleep(5000);

// (re)initialize sensors
XInputController?.UpdateSensors();

// (re)initialize ViGEm
VirtualClient = new ViGEmClient();
// (re)initialize ViGEm
VirtualClient = new ViGEmClient();

// update virtual controller
SetControllerMode(HIDmode);
SetControllerStatus(HIDstatus);
SetControllerMode(HIDmode);
}
break;
case PowerModes.Suspend:
VirtualClient.Dispose();
{
VirtualTarget.Dispose();
VirtualTarget = null;

VirtualClient.Dispose();
VirtualClient = null;
}
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ControllerService/ControllerService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputPath>$(SolutionDir)bin\$(Configuration)</OutputPath>
<DebugType>portable</DebugType>
<Version>0.9.10.3</Version>
<Version>0.9.10.4</Version>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
Expand Down
31 changes: 31 additions & 0 deletions ControllerService/Sensors/XInputAccelerometer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,37 @@ public void UpdateSensor(SensorFamily sensorFamily)
LogManager.LogInformation("{0} initialised as a {1}. Baud rate set to {2}", this.ToString(), sensorFamily.ToString(), ((SerialUSBIMU)sensor).GetInterval());
break;
}

StartListening(sensorFamily);
}

public void StartListening(SensorFamily sensorFamily)
{
switch (sensorFamily)
{
case SensorFamily.WindowsDevicesSensors:
((Accelerometer)sensor).ReadingChanged += ReadingChanged;
break;
case SensorFamily.SerialUSBIMU:
((SerialUSBIMU)sensor).ReadingChanged += ReadingChanged;
break;
}
}

public void StopListening(SensorFamily sensorFamily)
{
if (sensor is null)
return;

switch (sensorFamily)
{
case SensorFamily.WindowsDevicesSensors:
((Accelerometer)sensor).ReadingChanged -= ReadingChanged;
break;
case SensorFamily.SerialUSBIMU:
((SerialUSBIMU)sensor).ReadingChanged -= ReadingChanged;
break;
}
}

private void ReadingChanged(Vector3 AccelerationG, Vector3 AngularVelocityDeg)
Expand Down
32 changes: 30 additions & 2 deletions ControllerService/Sensors/XInputGirometer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,42 @@ public void UpdateSensor(SensorFamily sensorFamily)
{
case SensorFamily.WindowsDevicesSensors:
((Gyrometer)sensor).ReportInterval = (uint)updateInterval;
((Gyrometer)sensor).ReadingChanged += ReadingChanged;

LogManager.LogInformation("{0} initialised as a {1}. Report interval set to {2}ms", this.ToString(), sensorFamily.ToString(), updateInterval);
break;
case SensorFamily.SerialUSBIMU:
LogManager.LogInformation("{0} initialised as a {1}. Baud rate set to {2}", this.ToString(), sensorFamily.ToString(), ((SerialUSBIMU)sensor).GetInterval());
break;
}

StartListening(sensorFamily);
}

public void StartListening(SensorFamily sensorFamily)
{
switch (sensorFamily)
{
case SensorFamily.WindowsDevicesSensors:
((Gyrometer)sensor).ReadingChanged += ReadingChanged;
break;
case SensorFamily.SerialUSBIMU:
((SerialUSBIMU)sensor).ReadingChanged += ReadingChanged;
break;
}
}

LogManager.LogInformation("{0} initialised as a {1}. Baud rate set to {2}", this.ToString(), sensorFamily.ToString(), ((SerialUSBIMU)sensor).GetInterval());
public void StopListening(SensorFamily sensorFamily)
{
if (sensor is null)
return;

switch (sensorFamily)
{
case SensorFamily.WindowsDevicesSensors:
((Gyrometer)sensor).ReadingChanged -= ReadingChanged;
break;
case SensorFamily.SerialUSBIMU:
((SerialUSBIMU)sensor).ReadingChanged -= ReadingChanged;
break;
}
}
Expand Down
31 changes: 31 additions & 0 deletions ControllerService/Sensors/XInputInclinometer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,37 @@ public void UpdateSensor(SensorFamily sensorFamily)
LogManager.LogInformation("{0} initialised as a {1}. Baud rate set to {2}", this.ToString(), sensorFamily.ToString(), ((SerialUSBIMU)sensor).GetInterval());
break;
}

StartListening(sensorFamily);
}

public void StartListening(SensorFamily sensorFamily)
{
switch (sensorFamily)
{
case SensorFamily.WindowsDevicesSensors:
((Accelerometer)sensor).ReadingChanged += ReadingChanged;
break;
case SensorFamily.SerialUSBIMU:
((SerialUSBIMU)sensor).ReadingChanged += ReadingChanged;
break;
}
}

public void StopListening(SensorFamily sensorFamily)
{
if (sensor is null)
return;

switch (sensorFamily)
{
case SensorFamily.WindowsDevicesSensors:
((Accelerometer)sensor).ReadingChanged -= ReadingChanged;
break;
case SensorFamily.SerialUSBIMU:
((SerialUSBIMU)sensor).ReadingChanged -= ReadingChanged;
break;
}
}

private void ReadingChanged(Vector3 AccelerationG, Vector3 AngularVelocityDeg)
Expand Down
15 changes: 12 additions & 3 deletions ControllerService/Targets/DualShock4Target.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ControllerCommon.Utils;
using ControllerCommon.Managers;
using ControllerCommon.Utils;
using ControllerService.Sensors;
using Nefarius.ViGEm.Client;
using Nefarius.ViGEm.Client.Exceptions;
Expand Down Expand Up @@ -56,6 +57,8 @@ public DualShock4Target(XInputController xinput, ViGEmClient client) : base(xinp
virtualController = client.CreateDualShock4Controller();
virtualController.AutoSubmitReport = false;
virtualController.FeedbackReceived += FeedbackReceived;

LogManager.LogInformation("{0} initialized, {1}", ToString(), virtualController);
}

public override void Connect()
Expand Down Expand Up @@ -218,12 +221,18 @@ public override unsafe void UpdateReport(Gamepad Gamepad)
{
virtualController.SubmitRawReport(rawOutReportEx);
}
catch (VigemBusNotFoundException)
catch (VigemBusNotFoundException ex)
{
// todo: prevent this from happening !
LogManager.LogCritical(ex.Message);
}

base.SubmitReport();
}

public override void Dispose()
{
Disconnect();
base.Dispose();
}
}
}
Loading

0 comments on commit 25d751a

Please sign in to comment.