File: GetTouchDeviceInfo.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (85 lines) | stat: -rw-r--r-- 3,362 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function info = GetTouchDeviceInfo(deviceIndex)
% info = GetTouchDeviceInfo(deviceIndex)
%
% Return 'info' a struct with info about the specified touch input device
% 'deviceIndex'. 'info' has the following fields:
%
% 'product', 'serialNumber' and 'locationID' are self-explanatory.
%
% 'maxTouchpoints' The maximum number of simultaneously supported touch
% points on the device. 10 is a quite common number for typical touchscreens.
%
% 'touchDeviceType': 0 = Touchpad, 1 = Touchscreen.
%
% 'valuatorInfos': A struct array. Each slot contains info about the meaning,
% parameter range and resolution of the corresponding value in the Valuators
% vector returned as part of touch events. i'th slot == i'th vector entry.
% This is mostly for use with GetTouchValuators() to map raw valuator values
% into something meaningful.
%
% OS X: ___________________________________________________________________________
%
% This function currently returns nothing, as macOS does not support touch
% screens in a meaningful way as far as we know. And Psychtoolbox for macOS
% currently does not implement any special support for touchpads or such.
%
% _________________________________________________________________________________
% see also: GetTouchDeviceIndices, GetTouchValuators, TouchEventGet

% HISTORY
% 03-Oct-2017 mk  Wrote it.
% 02-Feb-2021 mk  Add what would be returned by a Windows-10 system, if we'd support it.

touchIndices=[];
productNames=cell(0);
allInfo=cell(0);

if nargin < 1 || isempty(deviceIndex)
    error('Required deviceIndex missing.');
end

if ~ismember(deviceIndex, GetTouchDeviceIndices)
    error('Provided deviceIndex is not a touch input device.');
end

% Get info from PsychHID Devices:
[idx, ~, allinfos] = GetTouchDeviceIndices;
i = find(idx == deviceIndex);
allinfos = allinfos{i};

info.touchDeviceType = allinfos.touchDeviceType;
info.maxTouchpoints = allinfos.maxTouchpoints;
info.product = allinfos.product;
info.serialNumber = allinfos.serialNumber;
info.locationID = allinfos.locationID;

% Get info about the different valuators:
if IsLinux
    % Query dynamic list from Linux. Will change depending on OS version and
    % specific capabilities of the digitizer device:
    [~, ~, ~, ~, ~, info.valuatorInfos] = GetMouse([], deviceIndex);
else
    if IsWin
        % Windows touch input, as of Windows-10 early February 2021, provides only
        % the following hard-coded properties (at most). See following for reference:
        % https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-touchinput

        % Always: X and Y 2D touch position, redundantly exposed as valuator:
        info.valuatorInfos(1).label = 'Abs MT Position X';
        info.valuatorInfos(2).label = 'Abs MT Position Y';

        % Minor/Major (width/height of approximated touch bounding box) are
        % optional, and dependent on digitizer device:
        info.valuatorInfos(3).label = 'Abs MT Touch Minor';
        info.valuatorInfos(4).label = 'Abs MT Touch Major';

        % There's one more optional (dependent on digitizer device) scalar
        % field, whose meaning is unspecified. Could be pressure, proximity, or
        % whatever. We'd return realmin ('single') if the field is not supported:
        info.valuatorInfos(5).label = 'ExtraInfo';
    else
        info.valuatorInfos = [];
    end
end

return;