cancel
Showing results for 
Search instead for 
Did you mean: 

How to get a state of flex button in TouchGFX?

KDyrb.1
Associate II

Hi,
I am writing here because I need a help.
I want to use flex button this way - when I hold pressed button then virtual function is executed, so when I release button then the virtual function stops.
I try for example .getPressed() in handleTickEvent, but it doesn't working. I try a sample with CustomButton from this forum but I can't use it enough.


Can somebody help me ?

I will be very grateful for help.

Best regards,
Kamil

13 REPLIES 13

So I have to debbuging it.
At the moment I can show my sampleTouch code:

bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
    /**
     * By default sampleTouch returns false,
     * return true if a touch has been detected, otherwise false.
     *
     * Coordinates are passed to the caller by reference by x and y.
     *
     * This function is called by the TouchGFX framework.
     * By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t);
     *
     */
	return ((bool) Touch_TouchGFXSampleTouch(&x, &y));
}

I use a 4' display with driver ILI9486 and XPT2046 touch driver and I use a library from him:
https://github.com/maudeve-it

Ok. With quick review fuction

Touch_TouchGFXSampleTouch

In z_touch_XPT2046.c seems have optional repeat features (that it in low level generates repeated clicks if display is touched continously). Maybe check that, it seems to be pretty complicated with all if-defs :D

Br JTP

Hi,
@JTP1 Thank for your advice!
I have checked in z_touch_XPT2046.c function Touch_TOUCHGFXSampleTouch in which is used a param DELAY_TOKEY_REPEAT. This param I have set as 1, when i set it to -1 then it help me - I can press button then output is set, while i hold button the state of outpust doesn't change, when i release button then output is reset - it works good. Here is a code of this function:


uint8_t Touch_TouchGFXSampleTouch(int32_t *x, int32_t *y){
	//	sTouchData result;
	uint8_t isTouch=0;				// preset to no touch
	uint16_t xx=0,yy=0;  			// need to convert library coordinates type (uint16_t) to TouchGFX ones (int32_t)
	static uint8_t flipTouch=0;		// switches 0/1, on every function call, until sensor is touched allowing to return key repeat
	static uint32_t touchTime=1; 	// tick value get on the first touch. 0 means display untouched.
	static uint16_t avgXX=0, avgYY=0;  			// need to convert library coordinates type (uint16_t) to TouchGFX one (int32_t)
	static uint8_t repetition=TOUCHGFX_REPEAT_IT+TOUCHGFX_REPEAT_NO;

	if (Touch_GotATouch(0)){				// polls interrupt flag not resetting it
		Touch_GetXYtouch(&xx,&yy,&isTouch);	// get touch sensor position
		if (!isTouch){						// received a "no touch"
			if (touchTime != 0){			// if previously touched
				if ((repetition--)>TOUCHGFX_REPEAT_NO+1){		// n-repetition of last touch sending
					*x = avgXX;
					*y = avgYY;
					isTouch=1;
				} else if ((repetition==255)) {  // that's -1
					touchTime=0;					// set display as untouched
					Touch_GotATouch(1);				// reset interrupt touch flag
					repetition=TOUCHGFX_REPEAT_IT+TOUCHGFX_REPEAT_NO;  //reset repetition counter
				}
			}
		} else {					// display touched

			if (touchTime==0) {				// if previously untouched
				avgXX =(xx/TOUCHGFX_SENSITIVITY)*TOUCHGFX_SENSITIVITY;
				avgYY =(yy/TOUCHGFX_SENSITIVITY)*TOUCHGFX_SENSITIVITY;
				touchTime=HAL_GetTick();	// store tick value at touch time
				flipTouch=1;				// set switch to send touch now
			} else {						// not a new touch
				if (((HAL_GetTick()-touchTime)>DELAY_TO_KEY_REPEAT) && (DELAY_TO_KEY_REPEAT > 0)){	// if timeout to key repeat is over (0 means no key repeat)
					flipTouch=!flipTouch;	// alternate every time function is called
				} else
					if (DELAY_TO_KEY_REPEAT == 0)
						flipTouch=0;		// (DELAY_TO_KEY_REPEAT == 0) means a single pulse, "-1" keep pulse as long as touch
			}
			if (flipTouch) { 	// return position only if the switching flag is on
				*x=(((avgXX*(TOUCHGFX_MOVAVG-1)+((xx/TOUCHGFX_SENSITIVITY)*TOUCHGFX_SENSITIVITY)))/TOUCHGFX_MOVAVG);
				*y=(((avgYY*(TOUCHGFX_MOVAVG-1)+((yy/TOUCHGFX_SENSITIVITY)*TOUCHGFX_SENSITIVITY)))/TOUCHGFX_MOVAVG);
				avgXX = *x;
				avgYY = *y;
			} else {			// otherwise return "no touch" from display
				isTouch = 0;
			}
		}
	}
	return isTouch;
}

#endif

I can say that in my project evrything works correctly, but I noticed in the last screen(I have 5 screens) i have to long hold/long press a button that detect that is pressed. Can you advice where will be a problem? With SPI baudrates?

Thank you very much for your help so far.!

Hi

Glad to hear you find your issue. I think this a good lesson that its not good idea to generate repeat clicks in the low level touch handler, at least with TouchGFX. In past, here in the community has been same kind of issues, perhaps in those the root cause has been similar.

About the 5th screen slowing down, it is difficult to say, especially if other screens works fine. Are you updating something complicated in tick handler at every tick of that screen ? Maybe that would slow down also the button recognition.

I would start start solving that problem by comparing the structure of working and not working screen, is there some difference in logic.

 

Br JTP