cancel
Showing results for 
Search instead for 
Did you mean: 

Analog input doesn't dispaly on monitor with Touchgfx

Acecream
Associate II

Hello, everyone

I just want to display the analog voltage value on Touchgfx using STM32H735g-dk, but the textAreaBuffer just didn't update the value that I want it to show, my code are as follows:

�?Model.cpp】

​#include <gui/model/Model.hpp>

#include <gui/model/ModelListener.hpp>

#include <cmsis_os.h> //add

extern osSemaphoreId binarySemAnalogHandle; //add

extern uint16_t uhADCxConvertedValue[10]; //add

Model::Model() : modelListener(0)

{

}

void Model::tick()

{

if(binarySemAnalogHandle != NULL) //add

{

if(osSemaphoreWait(binarySemAnalogHandle, 100) == osOK)

{

analogUpdatepresenter();

}

}

}

void Model::analogUpdatepresenter() //add

{

uint32_t sum = 0;

uint32_t average = 0;

for(int i = 0; i < 10; i++)

{

sum += uhADCxConvertedValue[i];

}

average = sum / 10;

modelListener->analogUpdatepresenter(average);

}

�?Screen1Presenter.cpp】

#include <gui/screen1_screen/Screen1View.hpp>

#include <gui/screen1_screen/Screen1Presenter.hpp>

Screen1Presenter::Screen1Presenter(Screen1View& v)

  : view(v)

{

}

void Screen1Presenter::activate()

{

}

void Screen1Presenter::deactivate()

{

}

//average is passed through the same variable from Model.cpp using modelListener

void Screen1Presenter::analogUpdatepresenter(uint32_t average)

{

view.analogUpdateview(average);

}

�?Screen1View.cpp】

#include <gui/screen1_screen/Screen1View.hpp>

#include <string.h>

extern uint32_t average; // newly add

extern uint16_t uhADCxConvertedValue[10];

Screen1View::Screen1View()

{

}

void Screen1View::setupScreen()

{

  Screen1ViewBase::setupScreen();

}

void Screen1View::tearDownScreen()

{

  Screen1ViewBase::tearDownScreen();

}

void Screen1View::analogUpdateview(uint32_t average) // average is coming from view.analogUpdateview from Screen1Presenter.cpp

{

memset(&textAreaADBuffer, '\0' , TEXTAREAAD_SIZE); // clear the textAreaADBuffer to all zeros

//Unicode::snprintfFloat(textAreaADBuffer, TEXTAREAAD_SIZE, "%.3f", average * 0.000805664);

//Unicode::snprintf(textAreaADBuffer, TEXTAREAAD_SIZE, "%.d", average);

//Unicode::snprintf(textAreaADBuffer, TEXTAREAAD_SIZE, "%s", touchgfx::TypedText(T___SINGLEUSE_F1FW).getText());

Unicode::snprintfFloat(textAreaADBuffer, TEXTAREAAD_SIZE, "%.3f", average * 0.000805664 - 0.132); //3.3/4096 = 0.000805664,4096_12 bit register

textAreaAD.invalidate();

}

Besides, I can get the average while I am debugging, but the final value"average * 0.000805664 - 0.132"​ just didn't go inside the textAreaADBuffer, anyone has any idea about it? Thank you in advance!

2 REPLIES 2
MM..1
Chief II

try

Unicode::snprintfFloat(textAreaADBuffer, TEXTAREAAD_SIZE, "%7.3f", 0.132);

JTP1
Lead

What does your "textAreaAD" exactly shows then ?

If its empty perhaps you must add resize command before invalidate ?

textAreaAD.resizeToCurrentText();

Otherwise your snprintfFloat- line seems to work OK in simulator and also in my eval card (V 4.21.1).