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

📄 lmscopedlg.cpp

📁 一个简单示波器的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//
// The user has requested triggering on channel 2.
//
//***************************************************************************
void ClmscopeDlg::OnBnClickedTriggerCh2()
{
    unsigned long ulValue;
    unsigned char ucChannel;

    //
    // Get the trigger type control selection and ask the scope to change
    // to this setting.
    //
    ulValue = (unsigned long)m_cTriggerType.GetItemData(
                                        m_cTriggerType.GetCurSel());
    ucChannel = m_cTriggerCh1.GetCheck() ? SCOPE_CHANNEL_1 : SCOPE_CHANNEL_2;
    ScopeControlSetTrigger(ucChannel, ulValue);
}

//***************************************************************************
//
// The scope control module is unable to find the device driver for the
// oscilloscope.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopeNoDriver(WPARAM wParam, LPARAM lParam)
{
    m_csbStatusBar.SetPaneTextByResource(0, IDS_STATUS_NO_DRIVER, TRUE);
    return((LRESULT)0);
}

//***************************************************************************
//
// The oscilloscope device has been connected and is ready to start
// communication. We call ScopeControlConnect() to perform the HELLO
// handshake.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopeDeviceAvailable(WPARAM wParam, LPARAM lParam)
{
    bool bRetcode;

    //
    // Update the status bar text since we now know the device is there.
    //
    m_csbStatusBar.SetPaneTextByResource(0, IDS_STATUS_FOUND, TRUE);

    //
    // Attempt to connect to the device.
    //
    bRetcode = ScopeControlConnect(NULL);

    return((LRESULT)0);
}

//***************************************************************************
//
// The oscilloscope device has responded to our ScopeControlConnect()
// call so we are now ready for business. We are passed a pointer to a
// tScopeSettings structure which we use to initialze the various user
// interface controls to match the current oscilloscope settings.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopeDeviceConnected(WPARAM wParam, LPARAM lParam)
{
    tScopeSettings *psSettings = (tScopeSettings *)lParam;

    //
    // Set our flags to indicate that the device is connected.
    //
    m_bConnected = TRUE;
    m_bReconnecting = FALSE;

    //
    // Update the enable/disable state of the various controls
    //
    UpdateControlEnables();

    //
    // Update the status bar text since are now in full communication
    // with the oscilloscope.
    //
    m_csbStatusBar.SetPaneTextByResource(0, IDS_STATUS_CONNECTED, TRUE);

    //
    // Set the states of our various controls to match the remote
    // settings.
    //
    SetControlsOnConnection(psSettings);

    //
    // Free the memory passed to us in lParam
    //
    LocalFree((HLOCAL)psSettings);

    //
    // Ask the scope to send us data automatically.
    //
    ScopeControlAutomaticDataTransmission(true);

    //
    // Start our PING timer.
    //
    m_bPingResponseReceived = TRUE;
    SetTimer(PING_TIMER, PING_FREQUENCY_MS, 0);

    return((LRESULT)0);
}

//***************************************************************************
//
// The oscilloscope device has been disconnected.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopeDeviceDisconnected(WPARAM wParam, LPARAM lParam)
{
    //
    // Set our flag to indicate that the device is not connected.
    //
    m_bConnected = FALSE;

    //
    // Update the enable/disable state of the various controls
    //
    UpdateControlEnables();

    //
    // Update the status bar text to indicate that the device has been
    // disconnected.
    //
    m_csbStatusBar.SetPaneTextByResource(0, IDS_STATUS_SEARCHING, TRUE);

    //
    // Stop our ping timer.
    //
    KillTimer(PING_TIMER);

    return((LRESULT)0);
}

//***************************************************************************
//
// This handler is called whenever the oscilloscope device has sent us a
// new waveform dataset.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopeData(WPARAM wParam, LPARAM lParam)
{
    //
    // Note that the CWaveformDisplay control is considered to "own"
    // the dataset pointer so we don't free up the previous one
    // here. This is done inside m_cWaveform.RenderWaveform.
    //

    //
    // Keep hold of the new dataset.
    //
    m_iSampleOffset = (int)wParam;
    m_psScopeData = (tScopeDataStart *)lParam;

    //
    // Update the text showing min, max and mean voltages for each
    // channel.
    //
    UpdateVoltageMeasurements();

    //
    // Update waveform display with new data.
    //
    m_cWaveform.RenderWaveform(m_psScopeData, m_iSampleOffset);

    //
    // Now that we have data, we can enable the "Save As" menu options.
    //
    if(!m_bSaveItemsEnabled)
    {
        //
        // Get a handle to the system menu.
        //
        CMenu* pSysMenu = GetSystemMenu(FALSE);

        //
        // Did we get the handle?
        //
        if(pSysMenu)
        {
            //
            // Yes - enable both the "Save As" menu options.
            //
            pSysMenu->EnableMenuItem(IDM_SAVEASBMP, MF_ENABLED);
            pSysMenu->EnableMenuItem(IDM_SAVEASCSV, MF_ENABLED);
        }

        //
        // Remember that we already enabled the options.
        //
        m_bSaveItemsEnabled = TRUE;
    }

    return((LRESULT)0);
}

//***************************************************************************
//
// Handle ping responses from the oscilloscope device.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopePingResponse(WPARAM wParam, LPARAM lParam)
{
    //
    // Set the flag indicating that our last ping was responded to.
    //
    m_iPingResponse++;
    m_bPingResponseReceived = TRUE;
    return((LRESULT)0);
}

//***************************************************************************
//
// The oscilloscope is reporting that automated data capture has stopped.
// Update the UI to match.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopeStopped(WPARAM wParam, LPARAM lParam)
{
    CString strStart;

    //
    // Remember which state we are in.
    //
    m_bStarted = FALSE;

    //
    // Get the "Start" string from our resources.
    //
    strStart.LoadString(IDS_START);

    //
    // Set the Stop/Start button text to indicate that the button will
    // now start capture rather than stop it.
    //
    m_cStopStart.SetWindowText(strStart);

    //
    // Enable the "One Shot Capture" button.
    //
    m_cOneShot.EnableWindow(TRUE);
    return((LRESULT)0);

}

//***************************************************************************
//
// The oscilloscope is reporting that automatic waveform capture has started.
// Update the UI to match.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopeStarted(WPARAM wParam, LPARAM lParam)
{
    CString strStop;

    //
    // Remember which state we are in.
    //
    m_bStarted = TRUE;

    //
    // Get the "Stop" string from our resources.
    //
    strStop.LoadString(IDS_STOP);

    //
    // Set the Stop/Start button text to indicate that the button will
    // now stop capture rather than stop it.
    //
    m_cStopStart.SetWindowText(strStop);

    //
    // Disable the "One Shot Capture" button.
    //
    m_cOneShot.EnableWindow(FALSE);

    //
    return((LRESULT)0);
}

//***************************************************************************
//
// The oscilloscope is reporting that the timebase has been changed.
// Update the UI to match.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopeTimebaseChanged(WPARAM wParam, LPARAM lParam)
{
    //
    // Update our combo box selection to match.
    //
    m_cTimebase.SetCurSelByValue((DWORD)lParam);

    //
    // Update the current waveform display with the new timebase.
    //
    m_cWaveform.SetTimebase((unsigned long)lParam);

    return((LRESULT)0);
}

//***************************************************************************
//
// The oscilloscope is reporting that the vertical scaling for a channel has
// been changed. Update the UI to match.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopeScaleChanged(WPARAM wParam, LPARAM lParam)
{
    //
    // Update our combo box selection to match and redraw
    // the waveform.
    //
    if(wParam == SCOPE_CHANNEL_1)
    {
        m_cChannel1Scale.SetCurSelByValue((DWORD)lParam);
        m_cWaveform.SetChannelScale(CHANNEL_1, (int)lParam);
    }
    else
    {
        m_cChannel2Scale.SetCurSelByValue((DWORD)lParam);
        m_cWaveform.SetChannelScale(CHANNEL_2, (int)lParam);
    }

    return((LRESULT)0);
}

//***************************************************************************
//
// The oscilloscope is reporting that the vertical position of a channel has
// been changed. Update the UI to match.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopePositionChanged(WPARAM wParam, LPARAM lParam)
{
    CString strText;
    long lPos;

    //
    // Format the offset as a string
    //
    ScaleAndFormatString(&strText,  (LPCTSTR)L"", (LPCTSTR)L"mV",
                         (LPCTSTR)L"V", (long)lParam);

    //
    // We invert the slider relative to the value received since Windows
    // insists that vertical sliders have the maximum value at the bottom
    // rather than the top.
    //
    lPos = REVERSE_SLIDER((long)lParam, POS_SLIDER_MAX, POS_SLIDER_MIN);

    //
    // Update our slider and text to show the new position.
    //
    if(wParam == SCOPE_CHANNEL_1)
    {

        m_cChannel1PosSlider.SetPos((int)lPos);
        m_cChannel1Pos.SetWindowTextW(strText);

        //
        // Update the current waveform display with the new offset.
        //
        m_cWaveform.SetChannelPos(CHANNEL_1, (int)lParam);
    }
    else
    {
        m_cChannel2PosSlider.SetPos((int)lPos);
        m_cChannel2Pos.SetWindowTextW(strText);

        //
        // Update the current waveform display with the new offset.
        //
        m_cWaveform.SetChannelPos(CHANNEL_2, (int)lParam);
    }

    return((LRESULT)0);
}

//***************************************************************************
//
// The oscilloscope is reporting that the trigger level has been changed.
// Update the UI to match.
//
//***************************************************************************
LRESULT ClmscopeDlg::OnScopeTriggerLevelChanged(WPARAM wParam, LPARAM lParam)
{
    CString strText;
    long lPos;

    //
    // Set the trigger level.
    //
    ScaleAndFormatString(&strText,  (LPCTSTR)L"", (LPCTSTR)L"mV",
                         (LPCTSTR)L"V", (long)lParam);
    m_cTriggerLevel.SetWindowTextW(strText);
    lPos = REVERSE_SLIDER((long)lParam, TRIGGER_LEVEL_SLIDER_MAX,
                          TRIGGER_LEVEL_SLIDER_MIN);
    m_cTriggerLevelSlider.SetPos((int)lPos);

    //
    // Update the current waveform display with the new timebase.
    //
    m_cWaveform.SetTriggerLevel((long)lParam);

    return((LRESULT)0);
}

⌨️ 快捷键说明

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