imrishabh18/nema-23-stepper-controller

A 57 mm four-layer RP2040 NEMA23 stepper-controller PCB with USB‑C/USB‑PD power input, protected motor rail, DRV8452 dual-winding driver, bidirectional current sensing, temperature/enable interlock, optional magnetic encoder, RGB LED and buzzer status indicators, and motor/test connectors.

Version
1.2.3
License
unset
Stars
0

routing/saved-routing.ts

import plan from './route-plan.json'

function canonical(value: any): string {
  const normalize = (v: any): any => typeof v === 'number' ? Math.round(v * 1e8) / 1e8
    : Array.isArray(v) ? v.map(normalize)
    : v && typeof v === 'object' ? Object.fromEntries(Object.keys(v).sort().map(k => [k, normalize(v[k])])) : v
  return JSON.stringify(normalize(value))
}
/** Validated fixed routing. Core still regenerates copper pours, vias and DRC.
 * Editing PCB geometry/connectivity requires regenerating and validating routes.
 */
export const savedRouting = async (input: unknown) => {
  if(canonical(input) !== canonical(plan.expectedInput))
    throw new Error('PCB geometry/connectivity changed. Regenerate and validate routing/route-plan.json; do not reuse stale routes.')
  const handlers = new Map<string, (event: any) => void>()
  return {
    on(name: string, fn: (event: any) => void) { handlers.set(name, fn) },
    stop() {},
    start() { handlers.get('complete')?.({traces: structuredClone(plan.traces)}) },
  }
}