// Util6308Dlg.cpp : implementation file // #include "stdafx.h" #include "math.h" #include "Util6308.h" #include "Util6308Dlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CUtil6308Dlg dialog CUtil6308Dlg::CUtil6308Dlg(I16 hCard, CWnd* pParent /*=NULL*/) : CDialog(CUtil6308Dlg::IDD, pParent) { int i; m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_hCard = hCard; for( i=0; iAppendMenu(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 // TODO: Add extra initialization here m_sdAOLevel0.SetRange( 0, 4095, TRUE ); m_sdAOLevel0.SetTicFreq( 5 ); m_sdAOLevel1.SetRange( 0, 4095, TRUE ); m_sdAOLevel1.SetTicFreq( 5 ); m_sdAOLevel2.SetRange( 0, 4095, TRUE ); m_sdAOLevel2.SetTicFreq( 5 ); m_sdAOLevel3.SetRange( 0, 4095, TRUE ); m_sdAOLevel3.SetTicFreq( 5 ); m_nTimer = SetTimer( 1, 200, NULL ); return TRUE; // return TRUE unless you set the focus to a control } void CUtil6308Dlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CUtil6308Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(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 function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CUtil6308Dlg::OnQueryDragIcon() { return static_cast(m_hIcon); } void CUtil6308Dlg::OnDO0Clicked() { // TODO: Add your control notification handler code here int CheckSts; CheckSts = ((CButton*)GetDlgItem( IDC_CHECK_DO0 ))->GetCheck(); if( CheckSts == BST_CHECKED ) { m_bDOData |= 0x01; } else if( CheckSts == BST_UNCHECKED ) { m_bDOData &= (~0x01); } DO_WritePort( m_hCard, 0, m_bDOData ); } void CUtil6308Dlg::OnDO1Clicked() { // TODO: Add your control notification handler code here int CheckSts; CheckSts = ((CButton*)GetDlgItem( IDC_CHECK_DO1 ))->GetCheck(); if( CheckSts == BST_CHECKED ) { m_bDOData |= 0x02; } else if( CheckSts == BST_UNCHECKED ) { m_bDOData &= (~0x02); } DO_WritePort( m_hCard, 0, m_bDOData ); } void CUtil6308Dlg::OnDO2Clicked() { // TODO: Add your control notification handler code here int CheckSts; CheckSts = ((CButton*)GetDlgItem( IDC_CHECK_DO2 ))->GetCheck(); if( CheckSts == BST_CHECKED ) { m_bDOData |= 0x04; } else if( CheckSts == BST_UNCHECKED ) { m_bDOData &= (~0x04); } DO_WritePort( m_hCard, 0, m_bDOData ); } void CUtil6308Dlg::OnDO3Clicked() { // TODO: Add your control notification handler code here int CheckSts; CheckSts = ((CButton*)GetDlgItem( IDC_CHECK_DO3 ))->GetCheck(); if( CheckSts == BST_CHECKED ) { m_bDOData |= 0x08; } else if( CheckSts == BST_UNCHECKED ) { m_bDOData &= (~0x08); } DO_WritePort( m_hCard, 0, m_bDOData ); } void CUtil6308Dlg::OnTimer(UINT_PTR nIDEvent) { // TODO: Add your message handler code here and/or call default U32 dwPortData; DI_ReadPort( m_hCard, 0, &dwPortData); dwPortData = ( dwPortData & 0x0F ); if( dwPortData != m_bDIData ) { m_bDIData = (U8)( dwPortData & 0xFF ); if( (dwPortData & 0x01) == 0x01 ) { m_DI0_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_RED) ) ; } else { m_DI0_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_BLACK) ) ; } if( (dwPortData & 0x02) == 0x02 ) { m_DI1_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_RED) ) ; } else { m_DI1_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_BLACK) ) ; } if( (dwPortData & 0x04) == 0x04 ) { m_DI2_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_RED) ) ; } else { m_DI2_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_BLACK) ) ; } if( (dwPortData & 0x08) == 0x08 ) { m_DI3_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_RED) ) ; } else { m_DI3_ON.SetIcon( AfxGetApp()->LoadIcon(IDI_ICON_BLACK) ) ; } } CDialog::OnTimer(nIDEvent); } void CUtil6308Dlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here if( m_nTimer != -1 ) KillTimer( m_nTimer ); } void CUtil6308Dlg::OnSliderV0Changed(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: Add your control notification handler code here int position; position = m_sdAOLevel0.GetPos(); m_AOValue[0] = m_AOValue[1] = position; AO_WriteChannel(m_hCard, 0, (I16)m_AOValue[0] ); AO_WriteChannel(m_hCard, 1, (I16)m_AOValue[1] ); *pResult = 0; } void CUtil6308Dlg::OnSliderV1Changed(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: Add your control notification handler code here int position; position = m_sdAOLevel1.GetPos(); m_AOValue[2] = m_AOValue[3] = position; AO_WriteChannel(m_hCard, 2, (I16)m_AOValue[2] ); AO_WriteChannel(m_hCard, 3, (I16)m_AOValue[3] ); *pResult = 0; } void CUtil6308Dlg::OnSliderV2Changed(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: Add your control notification handler code here int position; position = m_sdAOLevel2.GetPos(); m_AOValue[4] = m_AOValue[5] = position; AO_WriteChannel(m_hCard, 4, (I16)m_AOValue[4] ); AO_WriteChannel(m_hCard, 5, (I16)m_AOValue[5] ); *pResult = 0; } void CUtil6308Dlg::OnSliderV3Changed(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: Add your control notification handler code here int position; position = m_sdAOLevel3.GetPos(); m_AOValue[6] = m_AOValue[7] = position; AO_WriteChannel(m_hCard, 6, (I16)m_AOValue[6] ); AO_WriteChannel(m_hCard, 7, (I16)m_AOValue[7] ); *pResult = 0; }