diff --git a/src/Electron/main.js b/src/Electron/main.js index d25055d4e..193f6efaa 100644 --- a/src/Electron/main.js +++ b/src/Electron/main.js @@ -5,7 +5,6 @@ import { execSync } from "node:child_process"; import { BrowserWindow, app, dialog, ipcMain } from "electron"; import log from "electron-log"; -import _ from "lodash"; import { getPort, sendToPort } from "./lib/serialport"; @@ -127,9 +126,9 @@ function handleSetConfig(event, config) { * @param {Event} event The Electron renderer event * @param {Object} trigger The metadata for the event code trigger * @param {string} trigger.comName The COM name of the serial port - * @param {Object} trigger.eventCodes The list of possible event codes to be triggered * @param {string} trigger.productID The name of the product connected to the serial port * @param {string} trigger.vendorID The name of the vendor connected to the serial prot + * @param {Object} trigger.settings The list of possible event with relative event codes to be triggered */ function handleSetTrigger(event, trigger) { TRIGGER_CODES = trigger; @@ -176,7 +175,7 @@ async function handleGetCommit() { * @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.settings.test_connect.code)); } /** @@ -186,7 +185,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.settings).find( + (key) => TRIGGER_CODES.settings[key].code === code + ); + log.info(`Event: ${eventName}, code: ${code}`); handleEventSend(code); } else { log.warn("Photodiode event triggered but no code was sent"); diff --git a/src/config/eventCodes.json b/src/config/eventCodes.json deleted file mode 100644 index a4b83babe..000000000 --- a/src/config/eventCodes.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "fixation": 1, - "honeycomb": 2, - "open_task": 18, - "test_connect": 32 -} diff --git a/src/config/settings.json b/src/config/settings.json index d2a587e19..e42f523e6 100644 --- a/src/config/settings.json +++ b/src/config/settings.json @@ -2,7 +2,9 @@ "fixation": { "default_duration": 1000, "randomize_duration": true, - "durations": [250, 500, 750, 1000, 1250, 1500, 1750, 2000] + "durations": [250, 500, 750, 1000, 1250, 1500, 1750, 2000], + "code": 1, + "numBlinks": 1 }, "honeycomb": { "randomize_order": true, @@ -16,6 +18,16 @@ "stimulus": "assets/images/orange.png", "correct_response": "j" } - ] + ], + "code": 2, + "numBlinks": 2 + }, + "open_task": { + "code": 18, + "numBlinks": 18 + }, + "test_connect": { + "code": 32, + "numBlinks": 32 } } diff --git a/src/config/trigger.js b/src/config/trigger.js index cfa96d5e6..9102a56e5 100644 --- a/src/config/trigger.js +++ b/src/config/trigger.js @@ -1,4 +1,4 @@ -import event_codes from "./eventCodes.json"; +import settings from "./settings.json"; // includes event codes for each event // TODO @brown-ccv #333: Nest this data under "trigger_box" equipment in config.json @@ -13,14 +13,10 @@ export const productID = import.meta.env.EVENT_MARKER_PRODUCT_ID || ""; // export const comName = process.env.EVENT_MARKER_COM_NAME || "COM3"; 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; - // TODO: We should think of a cleaner way of exporting all this export const trigger = { vendorID, productID, comName, - eventCodes, + settings, }; diff --git a/src/experiment/procedures/honeycombProcedure.js b/src/experiment/procedures/honeycombProcedure.js index eb8bbfa56..35b51d488 100644 --- a/src/experiment/procedures/honeycombProcedure.js +++ b/src/experiment/procedures/honeycombProcedure.js @@ -1,7 +1,6 @@ import imageKeyboardResponse from "@jspsych/plugin-image-keyboard-response"; import { ENV, SETTINGS } from "../../config/"; -import { eventCodes } from "../../config/trigger"; import { pdSpotEncode, photodiodeGhostBox } from "../../lib/markup/photodiode"; import { buildFixationTrial } from "../trials/fixation"; import { getJsPsych } from "../../lib/utils"; @@ -39,12 +38,12 @@ export const buildHoneycombProcedure = () => { choices: honeycombSettings.timeline_variables.map((variable) => variable.correct_response), data: { // Record the correct_response passed as a timeline variable - code: eventCodes.honeycomb, + code: honeycombSettings.code, correct_response: getJsPsych().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(honeycombSettings.code); }, // Add a boolean value ("correct") to the data - if the user responded with the correct key or not on_finish: function (data) { diff --git a/src/experiment/trials/fixation.js b/src/experiment/trials/fixation.js index f6a07f0a4..fb9f4e535 100644 --- a/src/experiment/trials/fixation.js +++ b/src/experiment/trials/fixation.js @@ -1,13 +1,12 @@ import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response"; import { SETTINGS, ENV } from "../../config/"; -import { eventCodes } from "../../config/trigger"; import { pdSpotEncode, photodiodeGhostBox } from "../../lib/markup/photodiode"; import { div } from "../../lib/markup/tags"; import { getJsPsych } from "../../lib/utils"; const fixationSettings = SETTINGS.fixation; -const fixationCode = eventCodes.fixation; +const fixationCode = fixationSettings.code; /** * Builds a trial with a fixation dot and optional photodiode box. diff --git a/src/experiment/trials/holdUpMarker.js b/src/experiment/trials/holdUpMarker.js index 766c735f7..e8d713c8f 100644 --- a/src/experiment/trials/holdUpMarker.js +++ b/src/experiment/trials/holdUpMarker.js @@ -1,7 +1,6 @@ import htmlButtonResponse from "@jspsych/plugin-html-button-response"; -import { ENV, LANGUAGE } from "../../config/"; -import { eventCodes } from "../../config/trigger"; +import { ENV, LANGUAGE, SETTINGS } from "../../config/"; import { pdSpotEncode, photodiodeGhostBox } from "../../lib/markup/photodiode"; import { div, h1, p } from "../../lib/markup/tags"; @@ -27,6 +26,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(SETTINGS.test_connect.code); }, }; diff --git a/src/experiment/trials/honeycombTrials.js b/src/experiment/trials/honeycombTrials.js index de955fe9a..6203bea53 100644 --- a/src/experiment/trials/honeycombTrials.js +++ b/src/experiment/trials/honeycombTrials.js @@ -3,7 +3,6 @@ import instructionsResponse from "@jspsych/plugin-instructions"; import preloadResponse from "@jspsych/plugin-preload"; import { LANGUAGE, SETTINGS } from "../../config/"; -import { eventCodes } from "../../config/trigger"; import { b, div, image, p } from "../../lib/markup/tags"; import { getJsPsych } from "../../lib/utils"; @@ -61,7 +60,7 @@ export const buildDebriefTrial = { * 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 = getJsPsych().data.get().filter({ code: eventCodes.honeycomb }); + const responseTrials = getJsPsych().data.get().filter({ code: SETTINGS.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()); diff --git a/src/experiment/trials/initPhotodiode.js b/src/experiment/trials/initPhotodiode.js index 18177fdc8..f1fd51ed5 100644 --- a/src/experiment/trials/initPhotodiode.js +++ b/src/experiment/trials/initPhotodiode.js @@ -1,7 +1,6 @@ import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response"; -import { ENV } from "../../config/"; -import { eventCodes } from "../../config/trigger"; +import { ENV, SETTINGS } from "../../config/"; import { pdSpotEncode, photodiodeGhostBox } from "../../lib/markup/photodiode"; export const initPhotodiodeTrial = { @@ -18,6 +17,6 @@ export const initPhotodiodeTrial = { } // Flashes the photodiode when the trial first loads - pdSpotEncode(eventCodes.open_task); + pdSpotEncode(SETTINGS.open_task.code); }, };