Skip to content

Add new function

Victor Hugo Souza edited this page Nov 13, 2016 · 4 revisions

This is a simple tutorial on how to create new functions/interfaces inside Signal Hunter. Some other dependencies may appear while programming. Any further questions, contact us by e-mail.

1 - Creating Menu entry:
All new functions may be created inside the menu File and submenu Open. The submenu entries are created in gui/figure_processing.m file around line 69. For your new function, just add another entry bellow all others:

uimenu(hsubopen, 'Label', 'New Function', 'Callback', @callback_open);

Optional
Create the callback for the submenu selection in Tools panel (around line 108) with the corresponding index (here just for example is 4):

hsubtools(4) = uimenu(hmenutools, 'Label', 'New function', 'Callback', @callback_new_function);

2 - Creating open callback
All open callbacks are executed in the callback_open function (gui/figure_processing.m) within a switch-case procedure. Add your code following the layout of other cases.
Create the open callback for the new function as a new case. The string must be the same as that used in the submenu but all lowercase letters.

case 'new function'
    handles = callback_new_function(handles.fig);  % see item 3
    [reader, open_id] = reader_new_function(handles.config_dir);  % see item 4
    set(handles.hsubdata, 'Enable', 'on');  % Turn on load, save and export menu so they can be clicked.
    processed = process_new_function(reader);  % see item 6
    handles.reader = reader;  
    handles.processed = processed;
    handles = panel_new_function(handles);  % see item 7
    handles = graphs_new_function(handles);  % see item 8

3 - Processing tools menu
In case the optional was created in item 1: copy any other callback function (e.g. callback_multi) and change the index of hsubtools to the one created in item 1.

if strcmp(get(handles.hsubtools(4), 'Checked'),'on')
    set(handles.hsubtools(4), 'Checked', 'off');
else
    set(handles.hsubtools(:), 'Checked', 'off');
    set(handles.hsubtools(4), 'Checked', 'on');
end

4 - Reader file
Create a new file inside folder reader and named reader_new_function.m. Here, follow the convention of other reader files and write the code to read the data you need. Remember that there will be another file for processing, so avoid to pre-process data in reader function.

5 - Process file
Create a new file inside folder data and named process_new_function.m. This is the function to calculate and process all data before visualization. If you consider that some processing functions may be useful for others, try to create them in a sepparate file. See data/find_latency.m for example.

6 - Panel for buttons
Create a new file inside folder gui and named panel_new_function.m. This function may contain all buttons and callbacks specifics for your application. Graphical componentes are created in panel_creation function and callbacks may be created inside the same file.

7 - Graphs and axes
Create a new file inside folder gui and named graphs_new_function.m. This function creates the axes inside a panel to allow signal plot. Properties of the panel that may contain the axes are set in the function graph_creation. Then, axes are created inside the funciton graph_model. After this, plots will be executed in the graph_creation function, just after the call for graph_model.
The axes_ButtonDownFcn executes the code if the user clicks the axes. There, create a call to the dialog that will pop up:

handles = dialog_detect_multi(handles); % see item 10

8 - Plotting
To plot signals, create the file plot_new_function.m inside the folder data. If your application will allow the user to interact with axes, in order to change any mark, it is interesting to let plot functions as general as possible to be assessed by other functions, not only inside graph_creation.

9 - Dialog to manual selection
Create a new file inside folder gui and named dialog_detect_new_function.m. This file pops up a dialog with buttons and axes to allow user to manual select the previously calculated marks, such as amplitude and latency. The changes will be updated by executing the refresh_axes function inside graphs_new_function.m just after the dialog detect call.

10 - Save, Export and Load buttons
Save, Export and Load buttons are created in the gui/panel_files.m, which is called after the switch-case process in callback_open function inside gui/figure_processing.m. For all three cases, they are selected according to the pressed button and automatically forwarded to corresponding file (Save -> data/data_save.m; Export -> data/data_export.m; Load -> data/data_load.m).
Inside each file, there will be another switch case sentence that will use the id of "new function" (same used in callback_open).
Thus, add another case for the new function and also add a function named save_new_function or export_new_function or load_new_function to be called by the switch-case sentence. Inside these functions, write the specific save, export, load functions to your application.

Final considerations
Roughly, this is the pipeline for Signal Hunter. However, it is also a "white board" where you can freely create your own interface and pipeline. Remember always to comment and organize your code for others to read.

Hope to see your new function!

Signal Hunter Team

Clone this wiki locally