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

📄 usbhostlogicdlg.cpp

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

#include "stdafx.h"
#include "USBHOSTLOGIC.h"
#include "USBHOSTLOGICDlg.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

unsigned char  ADDataBuffer[8][4096];
bool g_KeepGoing = false;
float SamFreq[7]={156.25,312.5,625,1250,2500,5000,10000};

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CUSBHOSTLOGICDlg dialog

CUSBHOSTLOGICDlg::CUSBHOSTLOGICDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CUSBHOSTLOGICDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUSBHOSTLOGICDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

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

void CUSBHOSTLOGICDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUSBHOSTLOGICDlg)
	DDX_Control(pDX, IDC_EDIT_AMP, m_Edit_Amp);
	DDX_Control(pDX, IDC_SLIDERAMP, m_SliderAmp);
	DDX_Control(pDX, IDC_EDIT_FREQ, m_Edit_Freq);
	DDX_Control(pDX, IDC_SLIDERFREQ, m_SliderFreq);
	DDX_Control(pDX, IDC_USB_LIST, m_UsbList);
	DDX_Control(pDX, IDC_PICTURE_WAVE, m_Pictrue);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CUSBHOSTLOGICDlg, CDialog)
	//{{AFX_MSG_MAP(CUSBHOSTLOGICDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_EXIT_BUTTON, OnExitButton)
	ON_BN_CLICKED(IDC_CONFIG_BUTTON, OnConfigButton)
	ON_BN_CLICKED(IDC_CLEARLIST_BUTTON, OnClearlistButton)
	ON_BN_CLICKED(IDC_START_BUTTON, OnStartButton)
	ON_BN_CLICKED(IDC_DOWNFRAME_BUTTON, OnDownframeButton)
	ON_BN_CLICKED(IDC_UPFRAME_BUTTON, OnUpframeButton)
	ON_BN_CLICKED(IDC_FIRSTFRAME_BUTTON, OnFirstframeButton)
	ON_BN_CLICKED(IDC_LASTFRAME_BUTTON, OnLastframeButton)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDERFREQ, OnCustomdrawSliderfreq)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDERAMP, OnCustomdrawSlideramp)
	ON_MESSAGE(WM_DRAWPICTURE,OnDrawPicture)
	ON_BN_CLICKED(IDC_STRING_BUTTON, OnStringButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUSBHOSTLOGICDlg message handlers

BOOL CUSBHOSTLOGICDlg::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

    CheckRadioButton(IDC_TRIG0_RADIO,IDC_TRIG3_RADIO,IDC_TRIG0_RADIO);

	m_SliderFreq.SetRange(0,7);
	m_SliderFreq.SetPos(6);

	m_SliderAmp.SetRange(0,250);
	m_SliderAmp.SetPos(250);

	strcpy(DeviceName,"Ezusb-0");

	m_Frame=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;

    m_LeftRim=50;
	m_RightRim=40;
    m_UpRim=40;
    m_DownRim=40;

    for(int j=0;j<8;j++)
	{
	    for(int i=0;i<1024;i++)
		{		
		m_PointList[j][i].x = i;
		}
	}

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

void CUSBHOSTLOGICDlg::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 CUSBHOSTLOGICDlg::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 CUSBHOSTLOGICDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CUSBHOSTLOGICDlg::OnDrawPicture(WPARAM wParam,LPARAM lParam)
{
	for(int j=0;j<8;j++)
	{
		for(int i=0;i<1024;i++) 
		       m_PointList[j][i].y=ADDataBuffer[j][i+m_Frame];
	}

	CDC* pDC=m_Pictrue.GetDC();
	CBrush brush;

    brush.CreateSolidBrush(RGB(0,0,0));
	GetUDLRrect();
    pDC->FillRect(InnerRect,&brush);	
	DrawUDLRrect(pDC);
	
	GetRectBlc(0,0,1024,3);

	DrawBackLines(pDC);
	DrawCurve(pDC);
	
	DrawLab(pDC);
	ReleaseDC(pDC);
}
void CUSBHOSTLOGICDlg::OnFirstframeButton() 
{
	// TODO: Add your control notification handler code here
	m_Frame=0;	
	PostMessage(WM_DRAWPICTURE,0,0);
}

void CUSBHOSTLOGICDlg::OnLastframeButton() 
{
	// TODO: Add your control notification handler code here
	m_Frame=3072;
	PostMessage(WM_DRAWPICTURE,0,0);
}

void CUSBHOSTLOGICDlg::OnUpframeButton() 
{
	// TODO: Add your control notification handler code here
    if(m_Frame-1024>-1)
	{
		m_Frame-=1024;
		PostMessage(WM_DRAWPICTURE,0,0);
	}
	else
		MessageBox("已是首帧!", "错误", MB_ICONERROR | MB_OK);
}

void CUSBHOSTLOGICDlg::OnDownframeButton() 
{
	// TODO: Add your control notification handler code here
    if(m_Frame+1024<4096)
	{
		m_Frame+=1024;
		PostMessage(WM_DRAWPICTURE,0,0);
	}
	else
		MessageBox("已是末帧!", "错误", MB_ICONERROR | MB_OK);	
}




///////////////////////////////////////////////////////////////////
//
// 以下是画图的相关函数。
//
///////////////////////////////////////////////////////////////////
void CUSBHOSTLOGICDlg::GetUDLRrect()
{
	CRect rect;
	m_Pictrue.GetClientRect(&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 CUSBHOSTLOGICDlg::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)/8);	
	m_XOriginScale =m1;      
	m_YOriginScale =m2;      
}

void CUSBHOSTLOGICDlg::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 CUSBHOSTLOGICDlg::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);

⌨️ 快捷键说明

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