I Iet the scripts master the beast for me!
I can't auto-generate the keyboard layout (yet) but I can generate the .sch and .cmp files:
Controller and LED pads are still missing, but can be added at any time.
Code: Select all
#!/usr/bin/perl -w
my $counter=10000000; # must be 8 digits.
my $offseth=800;
my $offsetw=800;
my $step=800;
my $height=5;
my $width=15;
sub printpos
{
my $i = shift;
my $j = shift;
my $posi = shift;
my $posj = shift;
my $resi=$offseth+$posi+$i*$step;
my $resj=$offsetw+$posj+$j*$step;
print " $resi $resj ";
}
sub printindex
{
my $i = shift;
my $j = shift;
$j=($height-1)-$j;
print "$j:$i";
}
sub drawheader
{
print "EESchema Schematic File Version 2 date Sat 03 Nov 2012 04:10:08 PM CET\n";
print "LIBS:components\n";
print "EELAYER 24 0\n";
print "EELAYER END\n";
print "\$Descr A2 23400 16535\n";
print "Sheet 1 1\n";
print "Title \"\"\n";
print "Date \"3 nov 2012\"\n";
print "Rev \"\"\n";
print "Comp \"\"\n";
print "Comment1 \"\"\n";
print "Comment2 \"\"\n";
print "Comment3 \"\"\n";
print "Comment4 \"\"\n";
print "\$EndDescr\n";
}
sub drawrowline
{
my $n = shift;
print "Wire Wire Line\n";
print " ";
printpos(0,$n,-100,50);
printpos($width-1,$n,100,50);
print "\n";
}
sub drawcolline
{
my $n = shift;
print "Wire Wire Line\n";
print " ";
printpos($n,0,0,600);
printpos($n,$height,0,0);
print "\n";
}
sub printtimestamp
{
$counter++;
print "$counter";
}
sub drawcomponent
{
my $i = shift;
my $j = shift;
print "\$Comp\n";
print "L SWITCH_PUSH S";
printindex($i,$j);
print "\n";
print "U 1 1 ";
printtimestamp();
print "\n";
print "P";
printpos($i,$j,400,250);
print "\n";
print "F 0 \"S";
printindex($i,$j);
print "\" H";
printpos($i,$j,550,360);
print "50 0000 C CNN\n";
print "F 1 \"MX\" H";
printpos($i,$j,400,170);
print "50 0000 C CNN\n";
print " 1";
printpos($i,$j,400,250);
print "\n";
print " 1 0 0 -1\n";
print "\$EndComp\n";
print "\$Comp\n";
print "L DIODE D";
printindex($i,$j);
print "\n";
print "U 1 1 ";
printtimestamp();
print "\n";
print "P";
printpos($i,$j,400,600);
print "\n";
print "F 0 \"D";
printindex($i,$j);
print "\" H";
printpos($i,$j,400,700);
print "40 0000 C CNN\n";
print "F 1 \"D\" H";
printpos($i,$j,400,500);
print "40 0000 C CNN\n";
print " 1";
printpos($i,$j,400,600);
print "\n";
print " -1 0 0 1\n";
print "\$EndComp\n";
print "Wire Wire Line\n";
print " ";
printpos($i,$j,200,600);
printpos($i,$j,0,600);
print "\n";
print "Wire Wire Line\n";
print " ";
printpos($i,$j,700,250);
printpos($i,$j,700,600);
print "\n";
print "Wire Wire Line\n";
print " ";
printpos($i,$j,700,600);
printpos($i,$j,600,600);
print "\n";
print "Wire Wire Line\n";
print " ";
printpos($i,$j,100,250);
printpos($i,$j,100,50);
print "\n";
if($i!=$width-1)
{
print "Connection ~ ";
printpos($i,$j,100,50);
print "\n";
}
if($j!=0)
{
print "Connection ~ ";
printpos($i,$j,0,600);
print "\n";
}
print "\n";
}
sub main
{
for(@ARGV)
{
my $myinline = $_;
if($myinline eq "--help" || $myinline eq "-h")
{
print "NAME\n";
print " scheme.pl\n\n";
print "SYNOPSIS\n";
print " scheme.pl [options]\n\n";
print "EXAMPLE\n";
print " scheme.pl -s 5x12 > mykeyboard.sch\n\n";
print "nOPTIONS\n";
print " --size, -s nxm\n";
print " Size of the PCB-matrix\n\n";
print " --help, -h\n";
print " Print help message.\n";
exit;
}
if(($myinline eq "--size") || $myinline eq "-s")
{
$size_f=1;
next;
}
if($size_f)
{
$size_f=0;
$height=$myinline;
$width=$myinline;
$height =~ s/^([[:digit:]]+)[x]([[:digit:]]+)$/$1/;
$width =~ s/^([[:digit:]]+)[x]([[:digit:]]+)$/$2/;
next;
}
}
drawheader();
for(my $j=0; $j<$height; $j++)
{
drawrowline($j);
for(my $i=0; $i<$width; $i++)
{
drawcolline($i);
drawcomponent($i,$j);
}
}
}
main();
# eof
Usage:
scheme.pl -s 4x12 > mykeyboard.sch
Output is the content of a .sch file with the necessary matrix.
Run mykeyboard.sch through kicad-GUI and make a .net file out of it.
The necessary .cmp file is generated by this script:
Code: Select all
#!/bin/bash
# purpose: generate .cmp file from .brd source
echo "Cmp-Mod V01 Created by CvPcb (2012-04-29 BZR 3537)-testing date = Fri 03 Aug 2012 03:04:22 PM CEST"
cat "$@" | grep ^Li -A4 |
grep ^AR -v |
grep ^Op -v |
sed 's/^T0[[:space:]]\([^"]\+\)["]\([^"]\+\)["]\(.*\)$/Reference = \2;\nValeurCmp = \2;\nEndCmp/' |
sed 's/^Li\([[:space:]]*\)\([^[:space:]]\+\)/BeginCmp\nIdModule = \2;/' |
sed 's/^Sc\([[:space:]]*\)\([[:alnum:]]\+\)\([[:space:]]*\)$/TimeStamp = \/\2;/'|
sed 's/[-][-]//'
echo "EndListe"
Usage:
board.sh mykeyboard.brd > mykeyboard.cmp
Then you can load mykeyboard.brd into pcbnew and let it read the netlist (by clicking on the Read Netlist icon in the top panel). Ignore the error messages and you are done.
This is how it looks like: