forked from LabNeuroCogDevel/mgs_encode_memory.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pylink_help.py
80 lines (71 loc) · 2.54 KB
/
pylink_help.py
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
"""
eyelink eyetracker functions
largely from "brittAnderson"
https://stackoverflow.com/questions/35071433/psychopy-and-pylink-example
also see
pygaze
https://github.com/esdalmaijer/PyGaze/blob/6c07b263c91a0bd8c9c64aedfc2d76c18efa2abf/pygaze/_eyetracker/libeyelink.py
install instructions
- from internet
https://osdoc.cogsci.nl/2.9.0/devices/eyelink/#installing-pylink
- from the vendor
https://www.sr-support.com/showthread.php?16-Linux-Display-Software-Package
TODO: use pyGaze instead
"""
import pylink as pl
class eyelink:
"""
quick access to eyelink
should use pyGaze instead
"""
def __init__(self, sp):
""" initialize eyetracker
@param 'sp' screen res"""
el = pl.EyeLink()
# pygaze uses
# pylink.getEYELINK().setPupilSizeDiameter(True)
# pylink.getEYELINK().sendCommand(cmd)
el.sendCommand("screen_pixel_coords = 0 0 %d %d" % (sp[0], sp[1]))
el.quietMode(0) # allow messages
el.sendMessage("DISPLAY_COORDS 0 0 %d %d" % (sp[0], sp[1]))
el.sendCommand("select_parser_configuration 0")
el.sendCommand("scene_camera_gazemap = NO")
# area or diameter
el.sendCommand("pupil_size_diameter = YES")
self.el = el
self.sp = sp
def open(self, dfn):
"""open file"""
# pygaze note: cannot be more than 8 characters?!
if len(dfn) > 6:
raise Exception("%s is too long of a file name!" % dfn)
self.el.openDataFile(dfn + '.EDF')
def start(self):
"""start tracking"""
self.el.sendMessage("START")
error = self.el.startRecording(1, 1, 1, 1)
if error:
raise Exception("Failed to start pylink eye tracking!")
def stop(self):
"""cose file and stop tracking"""
self.el.sendMessage("END")
pl.endRealTimeMode()
pl.getEYELINK().setOfflineMode()
# el.sendCommand("set_offline_mode = YES")
self.el.closeDataFile()
def trigger(self, eventname):
"""send event discription"""
self.el.sendMessage(eventname)
def eyeTrkCalib(self, colordepth=32):
"""
callibration. not used?
@param colordepth - color depth of display (why?)
"""
sp = self.sp
pl.openGraphics(sp, colordepth)
pl.setCalibrationColors((255, 255, 255), (0, 0, 0))
pl.setTargetSize(int(sp[0]/70), int(sp[1]/300))
pl.setCalibrationSounds("", "", "")
pl.setDriftCorrectSounds("", "off", "off")
self.el.doTrackerSetup()
pl.closeGraphics()