MustafaMulla29/rp2040-bldc-motor-controller-new
A USB‑C PD–powered RP2040 BLDC motor controller PCB with 3.3 V logic, MCT8329A sensorless commutation, three MOSFET half-bridges, protected power switching, USB data, controls, and motor connectors.
- Version
- 0.3.82
- License
- unset
- Stars
- 0
scripts/render-schematic.mjs
/** Schematic-only preview. It is deliberately not evidence of PCB routing. */
import { Circuit } from "@tscircuit/core"
import { convertCircuitJsonToSchematicSvg, convertCircuitJsonToStackedSchematicSheetsSvg } from "circuit-to-svg"
import { Resvg } from "@resvg/resvg-js"
import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync } from "node:fs"
import Board from "../index.circuit.tsx"
// A supplied build artifact avoids rendering the same circuit twice.
let json
if (process.argv[2]) {
json = JSON.parse(readFileSync(process.argv[2], "utf8"))
} else {
const circuit = new Circuit({ platform: { partsEngineDisabled: true, pcbDisabled: true, routingDisabled: true } })
circuit.add(Board({ routingDisabled: true }))
await circuit.renderUntilSettled()
json = circuit.getCircuitJson()
}
const outputDir = ".tscircuit/schematics"
mkdirSync(outputDir, { recursive: true })
writeFileSync(`${outputDir}/circuit.json`, JSON.stringify(json, null, 2))
const sheets = json.filter(x => x.type === "schematic_sheet")
const expected = new Set(sheets.flatMap(s => ["svg", "png"].map(ext => `${String(s.sheet_index + 1).padStart(2, "0")}-${s.name}.${ext}`)))
for (const file of readdirSync(outputDir)) {
if (/^\d{2}-.*\.(svg|png)$/.test(file) && !expected.has(file)) unlinkSync(`${outputDir}/${file}`)
}
for (const sheet of sheets) {
const prefix = `${outputDir}/${String(sheet.sheet_index + 1).padStart(2, "0")}-${sheet.name}`
const page = convertCircuitJsonToSchematicSvg(json, { width: 2400, height: 1553, schematicSheetIndex: sheet.sheet_index })
writeFileSync(prefix + ".svg", page)
writeFileSync(prefix + ".png", new Resvg(page).render().asPng())
}
const svg = convertCircuitJsonToStackedSchematicSheetsSvg(json, { width: 1200, height: 777 })
writeFileSync(`${outputDir}/all-sheets.svg`, svg)
console.log(`Rendered ${sheets.length} native schematic sheets in ${outputDir}; ${process.argv[2] ? "from " + process.argv[2] : "PCB intentionally unrouted"}.`)