首页 > 解决方案 > 如何在STM32F429 TOUCHGFX的ScreenView页面中添加循环和延迟?

问题描述

当我在ScreenView页面的“handletickevent”函数中编写HCSR04传感器的软件时,画面死机,无法工作。我怎么解决这个问题?我想循环STM32F429的屏幕,我想让它在屏幕上刷新,但我做不到。如果您能提供不同的方式或建议,我将非常高兴。

!!如何在 touchgfx 屏幕上显示具有更新值的 HCSR04 传感器?

非常感谢大家。好作品。

#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();
}

标签: c++stm32stm32cubeidetouchgfx

解决方案


你不能在 ScreenView 中做业务逻辑,请在它的 Presenter 中处理。使用 tick_handler 读取您的数据,然后更新到您的屏幕视图。建议了解一下ToughGFX的MVP模型。


推荐阅读