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

This is the present content of Screen1View:

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

}

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]="abcdefghi";

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

JKris.8
Associate II

Should I do anything on ModelListner.hpp

JKris.8
Associate II

Kindly review the other codes also I have submitted

JKris.8
Associate II

ModelListener.hpp:

#ifndef MODELLISTENER_HPP

#define MODELLISTENER_HPP

#include <gui/model/Model.hpp>

/**

 * ModelListener is the interface through which the Model can inform the currently

 * active presenter of events. All presenters should derive from this class.

 * It also provides a model pointer for the presenter to interact with the Model.

 *

 * The bind function is called automatically.

 *

 * Add the virtual functions Model should be able to call on the active presenter to this class.

 */

class ModelListener

{

public:

  ModelListener() : model(0) {}

  virtual ~ModelListener() {}

 virtual uint8_t getRcvBuff() {}

/**

   * Sets the model pointer to point to the Model object. Called automatically

   * when switching screen.

   */

  void bind(Model* m)

  {

    model = m;

  }

protected:

  Model* model;

};

#endif /* MODELLISTENER_HPP */

JKris.8
Associate II

Dear Martin Please help me with this

Martin KJELDSEN
Chief III

Hi.

Can you debug? Do the buffers actually have any content? What're you seeing on screen?

You may be updating the text area correctly, BUT... you're not seeing it because the size of the area hasn't changed. Try disabling "auto resize" for the textarea in the designer and calling the following after updating the buffer.

myTextArea.resizeToCurrentText();

Martin KJELDSEN
Chief III

Debug and check the contents of the buffer - If they are correct then the solution above should work for you.

  1. I did debug and fund the "buffrec" receives the value. Kindly tell me which file I have to add "myTextArea.resizeToCurrentText();"

JKris.8
Associate II

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
Associate II

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