cancel
Showing results for 
Search instead for 
Did you mean: 

Touchgfx print unicode problem

Maximiliano
Senior

Good morning to all,

I am wanting to make a simple numeric keypad where I only press numbers and they are seen in a text area and then when I press a button it compares it with a char and if it is the same it does one thing or another.

My problem is that I can't see anything in the text area and if I send in the sprintf directly the variable contrasena_ing (which is of type char contrasena_ing[11]; ) it prints and the delete button erases but in fact it prints anything (from touch gfx the range of ascii characters is ok).

what am I doing wrong?

 

 

Info_5View::Info_5View()
{

}

void Info_5View::setupScreen()
{
    Info_5ViewBase::setupScreen();

    contrasena_ing[0] = '\0';
    pos = 0;
}

void Info_5View::tearDownScreen()
{
    Info_5ViewBase::tearDownScreen();
}


void Info_5View::service_unlock()
{
    // Override and implement this function in Info_5
	//Unicode::snprintf(unlock_textBuffer, UNLOCK_TEXT_SIZE, "%s",contrasena_ing);
	//unlock_text.invalidate();

	//char contrasena_ing[11];
}
void Info_5View::borrar_caracter()
{

	if(pos > 0)
	{
		pos--;
		contrasena_ing[pos] = '\0';

		Unicode::UnicodeChar buffer[11];

		Unicode::strncpy(buffer, contrasena_ing, 11);

		Unicode::snprintf(unlock_textBuffer, UNLOCK_TEXT_SIZE, "%s",buffer);
		unlock_text.invalidate();
	}
}
void Info_5View::boton_0()
{
	if(pos < 10)
	{
		pos++;
		contrasena_ing[pos] = '0';
		contrasena_ing[pos+1] = '\0';

		Unicode::UnicodeChar buffer[11];

		Unicode::strncpy(buffer, contrasena_ing, 11);

		Unicode::snprintf(unlock_textBuffer, UNLOCK_TEXT_SIZE, "%s",buffer);
		unlock_text.invalidate();
	}
}
void Info_5View::boton_1()
{
	if(pos < 10)
	{
		pos++;
		contrasena_ing[pos] = '1';
		contrasena_ing[pos+1] = '\0';

		Unicode::UnicodeChar buffer[11];

		Unicode::strncpy(buffer, contrasena_ing, 11);

		Unicode::snprintf(unlock_textBuffer, UNLOCK_TEXT_SIZE, "%s",buffer);
		unlock_text.invalidate();
	}
}

 

 


I share a part of the code where it is tested with the number 0 and 1 for the moment but it would be from 0 to 9.

I don't care that when changing the screen the entered value is not saved, that's why I don't send anything to the model.cpp.

1 ACCEPTED SOLUTION

Accepted Solutions
GaetanGodart
ST Employee

Hello @Maximiliano ,

 

So you don't want to use a keyboard widget but instead you want to add 10 buttons from 0 to 9?
Each of the button have an interaction to add the number to your char*.
You will also add 2 button, one to validate, one to delete.
The validate one compares your char* with another char* that is the password (you wrote char instead of char* I assume).

The issue is that when you print your char* to the textArea, you get random value instead of the values you pressed?

 

In this function :

void Info_5View::boton_0()
{
	if(pos < 10)
	{
		pos++;
		contrasena_ing[pos] = '0';
		contrasena_ing[pos+1] = '\0';

		Unicode::UnicodeChar buffer[11];

		Unicode::strncpy(buffer, contrasena_ing, 11);

		Unicode::snprintf(unlock_textBuffer, UNLOCK_TEXT_SIZE, "%s",buffer);
		unlock_text.invalidate();
	}
}

you start by incrementing the position, I think this should be done at the end.
For instance, when position is 0 (empty buffer), you want to write your value at position buffer[0], but since you increment first, you write your value at buffer[1] so you get "x0" (with x being random) instead of "0".

 

I hope this help!

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

View solution in original post

5 REPLIES 5
Marc_LM
Associate III

Max I recommend that you don't make custom buttons but use the keyboard widget.
It is harder at first but it will make thing simpler later.

Check Gaetan's T9 sample and the demo found in Designer.
Don't do my mistake, insert a buffer in the widget even if you don't want to show anything.

You will see things called callback.
Some of them for keys, others for callbackArea; you will be able to check the value of the callback to know what action to do.

thank you @Marc_LM  for your answer.
The problem is that I wanted something that is part of the interface, and the truth is that I feel that it will be more complicated to implement a numeric keypad widge.
In this case I do not need to save the input or anything is like to put a numerical code and if pressing a key matches change screen and almost everything I can do with touchgfx only remains the last step for it to work and is to know that I'm doing wrong with the buffer. When I press a key it writes and when I want to delete it erases the issue that prints something that does not make sense and surely is some detail regarding the buffer or type of unicode format.

is it so complicated what I want to do? maybe I am ignoring something but my idea is that simply for each button I call a function and that function adds or removes a character from the char global variable with a string and displays it every time it changes in the text area. Nothing to save the entered data or strange things.

GaetanGodart
ST Employee

Hello @Maximiliano ,

 

So you don't want to use a keyboard widget but instead you want to add 10 buttons from 0 to 9?
Each of the button have an interaction to add the number to your char*.
You will also add 2 button, one to validate, one to delete.
The validate one compares your char* with another char* that is the password (you wrote char instead of char* I assume).

The issue is that when you print your char* to the textArea, you get random value instead of the values you pressed?

 

In this function :

void Info_5View::boton_0()
{
	if(pos < 10)
	{
		pos++;
		contrasena_ing[pos] = '0';
		contrasena_ing[pos+1] = '\0';

		Unicode::UnicodeChar buffer[11];

		Unicode::strncpy(buffer, contrasena_ing, 11);

		Unicode::snprintf(unlock_textBuffer, UNLOCK_TEXT_SIZE, "%s",buffer);
		unlock_text.invalidate();
	}
}

you start by incrementing the position, I think this should be done at the end.
For instance, when position is 0 (empty buffer), you want to write your value at position buffer[0], but since you increment first, you write your value at buffer[1] so you get "x0" (with x being random) instead of "0".

 

I hope this help!

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

Thank you very much was that! How did I not realize it before.

is that the widget has its own style and size on the screen while the buttons that I put I put it exactly where I like and with its style and if you put the correct name in the programming it is just copy and paste changing the number of the key and that's it.

Hello @Maximiliano ,

 

I am glad it helped you!
Don't hesitate if you have other TouchGFX questions.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)