BRT Community
General Category => Discussion - EVE => Topic started by: vdc on May 13, 2021, 07:25:49 PM
-
Hi,
I'm working on Touch Function on BT817Q (Capacitive Touch).
I'm stuck at detecting if Touch is Pressed/Unpressed and Holding.
Init.
touch.status = TOUCH_UNPRESSED;
function
touch.tag = Gpu_Hal_Rd8(phost, REG_TOUCH_TAG);
switch(touch.status){
case TOUCH_UNPRESSED: // When status is Unpressed
if(tagID != 0){ // pressed // Check if tagID id valid, not equal 0 mean a button is touched touched
touch.status = TOUCH_PRESSED; // Set the status to pressed
touch.delay = 0; // Set the delay time to 0
}
break; // break;
case TOUCH_PRESSED: // When status is Pressed. Mean button is pressed or holding
if(tagID == 0) { // this check if the tag id is 0
touch.status = TOUCH_UNPRESSED; // Set the touch to unpressed
}
else if(tagID != 0) { // if the tag is not 0. Mean that button is valid or button is holding
touch.delay = 0; // set delay time to 0
}
else { // touch is none
if(++touch.delay > 10){ // increment delay time before set it to Unpressed
touch.status = TOUCH_UNPRESSED;
}
}
break;
default: // Should not be here but in case.
touch.status = TOUCH_UNPRESSED;
touch.delay = 0;
}
and I also have a function to check if PRESSED / UNPRESSED is change
uint32_t Touch_GetChange(void){
// Checking between PRESSED / UNPRESSED
if(touch.status != touch.prestat){
touch.prestat = touch.status;
return 1;
}
return 0;
}
in main loop, I run
// Main loop
if(Touch_GetChange()){
UARTprintf("TouchChanged \r\n");
}
The problem I have right now is the detect pressed/holding and unpressed is not really working. When I pressed the touch screen and moving my finder between buttons. The tag ID keep changing and Pressed / Unpressed changing. This cause the main loop Touch_GetChange() keep changing between 0 and 1.
What I want to do is detect is a button is pressed.
If button is pressed or holding
tag is set but do nothing
If button is released/unpressed
Trigger tag button function
I also want to set delay between pressed / unpressed to make less touch sensitivity in case someone accident touch the screen and button trigger function right away.
Anyone have a better idea how to work with touch screen tag ID ?
-
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;
}
-
In a more recent project my TFT_touch() function starts like this:
/* check for touch events and setup vars for TFT_display() */
void TFT_touch(void)
{
uint8_t tag = 0;
static uint8_t toggle_lock = 0;
if(EVE_busy()) /* is EVE still processing the last display list? */
{
return;
}
tag = EVE_memRead8(REG_TOUCH_TAG); /* read the value for the first touch point */
uint32_t touchtest = EVE_memRead32(REG_TOUCH_RAW_XY);
switch(tag)
{
case 0:
if(touchtest == 0xffffffff) /* display is no longer touched */
{
toggle_lock = 0;
}
break;
case 10:
if(toggle_lock == 0)
{
toggle_lock = 42;
uint16_t speed_mod = PST_Cmd_n_SpeedMechCmd % 500;
if(speed_mod == 0)
{
speed_mod = 500;
}
else
{
speed_mod = 500 - speed_mod;
}
PST_Cmd_n_SpeedMechCmd += speed_mod;
if(PST_Cmd_n_SpeedMechCmd > 8000)
{
PST_Cmd_n_SpeedMechCmd = 8000;
}
}
break;
...
So the lock on the button only goes away if a tag-value of 0x00 is reported and the finger has been
lifted from the display.
I had a few issues with touch-swipe operations which sometimes resulted in additional buttons beeing recognized as touched when it was necessary to place a button above a slider for example.
This can be explained with fat-finger syndrome or display-too-small-for-the-interface error but of course my "customer" was not amused by this explanation. :-)
https://github.com/RudolphRiedel/FT800-FT813