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
Martin KJELDSEN
Chief III

Hi @JKris.8​,

Did you mean to post some code as well? "I am posting the code below."

/Martin

Yes I will post code:

model.cpp:

#include <gui/model/Model.hpp>

#include <gui/model/ModelListener.hpp>

extern uint8_t buffrec[5];

uint8_t rcvbuff;

Model::Model() : modelListener(0)

{

}

void Model::tick()

{

rcvbuff=buffrec[0];

}

uint8_t Model::getRcvBuff()

{

return rcvbuff;

}

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

uint8_t getRcvBuff(void);

  /**

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

protected:

 uint8_t rcvbuff;

  /**

   * Pointer to the currently active presenter.

   */

  ModelListener* modelListener;

};

#endif /* MODEL_HPP */

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

{

}

Screen1Presenter.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

Screen1View.hpp:

#ifndef SCREEN1_VIEW_HPP

#define SCREEN1_VIEW_HPP

#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>

#include <gui/screen1_screen/Screen1Presenter.hpp>

#include <string.h>

#include "stm32f4xx.h"

#include "stm32f4xx_hal.h"

#include "stm32f4xx_hal_uart.h"

#include "stm32f429i_discovery.h"

int counter;

class Screen1View : public Screen1ViewBase

{

public:

  Screen1View();

  virtual ~Screen1View() {}

  virtual void setupScreen();

  virtual void tearDownScreen();

virtual void buttonUpClicked();

virtual void buttonDownClicked();

virtual void handleTickEvent();

 

protected:

uint8_t rcvbuff;   

};

#ifndef SCREEN1_VIEW_HPP

#define SCREEN1_VIEW_HPP

#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>

#include <gui/screen1_screen/Screen1Presenter.hpp>

#include <string.h>

#include "stm32f4xx.h"

#include "stm32f4xx_hal.h"

#include "stm32f4xx_hal_uart.h"

#include "stm32f429i_discovery.h"

int counter;

class Screen1View : public Screen1ViewBase

{

public:

  Screen1View();

  virtual ~Screen1View() {}

  virtual void setupScreen();

  virtual void tearDownScreen();

virtual void buttonUpClicked();

virtual void buttonDownClicked();

virtual void handleTickEvent();

 

protected:

uint8_t rcvbuff;   

};

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

}

void Screen1View::handleTickEvent()

{

rcvbuff=presenter->getRcvBuff();

 if(rcvbuff==1)

{

counter++;

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

}

else if(rcvbuff==5)

{

counter--;

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

}

}

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

}

HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

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

}

Martin KJELDSEN
Chief III

You need to invalidate the TextArea after updating its buffer (inside handleTickEvent() )

JKris.8
Associate II

I did...still its not working