imrishabh18/rp2040-motor-controller

A library of PCB component definitions covering MOSFETs, motor drivers, USB-PD control, sensors, current monitors, transistors, diodes, resistors, speakers, connectors, and mirrored bottom-side logos, with pin mappings, footprints, and 3D models.

Version
1.0.55
License
unset
Stars
5

scripts/export-schematic-snapshots.ts

import {convertCircuitJsonToSchematicSvg} from 'circuit-to-svg';
import {Resvg} from '@resvg/resvg-js';
import {getSchematicElementBounds} from '@tscircuit/circuit-json-util';
import {resolve} from 'node:path';
const json=await Bun.file('dist/index/circuit.json').json();
const output=resolve(process.argv[2] ?? '../../outputs/pg-power-good');
const sheets=json.filter((e:any)=>e.type==='schematic_sheet').sort((a:any,b:any)=>(a.sheet_index??0)-(b.sheet_index??0));
for(const sheet of sheets) {
 const scoped=json.filter((e:any)=>!e.type.startsWith('schematic_') || e.schematic_sheet_id===sheet.schematic_sheet_id);
 const full=convertCircuitJsonToSchematicSvg(scoped,{schematicSheetId:sheet.schematic_sheet_id,width:1800,height:1273});
 await Bun.write(`${output}/print/${sheet.name}.svg`,full);
 // A content-only projection for easy on-screen reading; printable A4 drawings remain included.
 const content=scoped.filter((e:any)=>e.type!=='schematic_sheet');
 const bounds=content.filter((e:any)=>['schematic_component','schematic_trace','schematic_net_label'].includes(e.type)).map((e:any)=>getSchematicElementBounds(e)).filter(Boolean);
 const minX=Math.min(...bounds.map((b:any)=>b.minX)),maxX=Math.max(...bounds.map((b:any)=>b.maxX));
 const minY=Math.min(...bounds.map((b:any)=>b.minY)),maxY=Math.max(...bounds.map((b:any)=>b.maxY));
 const height=Math.max(450,Math.round(1800*(maxY-minY+2)/(maxX-minX+2)));
 const svg=convertCircuitJsonToSchematicSvg(content,{width:1800,height});
 await Bun.write(`${output}/${sheet.name}.svg`,svg);
 await Bun.write(`${output}/${sheet.name}.png`,new Resvg(svg).render().asPng());
}
const html=`<!doctype html><html><head><meta charset="utf-8"><title>RP2040 motor controller — PG readback</title><style>body{font:16px system-ui;background:#f4f5f7;color:#142334;margin:0;padding:32px}main{max-width:1500px;margin:auto}h1{font-size:28px}p{line-height:1.5}.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(550px,1fr));gap:24px}article{background:white;border:1px solid #dfe5ed;border-radius:12px;padding:20px}h2{font-size:20px;margin:0 0 12px}img{width:100%;height:auto}a{color:#126ac1}</style></head><body><main><h1>RP2040 motor controller schematic</h1><p>Protected PG readback on GPIO7. All new components are on top. Functional groups with automatic component layout. Ten sheets; zero issues from the latest schematic style analyzer. Click a drawing to open the scalable SVG. Printable A4 drawings are in the print folder.</p><div class="grid">${sheets.map((s:any)=>`<article><h2>${s.sheet_index}. ${s.display_name??s.name}</h2><a href="${s.name}.svg"><img src="${s.name}.svg" alt="${s.display_name??s.name}"></a><p><a href="${s.name}.png">PNG snapshot</a> · <a href="print/${s.name}.svg">A4 sheet</a></p></article>`).join('')}</div></main></body></html>`;
await Bun.write(`${output}/index.html`,html);
console.log(JSON.stringify({output,snapshots:sheets.length}));