📄 steerdlg.cpp
字号:
// SteerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Steer.h"
#include "SteerDlg.h"
#include "afxmt.h"
#include "conio.h"
#include "math.h"
#include "Step32.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
static HWND hDlg;
static CEvent g_EndTh;
int baseAD=0x280;
int baseDrive=0x300;
unsigned char DDA,AD;
unsigned int LSP,HSP;
unsigned char xmode,ymode;
unsigned char xdir,ydir;
unsigned char xson,yson;
int m_nSteerAngle=2048;
UINT WorkThread(LPVOID param)
{
CString str;
short poll,lb,hb;
int n,channal0=0x00;
int ad;
n=0;
_outp(baseAD+4,0x03); //选择8253控制字
_outp(baseAD+7,0x74); //写#1计数器控制字
_outp(baseAD+4,0x01); //选#1计数器地址
_outp(baseAD+7,244); //写#1第一个字节值
_outp(baseAD+7,1); //写#1第二个字节值
_outp(baseAD+4,0x03);
_outp(baseAD+7,0xb4);
_outp(baseAD+4,0x02);
_outp(baseAD+7,144);
_outp(baseAD+7,1);
_outp(baseAD+4,0x04); //允许定时触发,屏蔽外触发
while(1)
{
_outp(baseAD,channal0);
poll=_inp(baseAD+1);
poll=poll&0x80;
while(!poll)
{
poll=_inp(baseAD+1);
poll=poll&0x80;
}
lb=_inp(baseAD+2)&0x00ff;
hb=_inp(baseAD+3)&0x000f;
ad=lb+hb*256;
// ad=(ad-2047)*10/4095;
str.Format("%d",ad);
::SetDlgItemText(hDlg,IDC_INPUT_VOLTAGE,str);
n=int((ad-m_nSteerAngle)/60);
MSTEP2_HSP_PULSE_MOVE(1, Y_axis, n);
if(::WaitForSingleObject(g_EndTh,0)==WAIT_OBJECT_0)
{
break;
}
}
return 0;
}
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSteerDlg dialog
CSteerDlg::CSteerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSteerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSteerDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSteerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSteerDlg)
DDX_Control(pDX, IDC_START_THREAD, m_BeginTh);
DDX_Control(pDX, IDC_END_THREAD, m_EndTh);
//}}AFX_DATA_MAP
/* if(pDX->m_bSaveAndValidate)
{
CSliderCtrl* pSlide=(CSliderCtrl*)GetDlgItem(IDC_SLIDER_ANGLE);
m_nSteerAngle=pSlide->GetPos();
}*/
}
BEGIN_MESSAGE_MAP(CSteerDlg, CDialog)
//{{AFX_MSG_MAP(CSteerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_START_THREAD, OnStartThread)
ON_BN_CLICKED(IDC_END_THREAD, OnEndThread)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSteerDlg message handlers
BOOL CSteerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
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
// TODO: Add extra initialization here
CSliderCtrl* pSlide=(CSliderCtrl*)GetDlgItem(IDC_SLIDER_ANGLE);
pSlide->SetRange(0,4096);
pSlide->SetPos(m_nSteerAngle);
CString strOri;
strOri.Format("%d",pSlide->GetPos());
SetDlgItemText(IDC_STATIC_ANGLE,strOri);
hDlg=GetSafeHwnd();
m_EndTh.EnableWindow(FALSE);
DDA=5;
AD=1;
LSP=1;
HSP=20;
xmode=PULSE_DIR;
ymode=PULSE_DIR;
xdir=NORMAL_DIR;
ydir=NORMAL_DIR;
xson=ON;
yson=ON;
MSTEP2_INITIAL();
MSTEP2_REGISTRATION(1, baseDrive);
MSTEP2_RESET_SYSTEM(1);
MSTEP2_SET_VAR(1, DDA, AD, LSP, HSP);
MSTEP2_SET_DEFDIR(1, xdir, ydir);
MSTEP2_SET_MODE(1, xmode, ymode);
MSTEP2_SET_SERVO_ON(1, xson, yson);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSteerDlg::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 CSteerDlg::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 CSteerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSteerDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CSliderCtrl* pSlide=(CSliderCtrl*)GetDlgItem(IDC_SLIDER_ANGLE);
CString str;
str.Format("%d",pSlide->GetPos());
SetDlgItemText(IDC_STATIC_ANGLE,str);
m_nSteerAngle=pSlide->GetPos();
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CSteerDlg::OnStartThread()
{
// TODO: Add your control notification handler code here
m_BeginTh.EnableWindow(FALSE);
m_EndTh.EnableWindow(TRUE);
g_EndTh.ResetEvent();
AfxBeginThread(WorkThread,GetSafeHwnd());
}
void CSteerDlg::OnEndThread()
{
// TODO: Add your control notification handler code here
m_BeginTh.EnableWindow(TRUE);
m_EndTh.EnableWindow(FALSE);
g_EndTh.SetEvent();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -