summaryrefslogtreecommitdiff
path: root/library.rb
diff options
context:
space:
mode:
Diffstat (limited to 'library.rb')
-rw-r--r--library.rb66
1 files changed, 61 insertions, 5 deletions
diff --git a/library.rb b/library.rb
index 1fb682b..0ba7cbc 100644
--- a/library.rb
+++ b/library.rb
@@ -1,23 +1,79 @@
1require "./lace" 1require "./lace"
2 2
3$smd = "0805" 3$passive = "0805"
4 4
5def r(ohms, footprint=$smd) 5def r(ohms, footprint=$passive)
6 ohms = ohms.to_s 6 ohms = ohms.to_s
7 ohms.sub!(/(ohms?|Ω)$/i, "") 7 ohms.sub!(/(ohms?|Ω)$/i, "")
8 comp("R", footprint, "resistor", "#{Lace.number(ohms)}Ω") 8 comp("R", footprint, "resistor", "#{Lace.number(ohms)}Ω")
9end 9end
10 10
11def c(farads, footprint=$smd) 11def c(farads, footprint=$passive)
12 farads = farads.to_s 12 farads = farads.to_s
13 farads.sub!(/f(arads?)?$/i, "") 13 farads.sub!(/f(arads?)?$/i, "")
14 comp("C", footprint, "capacitor", "#{Lace.number(farads)}F") 14 comp("C", footprint, "capacitor", "#{Lace.number(farads)}F")
15end 15end
16 16
17def d(spec, footprint=$smd) 17def d(spec, footprint=$passive)
18 comp("D", footprint, "diode", spec) 18 comp("D", footprint, "diode", spec)
19end 19end
20 20
21def led(spec, ohms, footprint=$smd) 21def led(ohms="1K", spec="red", footprint=$passive)
22 comp("D", footprint, "LED", spec) - self.r(ohms, footprint) 22 comp("D", footprint, "LED", spec) - self.r(ohms, footprint)
23end 23end
24
25$ic = "TSSOP"
26
27IC = Struct.new(:value, :pincount, :subparts, :automatic)
28
29$ic_definitions = {}
30$ic_available_parts = {}
31
32def define_ic(name, value, pincount, *subparts, &automatic)
33 $ic_definitions[name] = IC.new(value, pincount, subparts, automatic)
34end
35
36def stock_ic(name, value, &automatic)
37 case value
38 when /74.*00/; define_ic(name, value, 14, [1, 2, 3], [4, 5, 6], [13, 12, 11], [10, 9, 8], &automatic)
39 when /74.*04/; define_ic(name, value, 14, [1, 2], [3, 4], [5, 6], [13, 12], [11, 10], [9, 8], &automatic)
40 end
41end
42
43def ic(name)
44 parts = $ic_available_parts.fetch(name, [])
45 if parts.size < 1
46 raise "IC #{name} not defined!" unless $ic_definitions.member?(name)
47 info = $ic_definitions[name]
48 ic = comp("U", "#{$ic}-#{info.pincount}", name, info.value)
49 info.automatic.call(ic)
50 subs = info.subparts.map { | sub | sub.map { | pin | ic[pin] } }
51 subs.each do | sub |
52 if sub.size == 2
53 parts << pair(*sub)
54 else
55 parts << sub
56 end
57 end
58 end
59 part = parts.shift
60 $ic_available_parts[name] = parts
61 return part
62end
63
64def probe(attenuation=20, impedance=50)
65 jack = comp("J", "SMB", "SMB jack", "#{attenuation}x #{impedance}Ω probe")
66 jack[2] - jack[3] - jack[4] - jack[5]
67 if attenuation == 1
68 pair(jack[1], jack[2])
69 else
70 pair(r((attenuation-1)*impedance) - jack[1], jack[2])
71 end
72end
73
74def btn(color="black")
75 sw = comp("SW", "BTN", "SPST button", color)
76 sw[1] - sw[4]
77 sw[2] - sw[3]
78 pair(sw[1], sw[3])
79end