Skip to content

Commit

Permalink
Added Footprint To-92 (#123)
Browse files Browse the repository at this point in the history
* added to92 footprinter

* modify to92 footprinter

* modify to92 footprinter od and id

* modify to92 footprinter

* added to92 and to92_inline
  • Loading branch information
Rishikesh63 authored Feb 4, 2025
1 parent d63e0fa commit 507f740
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 0 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions src/fn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export { sot235 } from "./sot235"
export { breakoutheaders } from "./breakoutheaders"
export { hc49 } from "./hc49"
export { pad } from "./pad"
export { to92 } from "./to92"
86 changes: 86 additions & 0 deletions src/fn/to92.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
length,
type AnySoupElement,
type PcbSilkscreenPath,
} from "circuit-json"
import { z } from "zod"
import { platedhole } from "src/helpers/platedhole"
import { silkscreenRef, type SilkscreenRef } from "../helpers/silkscreenRef"

const generate_semicircle = (
centerX: number,
centerY: number,
radius: number,
) => {
return Array.from({ length: 25 }, (_, i) => {
const theta = (i / 24) * Math.PI
return {
x: centerX + Math.cos(theta) * radius,
y: centerY + Math.sin(theta) * radius,
}
})
}

export const to92_def = z.object({
fn: z.string(),
p: length.optional().default("1.27mm"),
id: length.optional().default("0.72mm"),
od: length.optional().default(".95mm"),
w: length.optional().default("4.5mm"),
h: length.optional().default("4.5mm"),
arrangement: z
.enum(["triangular", "inline"])
.optional()
.default("triangular"),
})

export type To92Def = z.input<typeof to92_def>

export const to92 = (
raw_params: To92Def,
): { circuitJson: AnySoupElement[]; parameters: any } => {
const parameters = to92_def.parse(raw_params)
const { p, id, od, w, h, arrangement } = parameters
const radius = w / 2
const holeY = h / 2

const plated_holes =
arrangement === "triangular"
? [
platedhole(1, 0, holeY, id, od),
platedhole(2, -p, holeY - p, id, od),
platedhole(3, p, holeY - p, id, od),
]
: [
platedhole(1, -p, holeY, id, od),
platedhole(2, 0, holeY, id, od),
platedhole(3, p, holeY, id, od),
]

const semicircle = generate_semicircle(0, h / 2, radius)

const silkscreenBody: PcbSilkscreenPath = {
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "",
route: [
...semicircle,
{ x: -radius, y: 0 },
{ x: radius, y: 0 },
semicircle[0],
],
stroke_width: 0.1,
pcb_silkscreen_path_id: "",
}

const silkscreenRefText: SilkscreenRef = silkscreenRef(0, h / 2 + 1, 0.5)

return {
circuitJson: [
...plated_holes,
silkscreenBody,
silkscreenRefText as AnySoupElement,
],
parameters,
}
}
1 change: 1 addition & 0 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type Footprinter = {
axial: () => FootprinterParamsBuilder<"p" | "id" | "od">
hc49: () => FootprinterParamsBuilder<"p" | "id" | "od" | "w" | "h">
sot235: () => FootprinterParamsBuilder<"h" | "p" | "pl" | "pw">
to92: () => FootprinterParamsBuilder<"w" | "h" | "p" | "id" | "od">
lqfp: (num_pins?: number) => FootprinterParamsBuilder<"w" | "h" | "pl" | "pw">
pushbutton: () => FootprinterParamsBuilder<
"tllabel" | "trlabel" | "bllabel" | "brlabel"
Expand Down
13 changes: 13 additions & 0 deletions tests/__snapshots__/to92_inline.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/__snapshots__/to92_triangular.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions tests/to92.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test, expect } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { to92 } from "../src/fn/to92"

test("to92 (triangular)", () => {
const soup = to92({ fn: "to92", arrangement: "triangular" }).circuitJson
const svgContent = convertCircuitJsonToPcbSvg(soup)

expect(soup).toBeDefined()
expect(soup.length).toBeGreaterThan(0)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "to92_triangular")
})

test("to92_inline (inline)", () => {
const soup = to92({ fn: "to92_inline", arrangement: "inline" }).circuitJson
const svgContent = convertCircuitJsonToPcbSvg(soup)

expect(soup).toBeDefined()
expect(soup.length).toBeGreaterThan(0)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "to92_inline")
})

0 comments on commit 507f740

Please sign in to comment.