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

📄 ezmrfrm.cpp

📁 EZ _USB Control PANEL 源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		m_wndTBarBlk.SetButtonInfo(9, IDC_DATA_VALUE, TBBS_SEPARATOR, 262); // bogart
		m_wndTBarBlk.GetItemRect(9, &rect);
		rect.top = 0;
		rect.bottom = rect.top + 200;
		if (!m_CBoxBlkData.Create(
			CBS_DROPDOWN|WS_VISIBLE|WS_TABSTOP|CBS_AUTOHSCROLL|WS_CHILD,
			rect, &m_wndTBarBlk, IDC_DATA_VALUE))
		{
			TRACE0("Failed to create combo-box\n");
			return FALSE;
		}
		m_CBoxBlkData.AddString("5");
		m_CBoxBlkData.SetCurSel(0);
		
	}


	{ //TPMDo: Add m_wndTBarRes manually; Add ID_VIEW_TBAR_RES menu toggle option
		if (!m_wndTBarRes.Create(this,
			WS_CHILD | CBRS_TOP | WS_VISIBLE | 
			CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
			ID_VIEW_TBAR_RES) ||
			!m_wndTBarRes.LoadToolBar(IDR_TBAR_RES))
		{
			TRACE0("Failed to create dialog bar m_wndTBarRes\n");
			return -1;		// fail to create
		}

		m_wndTBarRes.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
		EnableDocking(CBRS_ALIGN_ANY);
		DockControlBar(&m_wndTBarRes);

		NewTBarText(&m_wndTBarRes, 6, IDC_BPIPE_OPS_NUM, 30, "Pipe");
		m_wndTBarRes.SetButtonInfo(7, IDC_RESETPIPENUM, TBBS_SEPARATOR, 160); // bogart
		m_wndTBarRes.GetItemRect(7, &rect);
		rect.top = 0;
		rect.bottom = rect.top + 200;
		if (!m_CBoxResPipe.Create(
			CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL|WS_CHILD,
			rect, &m_wndTBarRes, IDC_RESETPIPENUM))
		{
			TRACE0("Failed to create combo-box\n");
			return FALSE;
		}

	}

	{	// Initialize dialog bar m_wndDlgMain
		if (!m_wndDlgMain.Create(this, CG_IDD_DLGMAIN,
			CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE,
			CG_ID_VIEW_DLGMAIN))
		{
			TRACE0("Failed to create dialog bar m_wndDlgMain\n");
			return -1;		// fail to create
		}

		m_wndDlgMain.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
		EnableDocking(CBRS_ALIGN_ANY);
		DockControlBar(&m_wndDlgMain);
		ShowControlBar(&m_wndDlgMain, FALSE, FALSE); // arange a little
		m_cPendListBox.SubclassDlgItem(IDC_OUTPUT_BOX, (CWnd*)&m_wndDlgMain);
	}


	{ //TPMDo: Add m_wndTBarCfg manually; Add ID_VIEW_TBAR_CFG menu toggle option
		if (!m_wndTBarCfg.Create(this,
			WS_CHILD | CBRS_TOP | WS_VISIBLE | 
			CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
			ID_VIEW_TBAR_CFG) ||
			!m_wndTBarCfg.LoadToolBar(IDR_TBAR_CFG))
		{
			TRACE0("Failed to create dialog bar m_wndTBarCfg\n");
			return -1;		// fail to create
		}

		m_wndTBarCfg.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
		EnableDocking(CBRS_ALIGN_ANY);
		DockControlBar(&m_wndTBarCfg);
		DockControlBarLeftOf(&m_wndTBarCfg,&m_wndTBarRes);

		NewTBarText(&m_wndTBarCfg, 2, IDC_BINTERFACE, 50, "Interface");
		NewTBarEBox(&m_wndTBarCfg, 3, IDC_INTERFACE, 50, "0", &m_EBoxIntf);

		NewTBarText(&m_wndTBarCfg, 5, IDC_BALTSET, 50, "AltSetting");
		NewTBarEBox(&m_wndTBarCfg, 6, IDC_ALTSET, 50, "0", &m_EBoxAltSet); //TPM H/W default
	}

	InitEzMrCtrlBars();
	UpdatePipes();

	return 0;
}

void CEzMrFrame::OnSelChangeOp() 
{
	// TPMDO: add ON_CBN_SELCHANGE(IDC_CBOX_MEM_ADDR, OnSelchangeMemAddr)
	// TPMDO: add afx_msg void OnSelChangeOp();
	TRACE("TPM:CEzMrFrame::OnSelChangeOp()\n");
	ShowEzMrCtrlBars();
}

void CEzMrFrame::OnSelChangeDev() 
{
	TRACE("TPM:CEzMrFrame::OnSelChangeDev()\n");
	m_SelDrv = m_CBoxDrv.GetCurSel();
}

void CEzMrFrame::OnSelChangeBlk() 
{
	TRACE("TPM:CEzMrFrame::OnSelChangeBlk()\n");
	UpdatePipes();
}


void CEzMrFrame::ShowEzMrCtrlBars(void)
{
	if(theApp.m_nPopUpOps)
	{
		for(int i=0; i< MAX_OP_NUMBER; i++)
				ShowControlBar(m_pwndTbar[i], FALSE, FALSE); // turn off all bars
		ShowControlBar(m_pwndTbar[m_CBoxOps.GetCurSel()], TRUE, FALSE); // turn on selected one
	}
}

void CEzMrFrame::InitEzMrCtrlBars(void)
{
	m_pwndTbar[OP_GET_DEVDES] = &m_wndTBarUna;
	m_pwndTbar[OP_GET_CONDES] = &m_wndTBarUna;
	m_pwndTbar[OP_GET_PIPINF] = &m_wndTBarUna;
	m_pwndTbar[OP_VEND_REQST] = &m_wndTBarVen;
	m_pwndTbar[OP_RW_BLK_BYT] = &m_wndTBarBlk;
	m_pwndTbar[OP_ANCHOR_DLD] = &m_wndTBarUna;
	m_pwndTbar[OP_RESET_PIPE] = &m_wndTBarRes;
	m_pwndTbar[OP_ABORT_PIPE] = &m_wndTBarRes;
	m_pwndTbar[OP_ISO_TRANSF] = &m_wndTBarIso;
	m_pwndTbar[OP_SET_INTERF] = &m_wndTBarCfg;
	m_pwndTbar[OP_8051__HOLD] = &m_wndTBarUna;
	m_pwndTbar[OP_8051___RUN] = &m_wndTBarUna;
	m_pwndTbar[OP_GETURBSTAT] = &m_wndTBarUna;
	m_pwndTbar[OP_GET_CFRAME] = &m_wndTBarUna;
	m_pwndTbar[OP_GET_STRING] = &m_wndTBarUna;
	m_pwndTbar[OP_RESET_PORT] = &m_wndTBarUna;

	if(theApp.m_nPopUpOps)
	{
		for(int i=0; i< MAX_OP_NUMBER; i++)
				ShowControlBar(m_pwndTbar[i], FALSE, FALSE); // turn off all bars
		ShowControlBar(m_pwndTbar[m_CBoxOps.GetCurSel()], TRUE, FALSE); // turn on selected one
	}
	else
	{
		for(int i=0; i< MAX_OP_NUMBER; i++)
				ShowControlBar(m_pwndTbar[i], TRUE, FALSE); // turn on all bars
	}

}


void CEzMrFrame::UpdatePipes(void)
{
	int i;

	CComboBox* pCBoxBlkPipe = (CComboBox*)m_wndTBarBlk.GetDlgItem(IDC_BLK_PIPE);
	CComboBox* pCBoxIsoPipe = (CComboBox*)m_wndTBarIso.GetDlgItem(IDC_ISO_PIPE);
	CComboBox* pCBoxResPipe = (CComboBox*)m_wndTBarRes.GetDlgItem(IDC_RESETPIPENUM);

	pCBoxBlkPipe->ResetContent();
	pCBoxIsoPipe->ResetContent();
	pCBoxResPipe->ResetContent();

		PUSBD_INTERFACE_INFORMATION pInterface;
		PUSBD_PIPE_INFORMATION pPipe;
		pInterface = (PUSBD_INTERFACE_INFORMATION) theApp.m_uInterfaceInfo;
		pPipe = pInterface->Pipes;
		if(pInterface->NumberOfPipes>=/*MAX_PIPES*/64)
		{
			theApp.report_error("Error updating pipes\n");
			return;
		}
		for(i=0; i < (int) pInterface->NumberOfPipes; i++)
		{ // Load Combo Box with list of operations
			CString pipe_end;
			pipe_end.Format("%-2d: Endpoint %-2d %s", i, (pPipe[i].EndpointAddress & 0x0F), 
				(pPipe[i].EndpointAddress >> 7) ? "IN" : "OUT");
			if(pPipe[i].PipeType == UsbdPipeTypeBulk)
			{
				pCBoxBlkPipe->AddString(pipe_end);
			}
			if(pPipe[i].PipeType == UsbdPipeTypeInterrupt)
			{ // Add Interrupt pipes to Bulk list
				pCBoxBlkPipe->AddString(pipe_end);
			}
			if(pPipe[i].PipeType == UsbdPipeTypeIsochronous)
				pCBoxIsoPipe->AddString(pipe_end);
			pCBoxResPipe->AddString(pipe_end);
		}
		pCBoxBlkPipe->SetCurSel(pCBoxBlkPipe->GetCount()-1);
		pCBoxIsoPipe->SetCurSel(pCBoxIsoPipe->GetCount()-1);
		pCBoxResPipe->SetCurSel(pCBoxResPipe->GetCount()-1);
}

void CEzMrFrame::UpdDrvCBox(void)
{
		int nIdxSubStr;
		CString strText = theApp.m_strUSBDevs;
		m_CBoxDrv.ResetContent();
		for(int i = 0; ((nIdxSubStr = strText.Find('\n')) != -1); i++)
		{ // Load Combo Box with list of operations
			CString strItem = strText.Left(nIdxSubStr);
			m_CBoxDrv.AddString(strItem);
			m_strDrv[i] = strItem;
			strText = strText.Mid(nIdxSubStr+1);
		}
}

void CEzMrFrame::OpStart(CThreadInfo* pParam)
{
	CString strPendMg;
	if((pParam->wParam) < MAX_OP_NUMBER)
		strPendMg.Format("Pending: OpIndex=%d: OpType=%d=%s", pParam->OpIndex, pParam->wParam, g_strIoctl[pParam->wParam]);
	else
		strPendMg.Format("Pending: OpIndex=%d: OpType=%d=???", pParam->OpIndex, pParam->wParam);
	TRACE("TPM:CEzMrFrame::OpStart():%s\n", strPendMg);
	m_cPendListBox.AddString(strPendMg);
}

void CEzMrFrame::OpDone(CThreadInfo* pParam)
{
	CString strPendMg;
	if(!m_cPendListBox)
		return;
	if((pParam->wParam) < MAX_OP_NUMBER)
	{
		strPendMg.Format("Pending: OpIndex=%d: OpType=%d=%s", pParam->OpIndex, pParam->wParam, g_strIoctl[pParam->wParam]);
	    TRACE("TPM:CEzMrFrame::OpDone():%s\n", strPendMg);
	    int nLbIdx = m_cPendListBox.SelectString(0, strPendMg);
	    if(nLbIdx != LB_ERR)
		{
	    	m_cPendListBox.DeleteString(nLbIdx);
		}
	    int curCursorPos = (pParam->hOutputBox)->GetTextLength();
	    if(curCursorPos)
	    	(pParam->hOutputBox)->SetSel(curCursorPos, curCursorPos);
	    (pParam->hOutputBox)->ReplaceSel(pParam->strIoctlOut);
	}
}

void CEzMrFrame::OnClose() 
{	
	CMDIChildWnd::OnClose();
}

void CEzMrFrame::OnEditVenData() 
{
	char text[MAX_CBOX_STRING];
	CString strInText;
	CString strItem;
	m_wndTBarVen.GetDlgItemText(IDC_VENDOR_DATA, text, MAX_CBOX_STRING);
	strInText = text;
	WORD value;

	int i = 0;
	for(strItem = strInText.SpanExcluding(" "); 
		strItem.GetLength() && (i < 64); 
		strItem = strInText.SpanExcluding(" "))
	{ // extract hex values from string into bulk buffer
		sscanf((LPTSTR)(LPCTSTR)strItem, "%x", &value);
		VenBuf[i++] = (char) value;
		strInText = strInText.Mid(strItem.GetLength());
		strInText.TrimLeft();
	}

	m_EBoxLen.SetReadOnly(FALSE);
	if(i == 1)
	{ // one value; get repeat length from UI
		int length = m_wndTBarVen.GetDlgItemInt(IDC_WLENGTH, NULL, FALSE);
		length = (length <= MAX_FILE_SIZE) ? length : MAX_FILE_SIZE;
		memset (VenBuf, value, length);
	}
	else  if(m_CBoxVenDir.GetCurSel()) //if direction is out
	{ // if multiple entries, set the count accordingly
		char strCount[81];
		itoa(i, strCount, 10);
		m_wndTBarVen.SetDlgItemText(IDC_WLENGTH, strCount);
		m_EBoxLen.SetReadOnly(TRUE);
	}
}

void CEzMrFrame::OnEditchangeData() 
{
	char text[MAX_CBOX_STRING];
	char strCount[81];
	CString strInText;
	CString strItem;
	WORD value;
	int i = 0;

	int bhy = m_CBoxBlkData.GetCurSel();
	if(bhy != CB_ERR)
		m_CBoxBlkData.GetLBText(bhy, strInText);
	else
	{
		m_wndTBarBlk.GetDlgItemText(IDC_DATA_VALUE, text, MAX_CBOX_STRING);
		strInText = text;
	}

	for(strItem = strInText.SpanExcluding(" "); 
		strItem.GetLength() && (i < 64); 
		strItem = strInText.SpanExcluding(" "))
	{ // extract hex values from string into bulk buffer
		sscanf((LPTSTR)(LPCTSTR)strItem, "%x", &value);
		BlkBuf[i++] = (char) value;
		strInText = strInText.Mid(strItem.GetLength());
		strInText.TrimLeft();
	}

	PUSBD_PIPE_INFORMATION pPipe = 
		((PUSBD_INTERFACE_INFORMATION)theApp.m_uInterfaceInfo)->Pipes;
	int pipeNum = m_wndTBarBlk.GetDlgItemInt(IDC_BLK_PIPE, NULL, FALSE);
	if(pPipe[pipeNum].EndpointAddress >> 7)
	{
		m_EBoxBlkLen.SetReadOnly(FALSE); // In pipes have arbitrary length
		return;
	}

	if(i==1)
	{ // one value; get repeat length from UI
		int length = m_wndTBarBlk.GetDlgItemInt(IDC_DATA_LENGTH, NULL, FALSE);
		if(length > MAX_FILE_SIZE)
		{
			theApp.report_error("Length exceeds Max transfer size. Length truncated.\n");
			length = MAX_FILE_SIZE;
			itoa(length, strCount, 10);
			m_wndTBarBlk.SetDlgItemText(IDC_DATA_LENGTH, strCount);
		}
		memset (BlkBuf, value, length);
		m_EBoxBlkLen.SetReadOnly(FALSE);
	}
	else
	{ // if multiple entries, set the count accordingly
		itoa(i, strCount, 10);
		m_wndTBarBlk.SetDlgItemText(IDC_DATA_LENGTH, strCount);
		m_EBoxBlkLen.SetReadOnly(TRUE);
	}

}

void CEzMrFrame::DockControlBarLeftOf(CToolBar* Bar,CToolBar* LeftOf)
{
	CRect rect;
	DWORD dw;
	UINT n;

	RecalcLayout(); // get MFC to adj dimensions of all docked ToolBars
	LeftOf->GetWindowRect(&rect);
	rect.OffsetRect(1,0);
	dw=LeftOf->GetBarStyle();
	n = 0;
	n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
	n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
	n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
	n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;

	DockControlBar(Bar,n,&rect); //simulate Toolbar dragged to location and docked
}

⌨️ 快捷键说明

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