function varargout = infra(varargin)
% INFRA M-file for infra.fig
%      INFRA, by itself, creates a new INFRA or raises the existing
%      singleton*.
%
%      H = INFRA returns the handle to a new INFRA or the handle to
%      the existing singleton*.
%
%      INFRA('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in INFRA.M with the given input arguments.
%
%      INFRA('Property','Value',...) creates a new INFRA or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before infra_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to infra_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 infra

% Last Modified by GUIDE v2.5 18-Nov-2009 15:39:30

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @infra_OpeningFcn, ...
                   'gui_OutputFcn',  @infra_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 infra is made visible.
function infra_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 infra (see VARARGIN)
handles.output = hObject;
p=inputParser;
p.addParamValue('pokyn',@(varargin)(eval('disp([mfilename ''/pokyn:'']),disp(varargin)')));
p.addParamValue('hParent',[]);
p.addParamValue('nazev','Měření snímání infra diody');
p.addParamValue('nastaveni',[]);
p.addParamValue('data',[]);
p.parse(varargin{:})
handles.pokyn=p.Results.pokyn;
handles.nastaveni=p.Results.nastaveni;
handles.data=p.Results.data;
set(handles.guiNazev,'String',p.Results.nazev);
%keyboard
if ~isfield(handles.nastaveni,'frekvence')
handles.nastaveni.frekvence=215;
end
set(handles.editfrek,'String',handles.nastaveni.frekvence);
set(handles.STfrek,'String',[num2str(round(16e6/2/handles.nastaveni.frekvence/100)/10) ' kHz'])

handles.hOvladac=[];
% Choose default command line output for infra
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);


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

%       prikaz - fce pro ovladani gui z venku
function prikaz(nazev,h,hodn)
%keyboard
if exist('nazev','var')
if exist(nazev)
    fce=str2func(nazev);
    if exist('hodn')
       fce(h,hodn); 
    else
        fce(h);
    end
else
    disp([mfilename '/Neznamy příkaz: ' nazev]);
end,end
% --- Outputs from this function are returned to the command line.
function varargout = infra_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)
varargout{1} = handles.output;
varargout{2} = @prikaz;

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


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



function editfrek_Callback(hObject, eventdata, handles)
% hObject    handle to editfrek (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 editfrek as text
%        str2double(get(hObject,'String')) returns contents of editfrek as a double
cislo=round(str2num(get(hObject,'String')));
if isempty(cislo)
set(hObject,'String',handles.nastaveni.frekvence);
else
    handles.nastaveni.frekvence=cislo;
    set(hObject,'String',handles.nastaveni.frekvence);
    set(handles.STfrek,'String',[num2str(round(16e6/2/cislo/100)/10) ' kHz'])
    guidata(hObject,handles);
    handles.pokyn('infrafrekvence',cislo);
end


% --- Executes during object creation, after setting all properties.
function editfrek_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editfrek (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 infradata(h,infradata)
handles=guidata(h);
plot(handles.axes1,infradata.x,infradata.y);
axis(handles.axes1,[-inf inf 0 1100]);
%keyboard


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over editfrek.
function editfrek_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to editfrek (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%keyboard
if isempty(handles.hOvladac)
handles.hOvladac=ovladac('hParent',hObject,... 
 'pokyn',@prikaz,'nazevhodnoty','frekvence','nazev','Frekvence','limity',[300 100 240 200]);
guidata(hObject,handles);
end

function frekvence(h,f)
handles=guidata(h);
set(handles.editfrek,'String',round(f));
guidata(h,handles);
editfrek_Callback(h, [], handles);

function uloz(a,h)
handles=guidata(h);
handles.hOvladac=[];
guidata(h,handles);


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


