1

我想在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 中。我只需要它在每个滴答声中都显示在屏幕上。

4

3 回答 3

1

在 TouchGFX 应用程序的视图类中编写的代码应该是可移植的,使其能够在模拟器或目标上运行。gcc例如,如果您通过 Windows 上的 TouchGFX 设计器运行您的应用程序,您将有未解析的HAL_ADC_. 将代码替换为调用视图呈现器,然后调用模型将提高可移植性,并将更好地封装功能,而不是将其保留在事件处理程序中。

将目标特定代码保留在模型中并加以保护#ifdef SIMULATOR将允许您从键盘事件、滴答事件或硬件的外部事件触发模拟器和目标代码版本。

于 2019-11-14T16:47:02.903 回答
1

如果你使用 HAL 库,你可以使用#ifndef SIMULATORblock

于 2020-01-29T17:18:53.013 回答
0

我相信我已经找到了问题的答案。在 View.cpp 中,我将 hadc3 声明为外部类型:

void Monitor_ScreenView::handleTickEvent()
{
    extern ADC_HandleTypeDef hadc3;
    float hullVoltage;


     HAL_ADC_Start(&hadc3);
     HAL_ADC_PollForConversion(&hadc3, 500);
     hullVoltage = HAL_ADC_GetValue(&hadc3)*0.00080586;

     Unicode::snprintfFloat(textArea2Buffer, 4, "%f", hullVoltage);
     textArea2.invalidate();
}

我认为不需要任何其他文件!干杯 ProXicT 和 Stack Overflow。

于 2019-11-04T22:33:55.710 回答