clean up SAMD21G symbol to eliminate bogus inherited attributes
[hw/altusmetrum] / packages / servo.5c
1 /*
2  * Copyright © 2016 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 load "footprint.5c"
19 import Footprint;
20
21 real dpi = 4800;
22
23 real pixtomm(real pix) = pix / dpi * 25.4;
24
25 typedef struct {
26         real    x;
27         real    y;
28 } pos_t;
29
30 real    origin_x = 423;
31 real    origin_y = 213;
32
33 real xmm(real xpix) = pixtomm(xpix - origin_x);
34
35 /* Image was of the bottom, mirror the result */
36 real ymm(real ypix) = pixtomm(1999 - (ypix - origin_y));
37
38 pos_t pos(real xpix, real ypix) = (pos_t) { .x = xmm(xpix), .y = ymm(ypix) };
39
40 pos_t ul = pos(543, 213);
41 pos_t ur = pos(2912, 213);
42 pos_t mll = pos(423, 1036);
43 pos_t mlr = pos(543, 1036);
44 pos_t mrl = pos(2912, 1036);
45 pos_t mrr = pos(3980, 1036);
46 pos_t ll = pos(423, 1955);
47 pos_t lr = pos(3980, 1955);
48
49 pos_t mount_ul = pos(761, 208);
50 pos_t mount_ur = pos(2082, 208);
51
52 pos_t mount_ll = pos(652, 1999);
53 pos_t mount_lr = pos(3500, 1999);
54
55 real mounting_hole = pixtomm(142);
56
57 pos_t pin_l = pos(423 + 257, 1955 - 826);
58 pos_t pin_r = pos(423 + 1788, 1955 - 826);
59
60 real index_pin = pixtomm(100);
61
62 void linepos(pos_t a, pos_t b) { line(a.x, a.y, b.x, b.y); }
63
64 void outline() {
65         linepos(ul, ur);
66         linepos(ur, mrl);
67         linepos(mrl, mrr);
68         linepos(mrr, lr);
69         linepos(lr, ll);
70         linepos(ll, mll);
71         linepos(mll, mlr);
72         linepos(mlr, ul);
73 }
74
75 void drill(pos_t a) {
76         pin_mm_options(a.x, a.y, mounting_hole, 0, "mount", "mount", "hole");
77 }
78
79 void pin(pos_t a) {
80         pin_mm_options(a.x, a.y, index_pin, 0, "pin", "pin", "hole");
81 }
82
83 void mount() {
84         drill(mount_ul);
85         drill(mount_ur);
86         drill(mount_ll);
87         drill(mount_lr);
88 }
89
90 void pins() {
91         pin(pin_l);
92         pin(pin_r);
93 }
94
95 real ysplit = ymm(1500);
96 real ygap = pixtomm(1536 - 1442);
97
98 void contact(pos_t ul, pos_t lr, string name, string num) {
99         pad_mm((ul.x + lr.x) / 2,
100                (ul.y + lr.y) / 2,
101                abs(lr.x - ul.x),
102                abs(lr.y - ul.y),
103                name, num);
104 }
105
106 void top_contact(real x, real width, string name, string num) {
107         contact((pos_t) { .x = x, .y = mll.y },
108                 (pos_t) { .x = x + width, .y = ysplit + ygap / 2 },
109                 name, num);
110 }
111
112 real contact_left = xmm(563 + 2909 - 2667);
113 real contact_right = xmm(2922);
114 real contact_width = pixtomm(3267 - 2901);
115
116 void bottom_contact(real x, real width, string name, string num) {
117         contact((pos_t) { .x = x, .y = ysplit - ygap / 2 },
118                 (pos_t) { .x = x + width, .y = ll.y },
119                 name, num);
120 }
121
122 element_start("servo");
123
124 outline();
125 mount();
126 pins();
127
128 bottom_contact(contact_left, contact_width, "1", "1");
129 bottom_contact(contact_right, contact_width, "2", "2");
130
131 top_contact(contact_left, contact_width, "3", "3");
132 top_contact(contact_right, contact_width, "4", "4");
133
134 element_end();