Skip to content

Instantly share code, notes, and snippets.

@grero
Created July 8, 2020 08:20
Show Gist options
  • Save grero/81020004a477383df757919b9c6b17ca to your computer and use it in GitHub Desktop.
Save grero/81020004a477383df757919b9c6b17ca to your computer and use it in GitHub Desktop.
import sys
import pylink
from pylinkwrapper import psychocal, connector
from psychopy import sound, visual,event, tools, data
from psychopy.tools import monitorunittools
import utils
import os
red = (1.0, 0.0, 0.0)
green = (0.0, 1.0, 0.0)
white = (1.0, 1.0, 1.0)
black = (-1.0, -1.0, -1.0)
blue = (-1.0, -1.0, 1.0)
yellow = (1.0, 1.0, -1.0)
class Calibration(psychocal.psychocal):
def __init__(self, w,h, tracker, window):
psychocal.psychocal.__init__(self, w, h, tracker, window)
self.targetout = visual.Circle(self.window, pos=(0, 0), radius=20,
fillColor=white,
lineColor=white, units='pix',
fillColorSpace='rgb',
lineColorSpace='rgb')
def setup_cal_display(self):
self.window.flip()
def draw_cal_target(self, x, y):
# Convert to psychopy coordinates
x = x - (self.sres[0] / 2)
y = -(y - (self.sres[1] / 2))
self.targetout.pos = (x, y)
self.targetout.draw()
self.window.flip()
def erase_cal_target(self):
self.window.flip()
def get_input_key(self):
ky = []
v = event.getKeys()
for key in v:
pylink_key = None
if len(key) == 1:
pylink_key = ord(key)
elif key == "escape":
pylink_key = pylink.ESC_KEY
elif key == "return":
# self.reward.deliver()
self.correct_fixation = True
pylink_key = pylink.ENTER_KEY
elif key == "pageup":
pylink_key = pylink.PAGE_UP
elif key == "pagedown":
pylink_key = pylink.PAGE_DOWN
elif key == "up":
pylink_key = pylink.CURS_UP
elif key == "down":
pylink_key = pylink.CURS_DOWN
elif key == "left":
pylink_key = pylink.CURS_LEFT
elif key == "right":
pylink_key = pylink.CURS_RIGHT
else:
print('Error! :{} is not a used key.'.format(key))
return
ky.append(pylink.KeyInput(pylink_key, 0))
return ky
screen_width = 1920
screen_height = 1200
win = visual.Window(
size=(screen_width, screen_height), fullscr=True, screen=1,
allowGUI=True, allowStencil=False,
monitor='testMonitor', color=[0, 0, 0], colorSpace='rgb',
blendMode='avg', useFBO=False)
filename = "test"
tracker = connector.Connect(window=win, edfname=filename + '.edf')
cnum = 13
calst = 'HV{}'.format(cnum)
tracker.tracker.setCalibrationType(calst)
genv = Calibration(tracker.sres[0], tracker.sres[1],
tracker.tracker, tracker.win)
tracker.send_command("remote_cal_enable = 0")
paval = 1000
tracker.tracker.setAutoCalibrationPacing(paval)
pylink.openGraphicsEx(genv)
tracker.tracker.doTrackerSetup(tracker.sres[0], tracker.sres[1])
win.close()
tracker.record_off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment