From f06b288fc90e316ec4aeb8025aef7eb41f4f8b9e Mon Sep 17 00:00:00 2001 From: Andy Connolly Date: Thu, 3 Dec 2020 00:34:42 -0500 Subject: [PATCH] ADD QR coding python util --- QRCoding/QR_util.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 QRCoding/QR_util.py diff --git a/QRCoding/QR_util.py b/QRCoding/QR_util.py new file mode 100644 index 0000000..a4ac1be --- /dev/null +++ b/QRCoding/QR_util.py @@ -0,0 +1,40 @@ +from psychopy import event, visual, core, clock +import qrcode +import time + +def waitTrigger(win, runNum, acqNum, qrDur=.05, qrPos=(-.5,-.5), qrSize=.2): + + + data = {"acqNum": acqNum, + "runNum": runNum, + "trialStart": time.time() + } + + print("Waiting for trigger pulse ... or key stroke '5'") + event.waitKeys(keyList=['5']) + clk = clock.Clock() + data["runStart"] = time.time() + + qr = visual.ImageStim(win, + qrcode.make(str(data)), + pos=qrPos + ) + qr.size = qr.size*qrSize + qr.draw() + win.flip() + core.wait(qrDur) + return clk + +def endRun(win, qrDur=.05, qrPos=(-.5,-.5), qrSize=.2): + + data = {"runEnd": time.time()} + + qr = visual.ImageStim(win, + qrcode.make(str(data)), + pos=qrPos + ) + qr.size = qr.size*qrSize + qr.draw() + win.flip() + core.wait(qrDur) +