Skip to content

Commit

Permalink
isPrepared and addstreamer
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Preumont committed Jul 24, 2023
1 parent b7c5e09 commit e6c9681
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions nodejs_package/brainflow/board-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class BoardControllerDLL extends BoardControllerFunctions {
this.dllPath = this.getDLLPath();
this.lib = this.getLib();

this.isPrepared = this.lib.func(CLike.is_prepared);
this.prepareSession = this.lib.func(CLike.prepare_session);
this.startStream = this.lib.func(CLike.start_stream);
this.getBoardDataCount = this.lib.func(CLike.get_board_data_count);
Expand All @@ -59,6 +60,7 @@ class BoardControllerDLL extends BoardControllerFunctions {
this.stopStream = this.lib.func(CLike.stop_stream);
this.getSamplingRate = this.lib.func(CLike.get_sampling_rate);
this.getEegChannels = this.lib.func(CLike.get_eeg_channels);
this.addStreamer = this.lib.func(CLike.add_streamer);
}

private getDLLPath() {
Expand Down Expand Up @@ -104,6 +106,22 @@ export class BoardShim {
this.boardController = new BoardControllerDLL();
}

public isPrepared(): boolean {
const prepared = [0];
const res = this.boardController.isPrepared(prepared, this.boardId, this.inputJson);
if (res !== BrainFlowExitCodes.STATUS_OK) {
throw new Error('Could not check prepared state');
}
return !!prepared[0];
}

public addStreamer(streamerParams: string, preset = BrainFlowPresets.DEFAULT_PRESET): void {
const res = this.boardController.addStreamer(streamerParams, preset, this.boardId, this.inputJson);
if (res !== BrainFlowExitCodes.STATUS_OK) {
throw new Error('Could not add streamer');
}
}

public prepareSession(): void {
const res = this.boardController.prepareSession(this.boardId, this.inputJson);
if (res !== BrainFlowExitCodes.STATUS_OK) {
Expand Down
9 changes: 9 additions & 0 deletions nodejs_package/brainflow/functions.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export enum BoardControllerCLikeFunctions {
prepare_session = 'int prepare_session (int board_id, const char *json_brainflow_input_params)',
release_all_sessions = 'int release_all_sessions ()',
release_session = 'int release_session (int board_id, const char *json_brainflow_input_params)',
add_streamer = 'int add_streamer (const char *streamer, int preset, int board_id, const char *json_brainflow_input_params)',

// '_Inout_' pointer -> dual input/output parameter.
is_prepared = 'int is_prepared (_Inout_ int *prepared, int board_id, const char *json_brainflow_input_params)',
get_board_data_count = 'int get_board_data_count (int preset, _Inout_ int *result, int board_id, const char *json_brainflow_input_params)',
get_board_data = 'int get_board_data (int data_count, int preset, _Inout_ double *data_buf, int board_id, const char *json_brainflow_input_params)',
get_num_rows = 'int get_num_rows (int board_id, int preset, _Inout_ int *num_rows)',
Expand All @@ -22,6 +24,13 @@ export enum BoardControllerCLikeFunctions {
}

export class BoardControllerFunctions {
addStreamer!: (
streamer: string,
preset: BrainFlowPresets,
boardId: BoardIds,
inputJson: string,
) => BrainFlowExitCodes;
isPrepared!: (prepared: number[], boardId: BoardIds, inputJson: string) => BrainFlowExitCodes;
prepareSession!: (boardId: BoardIds, inputJson: string) => BrainFlowExitCodes;
startStream!: (
numSamples: number,
Expand Down

0 comments on commit e6c9681

Please sign in to comment.