Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add num blinks #526

Merged
merged 11 commits into from
Aug 22, 2024
8 changes: 5 additions & 3 deletions src/Electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import path from "node:path";

import { BrowserWindow, app, dialog, ipcMain } from "electron";
import log from "electron-log";
import _ from "lodash";

import { getPort, sendToPort } from "./lib/serialport";

Expand Down Expand Up @@ -157,7 +156,7 @@ function handleGetCredentials() {
* @returns {Boolean} Whether or not the EEG machine is connected to the computer
*/
function handleCheckSerialPort() {
setUpPort().then(() => handleEventSend(TRIGGER_CODES.eventCodes.test_connect));
setUpPort().then(() => handleEventSend(TRIGGER_CODES.eventCodes.test_connect.code));
}

/**
Expand All @@ -167,7 +166,10 @@ function handleCheckSerialPort() {
*/
function handlePhotodiodeTrigger(event, code) {
if (code !== undefined) {
log.info(`Event: ${_.invert(TRIGGER_CODES.eventCodes)[code]}, code: ${code}`);
const eventName = Object.keys(TRIGGER_CODES.eventCodes).find(
(key) => TRIGGER_CODES.eventCodes[key].code === code
);
log.info(`Event: ${eventName}, code: ${code}`);
handleEventSend(code);
} else {
log.warn("Photodiode event triggered but no code was sent");
Expand Down
20 changes: 16 additions & 4 deletions src/config/eventCodes.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"fixation": 1,
"honeycomb": 2,
"open_task": 18,
"test_connect": 32
"fixation": {
"code": 1,
"numBlinks": 1
},
"honeycomb": {
"code": 2,
"numBlinks": 2
},
"open_task": {
"code": 18,
"numBlinks": 18
},
"test_connect": {
"code": 32,
"numBlinks": 32
}
}
4 changes: 2 additions & 2 deletions src/config/trigger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import event_codes from "./eventCodes.json";
import eventCodes from "./eventCodes.json";

// TODO @brown-ccv #333: Nest this data under "trigger_box" equipment in config.json

Expand All @@ -15,7 +15,7 @@ export const comName = import.meta.env.EVENT_MARKER_COM_NAME || "COM3";

/** Custom codes for specific task events - used to identify the trials */
// TODO @brown-ccv #354: Each event should have a code, name, and numBlinks
export const eventCodes = event_codes;
export { eventCodes };

// TODO: We should think of a cleaner way of exporting all this
export const trigger = {
Expand Down
4 changes: 2 additions & 2 deletions src/experiment/procedures/honeycombProcedure.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export function buildHoneycombProcedure(jsPsych) {
choices: honeycombSettings.timeline_variables.map((variable) => variable.correct_response),
data: {
// Record the correct_response passed as a timeline variable
code: eventCodes.honeycomb,
code: eventCodes.honeycomb.code,
correct_response: jsPsych.timelineVariable("correct_response"),
},
on_load: function () {
// Conditionally flashes the photodiode when the trial first loads
if (ENV.USE_PHOTODIODE) pdSpotEncode(eventCodes.honeycomb);
if (ENV.USE_PHOTODIODE) pdSpotEncode(eventCodes.honeycomb.code);
},
// Add a boolean value ("correct") to the data - if the user responded with the correct key or not
on_finish: function (data) {
Expand Down
2 changes: 1 addition & 1 deletion src/experiment/trials/fixation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { div } from "../../lib/markup/tags";
*/
export function buildFixationTrial(jsPsych) {
const fixationSettings = SETTINGS.fixation;
const fixationCode = eventCodes.fixation;
const fixationCode = eventCodes.fixation.code;

return {
type: htmlKeyboardResponse,
Expand Down
2 changes: 1 addition & 1 deletion src/experiment/trials/holdUpMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export const holdUpMarkerTrial = {
choices: [LANGUAGE.prompts.continue.button],
on_load: function () {
// Conditionally flash the photodiode when the trial first loads
if (ENV.USE_PHOTODIODE) pdSpotEncode(eventCodes.test_connect);
if (ENV.USE_PHOTODIODE) pdSpotEncode(eventCodes.test_connect.code);
},
};
2 changes: 1 addition & 1 deletion src/experiment/trials/honeycombTrials.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function buildDebriefTrial(jsPsych) {
* By accessing jsPsych inside the "stimulus" callback we have access to all of the data when this trial is run
* Calling jsPsych outside of the trial object would be executed to soon (when the experiment first starts) and would therefore have no data
*/
const responseTrials = jsPsych.data.get().filter({ code: eventCodes.honeycomb });
const responseTrials = jsPsych.data.get().filter({ code: eventCodes.honeycomb.code });
const correct_trials = responseTrials.filter({ correct: true });
const accuracy = Math.round((correct_trials.count() / responseTrials.count()) * 100);
const reactionTime = Math.round(correct_trials.select("rt").mean());
Expand Down
2 changes: 1 addition & 1 deletion src/experiment/trials/initPhotodiode.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export const initPhotodiodeTrial = {
}

// Flashes the photodiode when the trial first loads
pdSpotEncode(eventCodes.open_task);
pdSpotEncode(eventCodes.open_task.code);
},
};
Loading