Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/fn/jst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,20 @@ function generateSilkscreenBody(
numPins?: number,
p?: number,
): PcbSilkscreenPath {
if (variant === "ph") {
if (variant === "ph" && numPins && p) {
const pinSpan = (numPins - 1) * p
const bodyLeft = -pinSpan / 2 - 1.5
const bodyRight = pinSpan / 2 + 1.5
return {
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "",
route: [
{ x: -3, y: 3 },
{ x: 3, y: 3 },
{ x: 3, y: -2 },
{ x: -3, y: -2 },
{ x: -3, y: 3 },
{ x: bodyLeft, y: 3 },
{ x: bodyRight, y: 3 },
{ x: bodyRight, y: -2 },
{ x: bodyLeft, y: -2 },
{ x: bodyLeft, y: 3 },
],
stroke_width: 0.1,
pcb_silkscreen_path_id: "",
Expand Down Expand Up @@ -222,6 +225,8 @@ export const jst = (
const str = typeof raw_params.string === "string" ? raw_params.string : ""
const match = str.match(/(?:^|_)jst(\d+)(?:_|$)/)
const zhMatch = str.match(/(?:^|_)zh(\d+)(?:_|$)/)
// Match trailing pin count after variant, e.g. jst_ph_4, jst_sh_6
const trailingMatch = str.match(/(?:^|_)(\d+)(?:_|$)/)
if (match && match[1]) {
const parsed = Number.parseInt(match[1], 10)
if (!Number.isNaN(parsed)) {
Expand All @@ -234,6 +239,12 @@ export const jst = (
numPins = parsed
}
}
if (typeof numPins !== "number" && trailingMatch && trailingMatch[1]) {
const parsed = Number.parseInt(trailingMatch[1], 10)
if (!Number.isNaN(parsed)) {
numPins = parsed
}
}

if (typeof numPins !== "number") {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/jst.test.tsjst2_ph.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/__snapshots__/jst_ph_4.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions tests/jst_ph_4.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect, test } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("jst_ph_4 generates 4 pads", () => {
const circuitJson = fp.string("jst_ph_4").circuitJson()

const platedHoles = circuitJson.filter((e) => e.type === "pcb_plated_hole")
expect(platedHoles.length).toBe(4)

const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(import.meta.path)
})
1 change: 1 addition & 0 deletions tests/kicad-parity/__snapshots__/jst_ph_4.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading