mohan-bee/mini-mp3-player

Portable, battery-powered MP3 player hardware with USB charging, microSD storage, an MCU, VS10xx audio decoder, headphone output, status controls, and regulated power rails.

Version
1.2.0
License
unset
Stars
0

routing/saved-autorouting.ts

import saved from './autorouter-result.json'

// Preserve the autorouter result and its documented, local via-clearance repair.
// Never reuse copper after the routing input (placement, nets or rules) changes.
const canonical = (value: unknown) => JSON.stringify(value, (_key, item) =>
  item && typeof item === 'object' && !Array.isArray(item)
    ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b)))
    : item)

export async function savedAutorouting(input: unknown) {
  if (canonical(input) !== canonical(saved.input)) {
    throw new Error('Saved routing does not match this PCB. Remove algorithmFn:savedAutorouting from the board to reroute, then validate and refresh the saved result.')
  }
  const listeners = new Map<string, (event: { traces: typeof saved.traces }) => void>()
  return {
    on(event: string, listener: (event: { traces: typeof saved.traces }) => void) {
      listeners.set(event, listener)
    },
    start() {
      listeners.get('complete')?.({ traces: JSON.parse(JSON.stringify(saved.traces)) })
    },
    stop() {
      listeners.clear()
    },
  }
}