diff --git a/FreePIE.Core.Plugins/Dx/Device.cs b/FreePIE.Core.Plugins/Dx/Device.cs index 086d1fa9..8df09e5a 100644 --- a/FreePIE.Core.Plugins/Dx/Device.cs +++ b/FreePIE.Core.Plugins/Dx/Device.cs @@ -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 { @@ -36,6 +37,7 @@ public Device(Joystick joystick) Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; this.joystick = joystick; + SetRange(-10000, 10000); getPressedStrategy = new GetPressedStrategy(GetDown); @@ -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; @@ -438,6 +442,7 @@ private static TypeSpecificParameters GetTypeSpecificParameter(FFBEType effectTy } private static Dictionary GuidToEffectType = Enum.GetValues(typeof(FFBEType)).Cast().ToDictionary(EffectTypeGuidMap); + private bool isAxisReverse; private static Guid EffectTypeGuidMap(FFBEType et) { @@ -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); diff --git a/FreePIE.Core.Plugins/FreePIE.Core.Plugins.csproj b/FreePIE.Core.Plugins/FreePIE.Core.Plugins.csproj index 693e680c..65bfc1d4 100644 --- a/FreePIE.Core.Plugins/FreePIE.Core.Plugins.csproj +++ b/FreePIE.Core.Plugins/FreePIE.Core.Plugins.csproj @@ -10,7 +10,7 @@ Properties FreePIE.Core.Plugins FreePIE.Core.Plugins - v4.0 + v4.5.2 512 @@ -54,6 +54,9 @@ ..\Lib\Tobii\EyeXFramework.dll False + + ..\Lib\Logitech\x86\G940LedInterface.dll + ..\Lib\PPJoyWrapper\PPJoyWrapper.dll @@ -95,6 +98,7 @@ + diff --git a/FreePIE.Core.Plugins/JoystickPlugin.cs b/FreePIE.Core.Plugins/JoystickPlugin.cs index 66b0d17d..41090db6 100644 --- a/FreePIE.Core.Plugins/JoystickPlugin.cs +++ b/FreePIE.Core.Plugins/JoystickPlugin.cs @@ -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(); + } } } diff --git a/FreePIE.Core.Plugins/Logitech.cs b/FreePIE.Core.Plugins/Logitech.cs new file mode 100644 index 00000000..9b5f06db --- /dev/null +++ b/FreePIE.Core.Plugins/Logitech.cs @@ -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); + + } +} diff --git a/FreePIE.Core.Plugins/VJoy/VJoyGlobalHolder.cs b/FreePIE.Core.Plugins/VJoy/VJoyGlobalHolder.cs index 11224a77..546cbe25 100644 --- a/FreePIE.Core.Plugins/VJoy/VJoyGlobalHolder.cs +++ b/FreePIE.Core.Plugins/VJoy/VJoyGlobalHolder.cs @@ -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) diff --git a/FreePIE.Core.Plugins/VJoyPlugin.cs b/FreePIE.Core.Plugins/VJoyPlugin.cs index ea8c3d79..08e4ec37 100644 --- a/FreePIE.Core.Plugins/VJoyPlugin.cs +++ b/FreePIE.Core.Plugins/VJoyPlugin.cs @@ -157,9 +157,5 @@ public void registerFfbDevice(JoystickGlobal dev) holder.RegisterFfbDevice(dev.Device); } - public void printDeviceInfo(JoystickGlobal dev) - { - holder.PrintDeviceInfo(dev.Device); - } } } diff --git a/Lib/Logitech/x86/G940LedInterface.dll b/Lib/Logitech/x86/G940LedInterface.dll new file mode 100644 index 00000000..07f74cd9 Binary files /dev/null and b/Lib/Logitech/x86/G940LedInterface.dll differ diff --git a/Lib/Logitech/x86/G940LedInterface.pdb b/Lib/Logitech/x86/G940LedInterface.pdb new file mode 100644 index 00000000..5a55fdf5 Binary files /dev/null and b/Lib/Logitech/x86/G940LedInterface.pdb differ