cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Widget - Draw function "interrupted"

GPa.1
Associate III

I followed the Tutorial for the QR Code. It works when you draw just one custom widget. But when i add the same custom widget serveral times in the same Screen or in a custom Container, the code is not able to draw all the custom widgets, it seems that the draw function is interrupted and my QR Code it's not complete.

Maybe something about the HAL? Any suggestion?

I add my example project in 4.16.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
GPa.1
Associate III

Hello @Alexandre RENOUX​, @Romain DIELEMAN​ ,

Many thanks for asking.

Yes, there were some errors in the code and for sure the library it's not perfect (https://github.com/nayuki/QR-Code-generator/tree/master/cpp), but at the end i made it work changing the suggested draw code for the next one:

void QrCodeWidget::draw(const touchgfx::Rect& invalidatedArea) const
{
	if (!code)  {
	      return;
	}
 
       bool result = true;
       for(int yPos = 0; yPos < code->getSize(); yPos++) 	{
		for(int xPos = 0; xPos < code->getSize(); xPos++) 		{
			result = code->getModule(xPos, yPos);
		        Rect rect(xPos*scale, yPos*scale, scale, scale);
			translateRectToAbsolute(rect);
			HAL::lcd().fillRect(rect, result ? 0x00000000 : 0xffffffff, 255);  
		}
	}
}

Regards.

View solution in original post

5 REPLIES 5
GPa.1
Associate III

@Romain DIELEMAN​  @Martin KJELDSEN​  @Alexandre RENOUX​  any hint about this problem with a QR Code in a Custom Widget?

The custom widget doesn't work in combination with other widgets.

Hi,

Yes I tried and faced the same issue. I didn't investigate further into this but it must come from the QR widget in itself since we write directly into the framebuffer, it needs to be dissected and tested :downcast_face_with_sweat:.

/Romain

Alexandre RENOUX
Principal

Hello @GPa.1​ ,

I cannot see your project anymore and neither the image (if I remember well).

After some investigation, I believe the issue comes from the QR Code lib used which is not a TouchGFX or ST product.

I see in the lib that some vector class is used which involves dynamic allocation. We try to avoid that and only declare statically allocated variables. This might be a good start to see what is exactly the problem.

/Alexandre

GPa.1
Associate III

Hello @Alexandre RENOUX​, @Romain DIELEMAN​ ,

Many thanks for asking.

Yes, there were some errors in the code and for sure the library it's not perfect (https://github.com/nayuki/QR-Code-generator/tree/master/cpp), but at the end i made it work changing the suggested draw code for the next one:

void QrCodeWidget::draw(const touchgfx::Rect& invalidatedArea) const
{
	if (!code)  {
	      return;
	}
 
       bool result = true;
       for(int yPos = 0; yPos < code->getSize(); yPos++) 	{
		for(int xPos = 0; xPos < code->getSize(); xPos++) 		{
			result = code->getModule(xPos, yPos);
		        Rect rect(xPos*scale, yPos*scale, scale, scale);
			translateRectToAbsolute(rect);
			HAL::lcd().fillRect(rect, result ? 0x00000000 : 0xffffffff, 255);  
		}
	}
}

Regards.

Great to hear that 👍

And thanks for sharing the solution.

/Romain