1
votes

I would like to show adc values on my lcd screen on the stm32f746G - DISCO board. The main challenge comes from integrating the TouchGFX software. This generates the model, view, and presenter files necessary to output widgets and wildcards. I believe I have set up my adc pin correctly, PF10, as I am able to get the ADC value in main.cpp using:

while (1)
   {
      HAL_ADC_Start(&hadc3);
      HAL_ADC_PollForConversion(&hadc3, 500);
      hullVoltage = HAL_ADC_GetValue(&hadc3)*0.00080586;
      HAL_Delay(1000);
   }

But my main goal is showing this on my lcd screen. I have touchGFX setup where I can input a float to a wildcard in View.cpp. For example:

void Monitor_ScreenView::handleTickEvent()
{
     Unicode::snprintfFloat(textArea2Buffer, 4, "%f", 3.14f);
     textArea2.invalidate();
}

I will show you my model, view, and presenter cpp files to demonstrate where my issue lies.

model.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);
}

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

presenter.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);
}

The only error I get from this build is "hadc3 was not declared in this scope" from model.cpp.

I would be very gracious if I could get any insight from my code. Other than this, my code works, as I am able to turn on and off an LED with a button on the touch screen, I am able to print a float on the screen where I want, and I am able to get the adc value in main.cpp. I just need it to show on the screen every tick.

3
Post the code where hadc3 is declared. If you can't find such code - that's the issue.ProXicT

3 Answers

1
votes

The code written in the view classes in a TouchGFX application should be portable, making it able to run in a simulator or on target. E.g. If you were to run your application using gcc through the TouchGFX designer on Windows, you'd have unresolved symbols for HAL_ADC_. Replacing the code with a call to the views presenter and then to the model would improve portability and would encapsulate the functionality better rather than keeping it inside an event handler.

Keeping target specific code inside the model and guarding it with #ifdef SIMULATOR would allow you to trigger simulator and target versions of the code from either a keyboard event, a tick event or an external event from the hardware.

1
votes

If you use HAL library, you can use #ifndef SIMULATOR block

0
votes

I believe I have found the answer to my problem. In View.cpp I declared hadc3 as an extern type:

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

I don't think any other files were needed! Cheers ProXicT, and Stack Overflow.