cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX getting GUI user input data to FreeRTOS

HPam.1
Associate II

I am trying to get user input from the GUI to FreeRTOS. The text area buffer is transferred from my screen1View, to screen1Presenter, to model then added to a queue. Finally, my task in FreeRTOS will check for new data in the queue every 1 second.

The problem now is the received data. The user input in gui is 57346,the text area display this number correctly i.e. no space in between the numbers. But in my ucData[10] buffer, a 0 space exist in between the number i.e. 5070304060. How can I correctly transfer the user input to my main.c? Where is the cause for this ? Thank you!0693W000001reg7QAA.png

Other code information below if relevant.

Screen1View.cpp
 
void Screen1View::doUpdatePIDParam()
{
 
	presenter->doUpdatePIDParamB(
			textArea_PBuffer,
			textArea_IBuffer,
			textArea_DBuffer,
			textArea_TargetBuffer);
}
Screen1Presenter.cpp
 
void Screen1Presenter::doUpdatePIDParamB(
		Unicode::UnicodeChar *bufferP,
		Unicode::UnicodeChar  *bufferI,
		Unicode::UnicodeChar  *bufferD,
		Unicode::UnicodeChar  *bufferTarget)
{
	model->doUpdatePIDParamC(bufferP, bufferI, bufferD, bufferTarget);
}
Model.cpp
 
#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
#include <cmsis_os.h>
 
#include "FreeRTOS.h"
#include "queue.h"
#include "task.h"
 
 struct AMessage
  {
 	char ucData[ 10 ];
  } xMessage;
 
extern "C"{
	xQueueHandle messageQ3;
}
 
Model::Model() : modelListener(0)
{
	messageQ3 = xQueueCreate(10,sizeof( &xMessage ) );
}
 
void Model::tick()
{
}
 
void Model::doUpdatePIDParamC(
	unsigned short *bufferP,
	unsigned short *bufferI,
	unsigned short  *bufferD,
	unsigned short  *bufferTarget)
{
	struct AMessage *pxPointerToxMessage;
	 *(xMessage.ucData) =*bufferP;
	   xQueueSend(messageQ3,( void * ) &pxPointerToxMessage,( TickType_t ) 0 );
}
 
main.c
 
extern xQueueHandle messageQ3;
 
 struct AMessage
  {
	 char ucData[ 10 ];
  } xMessage;
 
struct AMessage *pxRxedPointer;
 
void taskGetGui(void *argument)
{
osDelay(5000);   //begin checking queue 5 seconds after kernel starts
	char msg1[10];   //buffer to store user input from gui
  for(;;)
  {
 
	  if( messageQ3 != NULL )
	     {if( xQueueReceive( messageQ3,&( pxRxedPointer ),( TickType_t ) 10 ) == pdPASS )
	        {
	           /* *pxRxedPointer now points to xMessage. */
	        }
	     }
    osDelay(1000);
  }
}

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

Your issue here may be that the input from the GUI is 16-bit unsigned while your tx buffer is char. Since your GUI input is in the ascii range, you can just discard the last 8-bits.

static void convertUnicodeToAscii(uint16_t* in, uint8_t* out)
{
    while(*in != 0)
    {
        *out++ = (uint8_t)*in++;
    }
    *out = 0;
}

View solution in original post

3 REPLIES 3
Martin KJELDSEN
Chief III

Your issue here may be that the input from the GUI is 16-bit unsigned while your tx buffer is char. Since your GUI input is in the ascii range, you can just discard the last 8-bits.

static void convertUnicodeToAscii(uint16_t* in, uint8_t* out)
{
    while(*in != 0)
    {
        *out++ = (uint8_t)*in++;
    }
    *out = 0;
}

eng23
Senior

I use Unicode to convert:

Unicode::fromUTF8((uint8_t*)function, textAreaFunctionBuffer, strlen(function));

In your case would be Unicode::toUTF8

HPam.1
Associate II

Thanks you very much for your help @Martin KJELDSEN​  and @eng23​ . Your assumption is correct, after using the convertUnicodeToAscii function, it solved my problem!