diff --git a/src/OutputMode/WindowsInk/Pointer/WinInkBasePointer.cs b/src/OutputMode/WindowsInk/Pointer/WinInkBasePointer.cs index 5c88b99..24eee92 100644 --- a/src/OutputMode/WindowsInk/Pointer/WinInkBasePointer.cs +++ b/src/OutputMode/WindowsInk/Pointer/WinInkBasePointer.cs @@ -1,5 +1,5 @@ using System.Numerics; -using OpenTabletDriver.Plugin.Attributes; +using OpenTabletDriver.Plugin; using OpenTabletDriver.Plugin.Platform.Display; using OpenTabletDriver.Plugin.Platform.Pointer; using OpenTabletDriver.Plugin.Tablet; @@ -13,6 +13,7 @@ namespace VoiDPlugins.OutputMode public unsafe abstract class WinInkBasePointer : IPressureHandler, ITiltHandler, IEraserHandler, ISynchronousPointer { private readonly Vector2 _conversionFactor; + private readonly int _pressureConv; private readonly IVirtualScreen _screen; private ThinOSPointer? _osPointer; private Vector2 _internalPos; @@ -44,9 +45,25 @@ namespace VoiDPlugins.OutputMode SharedStore.SetOrAdd(TIP_PRESSED, false); } + if (Instance.Extended) + { + Log.Write(name, "Using extended VMulti digitizer"); + _pressureConv = 16383; + } + else + { + _pressureConv = 8191; + } + VMultiInstance createInstance() { - return new VMultiInstance(name, new DigitizerInputReport()); + return new VMultiInstance(name, extended => + { + if (extended) + return DigitizerInputReport.Extended(); + else + return DigitizerInputReport.Normal(); + }); } } @@ -60,7 +77,7 @@ namespace VoiDPlugins.OutputMode public void SetPressure(float percentage) { - RawPointer->Pressure = (ushort)(percentage * 16383); + RawPointer->Pressure = (ushort)(percentage * _pressureConv); } public void SetTilt(Vector2 tilt) diff --git a/src/VoiDPlugins.Library/VMulti/Device/DigitizerInputReport.cs b/src/VoiDPlugins.Library/VMulti/Device/DigitizerInputReport.cs index dc58998..7d601ff 100644 --- a/src/VoiDPlugins.Library/VMulti/Device/DigitizerInputReport.cs +++ b/src/VoiDPlugins.Library/VMulti/Device/DigitizerInputReport.cs @@ -6,9 +6,12 @@ namespace VoiDPlugins.Library.VMulti.Device [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct DigitizerInputReport { + public const byte NormalReportID = 0x05; + public const byte ExtendedReportID = 0x06; + public DigitizerInputReport() { - Header = new VMultiReportHeader(Unsafe.SizeOf(), 0x06); + Header = new VMultiReportHeader(Unsafe.SizeOf(), ExtendedReportID); X = 0; Y = 0; Pressure = 0; @@ -16,6 +19,26 @@ namespace VoiDPlugins.Library.VMulti.Device YTilt = 0; } + private DigitizerInputReport(byte reportId) + { + Header = new VMultiReportHeader(Unsafe.SizeOf(), reportId); + X = 0; + Y = 0; + Pressure = 0; + XTilt = 0; + YTilt = 0; + } + + public static DigitizerInputReport Normal() + { + return new DigitizerInputReport(NormalReportID); + } + + public static DigitizerInputReport Extended() + { + return new DigitizerInputReport(ExtendedReportID); + } + public VMultiReportHeader Header; public ushort X; // X position of the pen from 0 to 32767 public ushort Y; // Y position of the pen from 0 to 32767 diff --git a/src/VoiDPlugins.Library/VMulti/VMultiInstance.cs b/src/VoiDPlugins.Library/VMulti/VMultiInstance.cs index 26a759c..09784ae 100644 --- a/src/VoiDPlugins.Library/VMulti/VMultiInstance.cs +++ b/src/VoiDPlugins.Library/VMulti/VMultiInstance.cs @@ -1,6 +1,8 @@ using System; +using System.Linq; using System.Runtime.CompilerServices; using HidSharp; +using HidSharp.Reports; using OpenTabletDriver.Plugin; using VoiDPlugins.Library.VMulti.Device; @@ -9,14 +11,16 @@ namespace VoiDPlugins.Library.VMulti public class VMultiInstance { private readonly HidStream? _device; + private readonly bool _extended; protected readonly byte[] Buffer; public unsafe VMultiReportHeader* Header { get; } + public bool Extended => _extended; public unsafe VMultiInstance(string name, int size) { Buffer = GC.AllocateArray(size, true); Header = (VMultiReportHeader*)Unsafe.AsPointer(ref Buffer[0]); - _device = Retrieve(name); + _device = Retrieve(name, out _extended); } public void Write() @@ -44,10 +48,12 @@ namespace VoiDPlugins.Library.VMulti return (buttons & bit) != 0; } - private static HidStream? Retrieve(string Name) + private static HidStream? Retrieve(string Name, out bool extended) { HidStream? VMultiDev = null; - foreach (var device in DeviceList.Local.GetHidDevices(productID: 47820)) + var devices = DeviceList.Local.GetHidDevices(vendorID: 255, productID: 47820).ToArray(); + + foreach (var device in devices) { if (device.GetMaxOutputReportLength() == 65 && device.GetMaxInputReportLength() == 65) { @@ -56,7 +62,25 @@ namespace VoiDPlugins.Library.VMulti } } - if (VMultiDev == null) + bool normal = false; + extended = false; + + foreach (var device in devices) + { + if (device.GetMaxInputReportLength() == 10) + { + var reportDescriptor = device.GetReportDescriptor(); + if (reportDescriptor.TryGetReport(ReportType.Input, DigitizerInputReport.NormalReportID, out _)) + normal = true; + if (reportDescriptor.TryGetReport(ReportType.Input, DigitizerInputReport.ExtendedReportID, out _)) + extended = true; + } + + if (normal && extended) + break; + } + + if (VMultiDev == null || (!normal && !extended)) { Log.WriteNotify(Name, "Cannot find VirtualHID. Install VMulti driver here: https://github.com/X9VoiD/vmulti-bin/releases/latest", LogLevel.Error); } @@ -74,5 +98,11 @@ namespace VoiDPlugins.Library.VMulti Pointer = (T*)Unsafe.AsPointer(ref Buffer[0]); *Pointer = initialValue; } + + public unsafe VMultiInstance(string name, Func initialValue) : base(name, Unsafe.SizeOf()) + { + Pointer = (T*)Unsafe.AsPointer(ref Buffer[0]); + *Pointer = initialValue(Extended); + } } } \ No newline at end of file