-
Notifications
You must be signed in to change notification settings - Fork 8
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
ref: Refactor photodiodeSpot
and photodiodeGhostBox
#337
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2ff0b89
ref: Renames photodiodeSpot and pdSpotEncode
RobertGemmaJr 73c6178
ref: Export photodiodeGhostBox as a constant, not a function
RobertGemmaJr 9b60a97
chore: TODO
RobertGemmaJr 3e361ac
chore: TODO number
RobertGemmaJr 68c7f4b
Merge branch 'chore-issues' into ref-photodiode_spot
RobertGemmaJr e84cb53
chore: TODO numbers
RobertGemmaJr 850a0c8
Merge branch 'main' into ref-photodiode_spot
RobertGemmaJr e8672ea
Merge branch 'ref-old-actions' into ref-photodiode_spot
RobertGemmaJr 83400fb
chore: TODO
RobertGemmaJr bab5efb
Merge branch 'main' into ref-photodiode_spot
RobertGemmaJr 2ff0fae
Merge branch 'main' into ref-photodiode_spot
RobertGemmaJr 6263182
style: Pass no-unused-vars as a warning
RobertGemmaJr 9660a15
Merge branch 'feat-v3.3' into ref-photodiode_spot
RobertGemmaJr 3e446e6
chore: lock
RobertGemmaJr df9045e
chore: comments
RobertGemmaJr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,30 +3,40 @@ import { config } from "../../config/main"; | |
import { div, span } from "./tags"; | ||
|
||
/** | ||
* Displays a box in the bottom right corner of the screen with the id "photodiode-spot" | ||
* The box is only visible if config.USE_PHOTODIODE is true | ||
* Markup for a box in the bottom right corner of the screen and a photodiode spot inside the ghost box | ||
* | ||
* Note the box will only be visible if USE_PHOTODIODE is true | ||
* Note that this trial is only available when running in Electron | ||
*/ | ||
function photodiodeGhostBox() { | ||
const spot = span("", { id: "photodiode-spot", class: "photodiode-spot" }); | ||
return div(spot, { | ||
id: "photodiode-box", | ||
class: config.USE_PHOTODIODE ? "photodiode-box visible" : "photodiode-box invisible", | ||
}); | ||
} | ||
const photodiodeGhostBox = div(span("", { id: "photodiode-spot", class: "photodiode-spot" }), { | ||
id: "photodiode-box", | ||
// TODO #355: Conditional check should be at the task level | ||
class: config.USE_PHOTODIODE ? "photodiode-box visible" : "photodiode-box invisible", | ||
}); | ||
|
||
/** | ||
* Repeatedly flashes a spot inside the photodiodeGhostBox and communicates with the USB port | ||
* Conditionally flashes a spot inside the photodiodeGhostBox and sends event codes to the serial port | ||
* | ||
* Note that this trial is only available when running in Electron | ||
* | ||
* @param {number} taskCode The code to be sent to the USB port (Electron only) | ||
* Note that this function must be executed inside the "on_load" callback of a trial | ||
* @param {number} taskCode The unique code for the given trial on which this function executes | ||
*/ | ||
function photodiodeSpot(taskCode) { | ||
function pdSpotEncode(taskCode) { | ||
if (!config.USE_ELECTRON) { | ||
throw new Error("photodiodeSpot trial is only available when running inside Electron"); | ||
} | ||
|
||
// Pulse the spot color from black to white | ||
if (config.USE_PHOTODIODE) { | ||
const blinkTime = 40; // TODO #333: Get blink time from config.json (40ms is the default) | ||
let numBlinks = taskCode; // TODO #354: Encode numBlinks in the event marker config | ||
repeatPulseFor(blinkTime, numBlinks); | ||
window.electronAPI.photodiodeTrigger(taskCode); | ||
} | ||
|
||
/** | ||
* Pulses the photodiode spot from black (on) to white (off) and runs a callback function | ||
* @param {number} ms The amount of time to flash the photodiode spot | ||
* @param {function} callback A callback function to execute after the flash | ||
*/ | ||
// TODO #331: Single photodiode color, pulse between visible and invisible here | ||
function pulseFor(ms, callback) { | ||
$(".photodiode-spot").css({ "background-color": "black" }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's jQuery in this??? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah! I'm afraid to touch it 😨 |
||
|
@@ -36,7 +46,11 @@ function photodiodeSpot(taskCode) { | |
}, ms); | ||
} | ||
|
||
// Repeat pulseFor i times | ||
/** | ||
* Recursive function that executes the pulseFor function i times | ||
* @param {number} ms The amount of time to flash the photodiode spot and wait before recursion | ||
* @param {number} i The number of times to repeat | ||
*/ | ||
function repeatPulseFor(ms, i) { | ||
if (i > 0) { | ||
pulseFor(ms, () => { | ||
|
@@ -46,14 +60,6 @@ function photodiodeSpot(taskCode) { | |
}); | ||
} | ||
} | ||
|
||
if (config.USE_PHOTODIODE) { | ||
// TODO #333: Pass blinkTime as config setting | ||
const blinkTime = 40; | ||
|
||
repeatPulseFor(blinkTime, taskCode); | ||
window.electronAPI.photodiodeTrigger(taskCode); | ||
} | ||
} | ||
|
||
export { photodiodeGhostBox, photodiodeSpot }; | ||
export { photodiodeGhostBox, pdSpotEncode }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
config
guaranteed to be defined when this is run? It always makes me a little nervous to put conditional stuff at the top level.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, but I agree I'd like to change it at some point.