-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen_flash_demo.py
More file actions
65 lines (53 loc) · 1.62 KB
/
Copy pathscreen_flash_demo.py
File metadata and controls
65 lines (53 loc) · 1.62 KB
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
from psychopy import core, visual, event, gui
import sys
from time import time_ns
from pupil_labs.realtime_api.simple import Device
N = 10 # Number of trials
# Get Neon address and port from user
dlg = gui.Dlg()
dlg.addField("Neon address", "10.55.56.125")
dlg.addField("Neon port", "8080")
dlg_data = dlg.show()
sys.exit() if not dlg.OK else None
NEON_ADDRESS = dlg_data[0]
NEON_PORT = int(dlg_data[1])
# Initialize the Neon device
try:
device = Device(address=NEON_ADDRESS, port=NEON_PORT)
except Exception as e:
print(f"Error connecting to Neon: {e}")
sys.exit()
# Experiment parameters and PsychoPy objects
win = visual.Window(screen=-1, fullscr=True, units="height", color=[-1, -1, -1])
win.mouseVisible = False
square = visual.Rect(
win, width=2, height=2, fillColor="white", lineColor="white", units="norm"
)
text = visual.TextStim(win, text="Press space to start", height=0.05)
# Display initial message and wait for space key to continue
text.draw()
win.flip()
event.waitKeys(keyList=["space"])
win.flip()
device.recording_start()
core.wait(3)
# Estimate clock offset
estimate = device.estimate_time_offset().time_offset_ms.median
clock_offset_ns = round(estimate * 1e6)
print(f"Clock median offset: {clock_offset_ns / 1e6} ms")
def send_event(device, clock_offset_ns):
device.send_event(
"Flash onset",
event_timestamp_unix_ns=int(time_ns() - clock_offset_ns),
)
for i in range(N):
square.draw()
win.callOnFlip(send_event, device, clock_offset_ns)
win.flip()
core.wait(0.75)
win.flip()
core.wait(3)
core.wait(1)
device.recording_stop_and_save()
device.close()
core.quit()