📄 lmscopedlg.cpp
字号:
{
//
// Add to our mean accumulation totals.
//
iMean[0] += (int)psElement[ulLoop].sSample1mVolts;
iMean[1] += (int)psElement[ulLoop].sSample2mVolts;
//
// New minimum value for either channel?
//
if(psElement[ulLoop].sSample1mVolts < iMin[0])
{
iMin[0] = (int)psElement[ulLoop].sSample1mVolts;
}
if(psElement[ulLoop].sSample2mVolts < iMin[1])
{
iMin[1] = (int)psElement[ulLoop].sSample2mVolts;
}
//
// New maximum value for either channel?
//
if(psElement[ulLoop].sSample1mVolts > iMax[0])
{
iMax[0] = (int)psElement[ulLoop].sSample1mVolts;
}
if(psElement[ulLoop].sSample2mVolts > iMax[1])
{
iMax[1] = (int)psElement[ulLoop].sSample2mVolts;
}
}
//
// Divide the mean accumulators by the number of samples to give
// the real means.
//
iMean[0] = iMean[0] / (int)m_psScopeData->ulTotalElements;
iMean[1] = iMean[1] / (int)m_psScopeData->ulTotalElements;
}
else
{
//
// Single channel data.
//
tScopeDataElement *psElement;
//
// Get a pointer to the first sample.
//
psElement = (tScopeDataElement *)((char *)m_psScopeData +
m_iSampleOffset);
//
// Determine the minimum, maximum and mean values for this channel.
//
for(ulLoop = 0; ulLoop < m_psScopeData->ulTotalElements; ulLoop++)
{
//
// Add to our mean accumulation total.
//
iMean[0] += (int)psElement[ulLoop].sSamplemVolts;
//
// New minimum value?
//
if(psElement[ulLoop].sSamplemVolts < iMin[0])
{
iMin[0] = (int)psElement[ulLoop].sSamplemVolts;
}
//
// New maximum value?
//
if(psElement[ulLoop].sSamplemVolts > iMax[0])
{
iMax[0] = (int)psElement[ulLoop].sSamplemVolts;
}
}
//
// Divide the mean accumulator by the number of samples to give
// the real mean.
//
iMean[0] = iMean[0] / (int)m_psScopeData->ulTotalElements;
}
//
// Calculations are complete so now update the display.
//
ScaleAndFormatString(&strMin, (LPCTSTR)L"", (LPCTSTR)L"mV",
(LPCTSTR)L"V", (long)iMin[0]);
ScaleAndFormatString(&strMax, (LPCTSTR)L"", (LPCTSTR)L"mV",
(LPCTSTR)L"V", (long)iMax[0]);
ScaleAndFormatString(&strMean, (LPCTSTR)L"", (LPCTSTR)L"mV",
(LPCTSTR)L"V", (long)iMean[0]);
//
// We always have at least 1 channel of data but which one
// is first?
//
if(m_psScopeData->bCh2SampleFirst)
{
m_cCh2Max.SetWindowText(strMax);
m_cCh2Min.SetWindowText(strMin);
m_cCh2Mean.SetWindowText(strMean);
}
else
{
m_cCh1Max.SetWindowText(strMax);
m_cCh1Min.SetWindowText(strMin);
m_cCh1Mean.SetWindowText(strMean);
}
//
// Do we have two channel data?
//
if(m_psScopeData->bDualChannel)
{
ScaleAndFormatString(&strMin, (LPCTSTR)L"", (LPCTSTR)L"mV",
(LPCTSTR)L"V", (long)iMin[1]);
ScaleAndFormatString(&strMax, (LPCTSTR)L"", (LPCTSTR)L"mV",
(LPCTSTR)L"V", (long)iMax[1]);
ScaleAndFormatString(&strMean, (LPCTSTR)L"", (LPCTSTR)L"mV",
(LPCTSTR)L"V", (long)iMean[1]);
//
// Which channel do these measurements relate to?
//
if(m_psScopeData->bCh2SampleFirst)
{
m_cCh1Max.SetWindowText(strMax);
m_cCh1Min.SetWindowText(strMin);
m_cCh1Mean.SetWindowText(strMean);
}
else
{
m_cCh2Max.SetWindowText(strMax);
m_cCh2Min.SetWindowText(strMin);
m_cCh2Mean.SetWindowText(strMean);
}
}
else
{
//
// Single channel data so we need to clear the text in
// the other channel's measurement display controls.
//
strMin = L"";
//
// If the channel 2 sample is first and this is single
// channel data, channel 1 must be disabled.
//
if(m_psScopeData->bCh2SampleFirst)
{
m_cCh1Max.SetWindowText(strMin);
m_cCh1Min.SetWindowText(strMin);
m_cCh1Mean.SetWindowText(strMin);
}
else
{
m_cCh2Max.SetWindowText(strMin);
m_cCh2Min.SetWindowText(strMin);
m_cCh2Mean.SetWindowText(strMin);
}
}
}
//***************************************************************************
//
// Add to the existing CStatusBar class to allow setting strings from a
// resource ID rather than a string pointer.
//
//***************************************************************************
CStatusBarExt::CStatusBarExt() : CStatusBar()
{
//
// Just use the existing CStatusBar constructor.
//
}
//***************************************************************************
//
// Set the pane text from a string in the application string table.
//
//***************************************************************************
BOOL CStatusBarExt::SetPaneTextByResource(int nIndex, int iStringID,
BOOL bUpdate)
{
CString strText;
strText.LoadStringW(iStringID);
return(this->SetPaneText(nIndex, (LPCTSTR)strText, bUpdate));
}
CComboBoxExt::CComboBoxExt() : CComboBox()
{
//
// Just use the existing CComboBox constructor.
//
}
//***************************************************************************
//
// Set the combo box selection based on the value assigned to an item
// rather than its index or string.
//
//***************************************************************************
int CComboBoxExt::SetCurSelByValue(DWORD dwValue)
{
int iLoop;
int iCount;
//
// How many items does this combo box contain?
//
iCount = GetCount();
//
// Check each looking for a data match with dwValue.
//
for(iLoop = 0; iLoop < iCount; iLoop++)
{
//
// Does this item's data match?
//
if(dwValue == (DWORD)GetItemData(iLoop))
{
//
// Yes - set the selection and return.
//
SetCurSel(iLoop);
return(iLoop);
}
}
//
// No item was found that has the supplied value associated with it.
//
return(CB_ERR);
}
//***************************************************************************
//
// Our keep-alive timer expired. Check to ensure that we got a response to
// our last ping. If we did, issue another ping, else send the HOST_HELLO
// message to try to reconnect to the device.
//
//***************************************************************************
void ClmscopeDlg::OnTimer(UINT_PTR nIDEvent)
{
if(nIDEvent == PING_TIMER)
{
//
// Have we received a response to our last ping?
//
if(m_bPingResponseReceived)
{
//
// Yes - the connection is still alive. Send another ping.
//
m_bPingResponseReceived = FALSE;
m_iPingCount++;
ScopeControlPing(0, 0);
}
else
{
//
// The connection appears to have been broken. Since we have not received a
// notification from ScopeControl, the break must not be due to physical
// removal of the USB device so send a new HOST_HELLO to reconnect at the
// application level.
//
m_bReconnecting = TRUE;
ScopeControlConnect(NULL);
}
}
CDialog::OnTimer(nIDEvent);
}
//***************************************************************************
//
// This function is called by Windows to give us an opportunity to set the
// background color of various controls in the dialog.
//
//***************************************************************************
HBRUSH ClmscopeDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
int iCtrlID;
//
// Are we being asked for the dialog background color?
//
if(nCtlColor == CTLCOLOR_DLG)
{
//
// Yes - make sure we pass back the grey color that matches
// the background of our Luminary Micro logo bitmap.
//
return((HBRUSH)m_cGreyBrush);
}
//
// Determine which control is being painted.
//
iCtrlID = pWnd->GetDlgCtrlID();
switch(iCtrlID)
{
//
// We use a black brush to paint the background of the waveform
// display control.
//
case IDC_WAVEFORM:
{
hbr = m_cBlackBrush;
}
break;
//
// All other controls use the default grey brush.
//
default:
pDC->SetBkColor(SCOPE_COLOR_DLG_BACKGROUND);
hbr = m_cGreyBrush;
break;
}
//
// Return the appropriate brush handle.
//
return(hbr);
}
//***************************************************************************
//
// Map help IDs so that right click provides context-sensitive help.
//
//***************************************************************************
void ClmscopeDlg::OnContextMenu(CWnd *pWnd, CPoint point)
{
CString strHelpFile;
int iCtrlID;
//
// Determine the path to the help file.
//
strHelpFile = AfxGetApp()->m_pszHelpFilePath;
strHelpFile += "::/ctrlhlp.txt";
//
// Which control is asking for help?
//
iCtrlID = pWnd->GetDlgCtrlID();
//
// Make sure the mouse was clicked on a control and not the dialog
// background before calling HtmlHelp. If we don't do this, right
// clicks not above a control result in a nasty error message box.
//
if((iCtrlID > 0) && (iCtrlID < CTRL_ID_MAX))
{
//
// Call the help system to show the help information in a
// popup.
//
::HtmlHelp(pWnd->GetSafeHwnd(), (LPCWSTR)strHelpFile,
HH_TP_HELP_CONTEXTMENU, (DWORD)g_pdwHelpIDs);
}
}
//***************************************************************************
//
// Map help IDs so that F1 provides context-sensitive help.
//
//***************************************************************************
BOOL ClmscopeDlg::OnHelpInfo(HELPINFO* pHelpInfo)
{
int iControlID;
//
// Which control is requesting help?
//
iControlID = pHelpInfo->iCtrlId;
//
// Make sure the control is something we are interested in showing
// help for.
//
if((iControlID > 0) && (iControlID < CTRL_ID_MAX))
{
CWinApp *theApp = AfxGetApp();
CString strHelpFile = theApp->m_pszHelpFilePath;
strHelpFile += "::/ctrlhlp.txt";
//
// Call the help system to show the help information in a
// popup.
//
::HtmlHelp((HWND)pHelpInfo->hItemHandle, (LPCWSTR)strHelpFile,
HH_TP_HELP_WM_HELP, (DWORD)g_pdwHelpIDs);
}
return(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -