我想在stm32f746G - DISCO板上的液晶屏上显示 adc 值。主要挑战来自于集成 TouchGFX 软件。这会生成输出小部件和通配符所需的模型、视图和演示器文件。我相信我已经正确设置了我的 adc 引脚 PF10,因为我能够使用以下方法获取 main.cpp 中的 ADC 值:
while (1)
{
HAL_ADC_Start(&hadc3);
HAL_ADC_PollForConversion(&hadc3, 500);
hullVoltage = HAL_ADC_GetValue(&hadc3)*0.00080586;
HAL_Delay(1000);
}
但我的主要目标是在我的液晶屏幕上显示这个。我有 touchGFX 设置,我可以在 View.cpp 中将浮点数输入到通配符。例如:
void Monitor_ScreenView::handleTickEvent()
{
Unicode::snprintfFloat(textArea2Buffer, 4, "%f", 3.14f);
textArea2.invalidate();
}
我将向您展示我的模型、视图和演示者 cpp 文件,以演示我的问题所在。
模型.cpp
#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
#ifndef SIMULATOR
#include "stm32746g_discovery.h"
#endif
void Model::getHullVoltage()
{
HAL_ADC_Start(&hadc3);
HAL_ADC_PollForConversion(&hadc3, 500);
hullVoltage = HAL_ADC_GetValue(&hadc3);
}
查看.cpp
#include <gui/monitor_screen_screen/Monitor_ScreenView.hpp>
#include <gui/model/Model.hpp>
#ifndef SIMULATOR
#include "stm32746g_discovery.h"
#endif
void Monitor_ScreenView::handleTickEvent()
{
Unicode::snprintfFloat(textArea2Buffer, 4, "%f", presenter->getHullVoltage());
textArea2.invalidate();
}
演示者.cpp
#include <gui/monitor_screen_screen/Monitor_ScreenView.hpp>
#include <gui/monitor_screen_screen/Monitor_ScreenPresenter.hpp>
// my functions
float Monitor_ScreenPresenter::getHullVoltage()
{
return(model->hullVoltage);
}
我从此构建中得到的唯一错误是 model.cpp 中的“hadc3 未在此范围内声明”。
如果我能从我的代码中获得任何见解,我将非常感激。除此之外,我的代码有效,因为我可以使用触摸屏上的按钮打开和关闭 LED,我可以在我想要的屏幕上打印一个浮点数,并且我可以获得 adc 值在 main.cpp 中。我只需要它在每个滴答声中都显示在屏幕上。