?? peridialog.cpp
字號(hào):
// PeriDialog.cpp : implementation file
// Peripheral Dialog: A/D Converter for ADuC812
#include "stdafx.h"
#include "Agsi.h"
#include "SPeriDLL.h"
#include "PeriDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Protoyptes for forward references
static void PeriUpdate (void);
static void PeriKill (AGSIDLGD *pM);
static void PeriDisp (AGSIMENU *pM);
/////////////////////////////////////////////////////////////////////////////
// CPeriDialog dialog
static CPeriDialog * pCPeriDialog;
BYTE initflag = 0;
// must not use 'const' here !
// iOpen Hwnd Dlg Proc. Rect: -1 := default Update Kill
AGSIDLGD PeriDlg = { 0, NULL, NULL, { -1, -1, -1, -1, }, PeriUpdate, PeriKill };
// nDelim *szText *fp nID nDlgId *pDlg;
AGSIMENU PeriMenu = { 1, "&A/D Converter" , PeriDisp, 0, IDD_ADCON, &PeriDlg }; // Peripheral Dialog
static DWORD adccon1, adccon2, adccon3, adcdatal, adcdatah, dmal, dmah, dmap; // Current values
static DWORD adccon1p, adccon2p, adccon3p, adcdatalp, adcdatahp, dmalp, dmahp, dmapp; // Previous values
// Output 2-digit Hexnumber to Text-Control of given Dialog
void StringHex2 (CWnd * pCWnd, DWORD val) {
char locbuffer[20];
sprintf (locbuffer, "0x%02X", val);
pCWnd->SetWindowText (locbuffer);
}
// Output 4-digit Hexnumber to Text-Control of given Dialog
void StringHex4 (CWnd * pCWnd, DWORD val) {
char locbuffer[20];
sprintf (locbuffer, "0x%04X", val);
pCWnd->SetWindowText (locbuffer);
}
// Output 6-digit Hexnumber to Text-Control of given Dialog
void StringHex6 (CWnd * pCWnd, DWORD val) {
char locbuffer[20];
sprintf (locbuffer, "0x%06X", val);
pCWnd->SetWindowText (locbuffer);
}
// Output Float number to Text-Control of given Dialog
void StringFloat (CWnd * pCWnd, float val) {
char locbuffer[20];
sprintf (locbuffer, "%1.4f", val);
pCWnd->SetWindowText (locbuffer);
}
static const char INPUT_ERR_TITLE [] = "Invalid number";
static const char INPUT_ERRMSG[] = "You have entered an invalid number!\n"
"The previous value will be restored.\n"
"Examples: 0x12\n";
static const char INPUT_OVR_TITLE [] = "Out of range";
static const char INPUT_OVRMSG[] = "You have entered a number that is out of range!\n";
long GetDlg8BNumber (CWnd * pCWnd, DWORD oldval) {
DWORD temp;
WORD n;
char lbuf[100];
n = pCWnd->GetWindowText (lbuf, 100);
lbuf[n] = '\0'; /* terminate string */
n = sscanf(lbuf, "%x", &temp);
if (n != 1) {
MessageBeep(MB_ICONEXCLAMATION);
pCWnd->MessageBox(&INPUT_ERRMSG[0], &INPUT_ERR_TITLE[0], MB_OK|MB_ICONSTOP);
StringHex2 (pCWnd, oldval);
return(-1);
}
if (temp > 0xFF) {
MessageBeep(MB_ICONEXCLAMATION);
pCWnd->MessageBox(INPUT_OVRMSG, INPUT_OVR_TITLE, MB_OK | MB_ICONSTOP);
StringHex2 (pCWnd, oldval);
return(-1);
}
StringHex2 (pCWnd, temp);
return(temp);
}
long GetDlg16BNumber (CWnd *pCWnd, DWORD oldval) {
DWORD temp;
WORD n;
char lbuf[100];
n = pCWnd->GetWindowText (lbuf, 100);
lbuf[n] = '\0'; /* terminate string */
n = sscanf(lbuf, "%x", &temp);
if (n != 1) {
MessageBeep(MB_ICONEXCLAMATION);
pCWnd->MessageBox(&INPUT_ERRMSG[0],&INPUT_ERR_TITLE[0],MB_OK|MB_ICONSTOP);
StringHex4 (pCWnd, oldval);
return(-1);
}
if (temp > 0xFFFF) {
MessageBeep(MB_ICONEXCLAMATION);
pCWnd->MessageBox(INPUT_OVRMSG, INPUT_OVR_TITLE, MB_OK | MB_ICONSTOP);
StringHex4 (pCWnd, oldval);
return(-1);
}
StringHex4 (pCWnd, temp);
return(temp);
}
long GetDlg24BNumber (CWnd *pCWnd, DWORD oldval) {
DWORD temp;
WORD n;
char lbuf[100];
n = pCWnd->GetWindowText (lbuf, 100);
lbuf[n] = '\0'; /* terminate string */
n = sscanf(lbuf, "%x", &temp);
if (n != 1) {
MessageBeep(MB_ICONEXCLAMATION);
pCWnd->MessageBox(INPUT_ERRMSG, INPUT_ERR_TITLE, MB_OK | MB_ICONSTOP);
StringHex6 (pCWnd, oldval);
return(-1);
}
if (temp > 0xFFFFFF) {
MessageBeep(MB_ICONEXCLAMATION);
pCWnd->MessageBox(INPUT_OVRMSG, INPUT_OVR_TITLE, MB_OK | MB_ICONSTOP);
StringHex6 (pCWnd, oldval);
return(-1);
}
StringHex6 (pCWnd, temp);
return(temp);
}
static const char INPUT_F_ERR_TITLE [] = "Invalid float number";
static const char INPUT_F_ERRMSG[] = "You have entered an invalid float number!\n"
"The previous value will be restored.\n"
"Example: 1.234\n";
float GetDlgFloat (CWnd * pCWnd, float oldval) {
WORD n;
float f;
char lbuf[100];
n = pCWnd->GetWindowText (lbuf, 100);
lbuf[n] = '\0'; /* terminate string */
n = sscanf(lbuf, "%f", &f);
if (n != 1) {
MessageBeep(MB_ICONEXCLAMATION);
pCWnd->MessageBox(INPUT_F_ERRMSG, INPUT_F_ERR_TITLE, MB_OK | MB_ICONSTOP);
sprintf (lbuf, "%1.4f", oldval);
pCWnd->SetWindowText (lbuf);
return((float)-1.9876e-36);
}
sprintf (lbuf, "%1.4f", f);
pCWnd->SetWindowText (lbuf);
return(f);
}
// This function handles a byte input in a dialog
void HandleByteInput(CWnd * pCWnd, AGSIADDR sfr) {
DWORD oldval, oldvalp, tmp;
Agsi.ReadSFR(sfr, &oldval, &oldvalp, 0xFF);
tmp = GetDlg8BNumber (pCWnd, oldval);
if (tmp != -1) {
Agsi.WriteSFR(sfr, tmp, 0xFF);
Agsi.UpdateWindows();
}
}
// This function handles a word input in a dialog
void HandleWordInput(CWnd * pCWnd, AGSIADDR sfrl, AGSIADDR sfrh) {
DWORD oldval, tmp, tmpp;
Agsi.ReadSFR(sfrl, &tmp, &tmpp, 0xFF);
oldval = tmp;
Agsi.ReadSFR(sfrh, &tmp, &tmpp, 0xFF);
oldval += tmp << 8;
tmp = GetDlg16BNumber (pCWnd, oldval);
if (tmp != -1) {
Agsi.WriteSFR(sfrl, tmp, 0xFF);
Agsi.WriteSFR(sfrh, tmp >> 8, 0xFF);
Agsi.UpdateWindows();
}
}
// This function handles a 3 byte input in a dialog
void Handle3ByteInput(CWnd * pCWnd, AGSIADDR sfrl, AGSIADDR sfrh, AGSIADDR sfrp) {
DWORD oldval, tmp, tmpp;
Agsi.ReadSFR(sfrl, &tmp, &tmpp, 0xFF);
oldval = tmp;
Agsi.ReadSFR(sfrh, &tmp, &tmpp, 0xFF);
oldval += tmp << 8;
Agsi.ReadSFR(sfrp, &tmp, &tmpp, 0xFF);
oldval += tmp << 16;
tmp = GetDlg24BNumber (pCWnd, oldval);
if (tmp != -1) {
Agsi.WriteSFR(sfrl, tmp, 0xFF);
Agsi.WriteSFR(sfrh, tmp >> 8, 0xFF);
Agsi.WriteSFR(sfrp, tmp >> 16, 0xFF);
Agsi.UpdateWindows();
}
}
// This function handles a float number input in a dialog
void HandleFloatInput(CWnd * pCWnd, AGSIVTR vtr) {
union fv tmp;
float result;
Agsi.ReadVTR(vtr, &tmp.DW);
result = GetDlgFloat (pCWnd, tmp.f);
if (result != -1.9876e-36) {
tmp.f = result;
Agsi.WriteVTR(vtr, tmp.DW);
}
}
// This function is intended to be called when a checkbox is clicked (SFR bit)
void WriteBit(AGSIADDR sfr, DWORD mask, DWORD set) {
DWORD value;
value = (set == 0) ? 0 : 0xFF;
Agsi.WriteSFR(sfr, value, mask);
Agsi.UpdateWindows();
}
// This function is intended to be called when a checkbox is clicked (VTR bit)
void WriteBitVTR(AGSIVTR vtr, DWORD mask, DWORD set) {
DWORD value;
Agsi.ReadVTR(vtr, &value);
if (set) value |= mask;
else value &= ~mask;
Agsi.WriteVTR(vtr, value);
}
static void PeriUpdate (void) { // Update Function
if (pCPeriDialog) pCPeriDialog->Update();
}
static void PeriKill (AGSIDLGD *pM) { // Kill Function
if (pCPeriDialog == NULL) return;
pCPeriDialog->SendMessage (WM_CLOSE);
pCPeriDialog = NULL;
pM->iOpen = 0;
pM->hw = NULL;
}
static void PeriDisp (AGSIMENU *pM) {
if (pM->pDlg->hw != NULL) { // created
PeriKill (pM->pDlg); // close
} else {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());// -- not necessary.
pCPeriDialog = new CPeriDialog (pM, NULL); // modeless construction
if (pCPeriDialog != NULL) { // construction was Ok.
pM->pDlg->hw = pCPeriDialog->m_hWnd; // Dialog handle
}
}
}
CPeriDialog::CPeriDialog (AGSIMENU *pMen, CWnd *pWnd) {
pM = pMen; // save DYM-Descriptor locally.
Create (IDD_ADCON, pWnd);
pCPeriDialog = this;
}
// standard constructor does not work here because we are using modeless dialogs
//CPeriDialog::CPeriDialog(CWnd* pParent /*=NULL*/)
// : CDialog(CPeriDialog::IDD, pParent)
//{
//{{AFX_DATA_INIT(CPeriDialog)
// NOTE: the ClassWizard will add member initialization here
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -