BlinkenArea - GitList
Repositories
Blog
Wiki
partlib
Code
Commits
Branches
Tags
Search
Tree:
cd92b87
Branches
Tags
master
stefan.experimental
partlib
pcb_stuff
genSMD.pl
move scripts into own subdir
Stefan Schuermans
commited
cd92b87
at 2014-01-11 13:44:27
genSMD.pl
Blame
History
Raw
#! /usr/bin/perl use strict; use warnings; if( @ARGV < 2 ) { print( STDERR "usage: $0 <length (10mil)> <width (10mil)>\n" ); exit( -1 ); } my $length = int( abs( $ARGV[0] ) ); my $width = int( abs( $ARGV[1] ) ); my $pad_width_factor = 1.1; my $pad_inner_ext = 20; my $pad_outer_ext = 20; my $silk_dist = 10; my $pcb_clearance = 3000; my $pcb_solder_add = 600; my $pcb_silk_width = 700; sub mil2pcb { my $mil = shift; my $pcb = $mil / 0.01; my $pcb_i = $pcb < 0 ? int( $pcb - 0.5 ) : int( $pcb + 0.5 ); return $pcb_i; } sub pad { my ($x1, $y1, $x2, $y2, $no) = @_; my $dx = abs( $x2 - $x1 ); my $dy = abs( $y2 - $y1 ); my $width = $dx < $dy ? $dx : $dy; my $width2 = $width / 2; my $cx = ($x1 + $x2) / 2; my $cy = ($y1 + $y2) / 2; my $dx1 = $x1 - $cx; my $dx2 = $x2 - $cx; my $dy1 = $y1 - $cy; my $dy2 = $y2 - $cy; $x1 += $dx1 < 0 ? $width2 : -$width2; $x2 += $dx2 < 0 ? $width2 : -$width2; $y1 += $dy1 < 0 ? $width2 : -$width2; $y2 += $dy2 < 0 ? $width2 : -$width2; my $pcb_width = mil2pcb( $width ); printf( "\tPad[%d %d %d %d %d %d %d \"%d\" \"%d\" \"square\"]\n", mil2pcb( $x1 ), mil2pcb( $y1 ), mil2pcb( $x2 ), mil2pcb( $y2 ), $pcb_width, $pcb_clearance, $pcb_width + $pcb_solder_add, $no, $no ); } sub line { my ($x1, $y1, $x2, $y2) = @_; printf( "\tElementLine[%d %d %d %d %d]\n", mil2pcb( $x1 ), mil2pcb( $y1 ), mil2pcb( $x2 ), mil2pcb( $y2 ), $pcb_silk_width ); } my $length_mil = $length * 10; my $width_mil = $width * 10; my $d_ver = $width_mil / 2; my $d_outer = $length_mil / 2 + $pad_outer_ext; my $d_inner = $length_mil / 2 - $pad_inner_ext; if( $d_inner < $length_mil / 4 ) { $d_inner = $length_mil / 4; } my $d_outline_ver = $d_ver + $silk_dist; my $d_outline_hor = $d_outer + $silk_dist; printf( "Element[\"\" \"SMD %02d%02d\" \"R1\" \"SMD %02d%02d\"" . " 0 0 %d %d 0 100 \"\"]\n(\n", $length, $width, $length, $width, mil2pcb( -$d_outline_hor ), mil2pcb( $d_outline_ver ) + 1000 ); pad( -$d_outer, -$d_ver, -$d_inner, $d_ver, 1 ); pad( $d_outer, -$d_ver, $d_inner, $d_ver, 2 ); line( -$d_outline_hor, -$d_outline_ver, $d_outline_hor, -$d_outline_ver ); line( -$d_outline_hor, $d_outline_ver, $d_outline_hor, $d_outline_ver ); line( -$d_outline_hor, -$d_outline_ver, -$d_outline_hor, $d_outline_ver ); line( $d_outline_hor, -$d_outline_ver, $d_outline_hor, $d_outline_ver ); print( "\t)\n" );