This commit is contained in:
Morgan 'ARR\!' Allen 2017-04-09 18:59:01 -07:00
commit 87a00b0ef9
8 changed files with 270 additions and 0 deletions

27
README.md Normal file
View file

@ -0,0 +1,27 @@
# pos2charmhigh
Converts KiCAD .pos placement file to Charmhigh Pick and Place CSV
## usage
```
pos2csv -i test/top.pos -f test/feeds.csv -o pnp.csv
```
### CLI
```
-i,
--input KiCAD .pos file
-o,
--output CSV file for the PnP
-f,
--feed Feed file from PnP
```
## Feed file
The feed file is generated by the Pick and Place. Go through the normal
setup process on the machine, saving the file to the SD card. Fetch the
project file from the card. The feed is the second section in the file.
Sections start with %.

35
bin/cmd.js Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env node
// translates KiCAD .pos files to Charmhigh PnP csv files
var pos2 = require("../");
var argv = require("minimist")(process.argv, {
alias: {
i: "input",
o: "output",
f: "feed",
q: "quite"
},
boolean: [ "quite" ],
default: {
quite: false
}
});
var input = argv.i || argv.input || argv._[2];
var output = argv.o || argv.output || argv._[3];
if(!input) {
return console.log("Need input filename");
}
if(!output) {
return console.log("Need output filename");
}
if(!argv.feed) {
return console.log("Need feed csv filename");
}
pos2(input, output, argv.feed, {
quite: argv.quite
});

63
index.js Normal file
View file

@ -0,0 +1,63 @@
var async = require("async");
var csv = require("fast-csv");
var fs = require("fs");
var through = require("through2");
module.exports = function(input, output, feedFile, opts) {
var data = "";
async.waterfall([function(next) {
var feeds = {};
fs.createReadStream(feedFile).pipe(csv())
.on("data", function(data){
feeds[data[6]] = {
x: data[3],
y: data[4],
feed: data[5],
slot: data[2]
}
})
.on("end", function() {
next(null, feeds)
});
}, function(feeds, next) {
var rs = fs.createReadStream(input);
var ws = fs.createWriteStream(output);
var wsCsv = csv.createWriteStream();
var seq = 0;
var tr = through.obj(function(chunk, enc, done) {
data += chunk.toString();
var lines = data.split("\n");
data = lines.pop();
for(var i = 0, line; i < lines.length; i++) {
line = lines[i];
var match = line.replace(/[\ ]+/g, " ").split(" ");
var p = match[1];
var x = match[3];
var y = match[4];
var r = match[5];
if(!feeds[p]) {
if(!opts.quite)
console.warn("No feed found for part: %s", p);
continue;
}
var feed = feeds[p];
this.push([ 0, seq++, feed.slot, x, y, r ]);
};
done();
});
rs.pipe(tr);
tr.pipe(wsCsv);
wsCsv.pipe(ws);
}]);
}

31
package.json Normal file
View file

@ -0,0 +1,31 @@
{
"name": "pos2charmhigh",
"version": "1.0.0",
"description": "Translates KiCAD .pos files to Charmhigh CSV",
"main": "index.js",
"scripts": {
"test": "tape test/test.js"
},
"bin": {
"pos2csv": "./bin/cmd.js"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/morganrallen/pos2charmhigh.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://gitlab.com/morganrallen/pos2charmhigh/issues"
},
"homepage": "https://gitlab.com/morganrallen/pos2charmhigh#README",
"dependencies": {
"async": "^2.3.0",
"fast-csv": "^2.4.0",
"minimist": "^1.2.0",
"through2": "^2.0.3"
},
"devDependencies": {
"tape": "^4.6.3"
}
}

5
test/feeds.csv Normal file
View file

@ -0,0 +1,5 @@
65535,1,1,0.00,0.00,4.00,2.2n
65535,1,2,0.00,0.00,4.00,10uF
65535,1,3,-0.25,0.00,4.00,10nF
65545,1,4,-0.25,0.00,4.00,100nF
65535,1,5,-0.25,0.00,4.00,27nF
1 65535 1 1 0.00 0.00 4.00 2.2n
2 65535 1 2 0.00 0.00 4.00 10uF
3 65535 1 3 -0.25 0.00 4.00 10nF
4 65545 1 4 -0.25 0.00 4.00 100nF
5 65535 1 5 -0.25 0.00 4.00 27nF

9
test/fixture.csv Normal file
View file

@ -0,0 +1,9 @@
0,0,1,248.2850,-101.2190,0.0000
0,1,3,237.9000,-99.6500,270.0000
0,2,4,237.8710,-103.0732,270.0000
0,3,4,213.8680,-99.4156,270.0000
0,4,2,238.7600,-106.2990,180.0000
0,5,2,228.6000,-76.6572,0.0000
0,6,3,228.1961,-58.5445,270.0000
0,7,2,218.4908,-51.4071,225.0000
0,8,2,217.2284,-50.6171,250.0000
1 0 0 1 248.2850 -101.2190 0.0000
2 0 1 3 237.9000 -99.6500 270.0000
3 0 2 4 237.8710 -103.0732 270.0000
4 0 3 4 213.8680 -99.4156 270.0000
5 0 4 2 238.7600 -106.2990 180.0000
6 0 5 2 228.6000 -76.6572 0.0000
7 0 6 3 228.1961 -58.5445 270.0000
8 0 7 2 218.4908 -51.4071 225.0000
9 0 8 2 217.2284 -50.6171 250.0000

29
test/test.js Normal file
View file

@ -0,0 +1,29 @@
var fs = require("fs");
var spawn = require("child_process").spawn;
var test = require("tape");
var output = "./test/tmp.csv";
var fixture = "./test/fixture.csv";
var cp = spawn("./bin/cmd.js", [
"-o", output,
"-f", "./test/feeds.csv",
"-i", "./test/top.pos",
"--quite"
]);
cp.stdout.on("data", function(d) {
console.log(d.toString());
});
cp.stderr.on("data", function(d) {
console.log(d.toString());
});
cp.on("close", function() {
test(function(t) {
t.deepEqual(fs.readFileSync(output), fs.readFileSync(fixture), "output correct");
t.end();
});
});

71
test/top.pos Normal file
View file

@ -0,0 +1,71 @@
### Module positions - created on Sun Apr 9 16:50:01 2017 ###
### Printed by Pcbnew version kicad 4.0.6-e0-6349~53~ubuntu16.04.1
## Unit = mm, Angle = deg.
## Side : top
# Ref Val Package PosX PosY Rot Side
ANT1 CON-SMA CON-SMA-EDGE 236.2708 -45.1104 180.0000 top
ANT2 CON-SMA CON-SMA-EDGE 247.5484 -45.1104 180.0000 top
ANT3 CON-SMA CON-SMA-EDGE 214.7570 -45.0850 180.0000 top
C1 C C_0402 214.8078 -99.4156 270.0000 top
C2 2.2n C_0402 248.2850 -101.2190 0.0000 top
C3 10nF C_0402 237.9000 -99.6500 270.0000 top
C4 100nF C_0402 237.8710 -103.0732 270.0000 top
C5 100nF C_0402 213.8680 -99.4156 270.0000 top
C6 27pF C_0402 233.9848 -87.4370 90.0000 top
C7 27pF C_0402 233.7918 -83.5039 270.0000 top
C8 10uF CP_Elec_3x5.3 238.7600 -106.2990 180.0000 top
C9 33nF C_0402 213.6140 -80.3351 270.0000 top
C10 10uF C_0402 228.6000 -76.6572 0.0000 top
C11 C_Small C_0402 219.0242 -95.9993 90.0000 top
C12 C_Small C_0402 225.2345 -102.8700 90.0000 top
C13 CP1_Small CP_Tantalum_Case-C_EIA-6032-28_Reflow 230.5050 -104.5210 270.0000 top
C14 CP1_Small CP_Elec_4x5.3 235.1405 -104.8385 270.0000 top
C15 22pF C_0402 227.5903 -64.8513 0.0000 top
C16 100pF C_0402 227.5420 -66.5480 0.0000 top
C17 10nF C_0402 228.1961 -58.5445 270.0000 top
C18 22pF C_0402 227.6221 -60.1574 0.0000 top
C19 1uF C_0402 229.6160 -59.4780 270.0000 top
C20 3.3nF C_0402 227.1446 -58.0072 270.0000 top
C21 1uF C_0402 217.2335 -64.9605 180.0000 top
C22 0.1uF C_0402 219.3061 -52.4408 210.0000 top
C23 0.1uF C_0402 219.9640 -55.0062 180.0000 top
C24 0.1uF C_0402 223.6470 -55.5840 90.0000 top
C25 10uF C_0402 218.4908 -51.4071 225.0000 top
C26 10uF C_0402 217.2284 -50.6171 250.0000 top
C27 1uF C_0402 219.7913 -53.6880 195.0000 top
C28 0.1uF C_0402 214.8840 -60.2615 90.0000 top
D1 D_Zener_Small_ALT D_0603 226.8220 -95.7072 180.0000 top
D2 D_Zener_Small_ALT D_0603 226.8728 -97.1804 180.0000 top
J1 USB_OTG USB_Micro-B_10103594-0001LF 246.4308 -104.8512 0.0000 top
J3 BATT Molex_PicoBlade_53261-0271_02x1.25mm_Angled 222.7072 -105.1560 0.0000 top
J5 CONN_02X05 Pin_Header_Straight_2x05_Pitch1.27mm_SMD 208.0260 -57.2770 270.0000 top
L1 10mH Inductor_1212 240.2840 -100.8380 270.0000 top
L2 L Choke_SMD_6.3x6.3_H3 232.4100 -96.6470 0.0000 top
R1 R R_0402 218.9429 -101.2698 90.0000 top
R2 R R_0402 217.9066 -101.2698 270.0000 top
R3 R R_0402 216.8398 -101.2698 90.0000 top
R4 10M R_0402 251.5870 -104.3940 90.0000 top
R5 470R R_0402 228.6000 -77.7773 180.0000 top
R6 27R R_0402 245.6180 -97.7900 270.0000 top
R7 27R R_0402 246.7610 -97.7900 270.0000 top
R8 10k R_0402 225.2675 -72.9285 90.0000 top
R9 1.5k R_0402 214.9450 -79.6900 270.0000 top
R10 2.2k R_0402 217.9625 -74.1782 270.0000 top
R11 R_Small R_0402 224.5614 -95.6056 180.0000 top
R12 20K R_0402 226.0524 -58.0005 270.0000 top
R13 R_Small R_0402 219.9640 -56.1848 180.0000 top
R14 2.2k R_0402 208.2165 -52.5780 180.0000 top
R15 2.2k R_0402 211.5820 -64.3890 90.0000 top
R16 R_Small R_0402 211.5820 -62.3976 90.0000 top
RV1 POT SW_DIP_x1_W5.9mm_Slide_Copal_CVS 214.6300 -104.6480 90.0000 top
U1 LT3652 DFN-12-1EP_3x3mm_Pitch0.45mm 217.6272 -98.7552 0.0000 top
U2 RN2483 RN2483 233.1212 -77.2668 0.0000 top
U3 MAX1658ESA SOIC-8_3.9x4.9mm_Pitch1.27mm 243.5860 -81.7880 180.0000 top
U5 ESP32 ESP32 220.5228 -60.5409 270.0000 top
U6 93CxxA SSOP-8_2.95x2.8mm_Pitch0.65mm 221.7420 -73.4060 0.0000 top
U7 FT2232D SSOP-48_7.5x15.9mm_Pitch0.635mm 221.3610 -83.8200 0.0000 top
U8 W25Q16JVSNIQ SOIJ-8_5.3x5.3mm_Pitch1.27mm 221.2340 -68.4530 0.0000 top
Y1 6Mhz Crystal_SMD_7050-2pin_7.0x5.0mm 230.4288 -85.4202 90.0000 top
Y2 40MHz Crystal_SMD_3225-4pin_3.2x2.5mm 227.7642 -62.5230 0.0000 top
Y3 32K Crystal_SMD_3215-2pin_3.2x1.5mm 216.5350 -56.2610 225.0000 top
## End