0

I'm making an app in UWP for Raspberry Pi 3B with this touch screen https://www.waveshare.com/wiki/5inch_HDMI_LCD_(B)

The touch panel on the screen is not lined up properly, so there is a need to calibrate it. But in order to do that I need access to raw coordinate data from it. I have tried using a Tapped event, but the OS registers those coordinates (the bad ones) from the touch screen and processes them, so basically the wrong button gets tapped.

I tried to connect to the touch screen from Windows.Devices.HumanInterfaceDevice.HidDevice:

private HidDevice _device;
    public HidDevice device
    {
        get
        {
            return _device;
        }
        set
        {
            _device = value;
        }
    }
    public MainPage()
    {
        this.InitializeComponent();
        EnumerateDevices(usgPage, vend, prodId);
    }
public async Task EnumerateDevices(ushort usgPage, ushort vend, ushort prodId, ushort usgId)
    {
         ushort usagePage = usgPage;
         ushort vendor = vend;
         ushort productId = prodId;
         ushort usageId = usgId;

        var selector = HidDevice.GetDeviceSelector(usagePage, usageId, vendor, productId);

        DeviceInformationCollection devices;
        devices = await DeviceInformation.FindAllAsync(selector);
        var a = devices[0].Id;
        try
        {
            devices = await DeviceInformation.FindAllAsync(selector);
        }
        catch
        {
            return;
        }
        device = await HidDevice.FromIdAsync(a, Windows.Storage.FileAccessMode.ReadWrite);
    }

Manifest

<Capabilities>
<DeviceCapability Name="humaninterfacedevice">
      <Device Id="vidpid:0EEF 0005">
        <Function Type="usage:000D 0004" />
      </Device>
</Capabilities>

Device list

But the device is always null, even though devices containes my touch screen. I think it is because the OS communicates with the touch screen, and as a result, I cannot interact with it.

I tried to disable PnP with

Get-PnpDevice | Where-Object {$_.FriendlyName -like '*touch screen*'} | Disable-PnpDevice -Confirm:$false

from powershell, which disabled the touch screen completely and I could not see it even in devices list.

So I tried to change registry with

reg add HKLM\Software\Microsoft\Wisp\Touch -v TouchGate -f -d 0 -t REG_DWORD

but the OS still interacted with the touch screen and it had no effect at all. Also, I checked whether the value in the registry has indeed changed and it has.

My idea is that if it would be possible somehow to tell the OS to ignore the input from the touchscreen but not disabling the HID device completely so I could connect to it from my UWP app and handle the coordinates myself (like calculating the correct position for pointer) and then I would inject with Windows.UI.Input.Preview.Injection.InputInjector a point with correct coordinates.

Alth0ugh
  • 1
  • 2
  • How do you call `EnumerateDevices`? – GSerg Feb 08 '20 at 11:33
  • @GSerg I use MVVM for my app and EnumerateDevices is in viewmodel. For now, I call it from the constructor of the class. – Alth0ugh Feb 08 '20 at 14:26
  • Please show that, not describe. If `device` is a class-level variable which you populate with a call to `EnumerateDevices(...)` from the class constructor and try to use it right after `EnumerateDevices()` returns, then of course it's not going to work because `async void` is not awaitable and it returns way before it has a chance to populate the `device`. It needs to be `async Task EnumerateDevices` and you must `await EnumerateDevices()` to properly use its result, which you [cannot do](https://stackoverflow.com/q/8145479/11683) from a constructor. – GSerg Feb 08 '20 at 14:40
  • @GSerg I have updated the code in the question. device is a property and during debugging I have set a breakpoint on the setter, so I can observe what value is being written to it. I have changed *void* to *Task* but still it returns *null*. Is it a problem that I am not awaiting the *EnumerateDevices(...)*? It still runs in the background and triggers the breakpoint. – Alth0ugh Feb 08 '20 at 15:14
  • @Alth0ugh, is the `value` always null in the setter when you observed? When the app run to the breakpoint on the setter, the `_device` has not been set the value. You may try to debug step by step to observe the value through pressing key F10. – Michael Xu Feb 10 '20 at 01:00
  • @Michael Xu, I have gone through the whole setter with F10: the *value* was still null and after assigning to *_device* it stays null. – Alth0ugh Feb 10 '20 at 07:02
  • @Alth0ugh, have you specified the device capabilities for HID in package manifest? Please refer to this document(https://learn.microsoft.com/en-us/uwp/schemas/appxpackage/how-to-specify-device-capabilities-for-hid). – Michael Xu Feb 11 '20 at 01:36
  • @MichaelXu-MSFT Yes, I have used the same document. If I did not use it, I would not be able to populate *devices*. I updated the question with my code from manifest. – Alth0ugh Feb 11 '20 at 10:07
  • Which driver were you using, inbox driver or lighting driver? If the device have supported hardware (either through I2C or USB HID touch), touch should function automatically using the [inbox class drivers](https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/touchscreen-device-bus-connectivity). You can check the driver which is using via Device Portal. – Michael Xu Feb 14 '20 at 08:49
  • @MichaelXu-MSFT I found something but I am not sure if that is what you were asking. I updated the question with a screenshot of the device list. – Alth0ugh Feb 16 '20 at 12:27

0 Answers0