mirror of
https://github.com/vale981/VoiDPlugins
synced 2025-03-05 09:11:38 -05:00
Support both normal and extended VMulti
This commit is contained in:
parent
300fe0ebe4
commit
a69fe346b2
3 changed files with 78 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using OpenTabletDriver.Plugin.Attributes;
|
using OpenTabletDriver.Plugin;
|
||||||
using OpenTabletDriver.Plugin.Platform.Display;
|
using OpenTabletDriver.Plugin.Platform.Display;
|
||||||
using OpenTabletDriver.Plugin.Platform.Pointer;
|
using OpenTabletDriver.Plugin.Platform.Pointer;
|
||||||
using OpenTabletDriver.Plugin.Tablet;
|
using OpenTabletDriver.Plugin.Tablet;
|
||||||
|
@ -13,6 +13,7 @@ namespace VoiDPlugins.OutputMode
|
||||||
public unsafe abstract class WinInkBasePointer : IPressureHandler, ITiltHandler, IEraserHandler, ISynchronousPointer
|
public unsafe abstract class WinInkBasePointer : IPressureHandler, ITiltHandler, IEraserHandler, ISynchronousPointer
|
||||||
{
|
{
|
||||||
private readonly Vector2 _conversionFactor;
|
private readonly Vector2 _conversionFactor;
|
||||||
|
private readonly int _pressureConv;
|
||||||
private readonly IVirtualScreen _screen;
|
private readonly IVirtualScreen _screen;
|
||||||
private ThinOSPointer? _osPointer;
|
private ThinOSPointer? _osPointer;
|
||||||
private Vector2 _internalPos;
|
private Vector2 _internalPos;
|
||||||
|
@ -44,9 +45,25 @@ namespace VoiDPlugins.OutputMode
|
||||||
SharedStore.SetOrAdd(TIP_PRESSED, false);
|
SharedStore.SetOrAdd(TIP_PRESSED, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Instance.Extended)
|
||||||
|
{
|
||||||
|
Log.Write(name, "Using extended VMulti digitizer");
|
||||||
|
_pressureConv = 16383;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_pressureConv = 8191;
|
||||||
|
}
|
||||||
|
|
||||||
VMultiInstance<DigitizerInputReport> createInstance()
|
VMultiInstance<DigitizerInputReport> createInstance()
|
||||||
{
|
{
|
||||||
return new VMultiInstance<DigitizerInputReport>(name, new DigitizerInputReport());
|
return new VMultiInstance<DigitizerInputReport>(name, extended =>
|
||||||
|
{
|
||||||
|
if (extended)
|
||||||
|
return DigitizerInputReport.Extended();
|
||||||
|
else
|
||||||
|
return DigitizerInputReport.Normal();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +77,7 @@ namespace VoiDPlugins.OutputMode
|
||||||
|
|
||||||
public void SetPressure(float percentage)
|
public void SetPressure(float percentage)
|
||||||
{
|
{
|
||||||
RawPointer->Pressure = (ushort)(percentage * 16383);
|
RawPointer->Pressure = (ushort)(percentage * _pressureConv);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTilt(Vector2 tilt)
|
public void SetTilt(Vector2 tilt)
|
||||||
|
|
|
@ -6,9 +6,12 @@ namespace VoiDPlugins.Library.VMulti.Device
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
public struct DigitizerInputReport
|
public struct DigitizerInputReport
|
||||||
{
|
{
|
||||||
|
public const byte NormalReportID = 0x05;
|
||||||
|
public const byte ExtendedReportID = 0x06;
|
||||||
|
|
||||||
public DigitizerInputReport()
|
public DigitizerInputReport()
|
||||||
{
|
{
|
||||||
Header = new VMultiReportHeader(Unsafe.SizeOf<DigitizerInputReport>(), 0x06);
|
Header = new VMultiReportHeader(Unsafe.SizeOf<DigitizerInputReport>(), ExtendedReportID);
|
||||||
X = 0;
|
X = 0;
|
||||||
Y = 0;
|
Y = 0;
|
||||||
Pressure = 0;
|
Pressure = 0;
|
||||||
|
@ -16,6 +19,26 @@ namespace VoiDPlugins.Library.VMulti.Device
|
||||||
YTilt = 0;
|
YTilt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DigitizerInputReport(byte reportId)
|
||||||
|
{
|
||||||
|
Header = new VMultiReportHeader(Unsafe.SizeOf<DigitizerInputReport>(), 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 VMultiReportHeader Header;
|
||||||
public ushort X; // X position of the pen from 0 to 32767
|
public ushort X; // X position of the pen from 0 to 32767
|
||||||
public ushort Y; // Y position of the pen from 0 to 32767
|
public ushort Y; // Y position of the pen from 0 to 32767
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using HidSharp;
|
using HidSharp;
|
||||||
|
using HidSharp.Reports;
|
||||||
using OpenTabletDriver.Plugin;
|
using OpenTabletDriver.Plugin;
|
||||||
using VoiDPlugins.Library.VMulti.Device;
|
using VoiDPlugins.Library.VMulti.Device;
|
||||||
|
|
||||||
|
@ -9,14 +11,16 @@ namespace VoiDPlugins.Library.VMulti
|
||||||
public class VMultiInstance
|
public class VMultiInstance
|
||||||
{
|
{
|
||||||
private readonly HidStream? _device;
|
private readonly HidStream? _device;
|
||||||
|
private readonly bool _extended;
|
||||||
protected readonly byte[] Buffer;
|
protected readonly byte[] Buffer;
|
||||||
public unsafe VMultiReportHeader* Header { get; }
|
public unsafe VMultiReportHeader* Header { get; }
|
||||||
|
public bool Extended => _extended;
|
||||||
|
|
||||||
public unsafe VMultiInstance(string name, int size)
|
public unsafe VMultiInstance(string name, int size)
|
||||||
{
|
{
|
||||||
Buffer = GC.AllocateArray<byte>(size, true);
|
Buffer = GC.AllocateArray<byte>(size, true);
|
||||||
Header = (VMultiReportHeader*)Unsafe.AsPointer(ref Buffer[0]);
|
Header = (VMultiReportHeader*)Unsafe.AsPointer(ref Buffer[0]);
|
||||||
_device = Retrieve(name);
|
_device = Retrieve(name, out _extended);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write()
|
public void Write()
|
||||||
|
@ -44,10 +48,12 @@ namespace VoiDPlugins.Library.VMulti
|
||||||
return (buttons & bit) != 0;
|
return (buttons & bit) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HidStream? Retrieve(string Name)
|
private static HidStream? Retrieve(string Name, out bool extended)
|
||||||
{
|
{
|
||||||
HidStream? VMultiDev = null;
|
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)
|
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);
|
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 = (T*)Unsafe.AsPointer(ref Buffer[0]);
|
||||||
*Pointer = initialValue;
|
*Pointer = initialValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public unsafe VMultiInstance(string name, Func<bool, T> initialValue) : base(name, Unsafe.SizeOf<T>())
|
||||||
|
{
|
||||||
|
Pointer = (T*)Unsafe.AsPointer(ref Buffer[0]);
|
||||||
|
*Pointer = initialValue(Extended);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue