1
0
mirror of git://projects.qi-hardware.com/kicad-libs.git synced 2024-11-28 18:06:15 +02:00

components/gencon.pl: structure code a little more clearly

This commit is contained in:
Werner Almesberger 2016-09-18 00:35:30 -03:00
parent 274c6c543f
commit e640742621

View File

@ -2,7 +2,7 @@
# #
# gencon.pl - Generate generic connectors # gencon.pl - Generate generic connectors
# #
# Copyright 2012 by Werner Almesberger # Copyright 2012, 2016 by Werner Almesberger
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -10,22 +10,26 @@
# (at your option) any later version. # (at your option) any later version.
# #
print "EESchema-LIBRARY Version 2.3 Date: `date`\n";
print "#encoding utf-8\n"; # Single and dual row, with the same number of pins in each row
for ($x = 1; $x <= 40; $x++) {
for ($y = 1; $y <= 2; $y++) { sub even
$name = "CONN_$x"; {
local ($x) = @_;
for (my $y = 1; $y <= 2; $y++) {
my $name = "CONN_$x";
$name .= "X$y" if $y > 1; $name .= "X$y" if $y > 1;
print "#\n# $name\n#\n"; print "#\n# $name\n#\n";
print "DEF $name CON 0 40 Y N 1 F N\n"; print "DEF $name CON 0 40 Y N 1 F N\n";
$h = $x / 2 * 100; my $h = $x / 2 * 100;
print "F0 \"CON\" 0 " . ($h + 50) . " 60 H V C CNN\n"; print "F0 \"CON\" 0 " . ($h + 50) . " 60 H V C CNN\n";
print "F1 \"$name\" 0 " . (-$h - 50) . " 60 H V C CNN\n"; print "F1 \"$name\" 0 " . (-$h - 50) . " 60 H V C CNN\n";
print "DRAW\n"; print "DRAW\n";
print "S -100 -$h 100 $h 0 1 0 N\n"; print "S -100 -$h 100 $h 0 1 0 N\n";
$n = 1; my $n = 1;
for ($px = 1; $px <= $x; $px++) { for (my $px = 1; $px <= $x; $px++) {
for ($py = 1; $py <= $y; $py++) { for (my $py = 1; $py <= $y; $py++) {
print "X $n $n " . (400 * ($py - 1.5) * 2) . print "X $n $n " . (400 * ($py - 1.5) * 2) .
" " . ($h - $px * 100 + 50) . " 300 " . " " . ($h - $px * 100 + 50) . " 300 " .
("?", "R", "L")[$py] . " 50 50 1 1 P\n"; ("?", "R", "L")[$py] . " 50 50 1 1 P\n";
@ -35,18 +39,24 @@ for ($x = 1; $x <= 40; $x++) {
print "ENDDRAW\n"; print "ENDDRAW\n";
print "ENDDEF\n"; print "ENDDEF\n";
} }
}
next if $x == 1;
$name = "CONN_$x" . "_" . ($x - 1); # Dual row, with rows differing by one pin (D-Sub and similar)
sub odd
{
local ($x) = @_;
my $name = "CONN_$x" . "_" . ($x - 1);
print "#\n# $name\n#\n"; print "#\n# $name\n#\n";
print "DEF $name CON 0 40 Y N 1 F N\n"; print "DEF $name CON 0 40 Y N 1 F N\n";
$h = $x / 2 * 100; my $h = $x / 2 * 100;
print "F0 \"CON\" 0 " . ($h + 50) . " 60 H V C CNN\n"; print "F0 \"CON\" 0 " . ($h + 50) . " 60 H V C CNN\n";
print "F1 \"$name\" 0 " . (-$h - 50) . " 60 H V C CNN\n"; print "F1 \"$name\" 0 " . (-$h - 50) . " 60 H V C CNN\n";
print "DRAW\n"; print "DRAW\n";
print "S -100 -$h 100 $h 0 1 0 N\n"; print "S -100 -$h 100 $h 0 1 0 N\n";
for ($px = 1; $px <= $x; $px++) { for (my $px = 1; $px <= $x; $px++) {
print "X $px $px -400 " . print "X $px $px -400 " .
($h - $px * 100 + 50) . " 300 R 50 50 1 1 P\n"; ($h - $px * 100 + 50) . " 300 R 50 50 1 1 P\n";
next if $px == $x; next if $px == $x;
@ -57,4 +67,12 @@ for ($x = 1; $x <= 40; $x++) {
print "ENDDRAW\n"; print "ENDDRAW\n";
print "ENDDEF\n"; print "ENDDEF\n";
} }
print "EESchema-LIBRARY Version 2.3 Date: `date`\n";
print "#encoding utf-8\n";
for ($x = 1; $x <= 40; $x++) {
&even($x);
&odd($x) if $x > 1;
}
print "#\n#End Library\n"; print "#\n#End Library\n";