2021-05-11 12:06 PM
HI,
I am using touchGFX 4.15. I can control the screen brightness using PWM. This is my requirement .
I tried implementing handleClickEvent in home screen. It is called on every touch event. But the buttons on my home screen dosent work any more once i implemented void HomeScreenView::handleClickEvent(const ClickEvent& evt) inside homescreen.cpp
What is the proper way to do this?
Thanks is advance!!
2021-05-11 12:23 PM
Use target STM32TouchController.cpp for wake back
and timer in model tick to point 1
2021-05-11 10:01 PM
Sorry i didnt got you. Can you explain more?
2021-05-12 01:21 AM
And my other question is why all the clickable items on the UI dosent respond once i define the handleClickEvent in HomeScreenView?
2021-05-12 01:28 AM
I believe what he meant was to set the second requirement within STM32TouchController.cpp, where you turn on the backlight when a touch has been detected as this is where you sample the touch and transfer it to your GUI.
Concerning the handleClickEvent implementation I believe he suggested to set it within the model class and not within the View (so model.cpp instead of HomwScreenView.cpp). The model is always "alive" which means you wont have to implement it within all yours screens, and is where you interact with the rest of your system. (the point 1 part I don't know :grinning_face_with_sweat:)
/Romain
2021-05-12 01:47 AM
Hi,
Could you share how you implemented it ? I suspect you have set it so that it waits for a click on the entire screen and does not take into account the other elements. It is a bit like if you put an invisible button over another button.
What you could try to do is to put everything within a container the size of the screenm and make the container clickable thanks to the mixin ClickListener.
/Romain
2021-05-12 08:43 AM
Hi Romain,
Thanks for your suggestion. I tired implementing the handleClickEvent inside model class. It dosent get called. It seems handleClickEvent has to be implemented inside a screen (view) class which has to be a view.
2021-05-12 09:08 AM
Hi Romain,
Thanks for your suggestion. I tires this. Actually it works. But when i click a button, the callback does not fire. But if i click any other place on the background (except buttons), it works. My requirement is to tap the touch event and also it should not disturb other elements handleClickEvent . So it seems your suggestion to modify the STM32TouchController.cpp is an option for now. But calling a driver from a another driver is not a good programming practice. Thats why i was searching for another method.
2021-12-28 07:01 PM
Hi,
I wished to have a screen timeout reset by a touch on my STM32H7#BI_DK (Tiny Shark).
The easiest way to do this with minimal impact on the TouchGFX code is to create a flag that is set by any touch event and which can be used by the process that controls the back-light.
What I did was:
/* rjgTypes.h */
typedef enum
{
FALSE = 0x0U,
TRUE = 0x1U,
} boolean;
extern volatile boolean touchDetectedFlag;
/********************************************************** /
/* main.c */
volatile boolean touchDetectedFlag;
/********************************************************** /
/* stm32h7b3i_discovery_ts.c */
#include "rjgTypes.h"
...
/**
* @brief Returns positions of a single touch screen.
* @param Instance TS instance. Could be only 0.
* @param TS_State Pointer to touch screen current state structure
* @retval BSP status
*/
int32_t BSP_TS_GetState(uint32_t Instance, TS_State_t *TS_State)
{
int32_t ret = BSP_ERROR_NONE;
uint32_t x_oriented, y_oriented;
uint32_t x_diff, y_diff;
if(Instance >= TS_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
FT5336_State_t state;
/* Get each touch coordinates */
if(Ts_Drv->GetState(Ts_CompObj[Instance], &state) < 0)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}/* Check and update the number of touches active detected */
else if(state.TouchDetected != 0U)
{
touchDetectedFlag = TRUE; /* RJG Mod */
x_oriented = state.TouchX;
y_oriented = state.TouchY;
...
/********************************************************** /
/* freertos.c */
/* This task Is where I control the lcd backlight - I use LPTIM3 in PWM to vary the brightness */
void monitorTask(void *argument)
{
uint32_t statusResult;
TimerHandle_t lcdBackLightTimer;
touchDetectedFlag = FALSE;
lcdBackLightTimer = xTimerCreate( "backLightTmr",
BACKLIGHT_TIMER_DELAY,
pdFALSE,
(void*) 0,
backLightTimerCallback );
xTimerStart(lcdBackLightTimer, 20); ...
...
/* Monitor task Infinite loop */
while(1)
{
if(touchDetectedFlag == TRUE)
{
touchDetectedFlag = FALSE;
resetBacklightTimer(lcdBackLightTimer);
}
if(blockingVars.HeaterBlock == NO_BLOCK) ...
/* Software timer call back - switches off backlight */
static void backLightTimerCallback(TimerHandle_t lcdBackLightTimer)
{
hlptim3.Instance->CMP = 0u;
__HAL_LPTIM_RESET_COUNTER(&hlptim3);
}
/* Backlight timer restart called when touch flag is set TRUE.
__inline static void resetBacklightTimer(TimerHandle_t lcdBackLightTimer)
{
hlptim3.Instance->CMP = 5000u;
__HAL_LPTIM_RESET_COUNTER(&hlptim3);
xTimerStart(lcdBackLightTimer, BACKLIGHT_TIMER_DELAY);
}
This is probably not the most elegant solution as it requires a mod to the board's touch driver, but it is simple, has virtually no impact on the speed of the touch driver and is virtually transparent to it, it works and you don't have to know C++ to do it.
I hope this meets your needs.
Best regards
Rob