📄 wdtsampledlg.cpp
字号:
// WDTSampleDlg.cpp : implementation file
//
#include "stdafx.h"
#include "WDTSample.h"
#include "WDTSampleDlg.h"
#include "WDT.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CWDTSampleDlg dialog
CWDTSampleDlg::CWDTSampleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWDTSampleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWDTSampleDlg)
m_nRadio_event = 0;
m_nRadio_irq = 0;
m_nEdit_time = 120;
m_nRadio_unit = 1;
m_nEdit_irq = 0;
m_time = 0;
m_bRadio10 = FALSE;
m_bWDTStart = FALSE;
m_bCheck = FALSE;
m_bTimer1 = FALSE;
m_bTimer2 = FALSE;
m_bTimer3 = FALSE;
m_bWDTCreated = FALSE;
//}}AFX_DATA_INIT
m_hMyEvent = NULL;
m_Initialized = false;
m_ThreadExit = false;
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
m_bInitOk=FALSE;
}
void CWDTSampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWDTSampleDlg)
DDX_Control(pDX, IDC_CHECK_AUTO, m_CheckAuto);
DDX_Radio(pDX, IDC_RADIO3, m_nRadio_event);
DDX_Radio(pDX, IDC_RADIO9, m_nRadio_irq);
DDX_Text(pDX, IDC_EDIT1, m_nEdit_time);
DDX_Radio(pDX, IDC_RADIO1, m_nRadio_unit);
DDX_Text(pDX, IDC_EDIT2, m_nEdit_irq);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWDTSampleDlg, CDialog)
//{{AFX_MSG_MAP(CWDTSampleDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
ON_BN_CLICKED(IDC_RADIO7, OnRadio7)
ON_BN_CLICKED(IDC_RADIO8, OnRadio8)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON_MANUAL, OnButtonManual)
ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
ON_BN_CLICKED(IDC_RADIO10, OnRadio10)
ON_BN_CLICKED(IDC_RADIO9, OnRadio9)
ON_BN_CLICKED(IDC_CHECK_AUTO, OnCheckAuto)
ON_BN_CLICKED(IDC_BUTTON_HELP, OnButtonHelp)
ON_MESSAGE(WM_NOTIFYICON, OnNotifyIcon)
ON_BN_CLICKED(IDC_BUTTON_WDT_CREATE, OnButtonWdtCreate)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWDTSampleDlg message handlers
BOOL CWDTSampleDlg::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
// Set static text font
CFont m_font;
LOGFONT lf;
::ZeroMemory(&lf, sizeof(lf));
lf.lfHeight =-120;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_BOLD;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = VARIABLE_PITCH|FF_ROMAN;
m_font.CreateFontIndirect (&lf);
// Set static text font.
GetDlgItem(IDC_STATICTEXT_TITLE)->SetFont(&m_font);
GetDlgItem(IDC_STATICTEXT_VALUE)->SetFont(&m_font);
GetDlgItem(IDC_STATICTEXT_UNITDIS)->SetWindowText("Minute");
GetDlgItem(IDC_RADIO9)->EnableWindow(FALSE);
GetDlgItem(IDC_RADIO10)->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT2)->EnableWindow(FALSE);
GetDlgItem(IDC_STATICTEXT_VALUE)->SetWindowText("0");
// Registe message,name is WDT_OVERFLOW_MESSAGE_NAME.
WM_WDT_OVERFLOW_MESSAGE = RegisterWindowMessage(WDT_OVERFLOW_MESSAGE_NAME);
// create system salver
NOTIFYICONDATA nd;
nd.cbSize = sizeof (NOTIFYICONDATA);
nd.hWnd = m_hWnd;
nd.uID = IDR_MAINFRAME;
nd.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
nd.uCallbackMessage = WM_NOTIFYICON;
nd.hIcon = m_hIcon;
strcpy(nd.szTip, "WDTSample");
Shell_NotifyIcon(NIM_ADD, &nd);
if(!InitEVOCIO())
{
MessageBox("Initialize EVOCIO driver error");
}
else
{
m_Initialized = true;
}
GetDlgItem(IDC_STATICTEXT_UNITDIS)->SetWindowText("Second");
SetTimer(4,10000,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CWDTSampleDlg::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 CWDTSampleDlg::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 CWDTSampleDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CWDTSampleDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_STATICTEXT_UNITDIS)->SetWindowText("Minute");
}
void CWDTSampleDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_STATICTEXT_UNITDIS)->SetWindowText("Second");
}
void CWDTSampleDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
// When select hardware reset,doesn't set irq.
GetDlgItem(IDC_RADIO9)->EnableWindow(FALSE);
GetDlgItem(IDC_STATICTEXT_IRQ)->EnableWindow(FALSE);
GetDlgItem(IDC_RADIO10)->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT2)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_WDT_CREATE)->EnableWindow(true);
}
void CWDTSampleDlg::OnRadio4()
{
// TODO: Add your control notification handler code here
// When select shutdown system,need set irq.
GetDlgItem(IDC_RADIO9)->EnableWindow(TRUE);
GetDlgItem(IDC_STATICTEXT_IRQ)->EnableWindow(TRUE);
GetDlgItem(IDC_RADIO10)->EnableWindow(TRUE);
if(m_bRadio10)
{
GetDlgItem(IDC_EDIT2)->EnableWindow(TRUE);
}
GetDlgItem(IDC_BUTTON_WDT_CREATE)->EnableWindow(true);
}
void CWDTSampleDlg::OnRadio5()
{
// TODO: Add your control notification handler code here
// When select reboot system,need set irq.
OnRadio4();
}
void CWDTSampleDlg::OnRadio6()
{
// TODO: Add your control notification handler code here
// When select set event,need set irq.
OnRadio4();
}
void CWDTSampleDlg::OnRadio7()
{
// TODO: Add your control notification handler code here
// When select send message,need set irq.
OnRadio4();
}
void CWDTSampleDlg::OnRadio8()
{
// TODO: Add your control notification handler code here
// When select call function,need set irq.
OnRadio4();
}
void CWDTSampleDlg::OnRadio9()
{
// TODO: Add your control notification handler code here
// Select search irq automatic.
GetDlgItem(IDC_EDIT2)->EnableWindow(FALSE);
m_bRadio10 = FALSE;
GetDlgItem(IDC_BUTTON_WDT_CREATE)->EnableWindow(true);
}
void CWDTSampleDlg::OnRadio10()
{
// TODO: Add your control notification handler code here
// Select user give irq.
GetDlgItem(IDC_EDIT2)->EnableWindow(TRUE);
GetDlgItem(IDC_STATICTEXT_IRQ)->SetWindowText("");
m_bRadio10 = TRUE;
GetDlgItem(IDC_BUTTON_WDT_CREATE)->EnableWindow(true);
}
void CWDTSampleDlg::OnTimer(UINT nIDEvent)
{
static CString strTemp;
int val;
switch(nIDEvent)
{
case 1: // Timer 1,display WDT current count value.
// Read current counting data and display.
val = WDTReadCounterVal();
if(val == -2)
{
// hardware not support get current countting value,
// such as sch311x,start a virtual counter
KillTimer(1);
m_bTimer1 = false;
if(m_unit == 0)
SetTimer(3,1000,NULL);
else if(m_unit == 1)
SetTimer(3,60*1000,NULL);
m_bTimer3 = true;
strTemp.Format("%i",m_time);
GetDlgItem(IDC_STATICTEXT_VALUE)->SetWindowText(strTemp);
}
else if(val != -1)
{
strTemp.Format("%i",val);
GetDlgItem(IDC_STATICTEXT_VALUE)->SetWindowText(strTemp);
}
break;
case 2: // Timer 2, Set WDT automatic.
OnButtonManual();
/* if(m_unit==0)
{
if(m_time==1)
SetTimer(2,500,NULL);
else
SetTimer(2,(m_time-1)*500,NULL); // After (m_time1-1)second,start WDT.
}
else if(m_unit==1)
{
if(m_time==1)
SetTimer(2,10000,NULL);
else
SetTimer(2,(m_time-1)*60000,NULL); // After (m_time1-1)second,start WDT.
}
m_bTimer2 = TRUE;*/
break;
case 3: // Timer3,set counting data to sch311x.
if((m_time == 0) || !m_bWDTCreated)
break;
strTemp.Format("%i",m_time--);
GetDlgItem(IDC_STATICTEXT_VALUE)->SetWindowText(strTemp);
break;
case 4:
if (FALSE==m_bInitOk)
{
OnButtonWdtCreate();
m_CheckAuto.SetCheck(1);
OnCheckAuto();
m_bInitOk=TRUE;
}
break;
default:
break;
}
CDialog::OnTimer(nIDEvent);
}
// Set WDT working in interrupt mode,and check user IRQ.
bool CWDTSampleDlg::CreateIntWDT()
{
int irq;
int result;
static CString strTemp;
if(m_nRadio_irq == -1)
{ // Not set the way of get irq.
MessageBox("Please setting IRQ","IRQ Setting",MB_OK);
return false;
}
else if(m_nRadio_irq == 0)
{ // Search irq automatic,return value is the searched irq number.
irq = WDTCreate(WDT_MODE_INTERRUPT,IRQ_SEARCH_AUTO);
if(irq >= 0)
{
// searched valid IRQ
strTemp.Format("%i",irq);
GetDlgItem(IDC_STATICTEXT_IRQ)->SetWindowText(strTemp);
}
else if(irq == -1)
{
// Invalid parameters
MessageBox("Create WDT parameters error!","Error",MB_OK);
return false;
}
if(irq == -3)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -