Comparing position of a click with a threshold

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
dabo_4430311
Level 2
Level 2
10 replies posted 10 questions asked 10 sign-ins

I would like  to check where a Click happened with respect to the X axis and therefore assigning a right or a left click, having the Maximum X-Axis position=395 and the Maximum Y-Axis position=395.

I didn't find a way to access the position of where a touchdown or a liftoff happened so I decided to use the CapSense_GetXYCoordinates(CapSense_TOUCHPAD0_WDGT_ID) function. However I am not sure if the output is in the correct format to be compared with the 198 value because the device seems to not work accordingly, always displaying a left click.

How could this be corrected and would there be a better way of doing this? Maybe accessing the touchdown and the lift off positions?

 

POS_X= (int) (CapSense_GetXYCoordinates(CapSense_TOUCHPAD0_WDGT_ID)<<16);

click = (gestureID == CapSense_ONE_FINGER_SINGLE_CLICK) ? 1u : 0u;

if(click && POS_X<=198){
leftButtonPress = 1u;
abMouseData[0u] = (leftButtonPress ? MOUSE_LB : 0u);
}

if(click && POS_X>198){
rightButtonPress = 1u;
abMouseData[0u] = (rightButtonPress ? MOUSE_RIGHT : 0u);

 

Thank you for your help

0 Likes
1 Solution
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @dabo_4430311 

 

The CapSense_GetXYCoordinates API returns the X coordinate in the lower 16 bits of the returned value. So the right way to comprehend the X position would be to using the bitwise AND operation. 

 

So, your code needs to be modified to

POS_X= (int) (CapSense_GetXYCoordinates(CapSense_TOUCHPAD0_WDGT_ID)&0xFFFF);

to obtain the right X coordinates.

 

You can try this change and check the performance as the data is sent with respect to the coordinates and if you set the maximum X and Y position as 395 in the component, the comparison with 198 in the code is correct.

 

Best regards, 
Hari

View solution in original post

0 Likes
1 Reply
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @dabo_4430311 

 

The CapSense_GetXYCoordinates API returns the X coordinate in the lower 16 bits of the returned value. So the right way to comprehend the X position would be to using the bitwise AND operation. 

 

So, your code needs to be modified to

POS_X= (int) (CapSense_GetXYCoordinates(CapSense_TOUCHPAD0_WDGT_ID)&0xFFFF);

to obtain the right X coordinates.

 

You can try this change and check the performance as the data is sent with respect to the coordinates and if you set the maximum X and Y position as 395 in the component, the comparison with 198 in the code is correct.

 

Best regards, 
Hari

0 Likes