#include "stdafx.h"
#include "../Verbpo.h"
#include "ECGRespSpo2Trend.h"
#include "../StaticValueECGNormal.h"
#include "../StaticValueRespNormal.h"
#include "../StaticValueSPO2Normal.h"
#include "../ThreadDraw.h"
INT CECGRespSpo2Trend::m_i32X=0;
INT CECGRespSpo2Trend::m_i32Y = 480;
INT CECGRespSpo2Trend::m_i32Height = 265;
INT  CECGRespSpo2Trend::m_i32Width = 938;
//在屏幕上单位长度的像素点个数
INT  CECGRespSpo2Trend::m_i32HRH = 300;
//波形的单位长度的数字量
INT  CECGRespSpo2Trend::m_i32HRL = 2048;
//在屏幕上单位长度的像素点个数
INT  CECGRespSpo2Trend::m_i32RespPixel = 65;
//波形的单位长度的数字量
INT  CECGRespSpo2Trend::m_i32RespValue = 256;
//在屏幕上单位长度的像素点个数
INT  CECGRespSpo2Trend::m_i32Spo2H = 100;
//波形的单位长度的数字量
INT  CECGRespSpo2Trend::m_i32Spo2L = 0;




IMPLEMENT_DYNAMIC(CECGRespSpo2Trend, CStatic)


CECGRespSpo2Trend::CECGRespSpo2Trend()
{
	m_i32Show=0;
	m_i32Time = 0;
	m_pi16Spo2 = new INT16[150];
	m_pi16HRBuf = new INT16[150];
	m_pCPonit = new CPoint[150 * 25];
	m_pRespWaveBuff1 = new INT16[150 * 25];
	m_pRespWaveBuff2 = new INT16[150 * 25];
	m_pi16RR = new INT16[150];
	m_i32RRBufW = 0, m_i32RRBufR = 0, m_i32RRBufL = 0;
	m_i32HRBufW = 0, m_i32HRBufR = 0, m_i32HRBufL = 0;
	m_i32Spo2BufW = 0, m_i32Spo2BufR = 0, m_i32Spo2BufL = 0;
	m_u16HRNum = 0;
	m_i32RespWaveBuffW1 = 0, m_i32RespWaveBuffR1 = 0, m_i32RespWaveBuffL1 = 0;
	m_i32RespWaveBuffW2 = 0, m_i32RespWaveBuffR2 = 0, m_i32RespWaveBuffL2 = 0;
	m_u16RespWaveSum = 0, m_u16RespWaveNum = 0;
}


CECGRespSpo2Trend::~CECGRespSpo2Trend()
{
	delete m_pi16Spo2;
	delete m_pi16HRBuf;
	delete m_pi16RR;
	delete m_pCPonit;
	delete m_pRespWaveBuff1;
	delete m_pRespWaveBuff2;
}


BEGIN_MESSAGE_MAP(CECGRespSpo2Trend, CStatic)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_WM_CREATE()
	ON_WM_DESTROY()
	ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()


int CECGRespSpo2Trend::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	INT i = 0, j = 0;
	// 获得控件区域
	//GetClientRect(&m_rectCtrl);
	//客户区DC，可以绘画及显示
	CClientDC pDC(this);

	((CThreadDraw *)theApp.m_pThrdDraw)->init_dc(&pDC);
	((CThreadDraw *)theApp.m_pThrdDraw)->m_i32Init = 1;
	//依附窗口DC创建兼容内存DC
	dcMem.CreateCompatibleDC(&pDC);
	//创建兼容位图
	bmp.CreateCompatibleBitmap(&pDC, CECGRespSpo2Trend::m_i32Width, CECGRespSpo2Trend::m_i32Height);
	dcMem.SelectObject(&bmp); //将位图选择进内存DC
	dcMem.FillSolidRect(0, 0, CECGRespSpo2Trend::m_i32Width, CECGRespSpo2Trend::m_i32Height, RGB(0, 0, 0));

	//dcMemBK.CreateCompatibleDC(&pDC);
	////创建兼容位图
	//bmpBK.CreateCompatibleBitmap(&pDC, CECGRespSpo2Trend::m_i32Width, CECGRespSpo2Trend::m_i32Height);
	//dcMemBK.SelectObject(&bmpBK); //将位图选择进内存DC
	//dcMemBK.FillSolidRect(0, 0, CECGRespSpo2Trend::m_i32Width, CECGRespSpo2Trend::m_i32Height, RGB(0, 0, 0));

	//dcMemBK2.CreateCompatibleDC(&pDC);
	////创建兼容位图
	//bmpBK2.CreateCompatibleBitmap(&pDC, CECGRespSpo2Trend::m_i32Width, CECGRespSpo2Trend::m_i32Height);
	//dcMemBK2.SelectObject(&bmpBK2); //将位图选择进内存DC
	//dcMemBK2.FillSolidRect(0, 0, CECGRespSpo2Trend::m_i32Width, CECGRespSpo2Trend::m_i32Height, RGB(0, 0, 0));

	font.CreateFont(18,                                          //   nHeight     
		0,                                                   //   nWidth     
		0,                                                   //   nEscapement   
		0,                                                   //   nOrientation     
		FW_NORMAL,                                   //   nWeight     
		FALSE,                                           //   bItalic     
		FALSE,                                           //   bUnderline     
		0,                                                   //   cStrikeOut     
		ANSI_CHARSET,                             //   nCharSet     
		OUT_DEFAULT_PRECIS,                 //   nOutPrecision     
		CLIP_DEFAULT_PRECIS,               //   nClipPrecision     
		DEFAULT_QUALITY,                       //   nQuality     
		DEFAULT_PITCH | FF_SWISS,     //   nPitchAndFamily       
		_T("宋体"));

	fontSet.CreateFont(32,                                          //   nHeight     
		0,                                                   //   nWidth     
		0,                                                   //   nEscapement   
		0,                                                   //   nOrientation     
		FW_NORMAL,                                   //   nWeight     
		FALSE,                                           //   bItalic     
		FALSE,                                           //   bUnderline     
		0,                                                   //   cStrikeOut     
		ANSI_CHARSET,                             //   nCharSet     
		OUT_DEFAULT_PRECIS,                 //   nOutPrecision     
		CLIP_DEFAULT_PRECIS,               //   nClipPrecision     
		DEFAULT_QUALITY,                       //   nQuality     
		DEFAULT_PITCH | FF_SWISS,     //   nPitchAndFamily       
		_T("宋体"));

	penBK = new CPen(PS_SOLID, 1, RGB(210, 210, 210));
	penGrid = new CPen(PS_DOT, 1, RGB(210, 210, 210));
	penECGLine = new CPen(PS_SOLID, 2, CStaticValueECGNormal::m_rgbText);
	penRespLine = new CPen(PS_SOLID, 2, CStaticValueRespNormal::m_rgbText);
	penSpo2Line = new CPen(PS_SOLID, 2, CStaticValueSPO2Normal::m_rgbText);

	//画出框子

	//dcMemBK.SelectObject(penBK);

	////上横线
	//dcMemBK.MoveTo(0,0);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 0);
	////下横线
	//dcMemBK.MoveTo(0, CECGRespSpo2Trend::m_i32Height-1);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, CECGRespSpo2Trend::m_i32Height - 1);
	////左竖线
	//dcMemBK.MoveTo(0, 0);
	//dcMemBK.LineTo(0, CECGRespSpo2Trend::m_i32Height);
	////右竖线
	//dcMemBK.MoveTo(CECGRespSpo2Trend::m_i32Width-1, 0);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width - 1, CECGRespSpo2Trend::m_i32Height - 1);

	////HR 横向 虚线
	//dcMemBK.SelectObject(penGrid);
	//dcMemBK.MoveTo(35, 2);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 2);

	//dcMemBK.MoveTo(35, 16);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width , 16);

	//dcMemBK.MoveTo(35, 30);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 30);

	//dcMemBK.MoveTo(35, 44);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width , 44);

	//dcMemBK.MoveTo(35, 58);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 58);

	//dcMemBK.MoveTo(35, 72);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 72);

	////HR 竖向 虚线
	//dcMemBK.MoveTo(35, 2);
	//dcMemBK.LineTo(35, 72);

	//dcMemBK.MoveTo(35 + 180, 2);
	//dcMemBK.LineTo(35 + 180, 72);

	//dcMemBK.MoveTo(35 + 180 * 2, 2);
	//dcMemBK.LineTo(35 + 180 * 2, 72);

	//dcMemBK.MoveTo(35 + 180 * 3, 2);
	//dcMemBK.LineTo(35 + 180 * 3, 72);

	//dcMemBK.MoveTo(35 + 180 * 4, 2);
	//dcMemBK.LineTo(35 + 180 * 4, 72);

	//dcMemBK.MoveTo(35 + 180 * 5, 2);
	//dcMemBK.LineTo(35 + 180 * 5, 72);

	////HR SPO2 分割线
	//dcMemBK.SelectObject(penBK);
	//dcMemBK.MoveTo(35, 74);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 74);

	////Spo2  横向 虚线
	//dcMemBK.SelectObject(penGrid);
	//dcMemBK.MoveTo(35, 76);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 76);

	//dcMemBK.MoveTo(35, 90);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 90);

	//dcMemBK.MoveTo(35, 104);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 104);

	//dcMemBK.MoveTo(35, 118);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 118);

	//dcMemBK.MoveTo(35, 132);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 132);

	//dcMemBK.MoveTo(35, 147);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 147);

	////Spo2  竖向 虚线
	//dcMemBK.MoveTo(35, 76);
	//dcMemBK.LineTo(35, 147);

	//dcMemBK.MoveTo(35 + 180, 76);
	//dcMemBK.LineTo(35 + 180, 147);

	//dcMemBK.MoveTo(35 + 180 * 2, 76);
	//dcMemBK.LineTo(35 + 180 * 2, 147);

	//dcMemBK.MoveTo(35 + 180 * 3, 76);
	//dcMemBK.LineTo(35 + 180 * 3, 147);

	//dcMemBK.MoveTo(35 + 180 * 4, 76);
	//dcMemBK.LineTo(35 + 180 * 4, 147);

	//dcMemBK.MoveTo(35 + 180 * 5, 76);
	//dcMemBK.LineTo(35 + 180 * 5, 147);

	////SPO2 RR分割线
	//dcMemBK.SelectObject(penBK);
	//dcMemBK.MoveTo(35, 149);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 149);

	////RR 横向 虚线
	//dcMemBK.SelectObject(penGrid);
	//dcMemBK.MoveTo(35, 151);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 151);

	//dcMemBK.SelectObject(penGrid);
	//dcMemBK.MoveTo(35, 168);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 168);

	//dcMemBK.MoveTo(35, 185);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 185);

	//dcMemBK.MoveTo(35, 202);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 202);

	//dcMemBK.MoveTo(35, 219);
	//dcMemBK.LineTo(CECGRespSpo2Trend::m_i32Width, 219);

	////RR 竖向 虚线
	//dcMemBK.MoveTo(35, 149);
	//dcMemBK.LineTo(35, 219);

	//dcMemBK.MoveTo(35 + 180, 149);
	//dcMemBK.LineTo(35 + 180, 219);

	//dcMemBK.MoveTo(35 + 180 * 2, 149);
	//dcMemBK.LineTo(35 + 180 * 2, 219);

	//dcMemBK.MoveTo(35 + 180 * 3, 149);
	//dcMemBK.LineTo(35 + 180 * 3, 219);

	//dcMemBK.MoveTo(35 + 180 * 4, 149);
	//dcMemBK.LineTo(35 + 180 * 4, 219);

	//dcMemBK.MoveTo(35 + 180 * 5, 149);
	//dcMemBK.LineTo(35 + 180 * 5, 219);

	//dcMemBK.SelectObject(&font);
	//dcMemBK.SetTextColor(CStaticValueECGNormal::m_rgbText);

	//dcMemBK.TextOut(0, 2, _T("350"));
	//dcMemBK.TextOut(0, 30, _T("HR"));
	//dcMemBK.TextOut(0, 58, _T("0"));
	//dcMemBK.SetTextColor(CStaticValueSPO2Normal::m_rgbText);
	//dcMemBK.TextOut(0, 76, _T("100"));
	//dcMemBK.TextOut(0, 104, _T("So2"));
	//dcMemBK.TextOut(0, 130, _T("0"));
	//dcMemBK.SetTextColor(CStaticValueRespNormal::m_rgbText);
	//dcMemBK.TextOut(0, 149, _T("120"));
	//dcMemBK.TextOut(0, 178, _T("RR"));
	//dcMemBK.TextOut(0, 206, _T("0"));




	//dcMemBK2.SelectObject(penBK);

	////上横线
	//dcMemBK2.MoveTo(0, 0);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 0);
	////下横线
	//dcMemBK2.MoveTo(0, CECGRespSpo2Trend::m_i32Height - 1);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, CECGRespSpo2Trend::m_i32Height - 1);
	////左竖线
	//dcMemBK2.MoveTo(0, 0);
	//dcMemBK2.LineTo(0, CECGRespSpo2Trend::m_i32Height);
	////右竖线
	//dcMemBK2.MoveTo(CECGRespSpo2Trend::m_i32Width - 1, 0);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width - 1, CECGRespSpo2Trend::m_i32Height - 1);

	////HR 横向 虚线
	//dcMemBK2.SelectObject(penGrid);
	//dcMemBK2.MoveTo(35, 2);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 2);

	//dcMemBK2.MoveTo(35, 16);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 16);

	//dcMemBK2.MoveTo(35, 30);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 30);

	//dcMemBK2.MoveTo(35, 44);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 44);

	//dcMemBK2.MoveTo(35, 58);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 58);

	//dcMemBK2.MoveTo(35, 72);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 72);

	////HR 竖向 虚线
	//dcMemBK2.MoveTo(35, 2);
	//dcMemBK2.LineTo(35, 72);

	//dcMemBK2.MoveTo(35 + 180, 2);
	//dcMemBK2.LineTo(35 + 180, 72);

	//dcMemBK2.MoveTo(35 + 180 * 2, 2);
	//dcMemBK2.LineTo(35 + 180 * 2, 72);

	//dcMemBK2.MoveTo(35 + 180 * 3, 2);
	//dcMemBK2.LineTo(35 + 180 * 3, 72);

	//dcMemBK2.MoveTo(35 + 180 * 4, 2);
	//dcMemBK2.LineTo(35 + 180 * 4, 72);

	//dcMemBK2.MoveTo(35 + 180 * 5, 2);
	//dcMemBK2.LineTo(35 + 180 * 5, 72);

	////HR SPO2 分割线
	//dcMemBK2.SelectObject(penBK);
	//dcMemBK2.MoveTo(35, 74);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 74);

	////Spo2  横向 虚线
	//dcMemBK2.SelectObject(penGrid);
	//dcMemBK2.MoveTo(35, 76);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 76);

	//dcMemBK2.MoveTo(35, 90);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 90);

	//dcMemBK2.MoveTo(35, 104);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 104);

	//dcMemBK2.MoveTo(35, 118);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 118);

	//dcMemBK2.MoveTo(35, 132);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 132);

	//dcMemBK2.MoveTo(35, 147);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 147);

	////Spo2  竖向 虚线
	//dcMemBK2.MoveTo(35, 76);
	//dcMemBK2.LineTo(35, 147);

	//dcMemBK2.MoveTo(35 + 180, 76);
	//dcMemBK2.LineTo(35 + 180, 147);

	//dcMemBK2.MoveTo(35 + 180 * 2, 76);
	//dcMemBK2.LineTo(35 + 180 * 2, 147);

	//dcMemBK2.MoveTo(35 + 180 * 3, 76);
	//dcMemBK2.LineTo(35 + 180 * 3, 147);

	//dcMemBK2.MoveTo(35 + 180 * 4, 76);
	//dcMemBK2.LineTo(35 + 180 * 4, 147);

	//dcMemBK2.MoveTo(35 + 180 * 5, 76);
	//dcMemBK2.LineTo(35 + 180 * 5, 147);

	////SPO2 RR分割线
	//dcMemBK2.SelectObject(penBK);
	//dcMemBK2.MoveTo(35, 149);
	//dcMemBK2.LineTo(CECGRespSpo2Trend::m_i32Width, 149);


	//dcMemBK2.SelectObject(&font);
	//dcMemBK2.SetTextColor(CStaticValueECGNormal::m_rgbText);

	//dcMemBK2.TextOut(0, 2, _T("350"));
	//dcMemBK2.TextOut(0, 30, _T("HR"));
	//dcMemBK2.TextOut(0, 58, _T("0"));
	//dcMemBK2.SetTextColor(CStaticValueSPO2Normal::m_rgbText);
	//dcMemBK2.TextOut(0, 76, _T("100"));
	//dcMemBK2.TextOut(0, 104, _T("So2"));
	//dcMemBK2.TextOut(0, 130, _T("0"));
	//dcMemBK2.SetTextColor(CStaticValueRespNormal::m_rgbText);
	//dcMemBK2.TextOut(0, 155, _T("呼吸"));
	//dcMemBK2.TextOut(0, 188, _T("波"));
	
	//Erase();
	//Draw_Time();
	//	return CStatic::OnCreate(lpCreateStruct);
	return TRUE;
}



void CECGRespSpo2Trend::OnDestroy()
{
	CStatic::OnDestroy();

	// TODO:  在此处添加消息处理程序代码

	dcMem.DeleteDC();
	bmp.DeleteObject();

	/*dcMemBK.DeleteDC();
	bmpBK.DeleteObject();

	dcMemBK2.DeleteDC();
	bmpBK2.DeleteObject();*/

	font.DeleteObject();
	fontSet.DeleteObject();
	delete penBK;
	delete penGrid;
	delete penECGLine;
	delete penRespLine;
	delete penSpo2Line;
}


//绘制心电波形
void CECGRespSpo2Trend::Draw_Wave()
{
	INT i = 0, j = 0, t = 0,k=0;
	dcMem.SelectObject(penRespLine);
	if (m_i32Time == 0)
	{
		m_i32RespWaveBuffR1 = (m_i32RespWaveBuffW1 + 25 * 75 - 1) % (25 * 75);
		for (i = 0; (i < m_i32RespWaveBuffL1); i++)
		{
			t = 35 + 180 * 5 - i * 12 / 25;
			//k = 219 - m_pRespWaveBuff1[m_i32RespWaveBuffR1] * CECGRespSpo2Trend::m_i32RespPixel / CECGRespSpo2Trend::m_i32RespValue;

			if (k < 151)
				k = 151;
			else if (k>219)
				k = 219;

			m_pCPonit[i].x = t;
			m_pCPonit[i].y = m_pRespWaveBuff1[m_i32RespWaveBuffR1];
			m_i32RespWaveBuffR1 = (m_i32RespWaveBuffR1 + 25 * 75 - 1) % (25 * 75);
		}
		dcMem.Polyline(m_pCPonit, m_i32RespWaveBuffL1);
	}
	else
	{
		m_i32RespWaveBuffR2 = (m_i32RespWaveBuffW2 + 25 * 150 - 1) % (25 * 150);
		for (i = 0; (i < m_i32RespWaveBuffL2); i++)
		{
			t = 35 + 180 * 5 - i * 6 / 25;
			
			if (k < 151)
				k = 151;
			else if (k>219)
				k = 219;

			m_pCPonit[i].x = t;
			m_pCPonit[i].y = m_pRespWaveBuff2[m_i32RespWaveBuffR2];
			m_i32RespWaveBuffR2 = (m_i32RespWaveBuffR2 + 25 * 150 - 1) % (25 * 150);
		}
		dcMem.Polyline(m_pCPonit, 25 * 150);
	}
}


void CECGRespSpo2Trend::Draw_HR()
{
	INT i = 0, j = 0, l = 0, t = 0, a = 0;
	if (m_i32HRBufL)
	{
		if (m_i32Time == 0)
		{
			l = 75;
			t = 12;
		}
		else
		{
			l = 150;
			t = 6;
		}
		m_i32HRBufR = (m_i32HRBufW + 150 - 1) % 150;
		a = (m_pi16HRBuf[m_i32HRBufR] - 0) * 14 / 60;
		if (a > 70)
		{
			a = 70;
		}
		else if (a < 0)
		{
			a = 0;
		}
		dcMem.SelectObject(penECGLine);
		dcMem.MoveTo(35 + 180 * 5, 72-a);
		
		for (i = 0; (i < m_i32HRBufL) && (i < l); i++)
		{
			dcMem.LineTo(35 + 180 * 5 - i*t, 72-a);
			m_i32HRBufR = (m_i32HRBufR + 150 - 1) % 150;
			a = (m_pi16HRBuf[m_i32HRBufR] - 0) * 14 / 60;
			if (a>70)
			{
				a = 70;
			}
			else if (a < 0)
			{
				a = 0;
			}
			dcMem.MoveTo(35 + 180 * 5 - i*t, 72 - a);
		}
	}	
}


void CECGRespSpo2Trend::Draw_Spo2()
{
	INT i = 0, j = 0, l = 0, t = 0, a = 0;
	if (m_i32Spo2BufL)
	{
		if (m_i32Time == 0)
		{
			l = 75;
			t = 12;
		}
		else
		{
			l = 150;
			t = 6;
		}
		m_i32Spo2BufR = (m_i32Spo2BufW + 150 - 1) % 150;
		a = (m_pi16Spo2[m_i32Spo2BufR] - 0) * 14 / 20;
		if (a > 70)
		{
			a = 70;
		}
		else if (a < 0)
		{
			a = 0;
		}
		dcMem.SelectObject(penSpo2Line);
		dcMem.MoveTo(35 + 180 * 5, 147 - a);

		for (i = 0; (i < m_i32Spo2BufL) && (i < l); i++)
		{
			dcMem.LineTo(35 + 180 * 5 - i*t, 147 - a);
			m_i32Spo2BufR = (m_i32Spo2BufR + 150 - 1) % 150;
			a = (m_pi16Spo2[m_i32Spo2BufR] - 0) * 14 / 20;
			if (a>70)
			{
				a = 70;
			}
			else if (a < 0)
			{
				a = 0;
			}
			dcMem.MoveTo(35 + 180 * 5 - i*t, 147 - a);
		}
	}
}


void CECGRespSpo2Trend::Draw_RR()
{
	INT i = 0, j = 0, l = 0, t = 0, a = 0;
	if (m_i32RRBufL)
	{
		if (m_i32Time == 0)
		{
			l = 75;
			t = 12;
		}
		else
		{
			l = 150;
			t = 6;
		}
		m_i32RRBufR = (m_i32RRBufW + 150 - 1) % 150;
		a = (m_pi16RR[m_i32RRBufR] - 0) * 17 / 30;
		if (a > 68)
		{
			a = 68;
		}
		else if (a < 0)
		{
			a = 0;
		}
		dcMem.SelectObject(penRespLine);
		dcMem.MoveTo(35 + 180 * 5, 219 - a);

		for (i = 0; (i < m_i32RRBufL) && (i < l); i++)
		{
			dcMem.LineTo(35 + 180 * 5 - i*t, 219 - a);
			m_i32RRBufR = (m_i32RRBufR + 150 - 1) % 150;
			a = (m_pi16RR[m_i32RRBufR] - 0) * 17 / 30;
			if (a>68)
			{
				a = 68;
			}
			else if (a < 0)
			{
				a = 0;
			}
			dcMem.MoveTo(35 + 180 * 5 - i*t, 219 - a);
		}
	}

}


void CECGRespSpo2Trend::Draw_Time()
{
	

	/*if (m_i32Time == 0)
	{
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(RGB(210, 210, 210));
		dcMem.TextOut(10 , 222, _T("-75s"));
		dcMem.TextOut(10+180, 222, _T("-60s"));
		dcMem.TextOut(10 + 180 * 2, 222, _T("-45s"));
		dcMem.TextOut(10 + 180 * 3, 222, _T("-30s"));
		dcMem.TextOut(10 + 180 * 4, 222, _T("-15s"));
		
		dcMem.SelectObject(&fontSet);
		dcMem.SetTextColor(CStaticValueECGNormal::m_rgbText);

		dcMem.TextOut(10 + 180 + 70, 222, _T("75秒"));
	}
	else
	{
		dcMem.SelectObject(&font);
		dcMem.SetTextColor(RGB(210, 210, 210));
		dcMem.TextOut(10, 222, _T("-150s"));
		dcMem.TextOut(10 + 180, 222, _T("-120s"));
		dcMem.TextOut(10 + 180 * 2, 222, _T("-90s"));
		dcMem.TextOut(10 + 180 * 3, 222, _T("-60s"));
		dcMem.TextOut(10 + 180 * 4, 222, _T("-30s"));

		dcMem.SelectObject(&fontSet);
		dcMem.SetTextColor(CStaticValueECGNormal::m_rgbText);

		dcMem.TextOut(10 + 180 + 70, 222, _T("150秒"));
	}

	dcMem.SelectObject(&fontSet);
	dcMem.SetTextColor(CStaticValueECGNormal::m_rgbText);
	if (m_i32Show == 0)
	{
		dcMem.TextOut(10 + 180 * 3+70, 222, _T("呼吸率"));
	}
	else
	{
		dcMem.TextOut(10 + 180 * 3 + 70, 222, _T("呼吸波"));
	}*/
}


void CECGRespSpo2Trend::Erase()
{
	/*if (m_i32Show==0)
		dcMem.BitBlt(0, 0, CECGRespSpo2Trend::m_i32Width, CECGRespSpo2Trend::m_i32Height, &dcMemBK, 0, 0, SRCCOPY);
	else
		dcMem.BitBlt(0, 0, CECGRespSpo2Trend::m_i32Width, CECGRespSpo2Trend::m_i32Height, &dcMemBK2, 0, 0, SRCCOPY);*/
}


void CECGRespSpo2Trend::add_data(UINT8 *wave, INT l, INT16 rr, INT16 hr, INT16 spo2)
{
	INT i = 0, j = 0;

	for (i = 0; i < l;i++)
	{
		m_u16RespWaveSum += wave[i];
		if (++m_u16RespWaveNum>=5)
		{
			m_u16RespWaveNum = 0;
			m_pRespWaveBuff1[m_i32RespWaveBuffW1] = 219 - m_u16RespWaveSum  * CECGRespSpo2Trend::m_i32RespPixel / CECGRespSpo2Trend::m_i32RespValue / 5;
			m_pRespWaveBuff2[m_i32RespWaveBuffW2] = 219 - m_u16RespWaveSum  * CECGRespSpo2Trend::m_i32RespPixel / CECGRespSpo2Trend::m_i32RespValue / 5;
			m_u16RespWaveSum = 0;
			

			m_i32RespWaveBuffW1 = (m_i32RespWaveBuffW1 + 1) % (25 * 75);
			m_i32RespWaveBuffW2 = (m_i32RespWaveBuffW2 + 1) % (25 * 150);
			if (m_i32RespWaveBuffL1<25 * 75)
			{
				m_i32RespWaveBuffL1++;
			}
			if (m_i32RespWaveBuffL2 < 25 * 150)
			{
				m_i32RespWaveBuffL2++;
			}
			
			if (++m_u16HRNum>=25)
			{
				m_u16HRNum = 0;
				m_pi16HRBuf[m_i32HRBufW] = hr;
				m_i32HRBufW = (m_i32HRBufW + 1) % 150;

				m_pi16Spo2[m_i32Spo2BufW] = spo2;
				m_i32Spo2BufW = (m_i32Spo2BufW + 1) % 150;

				m_pi16RR[m_i32RRBufW] = rr;
				m_i32RRBufW = (m_i32RRBufW + 1) % 150;

				if (m_i32HRBufL < 150)
				{
					m_i32HRBufL++;
				}
				if (m_i32Spo2BufL < 150)
				{
					m_i32Spo2BufL++;
				}
				if (m_i32RRBufL < 150)
				{
					m_i32RRBufL++;
				}
			}
		}
	}
}


void CECGRespSpo2Trend::show_change()
{
	m_i32Show = (m_i32Show + 1) % 2;
}


void CECGRespSpo2Trend::draw()
{
	/*Erase();
	
	if (m_i32Show==0)
	{
		Draw_RR();
	}
	else
	{
		Draw_Wave();
	}
	
	Draw_HR();
	Draw_Spo2();
	Draw_Time();
	Invalidate();*/
}


BOOL CECGRespSpo2Trend::OnEraseBkgnd(CDC* pDC)
{

	return TRUE;
}


void CECGRespSpo2Trend::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	//判断双击的位置

	//判断是否双击在 时间切换区域
	if ((point.x > (10 + 180 + 70)) && (point.x < (10 + 180 + 160)))
	{
		if ((point.y >(222)) && (point.y < (CECGRespSpo2Trend::m_i32Height)))
		{
			m_i32Time = (m_i32Time + 1) & 1;
			((CThreadDraw *)theApp.m_pThrdDraw)->time_change(m_i32Time);
		}
	}
	//判断是否双击在 呼吸切换区域
	if ((point.x >(10 + 180 * 3 + 70)) && (point.x < (10 + 180 * 3 + 160)))
	{
		if ((point.y >(222)) && (point.y < (CECGRespSpo2Trend::m_i32Height)))
		{
			m_i32Show = (m_i32Show + 1) & 1;
			((CThreadDraw *)theApp.m_pThrdDraw)->show_change(m_i32Show);
		}
	}
	//Erase();
	//Draw_Time();

	//Invalidate();
}


void CECGRespSpo2Trend::OnPaint()
{
	CPaintDC pDC(this);

	pDC.BitBlt(m_rectCtrl.left, m_rectCtrl.top, CECGRespSpo2Trend::m_i32Width, CECGRespSpo2Trend::m_i32Height, &dcMem, 0, 0, SRCCOPY);

	//	CStatic::OnPaint();
}

