forked from robertstarr/ulp_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-pogo-package.ulp
302 lines (252 loc) · 8.07 KB
/
make-pogo-package.ulp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#usage "<b>Generate Library Part for a PCB with Pogo Test Pads - v1.02</b>\n"
"<p>"
"This ULP generates a script from an existing board that can be run in a library to create a device "
"that represents the PCB with pogo pin holes that match the X/Y locations of "
"SMD adn through hole test points that contain the attribute 'POGOPIN'."
"<p>"
"The SMD test points can be on the top or bottom side of the board and "
"MUST also have an attribute of type 'POGOPIN' defined for each test point "
"that requires a hole location for mounting a pogo pin."
"<p>"
"<author>http://www.bobstarr.net</author>";
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED
real padDiameter = 52.0;
real padDrillSize = 32.0;
string padShape = "ROUND";
real wireSize = 0.0;
string nameSymbol = "TP";
string namePkgDev = "PCB-POGO";
string pinNames[];
int pinCount;
void DrawWire(UL_WIRE W)
{
if (W.arc)
{
printf("Arc CCW %.3f (%.3f %.3f) (%.3f %.3f) (%.3f %.3f);\n",
wireSize, /*u2mil(W.width)*/
u2mil(W.arc.x1), u2mil(W.arc.y1),
u2mil(W.arc.xc + W.arc.xc - W.arc.x1), u2mil(W.arc.yc + W.arc.yc - W.arc.y1),
u2mil(W.arc.x2), u2mil(W.arc.y2));
}
else
{
printf("WIRE %.3f (%.3f %.3f) (%.3f %.3f);\n",
wireSize, u2mil(W.x1), u2mil(W.y1), u2mil(W.x2), u2mil(W.y2) );
}
}
int MakePogoPackage(UL_BOARD B)
{
pinCount = 0;
// PROCESS BOTTOM SIDE FOR SMD TEST POINT PADS
printf("# \n");
printf("# CREATE PCB PACKAGE FOR POGOPINS\n");
printf("# \n");
printf("EDIT '%s.pac'\n", namePkgDev);
printf("GRID ");
if (B.grid.unit == GRID_UNIT_MIC)
printf ("microns");
else if (B.grid.unit == GRID_UNIT_MM)
printf ("mm");
else if (B.grid.unit == GRID_UNIT_MIL)
printf ("mil");
else if (B.grid.unit == GRID_UNIT_INCH)
printf ("inch");
printf(";\n");
B.elements(E)
{
int wasSmd, wasPad,
xmax =-2147483648,
xmin = 2147483647,
ymax = xmax,
ymin = xmin;
wasSmd = 0;
int addPogoPin = 0;
E.package.contacts(C)
{
if (C.smd && ((C.smd.layer == 1) || (C.smd.layer == 16)))
{
wasSmd = 1;
if (C.x > xmax) xmax = C.x;
if (C.y > ymax) ymax = C.y;
if (C.x < xmin) xmin = C.x;
if (C.y < ymin) ymin = C.y;
break;
}
if (C.pad)
{
wasPad = 1;
if (C.pad.x > xmax) xmax = C.pad.x;
if (C.pad.y > ymax) ymax = C.pad.y;
if (C.pad.x < xmin) xmin = C.pad.x;
if (C.pad.y < ymin) ymin = C.pad.y;
break;
}
}
// Check for DNP or BOM EXCLUDED PARTS
E.attributes(A)
{
if (A.name == "POGOPIN")
{
addPogoPin = 1;
// Exclude part from BOM?
if ((A.value == "F") || (A.value == "0"))
addPogoPin = 0;
}
}
if ((wasSmd || wasPad) && addPogoPin)
{
real x,y;
switch (B.grid.unit)
{
case GRID_UNIT_MIC:
x = u2mic((xmin + xmax) / 2);
y = u2mic((ymin + ymax) / 2);
break;
case GRID_UNIT_MIL:
x = u2mil((xmin + xmax) / 2);
y = u2mil((ymin + ymax) / 2);
break;
case GRID_UNIT_MM:
x = u2mm((xmin + xmax) / 2);
y = u2mm((ymin + ymax) / 2);
break;
case GRID_UNIT_INCH:
x = u2inch((xmin + xmax) / 2);
y = u2inch((ymin + ymax) / 2);
break;
}
string value = E.value, name = E.package.name;
int index = 0;
while ((index = strchr (value,' ',index)) >= 0)
{
value[index] = '_';
}
index = 0;
while ((index = strchr (name,' ',index)) >= 0)
{
name[index] = '_';
}
if (strlen (value) == 0) value = "none";
if (strlen (name) == 0) value = "none";
printf("# BOARD ==> %s, %s, %5.4f %5.4f %3.0f %s %s\n", E.name, name, x, y, E.angle, value, name);
printf("CHANGE DRILL %.4f;\n", padDrillSize);
printf("PAD '%s' %s %f R0 (%.4f %.4f);\n", E.name, padShape, padDiameter, x, y);
pinNames[pinCount] = E.name;
++pinCount;
}
}
if (pinCount)
{
printf("# \n");
printf("# CREATE PCB PACKAGE OUTLINE\n");
printf("# \n");
printf("GRID mil;\n");
printf("DISPLAY -20;\n\n");
printf("DISPLAY 51;\n\n");
printf("SET WIRE_BEND 2;\n");
B.wires(W)
{
if (W.layer == 20)
{
printf("CHANGE LAYER 51;\n");
DrawWire(W);
}
}
}
return pinCount;
}
void MakeTPSymbol()
{
printf("# \n");
printf("# CREATE THE TEST POINT PAD SYMBOL\n");
printf("# \n");
printf("Edit '%s.sym';\n", nameSymbol);
printf("Pin '%s' io dot long R0 pad 0 (0 0);\n", nameSymbol);
printf("Layer 95;\n");
printf("Change Size 1.778;\n");
printf("Change Ratio 10;\n");
printf("Change Align bottom left;\n");
printf("Change Font proportional;\n");
printf("Text '>NAME' R0 (6.6675 -0.9525);\n");
}
void MakeTPDevice()
{
int i;
if (pinCount < 1)
return;
printf("# \n");
printf("# CREATE PCB DEVICE FOR POGOPINS\n");
printf("# \n");
printf("EDIT '%s.dev'\n", namePkgDev);
printf("GRID MIL\n");
printf("Prefix 'X';\n");
printf("Description '<b>POGO PIN PCB</b>';\n");
printf("Value On;\n");
real y = 0.0;
for (i=0; i < pinCount; i++)
{
printf("Add %s '%s' Always 1 (0 %.2f);\n", nameSymbol, pinNames[i], y);
y -= 100;
}
printf("Package '%s' '''''';\n", namePkgDev);
printf("Technology '';\n");
string strConnect = "Connect ";
for (i=0; i < pinCount; i++)
{
string tmp;
sprintf(tmp, " '%s.%s' '%s'", pinNames[i], nameSymbol, pinNames[i]);
strConnect = strConnect + tmp;
if ((i % 6) == 5)
strConnect += "\\\n ";
}
printf("%s;\n\n", strConnect);
}
/*
* ULP Main
*/
void menue()
{
dlgDialog("Make Pogo Package") {
dlgGroup("Pogo Pin Package") {
dlgHBoxLayout { dlgLabel("Pad Diameter (mil) :"); dlgRealEdit(padDiameter); }
dlgHBoxLayout { dlgLabel("Pad Drill Size (mil) :"); dlgRealEdit(padDrillSize); }
}
dlgGroup("Test Point Device/Symbol") {
dlgHBoxLayout { dlgLabel("Package/Device Name :"); dlgStringEdit(namePkgDev); }
dlgHBoxLayout { dlgLabel("Symbol Pin Name :"); dlgStringEdit(nameSymbol); }
}
dlgPushButton("+&OK") { dlgAccept(); return; }
dlgPushButton("-&Cancel") { dlgReject(); exit (0);}
};
}
if (board) board(B)
{
int pinCount;
menue();
// Get filename
string fileName = dlgFileSave("Save File", filesetext(B.name, "_MakeLibPogoPackage.scr"), "*.scr");
if (fileName == "") exit(0);
output(fileName)
{
printf("# Auto Generated at %s<br>\n", t2string(time()));
printf("# %s;\n", EAGLE_SIGNATURE);
printf("# ADD TEST POINT HOLES TO LIBRARY PACKAGE\n");
printf("# Origin = (0.0,0.0)\n");
printf("# Units used = ");
printf("#\n");
if (MakePogoPackage(B) == 0)
{
dlgMessageBox("\nNo SMD testpoints with 'POGOPIN' attribute found!\n");
}
else
{
MakeTPSymbol();
MakeTPDevice();
}
}
}
else
{
dlgMessageBox("\n Start this ULP in a Board \n");
exit (0);
}