feat: add led5050 and led2835 footprints#512
feat: add led5050 and led2835 footprints#512dagangtj wants to merge 2 commits intotscircuit:mainfrom
Conversation
- led5050: 5.0mm x 5.0mm 6-pin RGB LED - led2835: 2.8mm x 3.5mm 2-pin SMD LED - Common LED packages for lighting applications Closes tscircuit#122
| export const led2835_def = z.object({ | ||
| fn: z.string().default("led2835"), | ||
| num_pins: z.number().default(2), | ||
| }) | ||
|
|
||
| /** | ||
| * LED 2835 footprint (2.8mm x 3.5mm SMD LED) | ||
| * Common 2-pin white/single color LED package | ||
| */ | ||
| export const led2835 = ( | ||
| parameters: z.input<typeof led2835_def>, | ||
| ): { circuitJson: AnySoupElement[]; parameters: any } => { | ||
| const pads: AnySoupElement[] = [] | ||
|
|
||
| // 2835 LED: 2.8mm x 3.5mm body, 2 pads | ||
| const padWidth = 0.9 | ||
| const padHeight = 2.8 | ||
| const xOffset = 1.45 | ||
|
|
||
| pads.push(rectpad(1, -xOffset, 0, padWidth, padHeight)) | ||
| pads.push(rectpad(2, xOffset, 0, padWidth, padHeight)) | ||
|
|
||
| return { | ||
| circuitJson: [...pads, silkscreenRef(0, 2.2, 0.5)], | ||
| parameters, | ||
| } |
There was a problem hiding this comment.
The num_pins parameter is defined in the schema (line 8) but never validated or used in the function implementation. The function always generates exactly 2 pads regardless of this parameter value. This creates a misleading API where users might expect to configure the pin count, but changes to this parameter will be silently ignored.
If num_pins should be fixed at 2, remove it from the schema:
export const led2835_def = z.object({
fn: z.string().default("led2835"),
})Or if it should be configurable, the schema needs to be parsed and the parameter needs to be used:
const parsed = led2835_def.parse(parameters)
const numPins = parsed.num_pins
// Then generate pads based on numPins| export const led2835_def = z.object({ | |
| fn: z.string().default("led2835"), | |
| num_pins: z.number().default(2), | |
| }) | |
| /** | |
| * LED 2835 footprint (2.8mm x 3.5mm SMD LED) | |
| * Common 2-pin white/single color LED package | |
| */ | |
| export const led2835 = ( | |
| parameters: z.input<typeof led2835_def>, | |
| ): { circuitJson: AnySoupElement[]; parameters: any } => { | |
| const pads: AnySoupElement[] = [] | |
| // 2835 LED: 2.8mm x 3.5mm body, 2 pads | |
| const padWidth = 0.9 | |
| const padHeight = 2.8 | |
| const xOffset = 1.45 | |
| pads.push(rectpad(1, -xOffset, 0, padWidth, padHeight)) | |
| pads.push(rectpad(2, xOffset, 0, padWidth, padHeight)) | |
| return { | |
| circuitJson: [...pads, silkscreenRef(0, 2.2, 0.5)], | |
| parameters, | |
| } | |
| export const led2835_def = z.object({ | |
| fn: z.string().default("led2835"), | |
| }) | |
| /** | |
| * LED 2835 footprint (2.8mm x 3.5mm SMD LED) | |
| * Common 2-pin white/single color LED package | |
| */ | |
| export const led2835 = ( | |
| parameters: z.input<typeof led2835_def>, | |
| ): { circuitJson: AnySoupElement[]; parameters: any } => { | |
| const pads: AnySoupElement[] = [] | |
| // 2835 LED: 2.8mm x 3.5mm body, 2 pads | |
| const padWidth = 0.9 | |
| const padHeight = 2.8 | |
| const xOffset = 1.45 | |
| pads.push(rectpad(1, -xOffset, 0, padWidth, padHeight)) | |
| pads.push(rectpad(2, xOffset, 0, padWidth, padHeight)) | |
| return { | |
| circuitJson: [...pads, silkscreenRef(0, 2.2, 0.5)], | |
| parameters, | |
| } | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
As suggested by graphite-app[bot], the num_pins parameter was defined but never validated or used in the function implementation. Since these LED footprints have fixed pin counts (2 for 2835, 6 for 5050), removed the misleading parameter from the schema.
|
@graphite-app[bot] Thanks for the review! I've removed the unused parameter from both and schemas as suggested. Since these LED footprints have fixed pin counts, the parameter was indeed misleading. Fixed in commit 54e662f. |
Adds support for common SMD LED footprints.
Changes
led5050: 5.0mm x 5.0mm 6-pin RGB LED packageled2835: 2.8mm x 3.5mm 2-pin SMD LED packageThese are widely used LED packages for lighting applications.
Closes #122