Announcements
Notice: Upload of PDF documents is currently unavailable across the Community due to an ongoing issue.

Need Help with ULP/Eagle Script: Drawn Squares Have Incorrect Dimensions

Need Help with ULP/Eagle Script: Drawn Squares Have Incorrect Dimensions

blaisebarrette
Advocate Advocate
476 Views
1 Reply
Message 1 of 2

Need Help with ULP/Eagle Script: Drawn Squares Have Incorrect Dimensions

blaisebarrette
Advocate
Advocate

Hi everyone!

 

I’m currently developing a ULP that generates QR codes directly in Fusion Electronics. It’s working quite well overall, but I’ve noticed a consistent issue: the QR codes generated are always slightly smaller than the requested size. Additionally, the size of the QR code seems to vary depending on whether the URL passed to it is short or long.

 

Capture d’écran, le 2024-12-21 à 14.01.23.png



Here’s the function responsible for drawing the squares:

 

 

output(scriptFile, "wt") {
        int qrSize = nLines;
        
        // Adjust the requested size to be divisible by the number of modules
        int adjustedSize = Size;
        while (adjustedSize % qrSize != 0) {
            adjustedSize++;
        }
        int moduleSize = adjustedSize / qrSize;
        
        printf("# QR Code Generator Script\n");
        printf("# Generated by QR Code ULP v%s\n", VERSION);
        printf("# QR Code Size: %d x %d modules\n", qrSize, qrSize);
        printf("# Original Size: %d mils\n", Size);
        printf("# Adjusted Size: %d mils\n", adjustedSize);
        printf("# Module Size: %d mils\n", moduleSize);
        printf("# Position: (%d, %d)\n", PosX, PosY);
        printf("\n");
        
        printf("GRID MIL 0.1;\n");
        printf("CHANGE LAYER %d;\n", LayerNumbers[SelectedLayer]);
        printf("SET WIRE_BEND 2;\n");
        
        // Create rectangles for QR code
        int isBottomLayer = (LayerNumbers[SelectedLayer] == 22 || LayerNumbers[SelectedLayer] == 52);
        
        // Calculate the starting point to center the QR code
        int startX = PosX - (Size / 2);  // Starting point based on the requested size
        int startY = PosY - (Size / 2);
        
        for (int row = 0; row < nLines; row++) {
            string line = lines[row];
            for (int col = 0; col < strlen(line); col++) {
                if (line[col] == '1') {
                    // Calculate the positions relative to the starting point
                    int x1 = startX + (col * moduleSize);
                    int y1 = startY + (row * moduleSize);
                    int x2 = x1 + moduleSize;
                    int y2 = y1 + moduleSize;
    
                    // Mirror X coordinates if bottom layer
                    if (isBottomLayer) {
                        int temp_x1 = x1;
                        x1 = -x2;
                        x2 = -temp_x1;
                    }
                    
                    printf("RECT (%d %d) (%d %d);\n", x1, y1, x2, y2);
                }
            }
        }
    }

 

 

 

You can find the complete ULP on my GitHub: https://github.com/blaisebarrette/QRCode-ULP-for-Fusion-electronics/tree/V1.0.2-developpment.

If you have experience with this type of issue or any suggestions to improve the implementation, your input would be greatly appreciated!

 

Thanks in advance for your help!

 

— Blaise

0 Likes
Accepted solutions (1)
477 Views
1 Reply
Reply (1)
Message 2 of 2

blaisebarrette
Advocate
Advocate
Accepted solution

Hi all! I found the solution!
QR codes are now created at the exact size requested.
Enjoy!

 

- Blaise