Skip to main content
JKris.8
Associate
May 23, 2019
Question

TouchGFX and UART Receive

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.

This topic has been closed for replies.

25 replies

JKris.8
JKris.8Author
Associate
May 25, 2019

Pls have a look at the files again:

model.cpp:

#include <gui/model/Model.hpp>

#include <gui/model/ModelListener.hpp>

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 "stm32f4xx_hal_def.h"

#include "stm32f4xx_it.h"

#include "gt911.h"

}

//Added by JK

extern uint8_t buffrec[5];

extern UART_HandleTypeDef huart1;

uint8_t rcvbuff;

Model::Model() : modelListener(0)

{

}

void Model::tick()

{

 rcvbuff=buffrec[0];

  

 

// if(modelListener != 0)

// {

modelListener->getRcvBuff();

// }

}

uint8_t Model::getRcvBuff()

{

return rcvbuff;

}

//Added by JK

model.hpp:

#ifndef MODEL_HPP

#define MODEL_HPP

#include <touchgfx/Utils.hpp>

class ModelListener;

/**

 * The Model class defines the data model in the model-view-presenter paradigm.

 * The Model is a singular object used across all presenters. The currently active

 * presenter will have a pointer to the Model through deriving from ModelListener.

 *

 * The Model will typically contain UI state information that must be kept alive

 * through screen transitions. It also usually provides the interface to the rest

 * of the system (the backend). As such, the Model can receive events and data from

 * the backend and inform the current presenter of such events through the modelListener

 * pointer, which is automatically configured to point to the current presenter.

 * Conversely, the current presenter can trigger events in the backend through the Model.

 */

class Model

{

public:

  Model();

  /**

   * Sets the modelListener to point to the currently active presenter. Called automatically

   * when switching screen.

   */

  void bind(ModelListener* listener)

  {

    modelListener = listener;

  }

  /**

   * This function will be called automatically every frame. Can be used to e.g. sample hardware

   * peripherals or read events from the surrounding system and inject events to the GUI through

   * the ModelListener interface.

   */

  void tick();

uint8_t getRcvBuff(void);

protected:

 uint8_t rcvbuff;

  /**

   * Pointer to the currently active presenter.

   */

  ModelListener* modelListener;

};

#endif /* MODEL_HPP */

JKris.8
JKris.8Author
Associate
May 25, 2019

screenpresenter.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()

{

}

ScreenPresenter.hpp:

#ifndef SCREEN1_PRESENTER_HPP

#define SCREEN1_PRESENTER_HPP

#include <gui/model/ModelListener.hpp>

#include <mvp/Presenter.hpp>

using namespace touchgfx;

class Screen1View;

class Screen1Presenter : public Presenter, public ModelListener

{

public:

  Screen1Presenter(Screen1View& v);

  /**

   * The activate function is called automatically when this screen is "switched in"

   * (ie. made active). Initialization logic can be placed here.

   */

  virtual void activate();

  /**

   * The deactivate function is called automatically when this screen is "switched out"

   * (ie. made inactive). Teardown functionality can be placed here.

   */

  virtual void deactivate();

  virtual ~Screen1Presenter() {};

 uint8_t getRcvBuff()

{

return model->getRcvBuff();

}

private:

  Screen1Presenter();

  Screen1View& view;

};

#endif // SCREEN1_PRESENTER_HPP

JKris.8
JKris.8Author
Associate
May 25, 2019

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
JKris.8Author
Associate
May 25, 2019

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

Martin KJELDSEN
Principal III
May 27, 2019

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

Martin KJELDSEN
Principal III
June 11, 2019

Hi @JKris.8​,

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

/Martin

Martin KJELDSEN
Principal III
June 11, 2019

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