Skip to content

Commit

Permalink
add smb footptint (#174)
Browse files Browse the repository at this point in the history
* add smb footptint

* add snapshot

* rename circuitJson
  • Loading branch information
techmannih authored Feb 11, 2025
1 parent bfe37e7 commit 3f4ed5a
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ export { minimelf } from "./minimelf"
export { sod882d } from "./sod882d"
export { melf } from "./melf"
export { micromelf } from "./micromelf"
export { smb } from "./smb"
99 changes: 99 additions & 0 deletions src/fn/smb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import type { AnySoupElement, PcbSilkscreenPath } from "circuit-json"
import { z } from "zod"
import { rectpad } from "../helpers/rectpad"
import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef"
import { length } from "circuit-json"

export const smb_def = z.object({
fn: z.string(),
num_pins: z.literal(2).default(2),
w: z.string().default("7.30mm"),
h: z.string().default("4.40mm"),
pl: z.string().default("2.50mm"),
pw: z.string().default("2.30mm"),
p: z.string().default("4.30mm"),
})

export const smb = (
raw_params: z.input<typeof smb_def>,
): { circuitJson: AnySoupElement[]; parameters: any } => {
const parameters = smb_def.parse(raw_params)

// Define silkscreen reference text
const silkscreenRefText: SilkscreenRef = silkscreenRef(
0,
length.parse(parameters.h) / 2 + 0.5,
0.3,
)

const silkscreenLine: PcbSilkscreenPath = {
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "",
route: [
{
x: length.parse(parameters.p) / 2,
y: length.parse(parameters.h) / 2,
},
{
x: -length.parse(parameters.w) / 2 - 0.1,
y: length.parse(parameters.h) / 2,
},
{
x: -length.parse(parameters.w) / 2 - 0.1,
y: -length.parse(parameters.h) / 2,
},
{
x: length.parse(parameters.p) / 2,
y: -length.parse(parameters.h) / 2,
},
],
stroke_width: 0.1,
pcb_silkscreen_path_id: "",
}

return {
circuitJson: smbWithoutParsing(parameters).concat(
silkscreenLine as AnySoupElement,
silkscreenRefText as AnySoupElement,
),
parameters,
}
}

// Get coordinates for smb pads
export const getSmbCoords = (parameters: {
pn: number
p: number
}) => {
const { pn, p } = parameters

if (pn === 1) {
return { x: -p / 2, y: 0 }
// biome-ignore lint/style/noUselessElse: <explanation>
} else {
return { x: p / 2, y: 0 }
}
}

// Function to generate smb pads
export const smbWithoutParsing = (parameters: z.infer<typeof smb_def>) => {
const pads: AnySoupElement[] = []

for (let i = 1; i <= parameters.num_pins; i++) {
const { x, y } = getSmbCoords({
pn: i,
p: Number.parseFloat(parameters.p),
})
pads.push(
rectpad(
i,
x,
y,
Number.parseFloat(parameters.pl),
Number.parseFloat(parameters.pw),
),
)
}
return pads
}
1 change: 1 addition & 0 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export type Footprinter = {
to92: () => FootprinterParamsBuilder<"w" | "h" | "p" | "id" | "od">
minimelf: () => FootprinterParamsBuilder<"w" | "h" | "p" | "pw" | "pl">
lqfp: (num_pins?: number) => FootprinterParamsBuilder<"w" | "h" | "pl" | "pw">
smb: () => FootprinterParamsBuilder<"w" | "h" | "p" | "pl" | "pw">
sod923: () => FootprinterParamsBuilder<"w" | "h" | "p" | "pl" | "pw">
pushbutton: () => FootprinterParamsBuilder<
"tllabel" | "trlabel" | "bllabel" | "brlabel"
Expand Down
13 changes: 13 additions & 0 deletions tests/__snapshots__/smb.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/smb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"

test("smb", () => {
const circuitJson = fp.string("smb").circuitJson()
const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "smb")
})

0 comments on commit 3f4ed5a

Please sign in to comment.