Skip to main content
KMew
Senior III
March 1, 2023
Solved

TouchGFX Wildcards: How to display a blank space

  • March 1, 2023
  • 2 replies
  • 2031 views

Hello,

I am using the TouchGFX application to display data gathered from CANbus communication, which I have verified is working. One feature I wanted to have is the following logic for fault error codes:

If a fault is present, display the error code in hexadecimal (with a user manual to outline the meaning of said error codes) in red.

If no fault is present, then I want NO text to be present. I do not want to show "0x00000000". I just want no text to be there at all.

I've attached a snippet of my code that writes the value into the wildcard currently. This solution does not work.

void Screen1View::UpdateFaults(uint64_t value){
	if(value != 0x00000000){
		Unicode::snprintf(textFaultSigBuffer, TEXTFAULTSIG_SIZE, "%x", value);
	}
	else{
		Unicode::snprintf(textFaultSigBuffer,TEXTFAULTSIG_SIZE, "%x","" );
	}
	 // Invalidate text area, which will result in it being redrawn in next tick.
	textFaultSig.invalidate();
}

Instead of displaying a blank space, it shows 8031650 (like in the picture).

Does anyone know how to make it just display no text at all?

This topic has been closed for replies.
Best answer by JTP1
 void Screen1View::UpdateFaults(uint64_t value){
 	if(value != 0x00000000){
 		Unicode::snprintf(textFaultSigBuffer, TEXTFAULTSIG_SIZE, "%x", value);
 		textFaultSig.setVisible(1); // Shows to object
 	}
 	else{
// 		Unicode::snprintf(textFaultSigBuffer,TEXTFAULTSIG_SIZE, "%x","" );
 		textFaultSig.setVisible(0); // Hides to object
 	}
 	 // Invalidate text area, which will result in it being redrawn in next tick.
 	textFaultSig.invalidate();
 }

Just set it visible or not, if I understand right what you need ?

2 replies

JTP1Best answer
Graduate II
March 1, 2023
 void Screen1View::UpdateFaults(uint64_t value){
 	if(value != 0x00000000){
 		Unicode::snprintf(textFaultSigBuffer, TEXTFAULTSIG_SIZE, "%x", value);
 		textFaultSig.setVisible(1); // Shows to object
 	}
 	else{
// 		Unicode::snprintf(textFaultSigBuffer,TEXTFAULTSIG_SIZE, "%x","" );
 		textFaultSig.setVisible(0); // Hides to object
 	}
 	 // Invalidate text area, which will result in it being redrawn in next tick.
 	textFaultSig.invalidate();
 }

Just set it visible or not, if I understand right what you need ?

KMew
KMewAuthor
Senior III
March 1, 2023

Hello JTP,

Yes, this is exactly what I needed! I just tried it and it worked exactly as I wanted.

Thank you!

MM..1
Chief III
March 1, 2023

Your error is

Unicode::snprintf(textFaultSigBuffer,TEXTFAULTSIG_SIZE, "%x","" );

right is

Unicode::snprintf(textFaultSigBuffer,TEXTFAULTSIG_SIZE, "" );

or

Unicode::snprintf(textFaultSigBuffer,TEXTFAULTSIG_SIZE, "%s","" );

KMew
KMewAuthor
Senior III
March 1, 2023

Ooohh interesting.

So if I did it your way, whatever was in the wildcard spot would go away and the non-wildcard part would stay, correct? For example:

"Fault: " - Non wildcard, so it would stay

But the wildcard part (the actual error code in hex) would be blank.

JTP's way gets rid of all wildcard and non-wildcard text, while yours gets rid of just the wildcard portion. This is most helpful! Now I can do both options.

Thank you MM!