cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX and UART Receive

JKris.8
Associate II

Dear Sir,

I am working in the R&D of Sectorqube. Our company has chosen the ST chip to be used for new product design and mass production. So presently I am using the 32F429IDISCOVERY board and a custom sized touchscreen of size 480 x 272. I am trying to integrate the UART and TouchGFX. On my test screen there are two buttons-UP and DOWN. When I press the UP button an array has been initialized to sent through the TX and similarly the case for DOWN button another array has been initialized to sent through TX. The transmission upon pressing the buttons is working properly as desired. With the help of CubeMX I integrated the code. For the RX part I ensured the data is received by sending back the array received to the TX and it worked properly. For example if I send '12345' to the RX, '12345' is transmitted back and being shown in the serial terminal.Here is the code:

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

HAL_UART_Transmit_IT(&huart1, (uint8_t *) buffrec, 5);

}

But what I am looking for is the text area which shows a number has to be changed upon receiving a particular array through RX. For example if the RX receive '12345' the number in the text area has to be incremented by one and if I receive '54321' the number in the textarea of the screen has to be decremented. I am posting the code below.

Kindly help me out. Thanks a lot in advace.

25 REPLIES 25
JKris.8
Associate II

Screen1View.cpp:

#include <gui/screen1_screen/Screen1View.hpp>

//Added by JK

extern "C"

 {

#include <string.h>

#include "stm32f4xx.h"

#include "stm32f4xx_hal.h"

#include "stm32f4xx_hal_uart.h"

#include "stm32f4xx_hal_i2c.h"

#include "stm32f429i_discovery.h"

#include "gt911.h"

}

extern UART_HandleTypeDef huart1;

extern uint8_t buffrec[5];

//Added by JK 

Screen1View::Screen1View()

{

}

void Screen1View::setupScreen()

{

  Screen1ViewBase::setupScreen();

}

//Added by JK 

void Screen1View::handleTickEvent()

{

rcvbuff=presenter->getRcvBuff();

 if(rcvbuff==1)

{

counter++;

Unicode::snprintf(textCounterBuffer, TEXTCOUNTER_SIZE, "%d", counter);

textCounter.invalidate();

}

else if(rcvbuff==5)

{

counter--;

Unicode::snprintf(textCounterBuffer, TEXTCOUNTER_SIZE, "%d", counter);

textCounter.invalidate();

}

}

void Screen1View::tearDownScreen()

{

  Screen1ViewBase::tearDownScreen();

}

//Added by JK

void Screen1View::buttonUpClicked()

{

uint8_t tx_buffer[10]="123456789";

touchgfx_printf("buttonUpClicked\n");

counter++;

Unicode::snprintf(textCounterBuffer, TEXTCOUNTER_SIZE, "%d", counter);

HAL_UART_Transmit(&huart1, tx_buffer ,sizeof(tx_buffer), 2000);

//Invalidate text area, which will result in it being redrown in next tick.

textCounter.invalidate();

}

void Screen1View::buttonDownClicked()

{

uint8_t tx_buffer[10]="012345678";

touchgfx_printf("buttonDownClicked\n");

counter--;

Unicode::snprintf(textCounterBuffer, TEXTCOUNTER_SIZE, "%d", counter);

HAL_UART_Transmit(&huart1, tx_buffer,sizeof(tx_buffer), 2000);

//Invalidate textarea, which will result in it being redrawn in next tick

textCounter.invalidate();

}

//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

//{

// HAL_UART_Transmit_IT(&huart1, (uint8_t *) buffrec, 5);

//}

//HAL_UART_Transmit(&huart1, buffrec, sizeof(buffrec), 2000);

//Added by JK

Screen1view.hpp:

#ifndef SCREEN1_VIEW_HPP

#define SCREEN1_VIEW_HPP

#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>

#include <gui/screen1_screen/Screen1Presenter.hpp>

class Screen1View : public Screen1ViewBase

{

public:

  Screen1View();

  virtual ~Screen1View() {}

  virtual void setupScreen();

  virtual void tearDownScreen();

virtual void buttonUpClicked();

virtual void buttonDownClicked();

virtual void handleTickEvent();

 

protected:

int counter;

uint8_t rcvbuff;   

};

#endif // SCREEN1_VIEW_HPP

JKris.8
Associate II

Please look the recent code and let me know any corrections to be made

You have to call that method on the text area exhibiting the problem (textCounter) after updating its buffer.

Martin KJELDSEN
Chief III

I'd prefer if you sent me an updated working project. if possible. Thanks.

Martin KJELDSEN
Chief III

Hi @JKris.8​,

Did you get anywhere with this? you're still welcome to send me a compiling project

/Martin

Martin KJELDSEN
Chief III

Working projects aside - Since you're getting the values you want, you simply have to do the following (as far as i understand) to update your text area:

  1. Convert the RX value to an integer
  2. Increment it
  3. Use the touchgfx function Unicode::snprintf() to write the integer value to a Unicode array (which is already configured as the wildcard buffer for a TextAreaWithWildcard using the setWildCard() method).
  4. invalidate your textarea.

The text should now be correctly updated on screen.

/Martin