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

📄 ui.c

📁 CNC.rar
💻 C
📖 第 1 页 / 共 5 页
字号:
                              (sizeof(g_sDiagButtons) /
                               sizeof(g_sDiagButtons[0])), ulX, ulY);

        //
        // See if a button was found.
        //
        if(ulTemp != 0xffffffff)
        {
            //
            // See if the button has an associated I2C command.
            //
            if(!(g_sDiagButtons[ulTemp].ucFlag & 0x80))
            {
                //
                // Toggle the piezo, causing it to click.  This provides
                // audible feedback that a button was pressed.
                //
                GPIOPinWrite(GPIO_PORTB_BASE, BEEP,
                             GPIOPinRead(GPIO_PORTB_BASE, BEEP) ^ BEEP);

                //
                // See if the I2C interface is busy.
                //
                if(I2CIdle())
                {
                    //
                    // Write the I2C command to the main microcontroler.
                    //
                    I2CWrite(&(g_sDiagButtons[ulTemp].ucFlag), 1);

                    //
                    // See if this is the ship command.
                    //
                    if(g_sDiagButtons[ulTemp].ucFlag != CMD_SHIP)
                    {
                        //
                        // A stop should be sent when the button is released.
                        //
                        HWREGBITW(&g_ulUIFlags, UI_FLAG_STOP_ON_RELEASE) = 1;
                    }
                    else
                    {
                        //
                        // A stop should not be send when the button is
                        // released since this is the ship command.
                        //
                        HWREGBITW(&g_ulUIFlags, UI_FLAG_STOP_ON_RELEASE) = 0;
                    }
                }
            }

            //
            // See if the backspace button was pressed.
            //
            else if(g_sDiagButtons[ulTemp].ucLabel == FONT_CHAR_BACKSPACE)
            {
                //
                // Toggle the piezo, causing it to click.  This provides
                // audible feedback that a button was pressed.
                //
                GPIOPinWrite(GPIO_PORTB_BASE, BEEP,
                             GPIOPinRead(GPIO_PORTB_BASE, BEEP) ^ BEEP);

                //
                // Exit diagnostic mode.
                //
                HWREGBITW(&g_ulUIFlags, UI_FLAG_DIAG) = 0;

                //
                // Update the entire screen and the indicators.
                //
                HWREGBITW(&g_ulUIFlags, UI_FLAG_UPDATE_SCREEN) = 1;
                HWREGBITW(&g_ulUIFlags, UI_FLAG_UPDATE) = 1;
            }
        }
    }
    else
    {
        //
        // See if a stop should be send on a button release.
        //
        if(HWREGBITW(&g_ulUIFlags, UI_FLAG_STOP_ON_RELEASE) == 1)
        {
            //
            // The screen is no longer being pressed, so stop the machine.
            //
            HWREGBITW(&g_ulUIFlags, UI_FLAG_STOP) = 1;

            //
            // Clear the stop on release flag.
            //
            HWREGBITW(&g_ulUIFlags, UI_FLAG_STOP_ON_RELEASE) = 0;
        }
    }
}

//*****************************************************************************
//
//! Handles screen press events for normal mode.
//!
//! \param ulX is the horizontal screen coordinate of the screen press.
//! \param ulY is the vertical screen coordinate of the screen press.
//!
//! This function is used in normal mode to take a screen press (or release)
//! event and determine what actions to take (if any) as a result of that user
//! action.
//!
//! \return None.
//
//*****************************************************************************
static void
UIMainPressHandler(unsigned long ulX, unsigned long ulY)
{
    unsigned long ulTemp;

    //
    // See if the debounced touch state is down, indicating that the touch
    // screen is being touched.
    //
    if(HWREGBITW(&g_ulUIFlags, UI_FLAG_DOWN) == 1)
    {
        //
        // Clear the "Run", "Backspace", and "Diag" button flags.
        //
        HWREGBITW(&g_ulUIFlags, UI_FLAG_RUN) = 0;
        HWREGBITW(&g_ulUIFlags, UI_FLAG_BACKSPACE) = 0;
        HWREGBITW(&g_ulUIFlags, UI_FLAG_DIAG_BUTTON) = 0;

        //
        // Find the button that was pressed.
        //
        ulTemp = UIFindButton(g_sButtons,
                              sizeof(g_sButtons) / sizeof(g_sButtons[0]), ulX,
                              ulY);

        //
        // See if a button was found.
        //
        if(ulTemp != 0xffffffff)
        {
            //
            // Toggle the piezo, causing it to click.  This provides audible
            // feedback that a button was pressed.
            //
            GPIOPinWrite(GPIO_PORTB_BASE, BEEP,
                         GPIOPinRead(GPIO_PORTB_BASE, BEEP) ^ BEEP);

            //
            // See if the machine is running.
            //
            if(HWREGBITW(&g_ulUIFlags, UI_FLAG_RUNNING) == 1)
            {
                //
                // The only button that works while the machine is running is
                // the "Run" button, which will stop the machine.
                //
                if(g_sButtons[ulTemp].ucLabel == FONT_CHAR_RUN)
                {
                    //
                    // Indicate that the machine is no longer running.
                    //
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_RUNNING) = 0;

                    //
                    // Stop the machine.
                    //
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_STOP) = 1;

                    //
                    // Indicate that the display needs to be updated.
                    //
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_UPDATE) = 1;
                }
            }

            //
            // See if the button has an associated flag.
            //
            else if((g_sButtons[ulTemp].ucFlag > 0) &&
                    (g_sButtons[ulTemp].ucFlag < 32))
            {
                //
                // If one of the demo buttons was pressed then clear all the
                // demo flags (only one demo button can be selected at a time).
                //
                if((g_sButtons[ulTemp].ucFlag >= UI_FLAG_DEMO1) &&
                   (g_sButtons[ulTemp].ucFlag <= UI_FLAG_DEMO6))
                {
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_DEMO1) = 0;
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_DEMO2) = 0;
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_DEMO3) = 0;
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_DEMO4) = 0;
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_DEMO5) = 0;
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_DEMO6) = 0;
                }

                //
                // Toggle the associated flags.
                //
                HWREGBITW(&g_ulUIFlags, g_sButtons[ulTemp].ucFlag) ^= 1;
            }

            //
            // See if the "Run" button was pressed.
            //
            else if(g_sButtons[ulTemp].ucLabel == FONT_CHAR_RUN)
            {
                //
                // Set the flag to indicate that the "Run" button is being
                // pressed.  If held long enough, this will cause the machine
                // to start running.
                //
                HWREGBITW(&g_ulUIFlags, UI_FLAG_RUN) = 1;
            }

            //
            // See if the capitalization button was pressed.
            //
            else if(g_sButtons[ulTemp].ucLabel == FONT_CHAR_Abc)
            {
                //
                // See if the user interface is in upper case mode.
                //
                if(HWREGBITW(&g_ulUIFlags, UI_FLAG_UPPER_CASE) == 1)
                {
                    //
                    // Move to lower case mode.
                    //
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_UPPER_CASE) = 0;
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_LOWER_CASE) = 1;
                }

                //
                // See if the user interface is in lower case mode.
                //
                else if(HWREGBITW(&g_ulUIFlags, UI_FLAG_LOWER_CASE) == 1)
                {
                    //
                    // Move to auto capitalization mode.
                    //
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_LOWER_CASE) = 0;
                }

                //
                // Otherwise, the user interface is in auto capitalization
                // mode.
                //
                else
                {
                    //
                    // Move to upper case mode.
                    //
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_UPPER_CASE) = 1;
                }
            }

            //
            // See if the backspace button was pressed.
            //
            else if(g_sButtons[ulTemp].ucLabel == FONT_CHAR_BACKSPACE)
            {
                //
                // See if there are characters to delete.
                //
                if(g_ulUIChars != 1)
                {
                    //
                    // Remove the last character from the string.
                    //
                    g_pucString[g_ulUIChars--] = '\0';
                    g_pucString[g_ulUIChars] = FONT_CHAR_CURSOR;

                    //
                    // Determine where to start displaying the string such that
                    // the last character and cursor are visible (i.e. display
                    // the rightmost portion of the string).
                    //
                    for(ulX = 1; UIStringWidthGet(g_pucString + ulX) > 304;
                        ulX++)
                    {
                    }

                    //
                    // Save the starting display position.
                    //
                    g_ulUIStart = ulX;

                    //
                    // Replace the NULL with a space so that the right part of
                    // the string will be space-filled, helping to erase the
                    // screen.
                    //
                    g_pucString[g_ulUIChars + 1] = ' ';

                    //
                    // Clear the shift flag.
                    //
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_SHIFT) = 0;
                }

                //
                // Set the flag to indicate that the "Backspace" button is
                // being pressed.  If held long enough, this will cause the
                // entire string to be erased.
                //
                HWREGBITW(&g_ulUIFlags, UI_FLAG_BACKSPACE) = 1;
            }

            //
            // See if the pen button was pressed.
            //
            else if(g_sButtons[ulTemp].ucLabel == FONT_CHAR_PEN)
            {
                //
                // Change the tool to the pen.
                //
                HWREGBITW(&g_ulUIFlags, UI_FLAG_PEN) = 1;
                HWREGBITW(&g_ulUIFlags, UI_FLAG_ROUTER) = 0;
            }

            //
            // See if the router button was pressed.
            //
            else if(g_sButtons[ulTemp].ucLabel == FONT_CHAR_ROUTER_25)
            {
                //
                // See if the pen is the currently selected tool.
                //
                if(HWREGBITW(&g_ulUIFlags, UI_FLAG_PEN) == 1)
                {
                    //
                    // Change the tool to the router.
                    //
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_PEN) = 0;
                    HWREGBITW(&g_ulUIFlags, UI_FLAG_ROUTER) = 1;
                }
                else
                {
                    //
                    // The router is already the selected tool, so change

⌨️ 快捷键说明

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