Skip to content

Commit

Permalink
fix option to setup LSL stream
Browse files Browse the repository at this point in the history
  • Loading branch information
timonmerk committed Sep 11, 2024
1 parent d36d855 commit e274f66
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 17 deletions.
Binary file modified gui_dev/bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion gui_dev/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"moduleResolution": "node",
"paths": {
"@/*": ["./src/*"]
}
},
"jsx": "react-jsx",
}
}
4 changes: 2 additions & 2 deletions gui_dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@mui/icons-material": "^5.16.7",
"@mui/material": "^5.16.7",
"immer": "^10.1.1",
"plotly.js-basic-dist-min": "^2.35.0",
"plotly.js-basic-dist-min": "^2.35.2",
"react": "next",
"react-dom": "next",
"react-icons": "^5.3.0",
Expand All @@ -36,6 +36,6 @@
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.11",
"prettier": "^3.3.3",
"vite": "^5.4.3"
"vite": "^5.4.4"
}
}
16 changes: 9 additions & 7 deletions gui_dev/src/pages/SourceSelection/SourceSelection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ export const SourceSelection = () => {
syncError,
setWorkflowStage,
isStageActive,
samplingRateValue,
lineNoiseValue,
samplingRateFeaturesValue,
//samplingRateValue,
//lineNoiseValue,
//samplingRateFeaturesValue,
streamParameters,
setSamplingRateValue,
setLineNoiseValue,
setSamplingRateFeaturesValue,
Expand All @@ -62,17 +63,17 @@ export const SourceSelection = () => {

<MyTextField
label="sfreq"
value={samplingRateValue}
value={streamParameters.samplingRateValue}
onChange={(event) => handleOnChange(event, setSamplingRateValue)}
/>
<MyTextField
label="line noise"
value={lineNoiseValue}
value={streamParameters.lineNoiseValue}
onChange={(event) => handleOnChange(event, setLineNoiseValue)}
/>
<MyTextField
label="sfreq features"
value={samplingRateFeaturesValue}
value={streamParameters.samplingRateFeaturesValue}
onChange={(event) =>
handleOnChange(event, setSamplingRateFeaturesValue)
}
Expand Down Expand Up @@ -140,7 +141,8 @@ export const SourceSelection = () => {
color="primary"
component={RouterLink}
to="/channels"
disabled={canProceedToChannelSelection}
//disabled={canProceedToChannelSelection} // TODO: This doesn't work with the current setup, no idea why... the state values are set correctly
// load here the channels and display them from the stream
>
Select Channels
</Button>
Expand Down
30 changes: 25 additions & 5 deletions gui_dev/src/pages/SourceSelection/StreamSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ export const StreamSelector = () => {
const [searchingStreams, setSearchingStreams] = useState(false);
const [selectedStreamName, setSelectedStreamName] = useState("");
const [isStreamNameValid, setIsStreamNameValid] = useState(false);
const { lslSource, selectLSLStream, fetchLSLStreams, connectToLSLStream } =
const { lslSource, selectLSLStream, fetchLSLStreams, initializeLSLStream,
streamParameters, setLineNoiseValue, setSamplingRateFeaturesValue,
setSamplingRateValue, setStreamParametersAllValid} =
useSessionStore((state) => ({
lslSource: state.lslSource,
selectLSLStream: state.selectLSLStream,
fetchLSLStreams: state.fetchLSLStreams,
connectToLSLStream: state.connectToLSLStream,
initializeLSLStream: state.initializeLSLStream,
streamParameters: state.streamParameters,
setLineNoiseValue: state.setLineNoiseValue,
setSamplingRateFeaturesValue: state.setSamplingRateFeaturesValue,
setSamplingRateValue: state.setSamplingRateValue,
setStreamParametersAllValid: state.setStreamParametersAllValid,
}));

const validateStreamName = (name) => {
Expand All @@ -40,8 +47,18 @@ export const StreamSelector = () => {
return () => clearTimeout(timer);
}, [selectedStreamName, validateStreamName]);

const handleSelectStream = (streamName) => {
const handleSelectStream = (streamName, sfreq) => {
setSelectedStreamName(streamName);
// set the samplingRateValue of the streamParameters
//streamParameters.samplingRateValue = sfreq;
// streamParameters.samplingRateFeaturesValue = 10;
// streamParameters.lineNoiseValue = 50;
// streamParameters.allValid = true;
setLineNoiseValue(50);
setSamplingRateFeaturesValue(10);
setSamplingRateValue(sfreq);
setStreamParametersAllValid(true);

setIsStreamNameValid(true);
};

Expand Down Expand Up @@ -69,7 +86,10 @@ export const StreamSelector = () => {
{lslSource.availableStreams.map((stream, index) => (
<TableRow
key={index}
onClick={() => handleSelectStream(stream.name)}
onClick={() => handleSelectStream(
stream.name,
stream.sfreq
)}
sx={{
cursor: "pointer",
"&:hover": { backgroundColor: "#505050" },
Expand Down Expand Up @@ -101,7 +121,7 @@ export const StreamSelector = () => {

const handleConnectStream = async () => {
if (isStreamNameValid) {
await connectToLSLStream(selectedStreamName);
await initializeLSLStream(); // selectedStreamName
}
};

Expand Down
34 changes: 32 additions & 2 deletions gui_dev/src/stores/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ export const useSessionStore = create(
allValid: false,
},

// write function to set streamParameters
setSamplingRateValue: (value) => {
set((state) => {
state.streamParameters.samplingRateValue = value;
});
},
setLineNoiseValue: (value) => {
set((state) => {
state.streamParameters.lineNoiseValue = value;
});
},
setSamplingRateFeaturesValue: (value) => {
set((state) => {
state.streamParameters.samplingRateFeaturesValue = value;
});
},
setStreamParametersAllValid: (value) => {
set((state) => {
state.streamParameters.allValid = value;
});
},

// Channel selection
channels: null,
selectedChannels: [],
Expand Down Expand Up @@ -217,15 +239,23 @@ export const useSessionStore = create(
"Content-Type": "application/json",
},
body: JSON.stringify({
stream_name: lslSource.selectedStream.name,
stream_name: lslSource.availableStreams[0].name,
sampling_rate_features: streamParameters.samplingRateValue,
line_noise: streamParameters.linenoiseValue,
line_noise: streamParameters.lineNoiseValue,
}),
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

// enable the next button
set({
sourceType: "lsl",
isSourceValid: true,
})

// make a alert that says that the stream is initialized in js
},

// Computed properties
Expand Down

0 comments on commit e274f66

Please sign in to comment.