News:

Welcome to the Bridgetek Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ Bridgetek Support

Please refer to our website for detailed information on all our products - Bridgetek - Bridging Technology

Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - GB

#1
Discussion - EVE / Re: TouchScreen with BT817Q
May 14, 2021, 01:20:42 PM
Hi,

There are many different ways to do this but here is one way,
This has a home screen with three buttons, each of which takes you to a different screen 1/2/3. From screen 1/2/3 you can tap the home button to go back.
The button is only taken as pressed if you have pen down and pen up within the button area. (this could be changed though if required)
It also prints the tag related variables on each screen for debug purposes.
I'm sure it could be improved further and optimised but seems to work as shown,

Hope it helps

uint8_t APP_HomeScreen(void);
void APP_Screen1(void);
void APP_Screen2(void);
void APP_Screen3(void);
void APP_CheckTouchStatus(void);

#define Home_Tag 100
#define Screen1_Tag 11
#define Screen2_Tag 12
#define Screen3_Tag 13

uint16_t Button_Home_Status = 0;
uint8_t TagVal = 0;
uint8_t LastTagVal = 0;
uint8_t Pen_Down_Tag = 0;
uint8_t Pen_Up_Tag = 0;

void eve_display(void)
{
    uint8_t Screen_Select = 0;

    while(1)
    {
        Screen_Select =  APP_HomeScreen();

        if (Screen_Select == Screen1_Tag)
            APP_Screen1();
        else if (Screen_Select == Screen2_Tag)
            APP_Screen2();
        else if (Screen_Select == Screen3_Tag)
            APP_Screen3();
    }
}



uint8_t APP_HomeScreen(void)
{
    uint16_t Button_Screen1_Status = 0;
    uint16_t Button_Screen2_Status = 0;
    uint16_t Button_Screen3_Status = 0;

    while(1)
    {
        EVE_LIB_BeginCoProList();                                               // Begin new screen
        EVE_CMD_DLSTART();                                                      // Tell co-processor to create new Display List
        EVE_CLEAR_COLOR_RGB(0, 0, 0);                                           // Specify color to clear screen to
        EVE_CLEAR_TAG(255);                                                     // Clear tag sets tag value when screen touched in non-tagged area
        EVE_CLEAR(1,1,1);                                                       // Clear color, stencil, and tag buffer

        EVE_CMD_TEXT(400, 40, 30, EVE_OPT_CENTER, "Home Screen");                   // Draw the text string

        EVE_TAG_MASK(1);                                                        // Enable tagging
        EVE_TAG(Screen1_Tag);                                                            // Tag following items with tag 11
        EVE_CMD_FGCOLOR(0x0000FF);                                              // Blue foreground color
        EVE_CMD_BUTTON(100, 100, 120, 50, 28, Button_Screen1_Status, "Screen 1");// Draw button

        EVE_TAG(Screen2_Tag);                                                             // Tag following items with tag 12
        EVE_CMD_FGCOLOR(0x00FF00);                                              // Green foreground color
        EVE_CMD_BUTTON(100, 200, 120, 50, 28, Button_Screen2_Status, "Screen 2");             // Draw button

        EVE_TAG(Screen3_Tag);                                                             // Tag following items with tag 13
        EVE_CMD_FGCOLOR(0xFF0000);                                              // Red foreground color
        EVE_CMD_BUTTON(100, 300, 120, 50, 28, Button_Screen3_Status, "Screen 3");             // Draw button

        EVE_TAG_MASK(0);                                                        // Disable tagging so that rest of screen content isn't tagged

        EVE_CMD_TEXT(300, 150, 26, 0, "Tag Value");
        EVE_CMD_NUMBER(400, 150, 26, 0, TagVal);
        EVE_CMD_TEXT(300, 180, 26, 0, "Last Tag Value");
        EVE_CMD_NUMBER(400, 180, 26, 0, LastTagVal);
        EVE_CMD_TEXT(300, 210, 26, 0, "Pen Down Tag");
        EVE_CMD_NUMBER(400, 210, 26, 0, Pen_Down_Tag);
        EVE_CMD_TEXT(300, 240, 26, 0, "Pen Up Tag");
        EVE_CMD_NUMBER(400, 240, 26, 0, Pen_Up_Tag);

        EVE_DISPLAY();                                                          // Tell EVE that this is end of list
        EVE_CMD_SWAP();                                                         // Swap buffers in EVE to make this list active

        EVE_LIB_EndCoProList();                                                 // Finish the co-processor list burst write
        EVE_LIB_AwaitCoProEmpty();                                              // Wait until co-processor has consumed all commands

        // ================ Check for button presses ===========================

        APP_CheckTouchStatus();

        //-------- Set buttons to pressed in/out states for visual effect -------

        Button_Screen1_Status = 0;
        Button_Screen2_Status = 0;
        Button_Screen3_Status = 0;

        if(TagVal == Screen1_Tag)
            Button_Screen1_Status = EVE_OPT_FLAT;
        else if(TagVal == Screen2_Tag)
            Button_Screen2_Status = EVE_OPT_FLAT;
        else if(TagVal == Screen3_Tag)
            Button_Screen3_Status = EVE_OPT_FLAT;

        //-------- Decide to change screen if user pressed down and up on button -------

        if((Pen_Down_Tag == Screen1_Tag) && (Pen_Up_Tag == Screen1_Tag))
            return Screen1_Tag;

        if((Pen_Down_Tag == Screen2_Tag) && (Pen_Up_Tag == Screen2_Tag))
            return Screen2_Tag;

        if((Pen_Down_Tag == Screen3_Tag) && (Pen_Up_Tag == Screen3_Tag))
            return Screen3_Tag;

    }
}



void APP_Screen1(void)
{
    while(1)
    {
        EVE_LIB_BeginCoProList();                                               // Begin new screen
        EVE_CMD_DLSTART();                                                      // Tell co-processor to create new Display List
        EVE_CLEAR_COLOR_RGB(0, 0, 0);                                           // Specify color to clear screen to
        EVE_CLEAR_TAG(255);
        EVE_CLEAR(1,1,1);                                                       // Clear color, stencil, and tag buffer

        EVE_CMD_TEXT(400, 40, 30, EVE_OPT_CENTER, "Screen 1");                                      // Draw the text string
        EVE_TAG_MASK(1);                                                        // Enable tagging
        EVE_TAG(100);                                                             // Tag following items with tag 100
        EVE_CMD_FGCOLOR(0x0000FF);                                              // Blue foreground color
        EVE_CMD_BUTTON(100, 400, 120, 50, 28, Button_Home_Status, "Home");             // Draw button

        EVE_TAG_MASK(0);                                                        // Disable tagging so that rest of screen content isn't tagged

        EVE_CMD_TEXT(300, 150, 26, 0, "Tag Value");
        EVE_CMD_NUMBER(400, 150, 26, 0, TagVal);
        EVE_CMD_TEXT(300, 180, 26, 0, "Last Tag Value");
        EVE_CMD_NUMBER(400, 180, 26, 0, LastTagVal);
        EVE_CMD_TEXT(300, 210, 26, 0, "Pen Down Tag");
        EVE_CMD_NUMBER(400, 210, 26, 0, Pen_Down_Tag);
        EVE_CMD_TEXT(300, 240, 26, 0, "Pen Up Tag");
        EVE_CMD_NUMBER(400, 240, 26, 0, Pen_Up_Tag);

        EVE_DISPLAY();                                                          // Tell EVE that this is end of list
        EVE_CMD_SWAP();                                                         // Swap buffers in EVE to make this list active

        EVE_LIB_EndCoProList();                                                 // Finish the co-processor list burst write
        EVE_LIB_AwaitCoProEmpty();                                              // Wait until co-processor has consumed all commands

        // ================ Check for button presses ===========================

        APP_CheckTouchStatus();

        //-------- Set buttons to pressed in/out states for visual effect -------
        Button_Home_Status = 0;

        if(TagVal == Home_Tag)
            Button_Home_Status = EVE_OPT_FLAT;

        //-------- Decide to change screen if user pressed down and up on button -------

        if((Pen_Down_Tag == Home_Tag) && (Pen_Up_Tag == Home_Tag))
            return;

    }
}


void APP_Screen2(void)
{
    while(1)
    {
        EVE_LIB_BeginCoProList();                                               // Begin new screen
        EVE_CMD_DLSTART();                                                      // Tell co-processor to create new Display List
        EVE_CLEAR_COLOR_RGB(0, 0, 0);                                           // Specify color to clear screen to
        EVE_CLEAR_TAG(255);
        EVE_CLEAR(1,1,1);                                                       // Clear color, stencil, and tag buffer

        EVE_CMD_TEXT(400, 40, 30, EVE_OPT_CENTER, "Screen 2");                                      // Draw the text string
        EVE_TAG_MASK(1);                                                        // Enable tagging
        EVE_TAG(100);                                                             // Tag following items with tag 100
        EVE_CMD_FGCOLOR(0x0000FF);                                              // Blue foreground color
        EVE_CMD_BUTTON(100, 400, 120, 50, 28, Button_Home_Status, "Home");             // Draw button

        EVE_TAG_MASK(0);                                                        // Disable tagging so that rest of screen content isn't tagged

        EVE_CMD_TEXT(300, 150, 26, 0, "Tag Value");
        EVE_CMD_NUMBER(400, 150, 26, 0, TagVal);
        EVE_CMD_TEXT(300, 180, 26, 0, "Last Tag Value");
        EVE_CMD_NUMBER(400, 180, 26, 0, LastTagVal);
        EVE_CMD_TEXT(300, 210, 26, 0, "Pen Down Tag");
        EVE_CMD_NUMBER(400, 210, 26, 0, Pen_Down_Tag);
        EVE_CMD_TEXT(300, 240, 26, 0, "Pen Up Tag");
        EVE_CMD_NUMBER(400, 240, 26, 0, Pen_Up_Tag);

        EVE_DISPLAY();                                                          // Tell EVE that this is end of list
        EVE_CMD_SWAP();                                                         // Swap buffers in EVE to make this list active

        EVE_LIB_EndCoProList();                                                 // Finish the co-processor list burst write
        EVE_LIB_AwaitCoProEmpty();                                              // Wait until co-processor has consumed all commands

        // ================ Check for button presses ===========================

        APP_CheckTouchStatus();

        //-------- Set buttons to pressed in/out states for visual effect -------
        Button_Home_Status = 0;

        if(TagVal == Home_Tag)
            Button_Home_Status = EVE_OPT_FLAT;

        //-------- Decide to change screen if user pressed down and up on button -------

        if((Pen_Down_Tag == Home_Tag) && (Pen_Up_Tag == Home_Tag))
            return;

    }
}

void APP_Screen3(void)
{
    while(1)
    {
        EVE_LIB_BeginCoProList();                                               // Begin new screen
        EVE_CMD_DLSTART();                                                      // Tell co-processor to create new Display List
        EVE_CLEAR_COLOR_RGB(0, 0, 0);                                           // Specify color to clear screen to
        EVE_CLEAR_TAG(255);
        EVE_CLEAR(1,1,1);                                                       // Clear color, stencil, and tag buffer

        EVE_CMD_TEXT(400, 40, 30, EVE_OPT_CENTER, "Screen 3");                                      // Draw the text string
        EVE_TAG_MASK(1);                                                        // Enable tagging
        EVE_TAG(100);                                                             // Tag following items with tag 100
        EVE_CMD_FGCOLOR(0x0000FF);                                              // Blue foreground color
        EVE_CMD_BUTTON(100, 400, 120, 50, 28, Button_Home_Status, "Home");             // Draw button

        EVE_TAG_MASK(0);                                                        // Disable tagging so that rest of screen content isn't tagged

        EVE_CMD_NUMBER(250, 200, 26, 0, TagVal);
        EVE_CMD_NUMBER(250, 220, 26, 0, LastTagVal);
        EVE_CMD_NUMBER(250, 240, 26, 0, Pen_Down_Tag);
        EVE_CMD_NUMBER(250, 260, 26, 0, Pen_Up_Tag);

        EVE_DISPLAY();                                                          // Tell EVE that this is end of list
        EVE_CMD_SWAP();                                                         // Swap buffers in EVE to make this list active

        EVE_LIB_EndCoProList();                                                 // Finish the co-processor list burst write
        EVE_LIB_AwaitCoProEmpty();                                              // Wait until co-processor has consumed all commands

        // ================ Check for button presses ===========================

        APP_CheckTouchStatus();

        //-------- Set buttons to pressed in/out states for visual effect -------
        Button_Home_Status = 0;

        if(TagVal == Home_Tag)
            Button_Home_Status = EVE_OPT_FLAT;

        //-------- Decide to change screen if user pressed down and up on button -------

        if((Pen_Down_Tag == Home_Tag) && (Pen_Up_Tag == Home_Tag))
            return;

    }
}



void APP_CheckTouchStatus(void)
{
// ================ Check for button presses ===========================

//-------- Get current touch tag -------
TagVal = HAL_MemRead8(EVE_REG_TOUCH_TAG);                                   // Get Tag value

//-------- Check for pen up and pen down tags -------
if((LastTagVal == 0) && (TagVal != 0))
Pen_Down_Tag = TagVal;

if ((LastTagVal != 0) && (TagVal == 0))
Pen_Up_Tag = LastTagVal;

LastTagVal = TagVal;

return;

}