require "./lace" $passive = "0805" def r(ohms, footprint=$passive) ohms = ohms.to_s ohms.sub!(/(ohms?|Ω)$/i, "") comp("R", footprint, "resistor", "#{Lace.number(ohms)}Ω") end def c(farads, footprint=$passive) farads = farads.to_s farads.sub!(/f(arads?)?$/i, "") comp("C", footprint, "capacitor", "#{Lace.number(farads)}F") end def d(spec, footprint=$passive) comp("D", footprint, "diode", spec) end def led(ohms="1K", spec="red", footprint=$passive) comp("D", footprint, "LED", spec) - self.r(ohms, footprint) end $ic = "TSSOP" def define_ic(name, value, pincount, *subparts, &automatic) parts = [] proc do if parts.size < 1 ic = comp("U", "#{$ic}-#{pincount}", name, value) automatic.call(ic) subs = subparts.map do | sub | if sub.respond_to?(:transform_values) sub.transform_values { | pin | ic[pin] } else sub.map { | pin | ic[pin] } end end subs.each do | sub | if sub.size == 2 parts << pair(*sub) else parts << sub end end end parts.shift end end def stock_ic(name, value, &automatic) case value when /74\D*00$/; define_ic(name, value, 14, {a: 1, b: 2, y: 3}, {a: 4, b: 5, y: 6}, {a: 13, b: 12, y: 11}, {a: 10, b: 9, y: 8}, &automatic) when /74\D*04$/; define_ic(name, value, 14, [1, 2], [3, 4], [5, 6], [13, 12], [11, 10], [9, 8], &automatic) end end def probe(attenuation=20, impedance=50) jack = comp("J", "SMB", "SMB jack", "#{attenuation}x #{impedance}Ω probe") jack[2] - jack[3] - jack[4] - jack[5] if attenuation == 1 pair(jack[1], jack[2]) else pair(r((attenuation-1)*impedance) - jack[1], jack[2]) end end def btn(color="black") sw = comp("SW", "BTN", "SPST button", color) sw[1] - sw[4] sw[2] - sw[3] pair(sw[1], sw[3]) end