How to add loop and delay in ScreenView page of STM32F429 TOUCHGFX?

754 Views Asked by At

When I write the software of the HCSR04 sensor in the "handletickevent" function on the ScreenView page, the screen freezes and does not work. How can I solve this problem? I want to loop the STM32F429's screen and I want it to refresh on the screen, but I couldn't. I would be very happy if you could give a different way or advice.

!! How can I show HCSR04 sensor with updated values ​​on touchgfx screen?

Thank you very much everyone. Good Work.

#include <gui/screenhcsr04_screen/ScreenHCSR04View.hpp>
#include "stm32f4xx_hal.h"
#include "DWT_Delay.h"

uint32_t time;
uint16_t distance;

uint32_t Read_HCSR04()
{
    uint32_t local_time=0;
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET); 
    DWT_Delay_us(10); 

    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET); 

    while(!HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_2)); 

    while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_2)) 
    {
        local_time++;

        DWT_Delay_us(1);
    }
    return local_time;
}

ScreenHCSR04View::ScreenHCSR04View()
{

}

void ScreenHCSR04View::setupScreen()
{
    ScreenHCSR04ViewBase::setupScreen();
}

void ScreenHCSR04View::tearDownScreen()
{
    ScreenHCSR04ViewBase::tearDownScreen();
}


void ScreenHCSR04View::handleTickEvent()
{
time = Read_HCSR04();
distance = time / 58 ;
Unicode::snprintf(textArea2Buffer, sizeof(textArea2Buffer), "%d", distance);
textArea2.invalidate();
}
1

There are 1 best solutions below

0
On

You can't do business logic in a ScreenView, please handle it in its presenter. Use tick_handler to read your data, then update to your screen view. Suggest to get understand the MVP model of ToughGFX.