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

📄 batttestdlg.cpp

📁 一个通过USB->UART读取C8051F060的程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// CBattTestDlg dialog
CBattTestDlg::CBattTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBattTestDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CBattTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBattTestDlg)
	DDX_Control(pDX, IDC_LOCKWFM_BTN, m_LockZeroBtn);
	DDX_Control(pDX, IDC_FIRETIME_EDIT, m_wndFireTm);
	DDX_Control(pDX, IDC_REPORT_BTN, m_btnReport);
	DDX_Control(pDX, IDC_MEAST2, m_wndMeasT2);
	DDX_Control(pDX, IDC_MEAST1, m_wndMeasT1);
	DDX_Control(pDX, IDC_MEAST22, m_wndMeasT22);
	DDX_Control(pDX, IDC_MEAST12, m_wndMeasT12);
	DDX_Control(pDX, IDC_MINMAX2, m_wndMaxMin2);
	DDX_Control(pDX, IDC_MINMAX1, m_wndMaxMin1);
	DDX_Control(pDX, IDC_PP2, m_wndPP2);
	DDX_Control(pDX, IDC_PP1, m_wndPP1);
	DDX_Control(pDX, IDC_MEAS2, m_wndMeas2);
	DDX_Control(pDX, IDC_MEAS1, m_wndMeas1);
	DDX_Control(pDX, IDC_MEAS22, m_wndMeas22);
	DDX_Control(pDX, IDC_MEAS12, m_wndMeas12);
	DDX_Control(pDX, IDC_MEASDELTAT1, m_wndDeltaT1);
	DDX_Control(pDX, IDC_MEASDELTAT2, m_wndDeltaT2);
	DDX_Control(pDX, IDC_MEAST3, m_wndMeasT3);
	DDX_Control(pDX, IDC_MEAST4, m_wndMeasT4);
	DDX_Control(pDX, IDC_MEAST32, m_wndMeasT32);
	DDX_Control(pDX, IDC_MEAST42, m_wndMeasT42);
	DDX_Control(pDX, IDC_MINMAX3, m_wndMaxMin3);
	DDX_Control(pDX, IDC_MINMAX4, m_wndMaxMin4);

	DDX_Control(pDX, IDC_PP3, m_wndPP3);
	DDX_Control(pDX, IDC_PP4, m_wndPP4);
	DDX_Control(pDX, IDC_MEAS3, m_wndMeas3);
	DDX_Control(pDX, IDC_MEAS4, m_wndMeas4);

	DDX_Control(pDX, IDC_MEAS32, m_wndMeas32);
	DDX_Control(pDX, IDC_MEAS42, m_wndMeas42);
	DDX_Control(pDX, IDC_MEASDELTAT3, m_wndDeltaT3);
	DDX_Control(pDX, IDC_MEASDELTAT4, m_wndDeltaT4);
	DDX_Control(pDX, IDC_FIREVLT_EDIT, m_wndFireVlt);
	DDX_Control(pDX, IDC_MEASCURVE1, m_ckCur1);
	DDX_Control(pDX, IDC_MEASCURVE2, m_ckCur2);
	DDX_Control(pDX, IDC_MAIN_GRAPH, m_Dlg);
	DDX_Control(pDX, IDC_ZOOM_CHECK, m_btnTrack);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBattTestDlg, CDialog)
	//{{AFX_MSG_MAP(CBattTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_ZOOM_CHECK, OnCurveTrack)
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_NEWTEST_BTN, OnNewTest)
	ON_BN_CLICKED(IDC_EXIT_BTN, OnExit)
	ON_BN_CLICKED(IDC_MEASCURVE1, OnMeasCurve)
	ON_BN_CLICKED(IDC_PLOT1, OnPlotVisible)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_OPENTEST_BTN, OnOpenTest)
	ON_BN_CLICKED(IDC_REPORT_BTN, OnReportBtn)
	ON_EN_CHANGE(IDC_FIREVLT_EDIT, OnChangeFireVlt)
	ON_BN_CLICKED(IDC_MEASCURVE2, OnMeasCurve)
	ON_BN_CLICKED(IDC_PLOT2, OnPlotVisible)
	ON_BN_CLICKED(IDC_CHGAXIS_BTN, OnChgYAxis)
	ON_BN_CLICKED(IDC_LOCKWFM_BTN, OnZero)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()



//////////////////////////////////////////////////////////////////////////////////////
// CBattTestDlg message handlers
#include "BattTestDlg.h"
UINT   _fpShowImportantWnd(LPVOID pData)
{
		CAboutDlg   dlg;	
		dlg.DoModal();
		
		return 1;
}

float CBattTestDlg::GetFireLvlVal()
{
		CString    rString;
		m_wndFireVlt.GetWindowText(rString);
		
		return  ::atof((LPCTSTR)rString);
}

#define  _USE4CHANNELS
BOOL CBattTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	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
	
	//////////////////////////////////////////////////////////////////////
    //
	//g_sMemManager.InitMem();
	
	//////////////////////////////////////////////////////////////////////
	//初始化界面资源
	CButton *pBtn = (CButton *)GetDlgItem(IDC_PLOT1);
	pBtn->SetCheck(1);
	pBtn = (CButton *)GetDlgItem(IDC_PLOT2);
	pBtn->SetCheck(1);
	
	//
	m_wndFireVlt.SetRange(0.00f, 60.0f);
	m_wndFireVlt.SetWindowText("21.5");
	
	m_Dlg.SetWfmAdjMode(CCalWfmGraph::adZoom);
	g_sCurveHelper.AcceptGraph(&m_Dlg);
	m_brushBk1.CreateSolidBrush(RGB(250, 250, 255));
	
	//////////////////////////////////////////////////////////////////////
	//
#ifdef   _USE4CHANNELS
	m_wndMeas3.SetWindowText("N/A");
	m_wndMeas4.SetWindowText("N/A");
	m_wndMeas32.SetWindowText("N/A");
	m_wndMeas42.SetWindowText("N/A");
	m_wndPP3.SetWindowText("N/A");
	m_wndPP4.SetWindowText("N/A");
	m_wndMeasT3.SetWindowText("N/A");
	m_wndMeasT4.SetWindowText("N/A");
	m_wndMeasT32.SetWindowText("N/A");
	m_wndMeasT42.SetWindowText("N/A");

	m_wndMaxMin3.SetWindowText("N/A");
	m_wndMaxMin4.SetWindowText("N/A");
	m_wndDeltaT3.SetWindowText("N/A");
	m_wndDeltaT4.SetWindowText("N/A");
#endif

	/////////////////////////////////////////////////////////////////////
	::AfxBeginThread(_fpShowImportantWnd, NULL);
	m_btnReport.EnableWindow(FALSE);
	m_LockZeroBtn.EnableWindow(FALSE);
	
	CString   strFireVlt;
	strFireVlt = ::AfxGetApp()->GetProfileString("配置", "激活门限", NULL);
	m_wndFireVlt.SetWindowText((LPCTSTR)strFireVlt);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

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









///////////////////////////////////////////////////////////////////////////////
//
#include "SelectBattDlg.h"
void CBattTestDlg::OnNewTest() 
{
		CSelectBattDlg    dlg;
		dlg.DoModal();
}

void CBattTestDlg::OnExit()
{
	    //关闭文件
		CString   strFireVlt;
		m_wndFireVlt.GetWindowText(strFireVlt);
	    ::AfxGetApp()->WriteProfileString("配置", "激活门限", (LPCTSTR)strFireVlt);
	    
		//
	    this->EndDialog(1);
}

BEGIN_EVENTSINK_MAP(CBattTestDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CBattTestDlg)
	ON_EVENT(CBattTestDlg, IDC_MAIN_GRAPH, -607 /* MouseUp */, OnMouseUpMainGraph, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
	ON_EVENT(CBattTestDlg, IDC_MAIN_GRAPH, -605 /* MouseDown */, OnMouseDownMainGraph, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
	ON_EVENT(CBattTestDlg, IDC_MAIN_GRAPH, 15 /* Zoom */, OnZoomMainGraph, VTS_NONE)
	ON_EVENT(CBattTestDlg, IDC_MAIN_GRAPH, 1 /* CursorChange */, OnCursorChange, VTS_PI4 VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
	ON_EVENT(CBattTestDlg, IDC_MAIN_GRAPH, 16 /* Pan */, OnPanGraph, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

//此时复原
void CBattTestDlg::OnMouseUpMainGraph(short Button, short Shift, long x, long y) 
{
		if (Button ==1 && g_nStartTag && g_bCurveTrack)
		{
				g_bZoom = (XPos > x && YPos > y);				
				g_nUpXPos = x;
				g_nUpYPos = y;

				if (g_bZoom) //恢复
				{
						this->OnResetGrp();
						g_nStartTag = FALSE;
				}
				else
				{
						g_bZoom = FALSE;
				}
		}
}

void CBattTestDlg::OnMouseDownMainGraph(short Button, short Shift, long x, long y) 
{
		g_bRightKeyTag = FALSE;
		if (Button == 1)	//左键
		{
				g_nStartTag    = TRUE;
				XPos    = x;
				YPos    = y;
				//
				g_nXPos = x;
				g_nYPos = y;
		}
}

void   ShiftCursor(CCalWfmGraph *pGraph)
{
		if (pGraph == NULL)
			return ;

		//移动光标
		CNiCursors sCursors= pGraph->GetCursors();
		CNiCursor  sCursor1 = sCursors.Item(1);
		CNiCursor  sCursor2 = sCursors.Item(2);
		
		///////////////////////////////////////////////////////////////////////////////
		CNiAxes sAxes= pGraph->GetAxes();
		CNiAxis  sAxe1 = sAxes.Item(1);
		CNiAxis  sAxe2 = sAxes.Item(2);
		
		///////////////////////////////////////////////////////////////////////////////
		double  Start= (sAxe1.GetMaximum()-sAxe1.GetMinimum())/4+sAxe1.GetMinimum();
		double  End  = sAxe1.GetMaximum() - (sAxe1.GetMaximum()-sAxe1.GetMinimum())/4;
		sCursor1.SetXPosition(Start);
		sCursor2.SetXPosition(End);

		///////////////////////////////////////////////////////////////////////////////
		g_sOldCursor1 = sCursor1.GetXPosition();
		g_sOldCursor2 = sCursor2.GetXPosition();
}

//////////////////////////////////////////////////////////////////////////////////////
// 根据当前的鼠标位置和Y轴的量程,设定Y轴的,放大状态,设定Y轴单格范围(10)。
#define   XAXISGAIN  10000
#define   XAXISMAX   180
void CBattTestDlg::OnZoomMainGraph() 
{
		////////////////////////////////////////////////////////////////////////////////////
		//计算当前屏显的PP值
		CNiAxis sAxisX = m_Dlg.GetAxes().Item(1);
		double  dMax = sAxisX.GetMaximum();
		double  dMin = sAxisX.GetMinimum();
		ULONG   nMaxIndex  = (ULONG)dMax;
		ULONG   nMinIndex  = (ULONG)dMin;

		//计算出该区域的PP值
		double _maxValue[2], _minValue[2];
		_maxValue[0] = ::GetMaxValFromArray((double *)&g_sACPlotValue[nMinIndex], max(nMaxIndex-nMinIndex-1, 1));
		_minValue[0] = ::GetMinValFromArray((double *)&g_sACPlotValue[nMinIndex], max(nMaxIndex-nMinIndex-1, 1));
		_maxValue[1] = ::GetMaxValFromArray((double *)&g_sDCPlotValue[nMinIndex], max(nMaxIndex-nMinIndex-1, 1));
		_minValue[1] = ::GetMinValFromArray((double *)&g_sDCPlotValue[nMinIndex], max(nMaxIndex-nMinIndex-1, 1));		

		//显示最大值/最小值
		this->ShowCalcValue(_maxValue, _minValue);
				
		//显示峰峰值
		char   szFmt[128];
		::sprintf(szFmt, "%.4f", ::fabs(_maxValue[0]-_minValue[0]));
		m_wndPP1.SetWindowText(szFmt);
}

//测量光标
void CBattTestDlg::OnMeasCurve() 
{
		CButton *pBtn1 =  (CButton *)GetDlgItem(IDC_MEASCURVE1);		
		CNiCursors  sCursors= m_Dlg.GetCursors();
		CNiCursor   pCursor = sCursors.Item(1);		
		if (pBtn1->GetCheck())
		{
				pCursor.SetXPosition(g_sOldCursor1);
				TRACE1("Cursor1 position = %.4f.\n", g_sOldCursor1);
		}
		pCursor.SetVisible(pBtn1->GetCheck()?true:false);
		g_bCursor1 = pBtn1->GetCheck();		
		
		//////////////////////////////////////////////////////////////////////////
		//
		CButton *pBtn2 = (CButton *)GetDlgItem(IDC_MEASCURVE2);
		pCursor = sCursors.Item(2);
		if (pBtn2->GetCheck())
		{
				pCursor.SetXPosition(g_sOldCursor2);
				TRACE1("Cursor2 position = %.4f.\n", g_sOldCursor2);
		}
		pCursor.SetVisible(pBtn2->GetCheck()?true:false);
		g_bCursor2 = pBtn2->GetCheck();
		

		///////////////////////////////////////////////////////////////
		//有1为真, 则仅执行一次
		if (!g_bRunOnce)	
		if ((g_bCursor1 == TRUE) || (g_bCursor2 == TRUE))
		{
				g_bCurveTrack  = TRUE;
				this->OnCurveTrack();
				m_Dlg.SetWfmAdjMode(CCalWfmGraph::adCursor);

				::ShiftCursor(&m_Dlg);
		}
		g_bRunOnce = !((g_bCursor1 == FALSE) && (g_bCursor2 == FALSE));
}

void CBattTestDlg::OnCurveTrack() 
{
		g_bCurveTrack = !g_bCurveTrack;		
		m_btnTrack.SetWindowText(g_bCurveTrack?"缩放":"平移");		
		m_Dlg.SetWfmAdjMode(g_bCurveTrack?CCalWfmGraph::adZoom:CCalWfmGraph::adPanXY);
}

//图形复位
void CBattTestDlg::OnResetGrp() 
{
		//////////////////////////////////////////////////////////////////////////////////
		//Y1-Axis
		CNiAxis sAxisY = m_Dlg.GetAxes().Item(2);
		g_sYAxisRange_Zoom.nMax = g_sRange.nMax;
		g_sYAxisRange_Zoom.nMin = g_sRange.nMin;		
		sAxisY.SetMinimum(g_sYAxisRange_Zoom.nMin);
		sAxisY.SetMaximum(g_sYAxisRange_Zoom.nMax); 
		
		//Y2-Axis
		sAxisY = m_Dlg.GetAxes().Item(3);
		sAxisY.SetMinimum(-3.0);
		sAxisY.SetMaximum(3.0);
		
		//////////////////////////////////////////////////////////////////////////////////
		//X-Axis
		CNiAxis sAxisX = m_Dlg.GetAxes().Item(1);			
	
		/////////////////////////////////////////////////////////////////////////////////
		//设置结束点对应全局数据中的索引位置
		g_sEndIndex = g_nXPots;
		g_sDelta    = UINT(XAXISMAXVAL);		//设置Chart一屏情况		
		if (g_sEndIndex > UINT(g_sDelta*1))   g_sStartIndex = g_sEndIndex-UINT(g_sDelta*1.0/*0.9*/);	//满一屏情况
		else  g_sStartIndex = 0;				//不满一屏情况
		
		g_sStartIndex = g_sStartIndex<=0?0:g_sStartIndex;
		
		g_sXAxisRange_Zoom.nMin = g_sStartIndex/10000.0;
		g_sXAxisRange_Zoom.nMax = g_sXAxisRange_Zoom.nMin + XAXISMAXVAL;	
		sAxisX.SetMaximum(g_sXAxisRange_Zoom.nMax);
		sAxisX.SetMinimum(g_sXAxisRange_Zoom.nMin);
		
		////////////////////////////////////////////////////////////////////////////////
		//基准
		::ShowRangeGraph(&m_Dlg, g_sStartIndex, g_sEndIndex-g_sStartIndex);

#if 1
		//////////////////////////////////////////////////////////////////////////
		//
		CButton *pBtn1 =  (CButton *)GetDlgItem(IDC_MEASCURVE1);
		CNiCursors  sCursors= m_Dlg.GetCursors();
		CNiCursor   pCursor = sCursors.Item(1);		
		pBtn1->SetCheck(FALSE);
		pCursor.SetVisible(pBtn1->GetCheck()?true:false);
		
		CButton *pBtn2 = (CButton *)GetDlgItem(IDC_MEASCURVE2);

⌨️ 快捷键说明

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