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

📄 usbhostfftdlg.cpp

📁 USB2.0原理与工程开发光盘(第二版)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// USBHOSTFFTDlg.cpp : implementation file
//

#include "stdafx.h"
#include "USBHOSTFFT.h"
#include "USBHOSTFFTDlg.h"

#include "process.h"
#include "usb100.h"
#include "winioctl.h"
#include "usbdriver.h"
#include "math.h"

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

#define WM_DRAWPICTURE WM_USER+1

HWND hWindow;
float MaxValue;
unsigned long  ADDataBuffer[1024];
bool g_KeepGoing = false;
bool g_Transfering = false;
void __cdecl ReceiveThreadFunction(HANDLE hDevice);
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUSBHOSTFFTDlg dialog

CUSBHOSTFFTDlg::CUSBHOSTFFTDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CUSBHOSTFFTDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUSBHOSTFFTDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

CUSBHOSTFFTDlg::~CUSBHOSTFFTDlg()
{
	BackLinePen.DeleteObject();
	CurvePen.DeleteObject();
	LabelFont.DeleteObject();
	TitleFont.DeleteObject();
}

void CUSBHOSTFFTDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUSBHOSTFFTDlg)
	DDX_Control(pDX, IDC_EDIT_FREQ, m_Edit_Freq);
	DDX_Control(pDX, IDC_SLIDERFREQ, m_SliderFreq);
	DDX_Control(pDX, IDC_CHANNEL0_RADIO, m_Channel0);
	DDX_Control(pDX, IDC_PICTURE_WAVE2, m_Pictrue2);
	DDX_Control(pDX, IDC_PICTURE_WAVE1, m_Pictrue1);
	DDX_Control(pDX, IDC_USB_LIST, m_UsbList);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CUSBHOSTFFTDlg, CDialog)
	//{{AFX_MSG_MAP(CUSBHOSTFFTDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()	
	ON_BN_CLICKED(IDC_CLEARLIST_BUTTON, OnClearlistButton)	
	ON_BN_CLICKED(IDC_START_BUTTON, OnStartButton)
	ON_BN_CLICKED(IDC_STOP_BUTTON, OnStopButton)
	ON_BN_CLICKED(IDC_EXIT_BUTTON, OnExitButton)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDERFREQ, OnCustomdrawSliderfreq)
	ON_BN_CLICKED(IDC_INTERFACE_BUTTON, OnInterfaceButton)
	ON_MESSAGE(WM_DRAWPICTURE,OnDrawPicture1)
	ON_BN_CLICKED(IDC_ENDPOINT_BUTTON, OnEndpointButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUSBHOSTFFTDlg message handlers

BOOL CUSBHOSTFFTDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_SliderFreq.SetRange(0,7);
	m_SliderFreq.SetPos(3);

    CheckRadioButton(IDC_CHANNEL0_RADIO,IDC_CHANNEL3_RADIO,IDC_CHANNEL3_RADIO);

	hWindow=*this;
	strcpy(DeviceName,"Ezusb-0");

	BackLinePen.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(128, 128, 128));
	CurvePen.CreatePen(PS_SOLID,1,RGB(255,255,0)); 
	LabelFont.CreateFont(14,0,0,0,50,FALSE,0,0,0,0,0,0,0,"Arial");    
	TitleFont.CreateFont(20,0,0,0,50,FALSE,0,0,0,0,0,0,0,"Arial");

	m_xStart=0;
	m_yStart=0;

    MaxValue=4096;			 
	m_yn_step=512;
	Frequence=0;

	m_xn_step=50000/8;

    m_LeftRim=50;
	m_RightRim=40;
    m_UpRim=40;
    m_DownRim=40;
	
	for(int j=0;j<512;j++) 
	{
		m_PointList[j].x = j;		
		m_PointList[j].y= 0;
	}	

	PostMessage(WM_DRAWPICTURE,0,0);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CUSBHOSTFFTDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CUSBHOSTFFTDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CUSBHOSTFFTDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CUSBHOSTFFTDlg::OnDrawPicture1(WPARAM wParam,LPARAM lParam)
{
	int temp=0;
	{
	  MaxValue=0;
      m_PointList[0].y=0;
	  for(int i=1;i<256;i++)
	  {		   
		   m_PointList[i].y = (unsigned long)sqrt(pow(ADDataBuffer[i],2)+pow(ADDataBuffer[i+256],2));
		   if(m_PointList[i].y>MaxValue)  
		   {			   
			   MaxValue=(float)m_PointList[i].y;
			   temp=i;
		   }
	  }	
	}
	m_yn_step=(int)MaxValue/8;
    Frequence=(float)(50000.0/256.0*temp);

    CRect rect;
	CDC* pDC;
	CBrush brush;

	m_Pictrue1.GetClientRect(&rect);
	GetUDLRrect(rect);
	GetRectBlc(0,0,256,MaxValue+100);
    pDC=m_Pictrue1.GetDC();	
	brush.CreateSolidBrush(RGB(0,0,0));
    pDC->FillRect(InnerRect,&brush);
	DrawBackLines(pDC);
	DrawUDLRrect(pDC);
    DrawLab(pDC,3);
	DrawCurve(pDC);
    
	temp=0;
	{
	  MaxValue=0;
      m_PointList[0].y=0;
	  for(int i=1;i<256;i++)
	  {		   
		   m_PointList[i].y = (unsigned long)sqrt(pow(ADDataBuffer[i+512],2)+pow(ADDataBuffer[i+768],2));
		   if(m_PointList[i].y>MaxValue)  
		   {			   
			   MaxValue=(float)m_PointList[i].y;
			   temp=i;
		   }
	  }	
	}
	m_yn_step=(int)MaxValue/8;
    Frequence=(float)(50000.0/256.0*temp);

	m_Pictrue2.GetClientRect(&rect);
	GetUDLRrect(rect);
	GetRectBlc(0,0,256,MaxValue+100);
    pDC=m_Pictrue2.GetDC();		
    pDC->FillRect(InnerRect,&brush);
	DrawBackLines(pDC);
	DrawUDLRrect(pDC);
    DrawLab(pDC,5);
	DrawCurve(pDC);
	ReleaseDC(pDC);
}
///////////////////////////////////////////////////////////////////
//
// 以下是画图的相关函数。
//
///////////////////////////////////////////////////////////////////
void CUSBHOSTFFTDlg::GetUDLRrect(CRect rect)
{

    m_InnerUHScreen = m_UpRim; 
    m_InnerDHScreen = rect.bottom - m_DownRim;
    m_InnerLWScreen = m_LeftRim;               
	m_InnerRWScreen = rect.right - m_RightRim;  

	Urect.top=0;
	Urect.bottom=m_InnerUHScreen;
	Urect.left=0;
	Urect.right=rect.right;

	Drect.top=m_InnerDHScreen;
	Drect.bottom=rect.bottom;
	Drect.left=0;
	Drect.right=rect.right;

	Lrect.top=m_InnerUHScreen;
	Lrect.bottom=m_InnerDHScreen;
    Lrect.left=0;
	Lrect.right=m_InnerLWScreen;

	Rrect.top=m_InnerUHScreen;
	Rrect.bottom=m_InnerDHScreen;
    Rrect.left=m_InnerRWScreen;
	Rrect.right=rect.right;

	InnerRect.top=m_InnerUHScreen;
	InnerRect.bottom=m_InnerDHScreen;
    InnerRect.left=m_InnerLWScreen;
	InnerRect.right=m_InnerRWScreen; 

	TotalRect.top=0;
	TotalRect.bottom=rect.bottom;
    TotalRect.left=0;
	TotalRect.right=rect.right;	
}

void CUSBHOSTFFTDlg::GetRectBlc(float xRectStart,float yRectStart,float xRectEnd,float yRectEnd)
{
	float m1,m2;  
	float x1,y1,x2,y2;
	x1=min(xRectStart,xRectEnd);
	x2=max(xRectStart,xRectEnd);
	y1=min(yRectStart,yRectEnd);
	y2=max(yRectStart,yRectEnd);
	
	float lx,ly;

  
	lx=x2-x1;	
    if(lx<0) return;   

  
    ly=y2-y1;
	if(ly<0) return;     


    m1=lx/(m_InnerRWScreen-m_InnerLWScreen);    
	m2=ly/(m_InnerDHScreen-m_InnerUHScreen);	
	m_XOriginScale =m1;    
	m_YOriginScale =m2;   
}

void CUSBHOSTFFTDlg::DrawUDLRrect (CDC *pDC)
{
	pDC->SetBkColor(12632256); 
    pDC->SetBkMode(OPAQUE);
	CBrush brush(pDC->GetBkColor ());
	pDC->FillRect(Urect,&brush);
	pDC->FillRect(Drect,&brush);
	pDC->FillRect(Lrect,&brush);
	pDC->FillRect(Rrect,&brush);
	pDC->DrawEdge(TotalRect,EDGE_SUNKEN,BF_RECT);
}

void CUSBHOSTFFTDlg::DrawBackLines (CDC *pDC)
{
    float xL;
	float xd;
	float xLine;
    xL=(float)(m_InnerRWScreen-m_InnerLWScreen);			
	if(xL<0) xL=-xL;
	if(xL==0) return;        
	xd=xL/8;       
    m_xLineStart[0]=(float)m_InnerLWScreen; 
	m_xn=0;
	xLine=xd;
	while(xLine<xL)
	{
		m_xn=m_xn+1;		
		m_xLineStart[m_xn]=m_xn*xd+m_InnerLWScreen;	 
		xLine=xLine+xd; 
	}
    m_xn=m_xn+1;
	m_xLineStart[m_xn]=(float)m_InnerRWScreen;

	float yL;
	float yd;
	float yLine;
	yL=(float)(m_InnerDHScreen-m_InnerUHScreen);
	if(yL<0) yL=-yL;
	if(yL==0) return;		
	yd=yL/8;				
    m_yLineStart[0]=(float)m_InnerDHScreen;
	m_yn=0;		        
	yLine=yd;
	while(yLine<yL)              
	{
		m_yn=m_yn+1;
		m_yLineStart[m_yn]=m_InnerDHScreen-m_yn*yd;
		yLine=yLine+yd;
	}
	m_yn=m_yn+1;
	m_yLineStart[m_yn]=(float)m_InnerUHScreen;
							
    CPen* pOldPen = pDC->SelectObject(&BackLinePen);

	int i;	
	for(i=0;i<m_xn+1;i++)
	{   		
	    pDC->MoveTo ((int)m_xLineStart[i],m_InnerUHScreen);

⌨️ 快捷键说明

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