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
10 changes: 6 additions & 4 deletions src/Electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since codes are now embedded under the settings.json, I had to import the entire settings object into the trigger object to access the code

*/
function handleSetTrigger(event, trigger) {
TRIGGER_CODES = trigger;
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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");
Expand Down
6 changes: 0 additions & 6 deletions src/config/eventCodes.json

This file was deleted.

16 changes: 14 additions & 2 deletions src/config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -16,6 +18,16 @@
"stimulus": "assets/images/orange.png",
"correct_response": "j"
}
]
],
"code": 2,
"numBlinks": 2
},
"open_task": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inserted these 2 events from the original event codes file

"code": 18,
"numBlinks": 18
},
"test_connect": {
"code": 32,
"numBlinks": 32
}
}
8 changes: 2 additions & 6 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 settings from "./settings.json"; // includes event codes for each event

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

Expand All @@ -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,
};
5 changes: 2 additions & 3 deletions src/experiment/procedures/honeycombProcedure.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
RobertGemmaJr marked this conversation as resolved.
Show resolved Hide resolved
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) {
Expand Down
3 changes: 1 addition & 2 deletions src/experiment/trials/fixation.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 2 additions & 3 deletions src/experiment/trials/holdUpMarker.js
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
},
};
3 changes: 1 addition & 2 deletions src/experiment/trials/honeycombTrials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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());
Expand Down
5 changes: 2 additions & 3 deletions src/experiment/trials/initPhotodiode.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -18,6 +17,6 @@ export const initPhotodiodeTrial = {
}

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