-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added to92 footprinter * modify to92 footprinter * modify to92 footprinter od and id * modify to92 footprinter * added to92 and to92_inline
- Loading branch information
1 parent
d63e0fa
commit 507f740
Showing
7 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}) |