Skip to content
Merged
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
2 changes: 1 addition & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions examples/led5050.example.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { JsCadView } from "jscad-fiber"
import { ExtrudedPads, Led5050 } from "../lib"

export default () => (
<JsCadView zAxisUp showGrid>
<Led5050 />
<ExtrudedPads footprint="led5050" />
</JsCadView>
)
9 changes: 6 additions & 3 deletions lib/Footprinter3d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import SOD723 from "./SOD723"
import { JSTZH1_5mm } from "./JSTZH1_5mm"
import { FPC } from "./FPC"
import { SmdPinHeader } from "./SmdPinHeader"
import { Led5050 } from "./Led5050"
import { RJ45 } from "./RJ45"

/**
Expand Down Expand Up @@ -133,6 +134,9 @@ export const Footprinter3d = ({ footprint }: { footprint: string }) => {
bodyy?: number
}

const colorMatch = footprint.match(/_color\(([^)]+)\)/)
const color = colorMatch ? colorMatch[1] : undefined

switch (fpJson.fn) {
case "dip":
return (
Expand Down Expand Up @@ -267,6 +271,8 @@ export const Footprinter3d = ({ footprint }: { footprint: string }) => {
bodyWidth={fpJson.bh}
/>
)
case "led5050":
return <Led5050 color={color} />

case "cap": {
switch (fpJson.imperial) {
Expand Down Expand Up @@ -486,9 +492,6 @@ export const Footprinter3d = ({ footprint }: { footprint: string }) => {
}
}

const colorMatch = footprint.match(/_color\(([^)]+)\)/)
const color = colorMatch ? colorMatch[1] : undefined

switch (fpJson.imperial) {
case "0402":
return <A0402 color={color} />
Expand Down
93 changes: 93 additions & 0 deletions lib/Led5050.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {
Comment thread
rushabhcodes marked this conversation as resolved.
Colorize,
Cuboid,
Cylinder,
Rotate,
Subtract,
Translate,
} from "jscad-fiber"
import { ChipBody } from "./ChipBody"

export interface Led5050Props {
color?: string
bodyColor?: string
leadColor?: string
}

export const Led5050 = ({
color = "#ffff00",
bodyColor = "#ffffff",
leadColor = "#dedede",
}: Led5050Props) => {
const bodySize = 5
const leadSpan = 5.4
const bodyBottom = 0.2
const bodyHeight = 1.3
const bodyTop = bodyBottom + bodyHeight
const leadLength = 1.4
const leadWidth = 1
const leadThickness = 0.2
const leadCenterX = leadSpan / 2 - leadLength / 2
const lensRadius = 2
const lensHeight = 0.25
const lensTop = 1.55
const cornerCutDepth = 0.3
const leadYPositions = [-1.7, 0, 1.7]
const leadSides = [-1, 1]

return (
<>
{leadYPositions.flatMap((y) =>
leadSides.map((side) => (
<Cuboid
key={`${side}-${y}`}
color={leadColor}
size={[leadLength, leadWidth, leadThickness]}
center={[side * leadCenterX, y, leadThickness / 2]}
/>
)),
)}

<Colorize color={bodyColor}>
<Subtract>
<ChipBody
width={bodySize}
length={bodySize}
height={bodyHeight}
heightAboveSurface={bodyBottom}
center={{ x: 0, y: 0, z: 0 }}
color={bodyColor}
taperRatio={0.036}
straightHeightRatio={0.01}
includeNotch={false}
/>
<Cylinder
radius={lensRadius}
height={lensHeight}
center={[0, 0, bodyTop - lensHeight / 2]}
/>
<Translate
offset={[
-bodySize / 2,
bodySize / 2,
bodyTop - cornerCutDepth / 2 + 0.005,
]}
>
<Rotate rotation={[0, 0, Math.PI / 4]}>
<Cuboid size={[0.9, 0.9, cornerCutDepth + 0.01]} />
</Rotate>
</Translate>
</Subtract>
</Colorize>

<Cylinder
color={color}
radius={lensRadius}
height={lensHeight}
center={[0, 0, lensTop - lensHeight / 2]}
/>
</>
)
}

export default Led5050
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ export * from "./MountedPcbModule"
export * from "./Screen"
export * from "./JSTZH1_5mm"
export * from "./FPC"
export * from "./Led5050"
export * from "./RJ45"
Binary file added tests/snapshots/__snapshots__/led5050.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions tests/snapshots/led5050.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, test } from "bun:test"
import "../fixtures/png-matcher"
import { renderFootprint } from "../helpers/render-footprint"

test("led5050", async () => {
const pngBuffer = await renderFootprint("led5050")
await expect(pngBuffer).toMatchPngSnapshot(import.meta.path)
})
Loading