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

📄 displayview.cpp

📁 USB HID 设备数据采集程序 HID外设使用的MC68HC908JB8ADW单片机
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DisplayView.cpp : implementation file
//

#include "stdafx.h"
#include "ENT_JAT.h"
#include "DisplayView.h"
#include "process.h"
extern "C"{
#include "setupapi.h"
#include "hidsdi.h"
}  

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define COMM_COUNT 6
/////////////////////////////////////////////////////////////////////////////
#define MAX_DATA_LEN    (8)
#define USB_VID    (0x0425)         // XXXX-十六进制数,需更改。
#define USB_PID    (0x0111)         // XXXX-十六进制数,需更改。
#define WM_MY_USB WM_USER+102
HANDLE m_HidHandle=NULL;
bool g_KeepGoing = false;
bool capture_flag=false;
int m_MaxDataLen;
BYTE recvDataBuf[8];

void __cdecl RecvThreadFunction(HANDLE hidHandle);

IMPLEMENT_DYNCREATE(DisplayView, CFormView)

DisplayView::DisplayView()
	: CFormView(DisplayView::IDD)
{
	//{{AFX_DATA_INIT(DisplayView)
	m_VoltageBlue = 0.0f;
	m_VoltageRed = 0.0f;
	//}}AFX_DATA_INIT
	isZoom=false;
	isRectangleSel=false;
	m_play_button_down=false;

	 m_jk1=false;
	 m_jk2=false;
	 m_jk3=false;
	 m_jk4=false;
	 m_jk5=false;
	 m_jk6=false;
}

DisplayView::~DisplayView()
{
}
/*
	DDX_Text(pDX, IDC_VLTG_BLUE, m_VoltageBlue);
	DDX_Text(pDX, IDC_VLTG_RED, m_VoltageRed);
*/
void DisplayView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DisplayView)
	DDX_Control(pDX, IDC_MOTO_SLIDER, m_motor_ctrl);
	DDX_Control(pDX, IDC_FLUXLINE, m_fluxline_ctrl);
	DDX_Control(pDX, IDC_VLTG_GREEN, m_vltgctrlGreen);
	DDX_Control(pDX, IDC_VLTG_RED, m_vltgctrlRed);
	DDX_Control(pDX, IDC_VLTG_BLUE, m_vltgctrlBlue);
	DDX_Control(pDX, IDC_DELETEVIOCE, m_deletevoice_but);
	DDX_Control(pDX, IDC_RIGHTPRESS, m_Right_txt);
	DDX_Control(pDX, IDC_LEFTPRESS, m_Left_txt);
	DDX_Control(pDX, IDC_STOP, m_stop_but);
	DDX_Control(pDX, IDC_START, m_start_but);
	DDX_Control(pDX, IDC_PLAY, m_play_but);
	DDX_Control(pDX, IDC_SAVE, m_save_but);
	DDX_Control(pDX, IDC_DISPLAY, m_DisplayWnd);
	DDX_Control(pDX, IDC_MSCOMM2, m_ComPort);

	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(DisplayView, CFormView)
	//{{AFX_MSG_MAP(DisplayView)
	ON_BN_CLICKED(IDC_DISPLAY, OnDisplay)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_PLAY, OnPlay)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_WM_MOUSEMOVE()
	ON_WM_MOUSEWHEEL()
	ON_WM_PAINT()
	ON_WM_CANCELMODE()
	ON_WM_CREATE()
	ON_WM_CAPTURECHANGED()
	ON_BN_CLICKED(IDC_LEFTPRESS, OnLeftpress)
	ON_BN_CLICKED(IDC_DOCUMENT, OnDocument)
	ON_BN_CLICKED(IDC_DELETEVIOCE, OnDeletevioce)
	ON_COMMAND(IDM_ZOOM, OnZoom)
	ON_UPDATE_COMMAND_UI(IDM_ZOOM, OnUpdateZoom)
	ON_COMMAND(IDM_RECTANGLESEL, OnRectanglesel)
	ON_UPDATE_COMMAND_UI(IDM_RECTANGLESEL, OnUpdateRectanglesel)
	ON_MESSAGE(WM_MY_USB,OnMyUSBEvent)
	ON_EN_CHANGE(IDC_VLTG_RED, OnChangeVltgRed)
	ON_EN_CHANGE(IDC_VLTG_BLUE, OnChangeVltgBlue)
	ON_COMMAND(IDM_JK1, OnJk1)
	ON_UPDATE_COMMAND_UI(IDM_JK1, OnUpdateJk1)
	ON_COMMAND(IDM_JK2, OnJk2)
	ON_UPDATE_COMMAND_UI(IDM_JK2, OnUpdateJk2)
	ON_COMMAND(IDM_JK3, OnJk3)
	ON_UPDATE_COMMAND_UI(IDM_JK3, OnUpdateJk3)
	ON_COMMAND(IDM_JK4, OnJk4)
	ON_UPDATE_COMMAND_UI(IDM_JK4, OnUpdateJk4)
	ON_COMMAND(IDM_JK5, OnJk5)
	ON_UPDATE_COMMAND_UI(IDM_JK5, OnUpdateJk5)
	ON_COMMAND(IDM_JK6, OnJk6)
	ON_UPDATE_COMMAND_UI(IDM_JK6, OnUpdateJk6)
	ON_WM_HSCROLL()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DisplayView diagnostics

#ifdef _DEBUG
void DisplayView::AssertValid() const
{
	CFormView::AssertValid();
}

void DisplayView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// DisplayView message handlers
extern unsigned char addata[];


void DisplayView::OnDisplay() 
{
	// TODO: Add your control notification handler code here
	
}
extern WORD vlot[][3];//20*60*50
extern int data_count;
FILE *stream_IN,* stream_OUT;
void DisplayView::OnSave() 
{
 CFileDialog fileDlg(FALSE);
 fileDlg.m_ofn.lpstrTitle="数据保存";
 fileDlg.m_ofn.lpstrFilter="Dat Files(*.dat)\0*.dat\0All Files(*.*)\0*.*\0\0";
 fileDlg.m_ofn.lpstrDefExt="dat";
 CString filename;
 if (IDOK==fileDlg.DoModal())
 {   
	 filename=fileDlg.GetPathName();
	
	 //char * f=fileDlg.GetBuffer (filename.GetLength());

	 stream_IN=fopen(filename,"w+");
	if(stream_IN==NULL){MessageBox("无法创建这个文件!");return;}

		fprintf(stream_IN,"%d\n",data_count);
		for(int i=0;i<data_count;i++)
		{
		fprintf(stream_IN,"%d\n",vlot[i][0]);
		fprintf(stream_IN,"%d\n",vlot[i][1]);
		fprintf(stream_IN,"%d\n",vlot[i][2]);
		}
		fclose( stream_IN );
	
 }
 	
}

void DisplayView::OnPlay() 
{
	m_play_button_down=true;
	CFileDialog fileDlg(TRUE);
	fileDlg.m_ofn.lpstrTitle="打开播放文件";
	fileDlg.m_ofn.lpstrFilter="Dat Files(*.dat)\0*.dat\0All Files(*.*)\0*.*\0\0";
    fileDlg.m_ofn.lpstrDefExt="dat";
	CString filename;
	if(IDOK==fileDlg.DoModal())
	{   
		filename=fileDlg.GetPathName();
		stream_OUT=fopen(filename,"r");
	if(stream_OUT==NULL){MessageBox("无法打开这个文件!");return;}
	    fscanf(stream_OUT,"%d\n",&data_count);
		for(int i=0;i<data_count;i++)
		{
		fscanf(stream_OUT,"%d\n",&vlot[i][0]);
		fscanf(stream_OUT,"%d\n",&vlot[i][1]);
		fscanf(stream_OUT,"%d\n",&vlot[i][2]);
		}
		fclose(stream_OUT);
	    Invalidate(true);
		fclose(stream_OUT);
	
	}


	
}

void DisplayView::OnStop() 
{
   capture_flag=false;
}

void DisplayView::OnStart() 
{ 
	
	if(m_HidHandle == NULL)
        if(!Search_HidDev())MessageBox("没有找到数据采集设备!");

   capture_flag=true;

}

void DisplayView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CFormView::OnMouseMove(nFlags, point);
}

BOOL DisplayView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
	// TODO: Add your message handler code here and/or call default
	
	return CFormView::OnMouseWheel(nFlags, zDelta, pt);
}

void DisplayView::OnPaint() 
{
	int x0,y0,x1,y1;
	CPaintDC dc(this); // device context for painting
	
	CRect rect;
	
	GetClientRect(&rect);
    
   	rect.bottom-=150;
	m_DisplayWnd.MoveWindow(&rect);
	
    GetClientRect(&rect);
	CPen redPen(PS_SOLID,2,RGB(255,0,0));
	CPen bluePen(PS_SOLID,2,RGB(0,0,255));
	CPen greenPen(PS_SOLID,2,RGB(0,255,0));
    CPen *oldPen;
	dc.SelectObject(&redPen);
	x0=rect.left+80;
	y0=rect.bottom-110;
	x1=x0+50;
	y1=y0;
    dc.MoveTo(x0,y0);
	dc.LineTo(x1,y1);
	dc.SelectObject(&oldPen);
	int x2,y2,x3,y3;
	dc.SelectObject(&bluePen);
	x2=x0;
	y2=y0+20;
	x3=x1;
	y3=y2;
	dc.MoveTo(x2,y2);
	dc.LineTo(x3,y3);
	dc.SelectObject(&greenPen);
	x2=x0;
	y2=y0+40;
	x3=x1;
	y3=y2;
	dc.MoveTo(x2,y2);
	dc.LineTo(x3,y3);

	dc.SelectObject(&oldPen);



	GetClientRect(&rect);
	int w=rect.Width();
	rect.left=w/6;
	rect.bottom-=75;
	rect.right=rect.left+80;
	rect.top=rect.bottom-30;
	m_start_but.MoveWindow(&rect);
 
	GetClientRect(&rect);
	rect.left=2*w/6;
	rect.bottom-=75;
	rect.right=rect.left+80;
	rect.top=rect.bottom-30;
	m_save_but.MoveWindow(&rect);

	GetClientRect(&rect);
	rect.left=3*w/6;
	rect.bottom-=75;
	rect.right=rect.left+80;
	rect.top=rect.bottom-30;
	m_play_but.MoveWindow(&rect); 

	GetClientRect(&rect);
	rect.left=4*w/6;
	rect.bottom-=75;
    rect.right=rect.left+80;
	rect.top=rect.bottom-30;
	m_stop_but.MoveWindow(&rect);

	GetClientRect(&rect);
	rect.left=5*w/6;
	rect.bottom-=75;
    rect.right=rect.left+80;
	rect.top=rect.bottom-30;
	m_deletevoice_but.MoveWindow(&rect);



   	GetClientRect(&rect);
	rect.left=10;
	rect.bottom-=60;
    rect.right=rect.left+80;
	rect.top=rect.bottom-20;
	m_fluxline_ctrl.MoveWindow(&rect);

	GetClientRect(&rect);
	rect.left=10;
	rect.bottom-=80;
    rect.right=rect.left+80;
	rect.top=rect.bottom-20;
	m_Right_txt.MoveWindow(&rect);

	GetClientRect(&rect);
	rect.left=10;
	rect.bottom-=80+20;
    rect.right=rect.left+80;
	rect.top=rect.bottom-20;
	m_Left_txt.MoveWindow(&rect);
    
	GetClientRect(&rect);
	rect.left=50;
	rect.bottom-=20;
    rect.right=rect.left+80;
	rect.top=rect.bottom-20;
	m_vltgctrlBlue.MoveWindow(&rect);

	GetClientRect(&rect);
	rect.left = 50 + 80 + 10;
	rect.bottom -= 20;
    rect.right =rect.left + 80;
	rect.top=rect.bottom - 20;
	m_vltgctrlRed.MoveWindow(&rect);

	GetClientRect(&rect);
	rect.left = 50 + 80 + 10 + 90;
	rect.bottom -= 20;
    rect.right =rect.left + 80;
	rect.top=rect.bottom - 20;
	m_vltgctrlGreen.MoveWindow(&rect);
   
	GetClientRect(&rect);
	rect.left = 50 + 80 + 10 + 90+100;
	rect.bottom -= 10;
    rect.right =rect.left + 180;
	rect.top=rect.bottom - 60;
	m_motor_ctrl.MoveWindow(&rect);
    
}

void DisplayView::OnCancelMode() 
{
	CFormView::OnCancelMode();
	
	// TODO: Add your message handler code here
	
}

BEGIN_EVENTSINK_MAP(DisplayView, CFormView)
    //{{AFX_EVENTSINK_MAP(DisplayView)
	ON_EVENT(DisplayView, IDC_MSCOMM2, 1 /* OnComm */, OnOnCommMscomm2, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void DisplayView::OnOnCommMscomm2() 
{
	/*VARIANT vR;
    static int count,i;

   
	if(m_ComPort.GetCommEvent()!=2)
	return;
	int l=m_ComPort.GetInBufferCount();
	if(l!=COMM_COUNT)return;
 
    busy_flag=true;
    unsigned char * data;
	m_ComPort.SetBreak(0);   
	m_ComPort.SetInputLen(COMM_COUNT); //6
    vR=m_ComPort.GetInput();
    data=(unsigned char *)vR.parray->pvData;
	if(data[0]==0x68)
	{
		m_DisplayWnd.AddOneData(data[1],data[2]);
	}*/
}

int DisplayView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CFormView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
       return 0;
}

void DisplayView::OnCaptureChanged(CWnd *pWnd) 
{

}

void DisplayView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
		m_motor_ctrl.SetRange (0,100);
	    m_motor_ctrl.SetPos (50);

}


void DisplayView::SendMessageToCom(unsigned char *data, int n)
{
	int i;
//	COleVariant varOutput;
	unsigned char Sum=0;
	CByteArray array;
	array.RemoveAll();
	array.SetSize(n);
	for(i=0;i<n;i++)
	array.SetAt(i,data[i]);

	if(!m_ComPort.GetPortOpen())
	m_ComPort.SetPortOpen(1);
	m_ComPort.SetOutput(COleVariant(array));
}

void DisplayView::OnFileWrite()
{

}

void DisplayView::OnLeftpress() 
{
	// TODO: Add your control notification handler code here
	
}

void DisplayView::OnDocument() 
{ 
}

void DisplayView::OnDeletevioce() 
{
	
	if(IDYES==MessageBox("是否确定删除所选区域数据?",NULL,MB_OKCANCEL))
	{
	  m_dltFlags=1;
	}
	
}



void DisplayView::OnZoom() 
{
	isRectangleSel=false;

⌨️ 快捷键说明

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