MustafaMulla29/rp2040-bldc-motor-controller

Hardware assembly metadata and PCB geometry for a controller board with a snap-off rotary-encoder section, plus four parallel 150 µF/50 V bulk electrolytic capacitors filtering the motor supply.

Version
2.0.40
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone MustafaMulla29/rp2040-bldc-motor-controller  # download the package files into ./rp2040-bldc-motor-controller
tsci add MustafaMulla29/rp2040-bldc-motor-controller    # add it to your project as @tsci/MustafaMulla29.rp2040-bldc-motor-controller

In 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.

scripts/check-schematic-invariants.mjs

/** Compare a schematic-only edit against a previously validated full build.
 * Usage: bun scripts/check-schematic-invariants.mjs BEFORE AFTER
 * IDs can change when presentation sections change; compare named connectivity
 * and the actual PCB geometry, never the schematic rendering's pixel output.
 */
import { readFileSync } from 'node:fs'
import assert from 'node:assert/strict'
const [beforePath,afterPath] = process.argv.slice(2)
if (!beforePath || !afterPath) throw new Error('Supply BEFORE and AFTER circuit JSON paths')
const before=JSON.parse(readFileSync(beforePath,'utf8'))
const after=JSON.parse(readFileSync(afterPath,'utf8'))
const stable=x=>JSON.stringify(x)
const sorted=xs=>xs.sort((a,b)=>stable(a).localeCompare(stable(b)))
function signature(json) {
  const components=new Map(json.filter(x=>x.type==='source_component').map(x=>[x.source_component_id,x.name]))
  const ports=new Map(json.filter(x=>x.type==='source_port').map(x=>[x.source_port_id,`${components.get(x.source_component_id) ?? x.source_component_id}:${x.pin_number ?? x.name}`]))
  const netNames=new Map()
  for(const n of json.filter(x=>x.type==='source_net')) {
    const k=n.subcircuit_connectivity_map_key
    if(k) netNames.set(k,[...(netNames.get(k)??[]),n.name].sort())
  }
  const connectivity=sorted(json.filter(x=>x.type==='source_port' && components.has(x.source_component_id)).map(x=>({
    port:ports.get(x.source_port_id), nets:netNames.get(x.subcircuit_connectivity_map_key)??[],
  })))
  function clean(x) {
    if(Array.isArray(x))return x.map(clean)
    if(!x || typeof x!=='object')return x
    const out={}
    for(const key of Object.keys(x).sort()) {
      if(/(^|_)id$|(^|_)ids$/.test(key) || key==='subcircuit_connectivity_map_key')continue
      out[key]=clean(x[key])
    }
    if(x.source_component_id && components.has(x.source_component_id))out.component=components.get(x.source_component_id)
    if(x.source_port_id && ports.has(x.source_port_id))out.port=ports.get(x.source_port_id)
    if(x.subcircuit_connectivity_map_key && netNames.has(x.subcircuit_connectivity_map_key))out.nets=netNames.get(x.subcircuit_connectivity_map_key)
    return out
  }
  const parts=sorted(json.filter(x=>x.type==='source_component').map(clean))
  const pcb=sorted(json.filter(x=>x.type.startsWith('pcb_') && !x.type.endsWith('_error') && !x.type.endsWith('_warning')).map(clean))
  assert(pcb.some(x=>x.type==='pcb_trace'),'Full routed build is required')
  return {connectivity,parts,pcb}
}
const a=signature(before),b=signature(after)
for(const key of ['connectivity','parts','pcb']) {
  assert.deepEqual(b[key],a[key],`${key} changed during schematic cleanup`)
  console.log(`PASS ${key}: ${b[key].length} records unchanged`)
}