-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lsl' of https://github.com/stephaniebrandl/bbci_public …
…into stephaniebrandl-lsl conflicts resolved
- Loading branch information
Showing
8 changed files
with
145 additions
and
113 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
run = true; | ||
last_mrk = ''; | ||
|
||
state_acquire= bbci_acquire_lsl('init'); | ||
cnt = zeros(64, 100); | ||
mrk = zeros(1, 100); | ||
|
||
step = 1; | ||
|
||
while state_acquire.running | ||
[cnt_new, cntTime, mrkTime, mrkDesc, state_acquire]= bbci_acquire_lsl(state_acquire); | ||
|
||
if not(isempty(mrkDesc)) | ||
fprintf('RECEIVED %s\n', mrkDesc{1}); | ||
fprintf('TIME %f \n', mrkTime); | ||
end | ||
|
||
% fprintf('Data %s at %f \n', cnt_new, cntTime); | ||
% fprintf('step %f \n', step) | ||
% last_mrk = mrkDesc; | ||
% last_mrkTime = mrkTime; | ||
% | ||
% cnt(:,step) = cnt_new; | ||
step = step + 1; | ||
end | ||
display('Streams broke off') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
% DEMO_BBCIONLINE_APPLY_LSL_STREAMING | ||
% this is just for testing / demonstrating the streaming of EEG data using | ||
% lsl | ||
|
||
% set up dummy classifier | ||
C= struct('b', 0); | ||
C.w= randn(8*2, 1); % 2 log-bandpower feature per channel | ||
|
||
% setup the bbci variable to define the online processing chain | ||
bbci= struct; | ||
bbci.source.acquire_fcn= @bbci_acquire_lsl; | ||
|
||
% define the dummy electrode setting | ||
clab = {'AF5' 'AF3' 'AF1' 'AFz' 'AF2' 'AF4' 'AF6' ... | ||
'F5' 'F3', 'F1' 'Fz' 'F2' 'F4' 'F6' ... | ||
'FC7' 'FC5'}; | ||
|
||
bbci.signal.clab = clab; | ||
% provide clab and markerstreamname to lsl acquire function | ||
bbci.source.acquire_param = {'clab', clab, 'markerstreamname', 'MyMarkerStream'}; | ||
|
||
bbci.feature.proc= {@proc_variance, @proc_logarithm}; | ||
bbci.feature.ival= [-500 0]; | ||
|
||
bbci.classifier.C= C; | ||
|
||
% specify file locations and logging | ||
% bbci.log.output= 'screen&file'; | ||
% bbci.log.file= fullfile(BTB.DataDir, 'tmp\log'); | ||
bbci.source.record_signals = 0; | ||
bbci.source.record_basename = fullfile(BTB.DataDir,'tmp\lsl_test'); | ||
bbci.quit_condition.running_time = 170; | ||
bbci_apply(bbci); | ||
% DEMO_BBCIONLINE_APPLY_LSL_STREAMING | ||
% this is just for testing / demonstrating the streaming of EEG data using | ||
% lsl | ||
|
||
% set up dummy classifier | ||
C= struct('b', 0); | ||
C.w= randn(8*2, 1); % 2 log-bandpower feature per channel | ||
|
||
% setup the bbci variable to define the online processing chain | ||
bbci= struct; | ||
bbci.source.acquire_fcn= @bbci_acquire_lsl; | ||
|
||
% define the dummy electrode setting | ||
clab = {'AF5' 'AF3' 'AF1' 'AFz' 'AF2' 'AF4' 'AF6' ... | ||
'F5' 'F3', 'F1' 'Fz' 'F2' 'F4' 'F6' ... | ||
'FC7' 'FC5'}; | ||
|
||
bbci.signal.clab = clab; | ||
% provide clab and markerstreamname to lsl acquire function | ||
bbci.source.acquire_param = {'clab', clab, 'markerstreamname', 'MyMarkerStream'}; | ||
|
||
bbci.feature.proc= {@proc_variance, @proc_logarithm}; | ||
bbci.feature.ival= [-500 0]; | ||
|
||
bbci.classifier.C= C; | ||
|
||
% specify file locations and logging | ||
% bbci.log.output= 'screen&file'; | ||
% bbci.log.file= fullfile(BTB.DataDir, 'tmp\log'); | ||
bbci.source.record_signals = 0; | ||
bbci.source.record_basename = fullfile(BTB.DataDir,'tmp\lsl_test'); | ||
bbci.quit_condition.running_time = 170; | ||
bbci_apply(bbci); |
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 |
---|---|---|
@@ -1,67 +1,71 @@ | ||
function bbci_trigger_lsl(value, varargin) | ||
%BBCI_TRIGGER_LSL Sends triggers using LabStreaminglayer | ||
% Sends trigger using the marker stream outlet defined in the | ||
% labstreaminglayer | ||
% | ||
% value trigger value, numeric or 'init' or 'close' case | ||
% varargin the argument given bbci_trigger: BTB.Acq.TriggerParam{:}. | ||
% In any case it should contain an LSL stream outlet of the | ||
% marker stream. | ||
|
||
% NOTE: The case that bbci.trigger.param{:} contains the lsl | ||
% stream is not enough because we dont have access to bbci struct | ||
% in this function in order to close the connection. | ||
|
||
|
||
global BTB | ||
|
||
if ischar(value) && strcmp(value, 'init'), | ||
if ~isdir('liblsl-Matlab') | ||
error('LSL Toolbox is not on the path. add it via addpath(genpath(''path_to_LSL/liblsl-Matlab''))') | ||
end | ||
% open LSL library to check for marker stream | ||
lib = lsl_loadlib(); | ||
mrks = lsl_resolve_byprop(lib, 'name', 'MyMarkerStream', 1, 1); | ||
% if there is no marker stream, then open one and save it in global BTB | ||
% structure. | ||
if isempty(mrks) | ||
source_id = ['sourceID' num2str(randi(50000))]; | ||
mrk_info = lsl_streaminfo(lib,'MyMarkerStream','Markers',1,1,'cf_string',source_id); | ||
% get the lsl stream outlet and save it as well as the lsl info object in BTB struct | ||
BTB.Acq.TriggerParam = {lsl_outlet(mrk_info), mrk_info}; | ||
BTB.Acq.TriggerFcn = @bbci_trigger_lsl; | ||
fprintf(['Started LSL marker stream with source id ' source_id '\n']); | ||
else | ||
% if there is a stream it has to be closed because otherwise the | ||
% acquire function might connect to the wrong stream. | ||
error(['There is a markerstream with ID ' BTB.Acq.LSLsourceID ' on the network, use bbci_trigger_lsl(''close'') first!']); | ||
end | ||
elseif ischar(value) && strcmp(value, 'close'), | ||
% try to close LSL marker stream | ||
try | ||
BTB.Acq.TriggerParam{1}.delete(); | ||
BTB.Acq.TriggerParam{2}.delete(); | ||
|
||
catch | ||
warning('There is no BTB struct or no LSL Markerstream with name MyMarkerStream to close.'); | ||
end | ||
|
||
elseif isnumeric(value) | ||
% hack to meet the format of the lsl marker stream and mimic the pp | ||
% marker format: 'S <markervalue>' | ||
marker = cat(2, 'S ', num2str(value)); | ||
% In case someone only sets bbci.trigger.fcn = @bbci_trigger_lsl | ||
if isempty(varargin), | ||
error('LSL marker stream was not set up correcty. Set BTB.Acq.TriggerFcn = @bbci_trigger_lsl and use ''bbci_trigger(''init'')'' '); | ||
end | ||
% push sample to marker stream outlet | ||
try | ||
varargin{1}.push_sample({marker}); | ||
catch | ||
error('LSL marker stream was not set up correcty. First use ''bbci_trigger(''init'')'', then ''bbci_trigger(value)'''); | ||
end | ||
else | ||
warning('The trigger has to be numeric or ''init'' or ''close'' : no trigger was sent') | ||
end | ||
end | ||
|
||
function bbci_trigger_lsl(value, varargin) | ||
%BBCI_TRIGGER_LSL Sends triggers using LabStreaminglayer | ||
% Sends trigger using the marker stream outlet defined in the | ||
% labstreaminglayer | ||
% | ||
% value trigger value, numeric or 'init' or 'close' case | ||
% varargin the argument given bbci_trigger: BTB.Acq.TriggerParam{:}. | ||
% In any case it should contain an LSL stream outlet of the | ||
% marker stream. | ||
|
||
% NOTE: The case that bbci.trigger.param{:} contains the lsl | ||
% stream is not enough because we dont have access to bbci struct | ||
% in this function in order to close the connection. | ||
|
||
% 11-2015 Jan Boelts | ||
|
||
|
||
global BTB | ||
|
||
if ischar(value) && strcmp(value, 'init'), | ||
if ~isdir('liblsl-Matlab') | ||
error('LSL Toolbox is not on the path. add it via addpath(genpath(''path_to_LSL/liblsl-Matlab''))') | ||
end | ||
% open LSL library to check for marker stream | ||
lib = lsl_loadlib(); | ||
mrks = lsl_resolve_byprop(lib, 'name', 'MyMarkerStream', 1, 1); | ||
% if there is no marker stream, then open one and save it in global BTB | ||
% structure. | ||
if isempty(mrks) | ||
source_id = ['sourceID' num2str(randi(50000))]; | ||
mrk_info = lsl_streaminfo(lib,'MyMarkerStream','Markers',1,1,'cf_string',source_id); | ||
% get the lsl stream outlet and save it as well as the lsl info object in BTB struct | ||
BTB.Acq.TriggerParam = {lsl_outlet(mrk_info), mrk_info}; | ||
BTB.Acq.TriggerFcn = @bbci_trigger_lsl; | ||
BTB.Acq.LSLsourceID = source_id; | ||
fprintf(['Started LSL marker stream with source id ' source_id '\n']); | ||
else | ||
% if there is a stream it has to be closed because otherwise the | ||
% acquire function might connect to the wrong stream. | ||
error(['There is a markerstream with ID ' BTB.Acq.LSLsourceID ' on the network, use bbci_trigger(''close'') first!']); | ||
end | ||
elseif ischar(value) && strcmp(value, 'close'), | ||
% try to close LSL marker stream | ||
try | ||
BTB.Acq.TriggerParam{1}.delete(); | ||
BTB.Acq.TriggerParam{2}.delete(); | ||
|
||
catch | ||
warning('There is no BTB struct or no LSL Markerstream with name MyMarkerStream to close.'); | ||
end | ||
|
||
elseif isnumeric(value) | ||
% hack to meet the format of the lsl marker stream and mimic the pp | ||
% marker format: 'S <markervalue>' | ||
marker = cat(2, 'S ', num2str(value)); | ||
% In case someone only sets bbci.trigger.fcn = @bbci_trigger_lsl | ||
if isempty(varargin), | ||
error('LSL marker stream was not set up correcty. Set BTB.Acq.TriggerFcn = @bbci_trigger_lsl and use ''bbci_trigger(''init'')'' '); | ||
end | ||
% push sample to marker stream outlet | ||
try | ||
varargin{1}.push_sample({marker}); | ||
catch | ||
error('LSL marker stream was not set up correcty. First use ''bbci_trigger(''init'')'', then ''bbci_trigger(value)'''); | ||
end | ||
else | ||
warning('The trigger has to be numeric or ''init'' or ''close'' : no trigger was sent') | ||
end | ||
end | ||
|
||
>>>>>>> b9ee3e0cb00b9a0abbd586a100c6a90147bdac3f |
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