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/check-saved-routing.mjs
/** Prevent stale saved copper from being accepted after a source/layout edit. */
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { savedRouting } from '../circuit/saved-routing.ts'
const plan=JSON.parse(readFileSync(new URL('../circuit/route-plan.json',import.meta.url),'utf8'))
assert.equal(new Set(plan.traces.map(t=>t.pcb_trace_id)).size,plan.traces.length,'Authored trace IDs must be unique')
for (const trace of plan.traces) for (const point of trace.route) {
if (point.route_type !== 'via') continue
assert.equal(point.via_hole_diameter, 0.3, `Unexpected via hole in ${trace.pcb_trace_id}`)
assert.equal(point.via_diameter, 0.45, `Unexpected via pad in ${trace.pcb_trace_id}`)
}
const router=await savedRouting(structuredClone(plan.expectedInput))
let output
router.on('complete',event=>{output=event.traces})
router.start()
assert.deepEqual(output,plan.traces)
assert.notEqual(output,plan.traces)
for (const key of ['bounds','obstacles','connections']) {
const changed=structuredClone(plan.expectedInput)
if (key==='bounds') changed.bounds.minX-=0.1
else if(key==='obstacles') changed.obstacles[0].center.x+=0.1
else changed.connections[0].name+='-changed'
await assert.rejects(()=>savedRouting(changed),/PCB geometry, connections or routing rules changed/)
}
const changedRules=structuredClone(plan.expectedInput)
changedRules.minTraceWidth+=0.01
await assert.rejects(()=>savedRouting(changedRules),/PCB geometry, connections or routing rules changed/)
console.log('PASS: saved copper matches its input; changed outline, pad, net and routing rule are rejected.')