gokul/fieldkit-usb

USB-C-powered ESP32-S3 Wi-Fi/Bluetooth handheld with an SMD 128x32 OLED, six navigation buttons, USB-C power/data, complete checked routing, and four native schematic sheets.

Version
0.4.2
License
UNLICENSED
Stars
0

scripts/fabrication-tables.ts

import { readFile, writeFile } from "node:fs/promises"

const circuit = JSON.parse(await readFile("dist/index/circuit.json", "utf8"))
const sources = circuit.filter((item: any) => item.type === "source_component")
const pcbBySource = new Map(circuit.filter((item: any) => item.type === "pcb_component").map((item: any) => [item.source_component_id, item]))
const csvCell = (value: unknown) => `"${String(value ?? "").replaceAll('"', '""')}"`
const value = (part: any) => part.display_resistance?.replace("Ω", "") ?? part.display_capacitance ?? part.display_inductance ?? ""
const footprint = (part: any) => {
  const pcb: any = pcbBySource.get(part.source_component_id)
  if (part.ftype === "simple_resistor") return "res0603"
  if (part.ftype === "simple_capacitor") return Math.max(pcb.width, pcb.height) > 2.6 ? "cap0805" : "cap0603"
  return part.supplier_part_numbers.jlcpcb[0]
}

const bom = [["Designator", "Comment", "Value", "Footprint", "JLCPCB Part #"]]
for (const part of sources) {
  const jlc = part.supplier_part_numbers?.jlcpcb?.[0]
  if (!jlc) throw new Error(`${part.name} has no JLCPCB part number`)
  const val = value(part)
  bom.push([part.name, val, val || jlc, footprint(part), jlc])
}
await writeFile("fabrication/jlcpcb-bom.csv", bom.map(row => row.map(csvCell).join(",")).join("\n") + "\n")

const placements = [["Designator", "Mid X", "Mid Y", "Layer", "Rotation"]]
for (const part of sources) {
  const pcb: any = pcbBySource.get(part.source_component_id)
  if (!pcb) throw new Error(`${part.name} has no PCB component`)
  placements.push([part.name, pcb.center.x.toFixed(3), pcb.center.y.toFixed(3), pcb.layer, String(pcb.rotation ?? 0)])
}
await writeFile("fabrication/jlcpcb-top-placement.csv", placements.map(row => row.join(",")).join("\n") + "\n")