File: hidtest_oldschool.py

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 (59 lines) | stat: -rw-r--r-- 1,747 bytes parent folder | download | duplicates (2)
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
# hidtest.py - Basic test of PsychHID for Python
# Also tests WaitSecs, as it is utilized here.
#
# Collects key responses for 5 seconds via KbQueues while being blocked on
# the main thread. The disabled latter part will perform some low-level access
# to a USB-HID device, to test HID report send/receive. However, this is so
# device specific as being useless without customization to your specific machine
# OS and HID device. Rest assured it has some use for Mario's laptop.
#
# The test will be subjec to change without notice, it is throwaway wip code.
#
# (c) 2018 Mario Kleiner - Licensed under MIT license.

from psychtoolbox import *

def run():

    # KbQueueTest
    WaitSecs('YieldSecs', 1);
    keys = [1] * 256;
    PsychHID('KbQueueCreate', [], keys);
    PsychHID('KbQueueStart');
    PsychHID('Keyboardhelper', -12);
    WaitSecs('YieldSecs', 5);
    PsychHID('KbQueueStop');
    PsychHID('Keyboardhelper', -10);
    while PsychHID('KbQueueFlush', [], 0):
        evt = PsychHID('KbQueueGetEvent');
        print(evt);

    PsychHID('KbQueueRelease');
    return;

    # USB HID reports test:
    #hiddevs = PsychHID('Devices')
    mouseIndex = 5;
    wheelDelta = 0;
    WaitSecs('YieldSecs', 1);

    options = dict();
    options['print'] = 0;
    err = PsychHID('ReceiveReports', mouseIndex, options);
    print(err);

    while not PsychHID('KbCheck')[0]:
        rep = PsychHID('GetReport', mouseIndex, 1, 0, 5);
        print(rep);
        WaitSecs('YieldSecs', 1);

    err = PsychHID('ReceiveReportsStop', mouseIndex)
    print(err);

    print('\n\nNow all the other remaining ones:\n\n');
    [rep, errs] = PsychHID('GiveMeReports', mouseIndex);
    print(errs);
    print('\n\nReports:\n\n');
    print(rep);

run()