⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mcp3002.cpp

📁 一个开源的心电图测量仪驱动和应用软件,可记录
💻 CPP
字号:
// MCP3002.cpp: implementation of the MCP3002 class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MCP3002.h"
#include "MultimediaTimer.h"
#include "ADC3002.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//Delcare out timer function
//Function must be static
static	void TimerFunction(void* obj,UINT idEvent);
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

MCP3002::MCP3002()
{

}

MCP3002::~MCP3002()
{

}

void TimerFunction(void* obj,UINT idEvent)
{
	//This is our timer actevated function
	//First get a pointer to class functions
	MCP3002* mcp = (MCP3002*) obj;
	//Activate class functions
	mcp->HandleTimer(idEvent);

}

void MCP3002::HandleTimer(UINT nIDEvant)
{
	//This function is activated from MM timer events
	//Because we need to make 5000 samples do them 
	if(i_mmcount<=5000)
	{
		//GetADC Samples
		Channel_0[i_mmcount] = ADC_Ch_0();
		Channel_1[i_mmcount] = ADC_Ch_1();
		//update counter
		i_mmcount++;
	}

	//After we have done all samples stop sampling and MM timer
	if(i_mmcount>5000)
	{
		MMT_Stop();//Stop MMTimer
		DoEndNotification();//Make a notification to the program
	}

}
void MCP3002::MMT_Stop()
{
	//This function stops the MM timer
	Sleep(10);
	TEnd = CTime::GetCurrentTime();
	//Stop timer
	MMTimer.StopTimer();
	Sleep(10);
}

void MCP3002::MMT_Start(unsigned short LPT)
{
	//This function sets the LPT type
	//Zero the counter and after this stop the timer
	//Now it can be restarted and do samples
	i_mmcount = 0;
	LPT_PORT = LPT;
	//If MMTimer alredy runs stop it now!
	MMT_Stop();
	//Before start timer get the time moment
	TStart = CTime::GetCurrentTime();
	//Do timer event any 2 msec = 500Hz +- 2Hz
	MMTimer.StartTimer(this,2,10,TimerFunction);

}

unsigned short MCP3002::ADC_Ch_0()
{
	return adc3002.GetChanne_0(LPT_PORT,10);

}

unsigned short MCP3002::ADC_Ch_1()
{
	return adc3002.GetChanne_1(LPT_PORT,10);

}

void MCP3002::SetEndSampleNotification(void *obj, EndSampleNotification endnotification)
{
	//Sets the end sample notification event
	//so it will be activated after sampling period
	object = obj;
	//See declaration of EndSampleNotification
	EndNotification = endnotification;

}

void MCP3002::DoEndNotification()
{
	//This function activates a function and pass a parameters
	//to in our class
	int len;
	len = 5000;
	//activates a function EndNotification see declaretion
	EndNotification(object,&Channel_0[0],&Channel_1[0],len,TStart,TEnd);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -