imrishabh18/nema-23-stepper-controller

A four-layer NEMA23 stepper motor controller PCB featuring an RP2040 MCU, DRV8452 dual-phase driver, USB‑C PD power input/protection, current and temperature sensing, status LED/buzzer, and optional magnetic encoder.

Version
1.3.2
License
unset
Stars
1

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)}) },
  }
}