-
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.
* add micromelf footprint * rename micromelf_def * update micromelf
- Loading branch information
1 parent
e795a13
commit e68afd7
Showing
4 changed files
with
122 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,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 micromelf_def = z.object({ | ||
fn: z.string(), | ||
num_pins: z.literal(2).default(2), | ||
w: z.string().default("3.0mm"), | ||
h: z.string().default("1.80mm"), | ||
pl: z.string().default("0.80mm"), | ||
pw: z.string().default("1.20mm"), | ||
pad_spacing: z.string().default("1.6mm"), | ||
}) | ||
|
||
export const micromelf = ( | ||
raw_params: z.input<typeof micromelf_def>, | ||
): { circuitJson: AnySoupElement[]; parameters: any } => { | ||
const parameters = micromelf_def.parse(raw_params) | ||
|
||
// Define silkscreen reference text | ||
const silkscreenRefText: SilkscreenRef = silkscreenRef( | ||
0, | ||
length.parse(parameters.h), | ||
0.3, | ||
) | ||
|
||
const silkscreenLine: PcbSilkscreenPath = { | ||
type: "pcb_silkscreen_path", | ||
layer: "top", | ||
pcb_component_id: "", | ||
route: [ | ||
{ | ||
x: length.parse(parameters.pad_spacing) / 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.pad_spacing) / 2, | ||
y: -length.parse(parameters.h) / 2, | ||
}, | ||
], | ||
stroke_width: 0.1, | ||
pcb_silkscreen_path_id: "", | ||
} | ||
|
||
return { | ||
circuitJson: microMelfWithoutParsing(parameters).concat( | ||
silkscreenLine as AnySoupElement, | ||
silkscreenRefText as AnySoupElement, | ||
), | ||
parameters, | ||
} | ||
} | ||
|
||
export const getMicroMelfCoords = (parameters: { | ||
pn: number | ||
pad_spacing: number | ||
}) => { | ||
const { pn, pad_spacing } = parameters | ||
|
||
if (pn === 1) { | ||
return { x: -pad_spacing / 2, y: 0 } | ||
// biome-ignore lint/style/noUselessElse: <explanation> | ||
} else { | ||
return { x: pad_spacing / 2, y: 0 } | ||
} | ||
} | ||
|
||
export const microMelfWithoutParsing = ( | ||
parameters: z.infer<typeof micromelf_def>, | ||
) => { | ||
const pads: AnySoupElement[] = [] | ||
|
||
for (let i = 1; i <= parameters.num_pins; i++) { | ||
const { x, y } = getMicroMelfCoords({ | ||
pn: i, | ||
pad_spacing: Number.parseFloat(parameters.pad_spacing), | ||
}) | ||
pads.push( | ||
rectpad( | ||
i, | ||
x, | ||
y, | ||
Number.parseFloat(parameters.pl), | ||
Number.parseFloat(parameters.pw), | ||
), | ||
) | ||
} | ||
return pads | ||
} |
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,9 @@ | ||
import { test, expect } from "bun:test" | ||
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg" | ||
import { fp } from "../src/footprinter" | ||
|
||
test("micromelf", () => { | ||
const circuitJson = fp.string("micromelf").circuitJson() | ||
const svgContent = convertCircuitJsonToPcbSvg(circuitJson) | ||
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "micromelf") | ||
}) |