c++ - 如何在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();
}
解决方案
你不能在 ScreenView 中做业务逻辑,请在它的 Presenter 中处理。使用 tick_handler 读取您的数据,然后更新到您的屏幕视图。建议了解一下ToughGFX的MVP模型。
推荐阅读
- java - 无法解析方法“setchecked(boolean)”共享首选项
- r - 绘制每个任务的时间长度
- svn - svnsync 失败并显示“E175002: REPORT request on '/
/!svn/rev/71' 失败" - regex - 将某个关键字后面的单词转换为小写
- python - 每 6 个月显示一次 x 轴日期
- qt - 在目标上使用 Qt 5.3 QML 视频得到错误:“找不到资源”代码在主机系统上工作,两者都是 Linux
- emscripten - 带 -O3 的 emscripten 剥离函数
- android - 带有证书固定应用程序的中间人代理
- java - 奇怪地扫描 NFC 标签时出现 IOException
- python - 对于 python 中的字典列表和其他类型的列表,切片复制的工作方式是否不同?