Commit 6841d560 authored by Rebecca Hirst's avatar Rebecca Hirst

update to use version 2021.2.3 methods

parent c49e98fd
No preview for this file type
......@@ -16,7 +16,7 @@ const psychoJS = new PsychoJS({
// open window:
psychoJS.openWindow({
fullscr: true,
color: new util.Color([0, 0, 0]),
color: new util.Color([(- 1), (- 1), (- 1)]),
units: 'height',
waitBlanking: true
});
......@@ -33,22 +33,22 @@ psychoJS.scheduleCondition(function() { return (psychoJS.gui.dialogComponent.but
// flowScheduler gets run if the participants presses OK
flowScheduler.add(updateInfo); // add timeStamp
flowScheduler.add(experimentInit);
flowScheduler.add(loading_trialRoutineBegin());
flowScheduler.add(loading_trialRoutineEachFrame());
flowScheduler.add(loading_trialRoutineEnd());
flowScheduler.add(webcam_trialRoutineBegin());
flowScheduler.add(webcam_trialRoutineEachFrame());
flowScheduler.add(webcam_trialRoutineEnd());
flowScheduler.add(intro_calibatrion_trialRoutineBegin());
flowScheduler.add(intro_calibatrion_trialRoutineEachFrame());
flowScheduler.add(intro_calibatrion_trialRoutineEnd());
flowScheduler.add(initializeEyetrackingRoutineBegin());
flowScheduler.add(initializeEyetrackingRoutineEachFrame());
flowScheduler.add(initializeEyetrackingRoutineEnd());
flowScheduler.add(inst1RoutineBegin());
flowScheduler.add(inst1RoutineEachFrame());
flowScheduler.add(inst1RoutineEnd());
flowScheduler.add(calibrationIntroRoutineBegin());
flowScheduler.add(calibrationIntroRoutineEachFrame());
flowScheduler.add(calibrationIntroRoutineEnd());
const trialsLoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(trialsLoopBegin(trialsLoopScheduler));
flowScheduler.add(trialsLoopScheduler);
flowScheduler.add(trialsLoopEnd);
flowScheduler.add(tracking_trialRoutineBegin());
flowScheduler.add(tracking_trialRoutineEachFrame());
flowScheduler.add(tracking_trialRoutineEnd());
flowScheduler.add(trackingTrialRoutineBegin());
flowScheduler.add(trackingTrialRoutineEachFrame());
flowScheduler.add(trackingTrialRoutineEnd());
flowScheduler.add(quitPsychoJS, '', true);
// quit if user presses Cancel in dialog box:
......@@ -58,7 +58,8 @@ psychoJS.start({
expName: expName,
expInfo: expInfo,
resources: [
{'name': 'calibration_trials.xlsx', 'path': 'calibration_trials.xlsx'}
{'name': 'calibration_trials.xlsx', 'path': 'calibration_trials.xlsx'},
{'name': 'webgazer-2.0.1.tp.js', 'path': 'webgazer-2.0.1.tp.js'}
]
});
......@@ -86,108 +87,117 @@ async function updateInfo() {
}
var loading_trialClock;
var loading_text;
var webcam_trialClock;
var intro_text;
var intro_calibatrion_trialClock;
var calibration_text;
var mouse_2;
var calibration_trialClock;
var initializeEyetrackingClock;
var webcamWarning;
var inst1Clock;
var instruction1Txt;
var inst1_resp;
var calibrationIntroClock;
var calibrationTxt;
var calibrationMouse;
var calibrationClock;
var calibration_square;
var mouse_3;
var tracking_trialClock;
var calibrationClick;
var trackingTrialClock;
var tracking_square;
var trackingTxt;
var tracking_resp;
var globalClock;
var routineTimer;
async function experimentInit() {
// Initialize components for Routine "loading_trial"
loading_trialClock = new util.Clock();
// Download the webgazer library and re-download seedrandom.js (since webgazer
// overrides it with a version that conflicts with PsychoJS)
psychoJS.downloadResources([
{ name: 'webgazer.js', path: 'js/webgazer-2.0.1.tp.js' },
{ name: 'seedrandom.js', path: 'https://cdnjs.cloudflare.com/ajax/libs/seedrandom/3.0.1/seedrandom.min.js' }
]);
// Initialize components for Routine "initializeEyetracking"
initializeEyetrackingClock = new util.Clock();
//initialize params of the webgazer package (used for eye tracking)
// Initialize x and y arrays; we use these to calculate running averages of
// current gaze position; the longer the window, the slower, but more fluent
// the updates
let averagingWindow = 10;
window.xGazes = new Array(averagingWindow ).fill(0);
window.yGazes = new Array(averagingWindow ).fill(0);
// Timestamp for last time eyes exited validation box
window.eyesExitedTimestamp= (new Date).getTime();
// No. of ms to keep webcam thumbnail visible after eyes returned into validation box
window.eyesReturnedDelay = 3000;
// DEBUG
window.psychoJS = psychoJS;
loading_text = new visual.TextStim({
webcamWarning = new visual.TextStim({
win: psychoJS.window,
name: 'loading_text',
text: 'Downloading additional resources. \n\nOne moment please...',
name: 'webcamWarning',
text: 'This experiment uses eye tracking. \n\nYou should see your web-browser request access to your webcam. You might need to click on this text to make that happen. Please permit access, and wait a little while. Your webcam video should appear in the top-left of the screen.',
font: 'Arial',
units: undefined,
pos: [0, 0], height: 0.1, wrapWidth: undefined, ori: 0,
color: new util.Color('white'), opacity: 1,
pos: [0, 0], height: 0.05, wrapWidth: undefined, ori: 0.0,
color: new util.Color('white'), opacity: undefined,
depth: -1.0
});
// Initialize components for Routine "webcam_trial"
webcam_trialClock = new util.Clock();
intro_text = new visual.TextStim({
// Initialize components for Routine "inst1"
inst1Clock = new util.Clock();
instruction1Txt = new visual.TextStim({
win: psychoJS.window,
name: 'intro_text',
text: 'demo_eye_tracking: starting webcam\n\nThis experiment demonstrates eye tracking via the webgazer library. \n\nYou should see your web-browser request access to your webcam. You might need to click on this text to make that happen. Please permit access, and wait a little while. Your webcam video should appear in the top-left of the screen.',
name: 'instruction1Txt',
text: 'Webgazer initialized. \nPress space to move on',
font: 'Arial',
units: undefined,
pos: [0, 0], height: 0.04, wrapWidth: undefined, ori: 0,
color: new util.Color('white'), opacity: 1,
depth: 0.0
pos: [0, 0], height: 0.05, wrapWidth: undefined, ori: 0.0,
color: new util.Color('white'), opacity: undefined,
depth: -1.0
});
// Initialize components for Routine "intro_calibatrion_trial"
intro_calibatrion_trialClock = new util.Clock();
calibration_text = new visual.TextStim({
inst1_resp = new core.Keyboard({psychoJS: psychoJS, clock: new util.Clock(), waitForStart: true});
// Initialize components for Routine "calibrationIntro"
calibrationIntroClock = new util.Clock();
calibrationTxt = new visual.TextStim({
win: psychoJS.window,
name: 'calibration_text',
text: "demo_eye_tracking: calibration\n\nNow we'll calibrate the eye tracker. Please try to keep your head still and within the rectangle you see in your webcam video. When you do so, the rectangle turns green.\n\nIn the next part of this experiment, the webcam video disappears. It will reappear when your head is too from the rectangle. If this happens, please move back into view. White squares appears at different locations on the screen. Please click each square with your mouse.\n\nClick anywhere to continue...",
name: 'calibrationTxt',
text: "OK great! we are almost ready to get started. \n\nFirst we need to calibrate the eye tracker. Please try to keep your head still. If you move your head too far away, you'r webcam will appear in the top left corner. If this happens, please move back into view. \n\nWhite squares will appear at different locations on the screen. Please click each square with your mouse.\n\nClick anywhere with the mouse to continue...",
font: 'Arial',
units: undefined,
pos: [0, 0], height: 0.04, wrapWidth: undefined, ori: 0,
color: new util.Color('white'), opacity: 1,
pos: [0, 0], height: 0.05, wrapWidth: undefined, ori: 0.0,
color: new util.Color('white'), opacity: undefined,
depth: 0.0
});
mouse_2 = new core.Mouse({
calibrationMouse = new core.Mouse({
win: psychoJS.window,
});
mouse_2.mouseClock = new util.Clock();
// Initialize components for Routine "calibration_trial"
calibration_trialClock = new util.Clock();
calibrationMouse.mouseClock = new util.Clock();
// Initialize components for Routine "calibration"
calibrationClock = new util.Clock();
calibration_square = new visual.Rect ({
win: psychoJS.window, name: 'calibration_square',
width: [0.022, 0.022][0], height: [0.022, 0.022][1],
ori: 0, pos: [0, 0],
lineWidth: 0, lineColor: new util.Color([1, 1, 1]),
fillColor: new util.Color([1, 1, 1]),
opacity: 1, depth: 0, interpolate: true,
width: [0.02, 0.02][0], height: [0.02, 0.02][1],
ori: 0.0, pos: [0, 0],
lineWidth: 1.0, lineColor: new util.Color('white'),
fillColor: new util.Color('white'),
opacity: undefined, depth: -1, interpolate: true,
});
mouse_3 = new core.Mouse({
calibrationClick = new core.Mouse({
win: psychoJS.window,
});
mouse_3.mouseClock = new util.Clock();
// Initialize components for Routine "tracking_trial"
tracking_trialClock = new util.Clock();
calibrationClick.mouseClock = new util.Clock();
// Initialize components for Routine "trackingTrial"
trackingTrialClock = new util.Clock();
tracking_square = new visual.Rect ({
win: psychoJS.window, name: 'tracking_square',
width: [0.02, 0.02][0], height: [0.02, 0.02][1],
ori: 0, pos: [0, 0],
lineWidth: undefined, lineColor: new util.Color([1, 1, 1]),
fillColor: new util.Color([(- 1), (- 1), (- 1)]),
opacity: 1, depth: 0, interpolate: true,
ori: 0.0, pos: [0, 0],
lineWidth: 1.0, lineColor: new util.Color('white'),
fillColor: new util.Color('white'),
opacity: undefined, depth: 0, interpolate: true,
});
trackingTxt = new visual.TextStim({
win: psychoJS.window,
name: 'trackingTxt',
text: 'Great! we are now tracking your eye movements! look around the screen to see how it works! \n\nPlease remember is important for you to keep your head still during the experiment. \n\nPress space to start',
font: 'Arial',
units: undefined,
pos: [0, 0], height: 0.05, wrapWidth: undefined, ori: 0.0,
color: new util.Color('white'), opacity: undefined,
depth: -1.0
});
tracking_resp = new core.Keyboard({psychoJS: psychoJS, clock: new util.Clock(), waitForStart: true});
// Create some handy timers
globalClock = new util.Clock(); // to track the time since experiment started
routineTimer = new util.CountdownTimer(); // to track time remaining of each (non-slip) routine
......@@ -199,22 +209,43 @@ async function experimentInit() {
var t;
var frameN;
var continueRoutine;
var loading_trialComponents;
function loading_trialRoutineBegin(snapshot) {
var initializeEyetrackingComponents;
function initializeEyetrackingRoutineBegin(snapshot) {
return async function () {
TrialHandler.fromSnapshot(snapshot); // ensure that .thisN vals are up to date
//------Prepare to start Routine 'loading_trial'-------
//------Prepare to start Routine 'initializeEyetracking'-------
t = 0;
loading_trialClock.reset(); // clock
initializeEyetrackingClock.reset(); // clock
frameN = -1;
continueRoutine = true; // until we're told otherwise
// update component parameters for each repeat
// Show webcam thumbnail and face feedback box, but not face overlay and gaze dot
window.webgazer.params.showVideoPreview = true;
window.webgazer.params.showFaceFeedbackBox = true;
window.webgazer.params.showFaceOverlay = false;
window.webgazer.params.showGazeDot = false
// Start eye tracking
window.webgazer
// Called on each eye tracking update
.setGazeListener(function(data, clock) {
if (data !== null) {
// Remove first element from gazes array, add current gaze at the end
window.xGazes.shift();
window.xGazes.push(data.x);
window.yGazes.shift();
window.yGazes.push(data.y);
}
})
.begin();
//.showPredictionPoints(true);
// keep track of which components have finished
loading_trialComponents = [];
loading_trialComponents.push(loading_text);
initializeEyetrackingComponents = [];
initializeEyetrackingComponents.push(webcamWarning);
loading_trialComponents.forEach( function(thisComponent) {
initializeEyetrackingComponents.forEach( function(thisComponent) {
if ('status' in thisComponent)
thisComponent.status = PsychoJS.Status.NOT_STARTED;
});
......@@ -223,23 +254,26 @@ function loading_trialRoutineBegin(snapshot) {
}
function loading_trialRoutineEachFrame() {
function initializeEyetrackingRoutineEachFrame() {
return async function () {
//------Loop for each frame of Routine 'loading_trial'-------
//------Loop for each frame of Routine 'initializeEyetracking'-------
// get current time
t = loading_trialClock.getTime();
t = initializeEyetrackingClock.getTime();
frameN = frameN + 1;// number of completed frames (so 0 is the first frame)
// update/draw components on each frame
// Continue once the webgazer global is available
continueRoutine = !window.hasOwnProperty('webgazer');
// Finish routine once everything is ready
continueRoutine =
!window.webgazer.isReady() ||
document.getElementById('webgazerFaceFeedbackBox') === null ||
document.getElementById('webgazerVideoFeed') === null;
// *loading_text* updates
if (t >= 0.0 && loading_text.status === PsychoJS.Status.NOT_STARTED) {
// *webcamWarning* updates
if (t >= 0.0 && webcamWarning.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
loading_text.tStart = t; // (not accounting for frame time here)
loading_text.frameNStart = frameN; // exact frame index
webcamWarning.tStart = t; // (not accounting for frame time here)
webcamWarning.frameNStart = frameN; // exact frame index
loading_text.setAutoDraw(true);
webcamWarning.setAutoDraw(true);
}
// check for quit (typically the Esc key)
......@@ -253,7 +287,7 @@ function loading_trialRoutineEachFrame() {
}
continueRoutine = false; // reverts to True if at least one component still running
loading_trialComponents.forEach( function(thisComponent) {
initializeEyetrackingComponents.forEach( function(thisComponent) {
if ('status' in thisComponent && thisComponent.status !== PsychoJS.Status.FINISHED) {
continueRoutine = true;
}
......@@ -269,15 +303,15 @@ function loading_trialRoutineEachFrame() {
}
function loading_trialRoutineEnd() {
function initializeEyetrackingRoutineEnd() {
return async function () {
//------Ending Routine 'loading_trial'-------
loading_trialComponents.forEach( function(thisComponent) {
//------Ending Routine 'initializeEyetracking'-------
initializeEyetrackingComponents.forEach( function(thisComponent) {
if (typeof thisComponent.setAutoDraw === 'function') {
thisComponent.setAutoDraw(false);
}
});
// the Routine "loading_trial" was not non-slip safe, so reset the non-slip timer
// the Routine "initializeEyetracking" was not non-slip safe, so reset the non-slip timer
routineTimer.reset();
return Scheduler.Event.NEXT;
......@@ -285,42 +319,29 @@ function loading_trialRoutineEnd() {
}
var webcam_trialComponents;
function webcam_trialRoutineBegin(snapshot) {
var _inst1_resp_allKeys;
var inst1Components;
function inst1RoutineBegin(snapshot) {
return async function () {
TrialHandler.fromSnapshot(snapshot); // ensure that .thisN vals are up to date
//------Prepare to start Routine 'webcam_trial'-------
//------Prepare to start Routine 'inst1'-------
t = 0;
webcam_trialClock.reset(); // clock
inst1Clock.reset(); // clock
frameN = -1;
continueRoutine = true; // until we're told otherwise
// update component parameters for each repeat
// Show webcam thumbnail and face feedback box, but not face overlay and gaze dot
window.webgazer.params.showVideoPreview = true;
window.webgazer.params.showFaceFeedbackBox = true;
window.webgazer.params.showFaceOverlay = false;
window.webgazer.params.showGazeDot = false
// Start eye tracking
window.webgazer
// Called on each eye tracking update
.setGazeListener(function(data, clock) {
if (data !== null) {
// Remove first element from gazes array, add current gaze at the end
window.xGazes.shift();
window.xGazes.push(data.x);
window.yGazes.shift();
window.yGazes.push(data.y);
}
})
.begin();
//.showPredictionPoints(true);
document.getElementById('webgazerFaceFeedbackBox').style.display = 'none';
document.getElementById('webgazerVideoFeed').style.display = 'none';
inst1_resp.keys = undefined;
inst1_resp.rt = undefined;
_inst1_resp_allKeys = [];
// keep track of which components have finished
webcam_trialComponents = [];
webcam_trialComponents.push(intro_text);
inst1Components = [];
inst1Components.push(instruction1Txt);
inst1Components.push(inst1_resp);
webcam_trialComponents.forEach( function(thisComponent) {
inst1Components.forEach( function(thisComponent) {
if ('status' in thisComponent)
thisComponent.status = PsychoJS.Status.NOT_STARTED;
});
......@@ -329,28 +350,47 @@ function webcam_trialRoutineBegin(snapshot) {
}
function webcam_trialRoutineEachFrame() {
function inst1RoutineEachFrame() {
return async function () {
//------Loop for each frame of Routine 'webcam_trial'-------
//------Loop for each frame of Routine 'inst1'-------
// get current time
t = webcam_trialClock.getTime();
t = inst1Clock.getTime();
frameN = frameN + 1;// number of completed frames (so 0 is the first frame)
// update/draw components on each frame
// *intro_text* updates
if (t >= 0.0 && intro_text.status === PsychoJS.Status.NOT_STARTED) {
// *instruction1Txt* updates
if (t >= 0.0 && instruction1Txt.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
intro_text.tStart = t; // (not accounting for frame time here)
intro_text.frameNStart = frameN; // exact frame index
instruction1Txt.tStart = t; // (not accounting for frame time here)
instruction1Txt.frameNStart = frameN; // exact frame index
intro_text.setAutoDraw(true);
instruction1Txt.setAutoDraw(true);
}
// Finish routine once everything is ready
continueRoutine =
!window.webgazer.isReady() ||
document.getElementById('webgazerFaceFeedbackBox') === null ||
document.getElementById('webgazerVideoFeed') === null;
// *inst1_resp* updates
if (t >= 0.0 && inst1_resp.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
inst1_resp.tStart = t; // (not accounting for frame time here)
inst1_resp.frameNStart = frameN; // exact frame index
// keyboard checking is just starting
psychoJS.window.callOnFlip(function() { inst1_resp.clock.reset(); }); // t=0 on next screen flip
psychoJS.window.callOnFlip(function() { inst1_resp.start(); }); // start on screen flip
psychoJS.window.callOnFlip(function() { inst1_resp.clearEvents(); });
}
if (inst1_resp.status === PsychoJS.Status.STARTED) {
let theseKeys = inst1_resp.getKeys({keyList: ['space'], waitRelease: false});
_inst1_resp_allKeys = _inst1_resp_allKeys.concat(theseKeys);
if (_inst1_resp_allKeys.length > 0) {
inst1_resp.keys = _inst1_resp_allKeys[_inst1_resp_allKeys.length - 1].name; // just the last key pressed
inst1_resp.rt = _inst1_resp_allKeys[_inst1_resp_allKeys.length - 1].rt;
// a response ends the routine
continueRoutine = false;
}
}
// check for quit (typically the Esc key)
if (psychoJS.experiment.experimentEnded || psychoJS.eventManager.getKeys({keyList:['escape']}).length > 0) {
return quitPsychoJS('The [Escape] key was pressed. Goodbye!', false);
......@@ -362,7 +402,7 @@ function webcam_trialRoutineEachFrame() {
}
continueRoutine = false; // reverts to True if at least one component still running
webcam_trialComponents.forEach( function(thisComponent) {
inst1Components.forEach( function(thisComponent) {
if ('status' in thisComponent && thisComponent.status !== PsychoJS.Status.FINISHED) {
continueRoutine = true;
}
......@@ -378,15 +418,22 @@ function webcam_trialRoutineEachFrame() {
}
function webcam_trialRoutineEnd() {
function inst1RoutineEnd() {
return async function () {
//------Ending Routine 'webcam_trial'-------
webcam_trialComponents.forEach( function(thisComponent) {
//------Ending Routine 'inst1'-------
inst1Components.forEach( function(thisComponent) {
if (typeof thisComponent.setAutoDraw === 'function') {
thisComponent.setAutoDraw(false);
}
});
// the Routine "webcam_trial" was not non-slip safe, so reset the non-slip timer
psychoJS.experiment.addData('inst1_resp.keys', inst1_resp.keys);
if (typeof inst1_resp.keys !== 'undefined') { // we had a response
psychoJS.experiment.addData('inst1_resp.rt', inst1_resp.rt);
routineTimer.reset();
}
inst1_resp.stop();
// the Routine "inst1" was not non-slip safe, so reset the non-slip timer
routineTimer.reset();
return Scheduler.Event.NEXT;
......@@ -395,25 +442,25 @@ function webcam_trialRoutineEnd() {
var gotValidClick;
var intro_calibatrion_trialComponents;
function intro_calibatrion_trialRoutineBegin(snapshot) {
var calibrationIntroComponents;
function calibrationIntroRoutineBegin(snapshot) {
return async function () {
TrialHandler.fromSnapshot(snapshot); // ensure that .thisN vals are up to date
//------Prepare to start Routine 'intro_calibatrion_trial'-------
//------Prepare to start Routine 'calibrationIntro'-------
t = 0;
intro_calibatrion_trialClock.reset(); // clock
calibrationIntroClock.reset(); // clock
frameN = -1;
continueRoutine = true; // until we're told otherwise
// update component parameters for each repeat
// setup some python lists for storing info about the mouse_2
// setup some python lists for storing info about the calibrationMouse
gotValidClick = false; // until a click is received
// keep track of which components have finished
intro_calibatrion_trialComponents = [];
intro_calibatrion_trialComponents.push(calibration_text);
intro_calibatrion_trialComponents.push(mouse_2);
calibrationIntroComponents = [];
calibrationIntroComponents.push(calibrationTxt);
calibrationIntroComponents.push(calibrationMouse);
intro_calibatrion_trialComponents.forEach( function(thisComponent) {
calibrationIntroComponents.forEach( function(thisComponent) {
if ('status' in thisComponent)
thisComponent.status = PsychoJS.Status.NOT_STARTED;
});
......@@ -424,35 +471,35 @@ function intro_calibatrion_trialRoutineBegin(snapshot) {
var prevButtonState;
var _mouseButtons;
function intro_calibatrion_trialRoutineEachFrame() {
function calibrationIntroRoutineEachFrame() {
return async function () {
//------Loop for each frame of Routine 'intro_calibatrion_trial'-------
//------Loop for each frame of Routine 'calibrationIntro'-------
// get current time
t = intro_calibatrion_trialClock.getTime();
t = calibrationIntroClock.getTime();
frameN = frameN + 1;// number of completed frames (so 0 is the first frame)
// update/draw components on each frame
// *calibration_text* updates
if (t >= 0.0 && calibration_text.status === PsychoJS.Status.NOT_STARTED) {
// *calibrationTxt* updates
if (t >= 0.0 && calibrationTxt.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
calibration_text.tStart = t; // (not accounting for frame time here)
calibration_text.frameNStart = frameN; // exact frame index
calibrationTxt.tStart = t; // (not accounting for frame time here)
calibrationTxt.frameNStart = frameN; // exact frame index
calibration_text.setAutoDraw(true);
calibrationTxt.setAutoDraw(true);
}
// *mouse_2* updates
if (t >= 0.0 && mouse_2.status === PsychoJS.Status.NOT_STARTED) {
// *calibrationMouse* updates
if (t >= 0.0 && calibrationMouse.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
mouse_2.tStart = t; // (not accounting for frame time here)
mouse_2.frameNStart = frameN; // exact frame index
calibrationMouse.tStart = t; // (not accounting for frame time here)
calibrationMouse.frameNStart = frameN; // exact frame index
mouse_2.status = PsychoJS.Status.STARTED;
mouse_2.mouseClock.reset();
prevButtonState = mouse_2.getPressed(); // if button is down already this ISN'T a new click
calibrationMouse.status = PsychoJS.Status.STARTED;
calibrationMouse.mouseClock.reset();
prevButtonState = calibrationMouse.getPressed(); // if button is down already this ISN'T a new click
}
if (mouse_2.status === PsychoJS.Status.STARTED) { // only update if started and not finished!
_mouseButtons = mouse_2.getPressed();
if (calibrationMouse.status === PsychoJS.Status.STARTED) { // only update if started and not finished!
_mouseButtons = calibrationMouse.getPressed();
if (!_mouseButtons.every( (e,i,) => (e == prevButtonState[i]) )) { // button state changed?
prevButtonState = _mouseButtons;
if (_mouseButtons.reduce( (e, acc) => (e+acc) ) > 0) { // state changed to a new click
......@@ -472,7 +519,7 @@ function intro_calibatrion_trialRoutineEachFrame() {
}
continueRoutine = false; // reverts to True if at least one component still running
intro_calibatrion_trialComponents.forEach( function(thisComponent) {
calibrationIntroComponents.forEach( function(thisComponent) {
if ('status' in thisComponent && thisComponent.status !== PsychoJS.Status.FINISHED) {
continueRoutine = true;
}
......@@ -489,23 +536,23 @@ function intro_calibatrion_trialRoutineEachFrame() {
var _mouseXYs;
function intro_calibatrion_trialRoutineEnd() {
function calibrationIntroRoutineEnd() {
return async function () {
//------Ending Routine 'intro_calibatrion_trial'-------
intro_calibatrion_trialComponents.forEach( function(thisComponent) {
//------Ending Routine 'calibrationIntro'-------
calibrationIntroComponents.forEach( function(thisComponent) {
if (typeof thisComponent.setAutoDraw === 'function') {
thisComponent.setAutoDraw(false);
}
});
// store data for psychoJS.experiment (ExperimentHandler)
_mouseXYs = mouse_2.getPos();
_mouseButtons = mouse_2.getPressed();
psychoJS.experiment.addData('mouse_2.x', _mouseXYs[0]);
psychoJS.experiment.addData('mouse_2.y', _mouseXYs[1]);
psychoJS.experiment.addData('mouse_2.leftButton', _mouseButtons[0]);
psychoJS.experiment.addData('mouse_2.midButton', _mouseButtons[1]);
psychoJS.experiment.addData('mouse_2.rightButton', _mouseButtons[2]);
// the Routine "intro_calibatrion_trial" was not non-slip safe, so reset the non-slip timer
_mouseXYs = calibrationMouse.getPos();
_mouseButtons = calibrationMouse.getPressed();
psychoJS.experiment.addData('calibrationMouse.x', _mouseXYs[0]);
psychoJS.experiment.addData('calibrationMouse.y', _mouseXYs[1]);
psychoJS.experiment.addData('calibrationMouse.leftButton', _mouseButtons[0]);
psychoJS.experiment.addData('calibrationMouse.midButton', _mouseButtons[1]);
psychoJS.experiment.addData('calibrationMouse.rightButton', _mouseButtons[2]);
// the Routine "calibrationIntro" was not non-slip safe, so reset the non-slip timer
routineTimer.reset();
return Scheduler.Event.NEXT;
......@@ -535,9 +582,9 @@ function trialsLoopBegin(trialsLoopScheduler, snapshot) {
const snapshot = trials.getSnapshot();
trialsLoopScheduler.add(importConditions(snapshot));
trialsLoopScheduler.add(calibration_trialRoutineBegin(snapshot));
trialsLoopScheduler.add(calibration_trialRoutineEachFrame());
trialsLoopScheduler.add(calibration_trialRoutineEnd());
trialsLoopScheduler.add(calibrationRoutineBegin(snapshot));
trialsLoopScheduler.add(calibrationRoutineEachFrame());
trialsLoopScheduler.add(calibrationRoutineEnd());
trialsLoopScheduler.add(endLoopIteration(trialsLoopScheduler, snapshot));
});
......@@ -553,20 +600,19 @@ async function trialsLoopEnd() {
}
var calibration_trialComponents;
function calibration_trialRoutineBegin(snapshot) {
var callib_color;
var calibrationComponents;
function calibrationRoutineBegin(snapshot) {
return async function () {
TrialHandler.fromSnapshot(snapshot); // ensure that .thisN vals are up to date
//------Prepare to start Routine 'calibration_trial'-------
//------Prepare to start Routine 'calibration'-------
t = 0;
calibration_trialClock.reset(); // clock
calibrationClock.reset(); // clock
frameN = -1;
continueRoutine = true; // until we're told otherwise
routineTimer.add(3.500000);
// update component parameters for each repeat
// setup some python lists for storing info about the mouse_3
mouse_3.clicked_name = [];
gotValidClick = false; // until a click is received
// Position calibration_square using width and height of window
var canvas = psychoJS.window.size;
var scaling = [
......@@ -578,13 +624,18 @@ function calibration_trialRoutineBegin(snapshot) {
calibration_y * scaling[1]
];
console.log(newPos);
calibration_square.setPos(newPos);
//calibration_square.setPos(newPos);
callib_color = 'white';
calibration_square.setPos([calibration_x, calibration_y]);
// setup some python lists for storing info about the calibrationClick
calibrationClick.clicked_name = [];
gotValidClick = false; // until a click is received
// keep track of which components have finished
calibration_trialComponents = [];
calibration_trialComponents.push(calibration_square);
calibration_trialComponents.push(mouse_3);
calibrationComponents = [];
calibrationComponents.push(calibration_square);
calibrationComponents.push(calibrationClick);