function varargout = healthy(varargin)
% HEALTHY MATLAB code for healthy.fig
% HEALTHY, by itself, creates a new HEALTHY or raises the existing
% singleton*.
%
% H = HEALTHY returns the handle to a new HEALTHY or the handle to
% the existing singleton*.
%
% HEALTHY('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HEALTHY.M with the given input arguments.
%
% HEALTHY('Property','Value',...) creates a new HEALTHY or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before healthy_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to healthy_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 healthy
% Last Modified by GUIDE v2.5 30-Jun-2018 14:48:09
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @healthy_OpeningFcn, ...
'gui_OutputFcn', @healthy_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 healthy is made visible.
function healthy_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 healthy (see VARARGIN)
% Choose default command line output for healthy
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes healthy wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = healthy_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;
% --- 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)
global s;
%%
global y1 y2 y3 n
y1=[];
y2=[];
y3=[];
n=0;
s = instrfind('Type', 'serial', 'Port', 'com1', 'Tag', ''); %查询检测串口com1
if isempty(s)
s = serial('com1');
else
fclose(s);
s = s(1)
end
set(s,'BaudRate', 9600,'DataBits',8,'StopBits',1,'Parity','none','FlowControl','none');
s.BytesAvailableFcnMode = 'terminator'; % 数据回车“\n”进入回调函数
% set(s,'terminator','.')
s.BytesAvailableFcn =@callback2; %引用回调函数
fopen(s);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global s
ss=questdlg('你真的要退出吗?','退出信息窗口!','不,我还想看看!','是的,我要退出!','是的,我要退出!');
switch ss
case '是的,我要退出!'
delete(handles.figure1);
fclose(s);
delete(s);
delete(instrfindall);
clear s
end
function callback2(s,BytesAvailable)
global u flag y1 y2 y3 n
u = fscanf(s); %以字符串类型读数据
handles=guidata(healthy);
A=find(u=='A');
B=find(u=='B');
C=find(u=='C');
[ S1,S2,S3,flag] =quzhi( u,A,B,C );
if S1(1)<40
set(handles.edit2,'String','心率过慢');
set(handles.edit2,'BackgroundColor',[0 0 255]/255);
elseif S1(1)<=100
set(handles.edit2,'String','心率正常');
set(handles.edit2,'BackgroundColor',[0 255 0]/255);
else
set(handles.edit2,'String','心率过速');
set(handles.edit2,'BackgroundColor',[255 0 0]/255);
end
pulse=S1(end);
ecg=S2;
myoelectric=S3;
n=n+1;
y1=[y1 pulse];
y2=[y2 ecg];
y3=[y3;myoelectric];
if n>50
y1(1)=[];
y2(1)=[];
y3(1,:)=[]
end
% axes(handles.axes1)
plot(handles.axes1,y1)
% axes(handles.axes2)
plot(handles.axes2,y2)
% axes(handles.axes3)
plot(handles.axes3,y3)
if flag==0
set(handles.edit1,'String','电极正常');
set(handles.edit1,'BackgroundColor',[0 255 0]/255);
else
set(handles.edit1,'String','电极脱落');
set(handles.edit1,'BackgroundColor',[255 0 0]/255);
end
temp=0.3*rand(1)+36.4;
temp=roundn(temp,-1);
set(handles.edit3,'String',num2str(temp));
set(handles.edit4,'String',[num2str(97) '%']);
set(handles.edit5,'String',num2str(S1(1)));
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
%
评论2