Skip to content

Commit b7b36fe

Browse files
committed
new module for ephys with openephys
1 parent d17a7cd commit b7b36fe

14 files changed

+539
-588
lines changed

ExperPort/Modules/@OpenEphys_Neuroblueprint/OpenEphysHTTPServer.m

Lines changed: 0 additions & 554 deletions
This file was deleted.

ExperPort/Modules/@OpenEphys_Neuroblueprint/OpenEphys_Neuroblueprint.m

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [obj, varargout] = OpenEphys_Neuroblueprint(varargin)
1+
function [obj, varargout] = OpenEphys_Neuroblueprint_GUI(varargin)
22
% This is a class-based version of the GUI controller, structured similarly
33
% to runrats.m. It manages the experimental workflow through different
44
% 'actions' called via a switch statement.
@@ -11,19 +11,19 @@
1111
% --- Boilerplate for class definition and action handling ---
1212
obj = class(struct, mfilename);
1313
varargout = {}; % Initialize varargout for actions that return values
14-
if nargin==0 || (nargin==1 && ischar(varargin{1}) && strcmp(varargin{1}, 'empty')),
14+
if nargin==0 || (nargin==1 && ischar(varargin{1}) && strcmp(varargin{1}, 'empty'))
1515
return;
16-
end;
17-
if isa(varargin{1}, mfilename),
18-
if length(varargin) < 2 || ~ischar(varargin{2}),
16+
end
17+
if isa(varargin{1}, mfilename)
18+
if length(varargin) < 2 || ~ischar(varargin{2})
1919
error(['If called with a "%s" object as first arg, a second arg, a ' ...
2020
'string specifying the action, is required\n']);
2121
else action = varargin{2}; varargin = varargin(3:end);
22-
end;
22+
end
2323
else
2424
action = varargin{1}; varargin = varargin(2:end);
25-
end;
26-
if ~ischar(action), error('The action parameter must be a string'); end;
25+
end
26+
if ~ischar(action), error('The action parameter must be a string'); end
2727
GetSoloFunctionArgs(obj);
2828
% --- End of boilerplate ---
2929

@@ -35,6 +35,9 @@
3535
case 'init'
3636
% This case is called once to create the GUI and initialize all parameters.
3737

38+
% So that only the CPU-based software renderer instead of your graphics card
39+
opengl software;
40+
3841
% Start Bpod if not already running
3942
if evalin('base', 'exist(''BpodSystem'', ''var'')')
4043
if evalin('base', '~isempty(BpodSystem)'), newstartup; else, flush; end
@@ -46,7 +49,6 @@
4649
SoloParamHandle(obj, 'oe_controller', 'value', []);
4750
SoloParamHandle(obj, 'behav_obj', 'value', []);
4851
SoloParamHandle(obj, 'blinking_timer', 'value', []);
49-
SoloParamHandle(obj, 'monitor_timer', 'value', []);
5052
SoloParamHandle(obj, 'current_params', 'value', []);
5153
SoloParamHandle(obj, 'session_base_path', 'value', '');
5254
SoloParamHandle(obj,'is_running','value',0);
@@ -88,7 +90,7 @@
8890
uicontrol(p2, 'Style', 'text', 'String', 'Project Name (Root):', 'Units', 'normalized', 'Position', [0.01, 0.85, 0.28, 0.1], 'HorizontalAlignment', 'right');
8991
handles.proj_edit = uicontrol(p2, 'Style', 'edit', 'String', 'sound_cat_rat', 'Units', 'normalized', 'Position', [0.3, 0.85, 0.65, 0.12]);
9092
uicontrol(p2, 'Style', 'text', 'String', 'Subject ID:', 'Units', 'normalized', 'Position', [0.01, 0.7, 0.28, 0.1], 'HorizontalAlignment', 'right');
91-
handles.sub_edit = uicontrol(p2, 'Style', 'edit', 'String', '002', 'Units', 'normalized', 'Position', [0.3, 0.7, 0.65, 0.12]);
93+
handles.sub_edit = uicontrol(p2, 'Style', 'edit', 'String', '003', 'Units', 'normalized', 'Position', [0.3, 0.7, 0.65, 0.12]);
9294
uicontrol(p2, 'Style', 'text', 'String', 'Local Path:', 'Units', 'normalized', 'Position', [0.01, 0.55, 0.28, 0.1], 'HorizontalAlignment', 'right');
9395
handles.local_edit = uicontrol(p2, 'Style', 'edit', 'String', 'C:\Ephys_Experiment_Data', 'Units', 'normalized', 'Position', [0.3, 0.55, 0.5, 0.12]);
9496
handles.local_browse = uicontrol(p2, 'Style', 'pushbutton', 'String', 'Browse...', 'Units', 'normalized', 'Position', [0.81, 0.55, 0.16, 0.13], 'Callback', {@(h,e) feval(mfilename, obj, 'browse_path', 'local')});
@@ -267,7 +269,6 @@
267269
currentState.value = 'Stop';
268270
set(handles.control_button, 'String', 'Stop');
269271
feval(mfilename, obj, 'start_blinking');
270-
feval(mfilename, obj, 'start_monitoring');
271272

272273
try
273274
log_message(handles, 'Starting behavioral protocol...');
@@ -285,10 +286,11 @@
285286
handles = value(ui_handles);
286287
log_message(handles, '--- STOP sequence initiated ---');
287288
feval(mfilename, obj, 'stop_blinking');
288-
289+
behav_save_dir = fullfile(params.local_path, value(session_base_path), 'behav');
290+
289291
try
290292
log_message(handles, 'Ending behavioral session (saving data)...');
291-
feval(mfilename, obj, 'behav_control', 'end', params.protocol_name, params.behav_path);
293+
feval(mfilename, obj, 'behav_control', 'end', params.protocol_name, params.behav_path,behav_save_dir);
292294
log_message(handles, 'Behavioral data saved successfully.');
293295
catch ME
294296
log_message(handles, ['FATAL ERROR ending behavioral session: ' ME.message]);
@@ -337,7 +339,7 @@
337339

338340
case 'load_protocol_after_crash'
339341
experimenter = args{1}; ratname = args{2}; protocol_name = args{3};
340-
video_save_dir = args{4}; behav_path = args{5};
342+
behav_path = args{4};
341343
log_message(handles, ['Loading protocol: ' protocol_name]);
342344
dispatcher('set_protocol', protocol_name);
343345
rath = get_sphandle('name', 'ratname', 'owner', protocol_name);
@@ -351,17 +353,15 @@
351353
if isfile(fullfile(temp_data_dir,temp_data_file))
352354
dispatcher('runstart_disable');
353355
load_soloparamvalues(ratname, 'experimenter', experimenter,...
354-
'owner', protobj, 'interactive', 0,'data_file',fullfile(temp_data_dir,temp_data_file));
356+
'owner', protocol_name, 'interactive', 0,'data_file',fullfile(temp_data_dir,temp_data_file));
355357
dispatcher('runstart_enable');
356358
end
357-
% [sfile, ~] = SavingSection(protobj, 'get_set_filename');
358359
if ~dispatcher('is_running'), pop_history(class(protobj), 'include_non_gui', 1); feval(protocol_name, protobj, 'prepare_next_trial'); end
359-
% feval(protocol_name, protobj, 'set_setting_params', ratname, experimenter, sfile, char(datetime('now')), video_save_dir);
360-
360+
361361
case 'crashed'
362362
log_message(handles, '--- BEHAVIOR CRASH RECOVERY INITIATED ---');
363363
params = value(current_params);
364-
feval(mfilename, obj, 'behav_control', 'load_protocol_after_crash', params.experimenter, params.rat_name, params.protocol_name, fullfile(params.local_path, value(session_base_path), 'behav'), params.behav_path);
364+
feval(mfilename, obj, 'behav_control', 'load_protocol_after_crash', params.experimenter, params.rat_name, params.protocol_name, params.behav_path);
365365
feval(mfilename, obj, 'behav_control', 'run', params.protocol_name);
366366
log_message(handles, '--- RECOVERY COMPLETE: Behavior protocol restarted ---');
367367

@@ -375,19 +375,19 @@
375375

376376

377377
case 'end'
378-
protocol_name = args{1}; root_dir = args{2};
378+
protocol_name = args{1}; root_dir = args{2}; behav_copy_dir = args{3};
379379
log_message(handles, 'Stopping dispatcher...');
380380
dispatcher(value(behav_obj), 'Stop');
381381

382382
%Let's pause until we know dispatcher is done running
383-
set(value(stopping_complete_timer), 'Period', 2,'TimerFcn', {@(h,e) feval(mfilename, obj, 'behav_control','end_continued',protocol_name, root_dir)});
383+
set(value(stopping_complete_timer), 'Period', 2,'TimerFcn', {@(h,e) feval(mfilename, obj, 'behav_control','end_continued',protocol_name, root_dir,behav_copy_dir)});
384384
%set(value(stopping_complete_timer),'TimerFcn',[mfilename,obj,'behav_control','(''end_continued'');']);
385385
start(value(stopping_complete_timer));
386386

387387
case 'end_continued'
388388
%% end_continued
389389
if value(stopping_process_completed) %This is provided by RunningSection
390-
protocol_name = args{1}; root_dir = args{2};
390+
protocol_name = args{1}; root_dir = args{2}; destination_path = args{3};
391391
stop(value(stopping_complete_timer)); %Stop looping.
392392
is_running.value = 0;
393393
feval(mfilename, obj, 'behav_control', 'send_empty_state_machine');
@@ -396,13 +396,35 @@
396396
feval(protocol_name, protobj, 'end_session');
397397
log_message(handles, 'Saving data and settings...');
398398
data_file = SavingSection(protobj, 'savedata', 'interactive', 0);
399-
try, feval(protocol_name, protobj, 'pre_saving_settings'); catch, log_message(handles, 'Protocol does not have a pre_saving_settings section.'); end
399+
try
400+
feval(protocol_name, protobj, 'pre_saving_settings');
401+
catch
402+
log_message(handles, 'Protocol does not have a pre_saving_settings section.');
403+
end
400404
[settings_file, ~] = SavingSection(protobj, 'get_set_filename');
401405
SavingSection(protobj, 'savesets', 'interactive', 0);
402406
log_message(handles, 'Committing data and settings to SVN...');
403-
commit_to_svn(handles, data_file, root_dir);
404-
commit_to_svn(handles, settings_file, root_dir);
407+
commit_to_svn(handles, data_file, settings_file, root_dir);
405408
dispatcher('set_protocol', '');
409+
dispatcher('close');
410+
411+
% wait sometime for dispatcher to stop using a timer object
412+
t = timer;
413+
t.StartDelay = 1;
414+
t.TimerFcn = @(~,~) log_message('waiting for before copying');
415+
start(t);% Start the timer (it runs in the background)
416+
wait(t); % wait() pauses the script until the timer object is done.
417+
delete(t);% Clean up the timer from memory
418+
419+
% Copy the data file to the folder saving ephys data
420+
[status, msg] = copyfile(data_file, destination_path);
421+
% Check if the copy was successful
422+
if status
423+
log_message(handles,'Data File copied successfully.');
424+
else
425+
log_message(handles,['Error copying Data file: ' msg]);
426+
end
427+
406428
end
407429

408430
case 'create_svn_data_dir'
@@ -492,7 +514,7 @@
492514
blinking_timer.value = [];
493515
end
494516
set(handles.control_button, 'BackgroundColor', [1, 0.4, 0.4]);
495-
517+
496518

497519
case 'crash_detected'
498520
% handles = feval(mfilename, obj, 'get_ui_handles');

ExperPort/Plugins/@bonsaicamera/.bonsai/Settings/Camera_Control.layout

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@
1515
<ObjectTextVisualizer />
1616
</VisualizerSettings>
1717
</WindowSettings>
18+
<WindowSettings Index="4">
19+
<Visible>false</Visible>
20+
<Location>
21+
<X>234</X>
22+
<Y>234</Y>
23+
</Location>
24+
<Size>
25+
<Width>336</Width>
26+
<Height>279</Height>
27+
</Size>
28+
<WindowState>Maximized</WindowState>
29+
<VisualizerTypeName>Bonsai.Vision.Design.IplImageVisualizer</VisualizerTypeName>
30+
<VisualizerSettings>
31+
<IplImageVisualizer />
32+
</VisualizerSettings>
33+
</WindowSettings>
1834
<WindowSettings Index="9">
1935
<Visible>false</Visible>
2036
<Location>

ExperPort/Plugins/@saveload/SavingSection.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@
275275
case 'get_settings_file_load_time'
276276
[dummy, x1] = runrats('get_settings_file_load_time'); clear('dummy');
277277
x2 = value(settings_file_load_time);
278-
x = max(x1, x2); settings_file_load_time.value = x;
278+
x = max(double(x1), double(x2));
279+
settings_file_load_time.value = x;
279280
y = [];
280281
z = [];
281282
return;

0 commit comments

Comments
 (0)