function varargout = NQR_ML505_GUI(varargin)
% NQR_ML505_GUI MATLAB code for NQR_ML505_GUI.fig
%      NQR_ML505_GUI, by itself, creates a new NQR_ML505_GUI or raises the existing
%      singleton*.
%
%      H = NQR_ML505_GUI returns the handle to a new NQR_ML505_GUI or the handle to
%      the existing singleton*.
%
%      NQR_ML505_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in NQR_ML505_GUI.M with the given input arguments.
%
%      NQR_ML505_GUI('Property','Value',...) creates a new NQR_ML505_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before NQR_ML505_GUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to NQR_ML505_GUI_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help NQR_ML505_GUI

% Last Modified by GUIDE v2.5 09-Apr-2013 19:34:30

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @NQR_ML505_GUI_OpeningFcn, ...
                   'gui_OutputFcn',  @NQR_ML505_GUI_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before NQR_ML505_GUI is made visible.
function NQR_ML505_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to NQR_ML505_GUI (see VARARGIN)

% Choose default command line output for NQR_ML505_GUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes NQR_ML505_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = NQR_ML505_GUI_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit_NQR_frequency_Callback(hObject, eventdata, handles)
% hObject    handle to edit_NQR_frequency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_NQR_frequency as text
%        str2double(get(hObject,'String')) returns contents of edit_NQR_frequency as a double


% --- Executes during object creation, after setting all properties.
function edit_NQR_frequency_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_NQR_frequency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_ex_pulse_Callback(hObject, eventdata, handles)
% hObject    handle to edit_ex_pulse (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_ex_pulse as text
%        str2double(get(hObject,'String')) returns contents of edit_ex_pulse as a double


% --- Executes during object creation, after setting all properties.
function edit_ex_pulse_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_ex_pulse (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_meas_delay_Callback(hObject, eventdata, handles)
% hObject    handle to edit_meas_delay (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_meas_delay as text
%        str2double(get(hObject,'String')) returns contents of edit_meas_delay as a double


% --- Executes during object creation, after setting all properties.
function edit_meas_delay_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_meas_delay (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_repetition_time_Callback(hObject, eventdata, handles)
% hObject    handle to edit_repetition_time (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_repetition_time as text
%        str2double(get(hObject,'String')) returns contents of edit_repetition_time as a double


% --- Executes during object creation, after setting all properties.
function edit_repetition_time_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_repetition_time (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_repetition_number_Callback(hObject, eventdata, handles)
% hObject    handle to edit_repetition_number (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_repetition_number as text
%        str2double(get(hObject,'String')) returns contents of edit_repetition_number as a double


% --- Executes during object creation, after setting all properties.
function edit_repetition_number_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_repetition_number (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popupmenu_VGA_gain.
function popupmenu_VGA_gain_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu_VGA_gain (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu_VGA_gain contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu_VGA_gain


% --- Executes during object creation, after setting all properties.
function popupmenu_VGA_gain_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu_VGA_gain (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

 set(hObject, 'String', {'-10 dB', '-7 dB', '-4 dB', '-1 dB', '+2 dB', '+5 dB', '+8 dB', '+11 dB', '+14 dB', '+17 dB', '+20 dB',...
                         '+23 dB', '+26 dB', '+29 dB', '+32 dB', '+35 dB'});


% --- Executes on button press in pushbutton_start.
function pushbutton_start_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_start (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


x = get( handles.edit_NQR_frequency, 'String');
if isempty( findstr( x, ',')) == 0
    handle_dlg = errordlg( 'Při zadávání desetinného čísla nelze použít desetinnou čárku, musí být použito desetinné tečky!', 'Nesprávný formát budící frekvence');
    uiwait( handle_dlg);
    return;
end
if isempty( x)
    handle_dlg = errordlg( 'Do vstupního pole nebyla zadána žádná hodnota!', 'Nesprávný formát budící frekvence');
    uiwait( handle_dlg);
    return;
end
NQR_frequency_value = str2double( x);
if (NQR_frequency_value < 1) || (NQR_frequency_value > 30)
    handle_dlg = errordlg( 'Hodnota musí být v rozmezí 1 až 30 MHz!', 'Nesprávná hodnota budící frekvence');
    uiwait( handle_dlg);
    return;
end


popup_sel_index = get( handles.popupmenu_VGA_gain, 'Value');
switch popup_sel_index
    case 1
        VGA_gain_value = -10;
    case 2
        VGA_gain_value = -7;
    case 3
        VGA_gain_value = -4;
    case 4
        VGA_gain_value = -1;
    case 5
        VGA_gain_value = 2;
    case 6
        VGA_gain_value = 5;
    case 7
        VGA_gain_value = 8;
    case 8
        VGA_gain_value = 11;
    case 9
        VGA_gain_value = 14;
    case 10
        VGA_gain_value = 17;
    case 11
        VGA_gain_value = 20;
    case 12
        VGA_gain_value = 23;
    case 13
        VGA_gain_value = 26;
    case 14
        VGA_gain_value = 29;
    case 15
        VGA_gain_value = 32;
    case 16
        VGA_gain_value = 35;
end


x = get( handles.edit_ex_pulse, 'String');
if isempty( findstr( x, ',')) == 0
    handle_dlg = errordlg( 'Při zadávání desetinného čísla nelze použít desetinnou čárku, musí být použito desetinné tečky!', 'Nesprávný formát šířky budícího pulsu');
    uiwait( handle_dlg);
    return;
end
if isempty( x)
    handle_dlg = errordlg( 'Do vstupního pole nebyla zadána žádná hodnota!', 'Nesprávný formát šířky budícího pulsu');
    uiwait( handle_dlg);
    return;
end
Ex_pulse_width_value = str2double( x);
if (Ex_pulse_width_value < 50E-3) || (Ex_pulse_width_value > 21.47E6)
    handle_dlg = errordlg( 'Hodnota musí být v rozmezí 50 ns až 21,47 s!', 'Nesprávná hodnota šířky budícího pulsu');
    uiwait( handle_dlg);
    return;
end


x = get( handles.edit_meas_delay, 'String');
if isempty( findstr( x, ',')) == 0
    handle_dlg = errordlg( 'Při zadávání desetinného čísla nelze použít desetinnou čárku, musí být použito desetinné tečky!', 'Nesprávný formát mrtvé doby přijímače');
    uiwait( handle_dlg);
    return;
end
if isempty( x)
    handle_dlg = errordlg( 'Do vstupního pole nebyla zadána žádná hodnota!', 'Nesprávný formát mrtvé doby přijímače');
    uiwait( handle_dlg);
    return;
end
Measuring_delay_value = str2double( x);
if (Measuring_delay_value < 50E-3) || (Measuring_delay_value > 21.47E6)
    handle_dlg = errordlg( 'Hodnota musí být v rozmezí 50 ns až 21,47 s!', 'Nesprávná hodnota mrtvé doby přijímače');
    uiwait( handle_dlg);
    return;
end


x = get( handles.edit_repetition_time, 'String');
if isempty( findstr( x, ',')) == 0
    handle_dlg = errordlg( 'Při zadávání desetinného čísla nelze použít desetinnou čárku, musí být použito desetinné tečky!', 'Nesprávný formát opakovací periody budících pulsů');
    uiwait( handle_dlg);
    return;
end
if isempty( x)
    handle_dlg = errordlg( 'Do vstupního pole nebyla zadána žádná hodnota!', 'Nesprávný formát opakovací periody budících pulsů');
    uiwait( handle_dlg);
    return;
end
Repetition_time_value = str2double( x);
if (Repetition_time_value < 50E-6) || (Repetition_time_value > 21.47E3)
    handle_dlg = errordlg( 'Hodnota musí být v rozmezí 50 ns až 21,47 s!', 'Nesprávná hodnota opakovací periody budících pulsů');
    uiwait( handle_dlg);
    return;
end


x = get( handles.edit_repetition_number, 'String');
if (isempty( findstr( x, ',')) && isempty( findstr( x, '.'))) == 0
    handle_dlg = errordlg( 'Jako vstupní hodnotu nelze použít desetinné číslo!', 'Nesprávný formát počtu opakování');
    uiwait( handle_dlg);
    return;
end
if isempty( x)
    handle_dlg = errordlg( 'Do vstupního pole nebyla zadána žádná hodnota!', 'Nesprávný formát počtu opakování');
    uiwait( handle_dlg);
    return;
end
Repetition_number_value = str2double( x);
if (Repetition_number_value < 1) || (Repetition_number_value > 2730)
    handle_dlg = errordlg( 'Hodnota musí být v rozmezí 1 až 2730!', 'Nesprávná hodnota počtu opakování');
    uiwait( handle_dlg);
    return;
end

UDP( NQR_frequency_value, VGA_gain_value, Ex_pulse_width_value, Measuring_delay_value, Repetition_time_value, Repetition_number_value);
