📄 mdt_aiptestdlg.cpp
字号:
}
void CMDT_AIPTestDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
if(m_hAIP)
{
CloseHandle(m_hAIP);
m_hAIP=NULL;
}
CDialog::OnClose();
}
void CMDT_AIPTestDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
if(m_hAIP)
{
CloseHandle(m_hAIP);
m_hAIP=NULL;
}
}
void CMDT_AIPTestDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int i;
DWORD dwCode;
DWORD ADCChannel;
BOOL bRc;
DWORD dwBytesReturned;
USHORT strTemp[100];
DWORD ADCValue[4];
DWORD dwLEDValue;
DWORD dwDIOOutValue;
DWORD dwDIOInValue;
switch(nIDEvent)
{
case TIMER_ADC:
if(m_hAIP)
{
for(i=1;i<=4;i++)
{
dwCode=IOCTL_AIP_GET_ADC_VALUE;
ADCChannel=i;
bRc = DeviceIoControl(
m_hAIP,
dwCode,
&ADCChannel,
sizeof(ADCChannel),
&ADCValue[i-1],
sizeof(ADCValue[i-1]),
&dwBytesReturned, NULL
);
}
wsprintf(strTemp,_T("ADC [%4d] [%4d] [%4d] [%4d]"),ADCValue[0],ADCValue[1],ADCValue[2],ADCValue[3]);
m_ListBox.AddString(strTemp);
}
else
{
m_ListBox.AddString(_T("AIP Handle Fail"));
OnAdcButton();
}
m_ListBox.SetCurSel(m_ListBox.GetCount() - 1);
break;
case TIMER_LED:
if(m_hAIP)
{
dwCode=IOCTL_AIP_GET_LED_OUT;
bRc = DeviceIoControl(
m_hAIP,
dwCode,
0, 0,
&dwLEDValue,
sizeof(dwLEDValue),
&dwBytesReturned, NULL
);
dwLEDValue = dwLEDValue << 1;
if((dwLEDValue & 0x1f) == 0)
dwLEDValue=1;
dwCode=IOCTL_AIP_SET_LED_OUT;
bRc = DeviceIoControl(
m_hAIP,
dwCode,
&dwLEDValue,
sizeof(dwLEDValue),
0, 0, &dwBytesReturned, NULL
);
dwCode=IOCTL_AIP_GET_LED_OUT;
bRc = DeviceIoControl(
m_hAIP,
dwCode,
0, 0,
&dwLEDValue,
sizeof(dwLEDValue),
&dwBytesReturned, NULL
);
if(bRc)
{
wsprintf(strTemp,_T("LED %d %d %d %d %d")
,dwLEDValue & (1 << 0) ? 1 : 0
,dwLEDValue & (1 << 1) ? 1 : 0
,dwLEDValue & (1 << 2) ? 1 : 0
,dwLEDValue & (1 << 3) ? 1 : 0
,dwLEDValue & (1 << 4) ? 1 : 0
);
m_ListBox.AddString(strTemp);
}
}
else
{
m_ListBox.AddString(_T("AIP Handle Fail"));
OnLedButton();
}
m_ListBox.SetCurSel(m_ListBox.GetCount() - 1);
break;
case TIMER_DOUT:
if(m_hAIP)
{
dwCode=IOCTL_AIP_GET_DIO_OUT;
bRc = DeviceIoControl(
m_hAIP,
dwCode,
0, 0,
&dwDIOOutValue,
sizeof(dwDIOOutValue),
&dwBytesReturned, NULL
);
dwDIOOutValue = dwDIOOutValue << 1;
if((dwDIOOutValue & 0xff) == 0)
dwDIOOutValue=1;
dwCode=IOCTL_AIP_SET_DIO_OUT;
bRc = DeviceIoControl(
m_hAIP,
dwCode,
&dwDIOOutValue,
sizeof(dwDIOOutValue),
0, 0, &dwBytesReturned, NULL
);
dwCode=IOCTL_AIP_GET_DIO_OUT;
bRc = DeviceIoControl(
m_hAIP,
dwCode,
0, 0,
&dwDIOOutValue,
sizeof(dwDIOOutValue),
&dwBytesReturned, NULL
);
if(bRc)
{
wsprintf(strTemp,_T("D OUT %d %d %d %d %d %d %d %d")
,dwDIOOutValue & (1 << 0) ? 1 : 0
,dwDIOOutValue & (1 << 1) ? 1 : 0
,dwDIOOutValue & (1 << 2) ? 1 : 0
,dwDIOOutValue & (1 << 3) ? 1 : 0
,dwDIOOutValue & (1 << 4) ? 1 : 0
,dwDIOOutValue & (1 << 5) ? 1 : 0
,dwDIOOutValue & (1 << 6) ? 1 : 0
,dwDIOOutValue & (1 << 7) ? 1 : 0
);
m_ListBox.AddString(strTemp);
}
}
else
{
m_ListBox.AddString(_T("AIP Handle Fail"));
OnDoutButton();
}
m_ListBox.SetCurSel(m_ListBox.GetCount() - 1);
break;
case TIMER_DIN:
if(m_hAIP)
{
dwCode=IOCTL_AIP_GET_DIO_IN;
bRc = DeviceIoControl(
m_hAIP,
dwCode,
0,
NULL,
&dwDIOInValue,
sizeof(dwDIOInValue),
&dwBytesReturned, NULL
);
wsprintf(strTemp,_T("D IN %d %d %d %d %d %d %d %d")
,dwDIOInValue & (1 << 0) ? 1 : 0
,dwDIOInValue & (1 << 1) ? 1 : 0
,dwDIOInValue & (1 << 2) ? 1 : 0
,dwDIOInValue & (1 << 3) ? 1 : 0
,dwDIOInValue & (1 << 4) ? 1 : 0
,dwDIOInValue & (1 << 5) ? 1 : 0
,dwDIOInValue & (1 << 6) ? 1 : 0
,dwDIOInValue & (1 << 7) ? 1 : 0
);
m_ListBox.AddString(strTemp);
}
else
{
m_ListBox.AddString(_T("AIP Handle Fail"));
OnDinButton();
}
m_ListBox.SetCurSel(m_ListBox.GetCount() - 1);
break;
}
CDialog::OnTimer(nIDEvent);
}
void CMDT_AIPTestDlg::OnAdcButton()
{
// TODO: Add your control notification handler code here
CString strText;
m_ADCButton.GetWindowText(strText);
if(strText.Compare(_T("ADC Start")) == 0)
{
SetTimer(TIMER_ADC,DELAY_ADC,NULL);
m_ADCButton.SetWindowText(_T("ADC Stop"));
}
else
{
KillTimer(TIMER_ADC);
m_ADCButton.SetWindowText(_T("ADC Start"));
}
}
void CMDT_AIPTestDlg::OnLedButton()
{
// TODO: Add your control notification handler code here
CString strText;
DWORD dwLEDValue;
DWORD dwCode;
BOOL bRc;
DWORD dwBytesReturned;
m_LEDButton.GetWindowText(strText);
if(strText.Compare(_T("LED Start")) == 0)
{
dwLEDValue=0x01;
dwCode=IOCTL_AIP_SET_LED_OUT;
bRc = DeviceIoControl(
m_hAIP,
dwCode,
&dwLEDValue,
sizeof(dwLEDValue),
0, 0, &dwBytesReturned, NULL
);
SetTimer(TIMER_LED,DELAY_LED,NULL);
m_LEDButton.SetWindowText(_T("LED Stop"));
}
else
{
KillTimer(TIMER_LED);
m_LEDButton.SetWindowText(_T("LED Start"));
}
}
BOOL CMDT_AIPTestDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
int i;
if(pMsg->message == WM_KEYDOWN)
{
switch(pMsg->wParam)
{
case KEY_FN_1:
m_ListBox.AddString(_T("[Button] KEY_FN_1"));
break;
case KEY_FN_2:
m_ListBox.AddString(_T("[Button] KEY_FN_2"));
break;
case KEY_FN_3:
m_ListBox.AddString(_T("[Button] KEY_FN_3"));
break;
case KEY_FN_4:
m_ListBox.AddString(_T("[Button] KEY_FN_4"));
break;
case KEY_UP:
m_ListBox.AddString(_T("[Button] KEY_UP"));
BLUpDn_UP(v_pGPIOReg);
for(i=0;i<10;i++){
BL_INC_LOW(v_pGPIOReg);
Sleep(20);
BL_INC_HIGH(v_pGPIOReg);
Sleep(20);
}
BL_INC_LOW(v_pGPIOReg);
break;
case KEY_DOWN:
m_ListBox.AddString(_T("[Button] KEY_DOWN"));
BLUpDn_DN(v_pGPIOReg);
for(i=0;i<10;i++){
BL_INC_LOW(v_pGPIOReg);
Sleep(20);
BL_INC_HIGH(v_pGPIOReg);
Sleep(20);
}
BL_INC_LOW(v_pGPIOReg);
break;
case KEY_LEFT:
m_ListBox.AddString(_T("[Button] KEY_LEFT"));
break;
case KEY_RIGHT:
m_ListBox.AddString(_T("[Button] KEY_RIGHT"));
break;
case KEY_ENTER:
m_ListBox.AddString(_T("[Button] KEY_ENTER"));
break;
case KEY_STANBY:
m_ListBox.AddString(_T("[Button] KEY_STANBY"));
break;
case KEY_MODE:
m_ListBox.AddString(_T("[Button] KEY_MODE"));
break;
case KEY_MENU:
m_ListBox.AddString(_T("[Button] KEY_MENU"));
break;
}
m_ListBox.SetCurSel(m_ListBox.GetCount() - 1);
}
return CDialog::PreTranslateMessage(pMsg);
}
void CMDT_AIPTestDlg::OnDoutButton()
{
// TODO: Add your control notification handler code here
CString strText;
DWORD dwOUTValue;
DWORD dwCode;
BOOL bRc;
DWORD dwBytesReturned;
m_DOutButton.GetWindowText(strText);
if(strText.Compare(_T("D Out Start")) == 0)
{
dwOUTValue=0x01;
dwCode=IOCTL_AIP_SET_DIO_OUT;
bRc = DeviceIoControl(
m_hAIP,
dwCode,
&dwOUTValue,
sizeof(dwOUTValue),
0, 0, &dwBytesReturned, NULL
);
SetTimer(TIMER_DOUT,DELAY_DOUT,NULL);
m_DOutButton.SetWindowText(_T("D Out Stop"));
}
else
{
KillTimer(TIMER_DOUT);
m_DOutButton.SetWindowText(_T("D Out Start"));
}
}
void CMDT_AIPTestDlg::OnDinButton()
{
// TODO: Add your control notification handler code here
CString strText;
m_DInButton.GetWindowText(strText);
if(strText.Compare(_T("D In Start")) == 0)
{
SetTimer(TIMER_DIN,DELAY_DIN,NULL);
m_DInButton.SetWindowText(_T("D In Stop"));
}
else
{
KillTimer(TIMER_DIN);
m_DInButton.SetWindowText(_T("D In Start"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -