⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oper_int.cpp

📁 a program that generates a pulse-width modulated (PWM)signal.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    while (Length++ < Twid)
        strcat (OutString, " ");
    X = (InOrOut == DATA_INPUT) ? (COL_INDATA) : (COL_OUTDATA);
    gotoxy (X, ScreenRect.top);
    OPI_print (OutString);
    }


//=====================================================================================
//  Class:  CDataItemList
//      This class is derived from CListObj, which faciliates keeping a list of some
//      objects (in this case, CDataItem's) derived from CBaseObj.  Two data item
//      lists are kept by an operator window, one for input and one for output items.
//=====================================================================================

//-------------------------------------------------------------------------------------
//  Constructor:  CDataItemList
//      Here we save the type of list, input or output; also zero initialize index

CDataItemList::CDataItemList (IO_Type aIO_Type)
    {
    InOrOut = aIO_Type;
    ListIndex = 1;                          //  This index determines Y coord. of item
    }


//-------------------------------------------------------------------------------------
//  Destructor:  ~CDataItemList
//      This destructor is here to free up the memory used by the CDataItemList.  

CDataItemList::~CDataItemList (void)
    {
    CDataItem* pCurItem;                    //  These pointers are to step through
    CDataItem* pTemp;                       //  the list, deleting the objects we find


    pCurItem = (CDataItem*) GetHead ();     //  Start at first one and keep deleting
    while (pCurItem != NULL)
        {
        pTemp = pCurItem;
        pCurItem = (CDataItem*) GetNext (); 
        delete (pTemp);
        }
    }

        
//-------------------------------------------------------------------------------------
//  Function:  Insert 
//      This function creates a new object of type CDataItem and puts that item into 
//      the CDataItem list.  

void CDataItemList::Insert (DataType aType, const char* aName, void* apData)
    {
    CDataItem* pNew;                        //  Pointer to give our new creation life

    //  Before bothering with calculations, make sure there's room in the list.  If 
    //  there is, create the object and put a pointer to it in the list 
    if (HowMany () < MAX_ITEMS)
        {
        pNew = new CDataItem (aType, InOrOut, aName, apData, ListIndex++);
        CBasicList::Insert ((void*)pNew);
        }
    }


//-------------------------------------------------------------------------------------
//  Function:  PaintOne 
//      This function repaints a single item in the list.  It uses the current-item 
//      pointer to choose an item (beware of other functions moving the pointer).  If 
//      we have come to the end of the list, it returns FALSE so the calling program
//      knows when to change over display to the other list.  

bool CDataItemList::PaintOne (void)
    {
    static CDataItem* pShowIt = NULL;       //  Pointer to item being shown now


    //  Current-item pointer points to the item to be displayed.  If we're at the end,
    //  the pointer is NULL, so move to the beginning of the list and don't draw any-
    //  thing, just return false so calling program will draw from the other list.
    pShowIt = (CDataItem*) GetCurrent ();

    //  Here's where we call the function to actually draw the thing
    if (pShowIt != NULL)
        pShowIt->Paint ();

    //  Move the item-to-draw pointer to the next item in the list
    if ((pShowIt = (CDataItem*) GetNext ()) == NULL)
        {
        GetHead ();
        return false;
        }

    return true;
    }


//=====================================================================================
//  Class:  CKeyItem
//      This class represents a key which can be pressed by the user.  It contains a 
//      label to be displayed at the bottom of the screen which shows what the key 
//      does and a pointer to the function which will run when the key is pressed.  
//=====================================================================================

//-------------------------------------------------------------------------------------
//  Constructor:  CKeyItem 
//      This constructor creates a key item with labels and a key function it can run.  

CKeyItem::CKeyItem (int aKeyChar, const char* aLab1, const char* aLab2,
                    void (*aFunc)(), int aSerialNumber)
    {
    KeyChar = aKeyChar;
    strcpy (line1, aLab1);
    strcpy (line2, aLab2);
    KeyFunction = aFunc;
    SerialNumber = aSerialNumber;
    }


//-------------------------------------------------------------------------------------
//  Destructor:  ~CKeyItem 
//      This destructor is here to free up the memory used by the CDataItem object.  

CKeyItem::~CKeyItem (void)
    {
    }


//-------------------------------------------------------------------------------------
//  Function:  RunKeyFunction 
//      This function simply runs the function whose address has been provided.  

void CKeyItem::RunKeyFunction (void)
    {
    KeyFunction ();
    }


//-------------------------------------------------------------------------------------
//  Function:  Paint
//      This function displays the key item information in the proper space near the
//      bottom of the screen.  In order to most correctly imitate the DOS version, it
//      puts the data on the same lines - numbers 23, 24, and 25.

void CKeyItem::Paint (void)
    {
    int X;                          //  Coordinates for displaying key item on screen
    static char OutString[32];      //  Temporary storage for text to be displayed


    X = (SerialNumber * 10) + 1;
    sprintf (OutString, "Ctrl-%c", KeyChar);
    gotoxy (X, 23);
    OPI_print (OutString);
    gotoxy (X, 24);
    OPI_print (line1);
    gotoxy (X, 25);
    OPI_print (line2);
    }


//=====================================================================================
//  Class:  CKeyItemList 
//      This class just implements a list of key redefinitions.  
//=====================================================================================

//-------------------------------------------------------------------------------------
//  Constructor:  CKeyItemList 
//      This no-parameters constructor does very little, if anything, at all.  

CKeyItemList::CKeyItemList (void)
    {
    }


//-------------------------------------------------------------------------------------
//  Destructor:  ~CKeyItemList 
//      This destructor is here to free up the memory used by the CDataItem object.  

CKeyItemList::~CKeyItemList (void)
    {
    CKeyItem* pCurItem;                     //  These pointers are to step through
    CKeyItem* pTemp;                        //  the list, deleting the objects we find


    pCurItem = (CKeyItem*) GetHead ();      //  Start at first one and keep deleting
    while (pCurItem != NULL)
        {
        pTemp = pCurItem;
        pCurItem = (CKeyItem*) GetNext (); 
        delete (pTemp);
        }
    }


//-------------------------------------------------------------------------------------
//  Function:  Insert 
//      This function adds a key item to the key item list.  The item gets added at 
//      the end of the list.  

void CKeyItemList::Insert (int aKeyNum, const char* aLab1, const char* aLab2,
                           void (*aFunc)(), int aSerialNumber)
    {
    CKeyItem* pNew;


    //  Call constructor to create a new key mapping item 
    pNew = new CKeyItem (aKeyNum, aLab1, aLab2, aFunc, aSerialNumber++);
    CBasicList::Insert ((void*)pNew);
    }


//=====================================================================================
//  Class:  OperatorWindow 
//      This class holds together all the stuff needed to run an operator window.  
//=====================================================================================

//-------------------------------------------------------------------------------------
//  Constructor:  COperatorWindow
//      Here we create a new operator window, complete with an input buffer but no 
//      input or output items.  Those items are added by the user later.  

COperatorWindow::COperatorWindow (const char* aTitle)
    {
    Title = new char[128];                  //  Make some space for the title
    strncpy (Title, aTitle, 126);           //  and put the given text into it

    //  Call the constructors to create lists of input items, output items, and keys
    InputItems = new CDataItemList (DATA_INPUT);
    OutputItems = new CDataItemList (DATA_OUTPUT);
    KeyItems = new CKeyItemList ();

    InputBuffer = new char[64];             //  Allocate buffer for user input 
    InputBuffer[0] = '\0';                  //  Set it to the null string 
    InputIndex = 0;                         //  Set character-accessed index to 0
    SelectedInput = NULL;                   //  There's no input item to point to yet 
    KeyItemSerialNumber = 0;                //  Used to give each key its own number
    }


//-------------------------------------------------------------------------------------
//  Destructor:  ~COperatorWindow 
//      This destructor is here to free up the memory used by the COperatorWindow.  It 
//      also closes the operator window, setting the current-op-win pointer to NULL and
//      clearing the screen (in DOS mode).  

COperatorWindow::~COperatorWindow (void)
    {
    Close ();

    DELETE_ARRAY Title;
    delete (InputItems);
    delete (OutputItems);
    delete (KeyItems);
    DELETE_ARRAY InputBuffer;
    }


//-------------------------------------------------------------------------------------
//  Function:  AddInputItem
//      This function places an input item into the operator window's list.  There are
//      several overloaded versions for different types of input pointers:  DT_INT,
//      DT_LONG, DT_FLOAT, DT_DOUBLE, DT_LONG_DBL, and DT_STRING

void COperatorWindow::AddInputItem (const char* aLabel, int* aData)
    {
    InputItems->Insert (DT_INT, aLabel, (void*)aData);

    //  If there's no input item selected, this one's the first; set pointer to it
    SelectedInput = (CDataItem*) InputItems->GetHead ();
    }

void COperatorWindow::AddInputItem (const char* aLabel, long* aData)
    {
    InputItems->Insert (DT_LONG, aLabel, (void*)aData);
    SelectedInput = (CDataItem*) InputItems->GetHead ();
    }

void COperatorWindow::AddInputItem (const char* aLabel, float* aData)
    {
    InputItems->Insert (DT_FLOAT, aLabel, (void*)aData);
    SelectedInput = (CDataItem*) InputItems->GetHead ();
    }

void COperatorWindow::AddInputItem (const char* aLabel, double* aData)
    {
    InputItems->Insert (DT_DOUBLE, aLabel, (void*)aData);
    SelectedInput = (CDataItem*) InputItems->GetHead ();
    }

void COperatorWindow::AddInputItem (const char* aLabel, long double* aData)
    {
    InputItems->Insert (DT_LONG_DBL, aLabel, (void*)aData);
    SelectedInput = (CDataItem*) InputItems->GetHead ();
    }

void COperatorWindow::AddInputItem (const char* aLabel, char* aData)
    {
    InputItems->Insert (DT_STRING, aLabel, (void*)aData);
    SelectedInput = (CDataItem*) InputItems->GetHead ();
    }


//-------------------------------------------------------------------------------------
//  Function:  AddOutputItem 
//      This function puts an output item into the operator window's list.  It's over-
//      loaded just like the AddInputItem() methods for the same reason.  

void COperatorWindow::AddOutputItem (const char* aLabel, int* aData)
    {
    OutputItems->Insert (DT_INT, aLabel, (void*)aData);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -