MustafaMulla29/usb-pd-motherboard
4-layer USB-C PD hub motherboard with 20 V USB-C input, Linux T113-S3 computer, CH338F USB hub, four individually controlled 5–20 V PD outputs, USB data/camera ports, regulated rails, and hardware watchdog/E-stop safety interlock.
- Version
- 1.0.24
- License
- unset
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone MustafaMulla29/usb-pd-motherboard # download the package files into ./usb-pd-motherboard
tsci add MustafaMulla29/usb-pd-motherboard # add it to your project as @tsci/MustafaMulla29.usb-pd-motherboardIn a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.
enclosure/build.tsx
// Build the enclosure: JSCAD plans per printed part, native tscircuit assembly check, then STL/GLB through
// export_solid.py (Manifold solid kernel). Run from the project root with: bun run enclosure:build
import { mkdir, writeFile } from "node:fs/promises"
import { Circuit } from "tscircuit"
import { renderToJscadPlan } from "jscad-fiber/headless"
import { executeJscadOperations } from "jscad-planner"
import modeling from "@jscad/modeling"
import Enclosure from "./enclosure.circuit"
import { printableParts, printOrientation, printQuantity } from "./parts"
import { body, design, openings } from "./dimensions"
import reference from "./reference-board.json"
import { measure } from "./measure-reference"
process.chdir(import.meta.dir)
await mkdir("dist", { recursive: true })
// The enclosure is drawn from reference-board.json. Stop if the built board no longer matches it.
const current = measure(), strip = (r: any) => JSON.stringify({ ...r, sha256: undefined })
if (strip(current) !== strip(reference)) throw new Error("Board changed since reference-board.json: run `bun enclosure/measure-reference.ts` and review the enclosure")
const report: any = { boardSha256: current.sha256, outside: { width: 2 * body.outerHalfX, depth: 2 * body.outerHalfY, height: design.top - design.bottom }, design, openings, parts: {} }
for (const [name, Part] of Object.entries(printableParts)) {
const plan = renderToJscadPlan(<Part />)
const shape = executeJscadOperations(modeling as any, plan)
const bounds = modeling.measurements.measureBoundingBox(shape)
const volume = modeling.measurements.measureVolume(shape)
if (!(volume > 0)) throw new Error(`Empty part ${name}`)
await writeFile(`dist/${name}.jscad.json`, JSON.stringify(plan))
report.parts[name] = { bounds, volumeMm3: volume, printQuantity: printQuantity[name], printOrientation: printOrientation[name] }
console.log(`${name}: ${(volume / 1000).toFixed(1)} cm³, bounds ${bounds.map((b: number[]) => b.map((v) => v.toFixed(2)).join(",")).join(" → ")}`)
}
const circuit = new Circuit()
circuit.add(<Enclosure />)
await circuit.renderUntilSettled()
const json = circuit.getCircuitJson()
const errors = json.filter((r: any) => r.type.endsWith("_error"))
report.nativeAssemblyErrors = errors
await writeFile("dist/enclosure.circuit.json", JSON.stringify(json))
await writeFile("dist/build-report.json", JSON.stringify(report, null, 2) + "\n")
if (errors.length) throw new Error("tscircuit assembly errors:\n" + errors.map((e: any) => `${e.type}: ${e.message}`).join("\n"))
const exporter = Bun.spawn([".venv/bin/python", "export_solid.py"], { stdout: "inherit", stderr: "inherit" })
if ((await exporter.exited) !== 0) throw new Error("Solid export failed")
console.log("Wrote enclosure/dist: STL (print orientation), assembled GLB per part, build-report.json")