Skip to content

Commit

Permalink
Logitech G940 LED interface plugin supported
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberluke committed Sep 17, 2022
1 parent 4933314 commit 5a3b420
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 16 deletions.
82 changes: 76 additions & 6 deletions FreePIE.Core.Plugins/Dx/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Globalization;
using System.Text;
using FreePIE.Core.Plugins.VJoy;
using static FreePIE.Core.Plugins.Logitech;

namespace FreePIE.Core.Plugins.Dx
{
Expand Down Expand Up @@ -36,6 +37,7 @@ public Device(Joystick joystick)
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

this.joystick = joystick;

SetRange(-10000, 10000);
getPressedStrategy = new GetPressedStrategy<int>(GetDown);

Expand Down Expand Up @@ -291,11 +293,13 @@ public void setConditionReport(int blockIndex, int centerPointOffset, int deadBa
{
CheckFfbSupport("Unable to set constant force");

int lastConditionId = isY ? 1 : 0; //G940 is reversed here
/*if (isY == false)
int lastConditionId = isY ? 0 : 1;

if (isAxisReverse)
{
initializeConditionForce();
}*/
//G940 is reversed here
lastConditionId = isY ? 1 : 0;
}

effectParams[blockIndex].Parameters.AsConditionSet().Conditions[lastConditionId].Offset = centerPointOffset;
effectParams[blockIndex].Parameters.AsConditionSet().Conditions[lastConditionId].DeadBand = deadBand;
Expand Down Expand Up @@ -438,6 +442,7 @@ private static TypeSpecificParameters GetTypeSpecificParameter(FFBEType effectTy
}

private static Dictionary<Guid, FFBEType> GuidToEffectType = Enum.GetValues(typeof(FFBEType)).Cast<FFBEType>().ToDictionary(EffectTypeGuidMap);
private bool isAxisReverse;

private static Guid EffectTypeGuidMap(FFBEType et)
{
Expand Down Expand Up @@ -489,14 +494,79 @@ private void PrepareFfb()
ax.Add((int)deviceObject.ObjectType);
Console.WriteLine("ObjectType: " + deviceObject.ObjectType);
}
//ax.Reverse(); // G940 fix vs VJoy default
if (ax.Capacity >= 2)
{
/**
* G940
AxisEnabledDirection
[0] = 16777474
[1] = 16777218
Vjoy
[0] = 16777218
[1] = 16777474
*/
if (ax[0] == 16777474 && ax[1] == 16777218)
{
Console.WriteLine("Reversed Axis detected. Enabling automatic XY axes reversed position in effect buffer queue");
ax.Reverse();
isAxisReverse = true;
}
}
Axes = ax.ToArray();
}

public bool isG940Throttle()
{
return Name == "Logitech G940 Throttle";
}

public void setG940LED(int button, LogiColor color)
{
if (!isG940Throttle())
{
return;
}

unsafe
{
ButtonSetColor((IntPtr)joystick.InternalPointer, (LogiPanelButton)(button - 1), color);
}
}

public void setAllG940LED(LogiColor color)
{
if (!isG940Throttle())
{
return;
}

unsafe
{
SetAllButtonsColor((IntPtr)joystick.InternalPointer, color);
}
}

public bool isG940LED(int button, LogiColor color)
{
if (!isG940Throttle())
{
return false;
}

unsafe
{
return IsButtonColor((IntPtr)joystick.InternalPointer, (LogiPanelButton)(button - 1), color);
}
}

public void printSupportedEffects()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat(" >> Device: {0}", Name);
sb.AppendFormat(" >> Device: {0}\n", Name);
sb.AppendFormat(" >> Device GUID: {0}\n", InstanceGuid);
sb.AppendFormat(" >> Device Supports FFB: {0}\n", SupportsFfb);

foreach (EffectInfo effect in joystick.GetEffects())
{
sb.AppendFormat(" >> Effect Name: {0}\n", effect.Name);
Expand Down
6 changes: 5 additions & 1 deletion FreePIE.Core.Plugins/FreePIE.Core.Plugins.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FreePIE.Core.Plugins</RootNamespace>
<AssemblyName>FreePIE.Core.Plugins</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down Expand Up @@ -54,6 +54,9 @@
<HintPath>..\Lib\Tobii\EyeXFramework.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="G940LedInterface">
<HintPath>..\Lib\Logitech\x86\G940LedInterface.dll</HintPath>
</Reference>
<Reference Include="PPJoyWrapper">
<HintPath>..\Lib\PPJoyWrapper\PPJoyWrapper.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -95,6 +98,7 @@
<Compile Include="Dx\Device.cs" />
<Compile Include="JoystickPlugin.cs" />
<Compile Include="KeyboardPlugin.cs" />
<Compile Include="Logitech.cs" />
<Compile Include="MemoryMapping\ArgumentExtension.cs" />
<Compile Include="MemoryMapping\MappedMemory.cs" />
<Compile Include="MemoryMapping\SharedMemoryWorker.cs" />
Expand Down
24 changes: 24 additions & 0 deletions FreePIE.Core.Plugins/JoystickPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,29 @@ public bool AutoCenter

public bool supportsFfb { get { return device.SupportsFfb; } }

public void printDeviceInfo()
{
device.printSupportedEffects();
}

public void setG940LED(int button, LogiColor color)
{
device.setG940LED(button, color);
}

public void setAllG940LED(LogiColor color)
{
device.setAllG940LED(color);
}

public bool isG940LED(int button, LogiColor color)
{
return device.isG940LED(button, color);
}

public void printSupportedEffects()
{
device.printSupportedEffects();
}
}
}
32 changes: 32 additions & 0 deletions FreePIE.Core.Plugins/Logitech.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using FreePIE.Core.Contracts;
using System;
using System.Runtime.InteropServices;

namespace FreePIE.Core.Plugins
{
[GlobalEnum]
public enum LogiPanelButton
{
LOGI_UNDEFINED = -1, LOGI_P1, LOGI_P2, LOGI_P3, LOGI_P4, LOGI_P5, LOGI_P6, LOGI_P7, LOGI_P8
}

[GlobalEnum]
public enum LogiColor
{
LOGI_OFF, LOGI_GREEN, LOGI_AMBER, LOGI_RED
}

public class Logitech
{

[DllImport("G940LedInterface.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_ButtonSetColor")]
public extern static ulong ButtonSetColor(IntPtr device, LogiPanelButton button, LogiColor color);

[DllImport("G940LedInterface.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_SetAllButtonsColor")]
public extern static ulong SetAllButtonsColor(IntPtr device, LogiColor color);

[DllImport("G940LedInterface.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_IsButtonColor")]
public extern static bool IsButtonColor(IntPtr device, LogiPanelButton button, LogiColor color);

}
}
5 changes: 0 additions & 5 deletions FreePIE.Core.Plugins/VJoy/VJoyGlobalHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ public VJoyGlobalHolder(uint index)
Joystick.ResetVJD(index);
}

public void PrintDeviceInfo(Device device)
{
device.printSupportedEffects();
}

public void SetButton(int button, bool pressed)
{
if (button >= maxButtons)
Expand Down
4 changes: 0 additions & 4 deletions FreePIE.Core.Plugins/VJoyPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,5 @@ public void registerFfbDevice(JoystickGlobal dev)
holder.RegisterFfbDevice(dev.Device);
}

public void printDeviceInfo(JoystickGlobal dev)
{
holder.PrintDeviceInfo(dev.Device);
}
}
}
Binary file added Lib/Logitech/x86/G940LedInterface.dll
Binary file not shown.
Binary file added Lib/Logitech/x86/G940LedInterface.pdb
Binary file not shown.

0 comments on commit 5a3b420

Please sign in to comment.