mohan-bee/infrared-battle-tag

A compact board featuring an ATtiny1616 microcontroller, tactile switch, and MMBT2222A transistor, with VCC/GND power and the switch connected to the MCU’s PA4 input.

Version
1.0.2
License
unset
Stars
0

evidence/verify-connectivity.ts

// Independent intended-net audit of the final routed circuit, using physical pin numbers.
const circuit = await Bun.file("dist/index/circuit.json").json()
const components = new Map(circuit.filter((x: any) => x.type === "source_component").map((x: any) => [x.name, x.source_component_id]))
function net(ref: string) {
  const [name, pin] = ref.split(".")
  const port = circuit.find((x: any) => x.type === "source_port" && x.source_component_id === components.get(name) && x.pin_number === Number(pin))
  if (!port) throw new Error(`Missing ${ref}`)
  const internal = circuit.filter((x: any) => x.type === "source_component_internal_connection" && x.source_port_ids.includes(port.source_port_id))
  const peers = new Set([port.source_port_id, ...internal.flatMap((x: any) => x.source_port_ids)])
  const keys = new Set(circuit.filter((x: any) => x.type === "source_port" && peers.has(x.source_port_id) && x.subcircuit_connectivity_map_key).map((x: any) => x.subcircuit_connectivity_map_key))
  if (keys.size !== 1) throw new Error(`Unconnected or conflicting internal net: ${ref}`)
  return [...keys][0]
}
const expected = [
  ["J1.1", "D1.2"],
  ["D1.1", "U1.1", "C1.1", "C2.1", "R1.1", "R4.1", "R8.1", "R9.1", "J2.1"],
  ["J1.2", "U1.20", "C1.2", "C2.2", "Q1.2", "R3.2", "U2.2", "C3.2", "LED2.2", "LED3.2", "LED4.2", "SW1.3", "SW1.4", "SW2.3", "SW2.4", "J2.3"],
  ["U1.2", "R2.1"], ["R2.2", "R3.1", "Q1.1"],
  ["R1.2", "LED1.1"], ["LED1.2", "Q1.3"],
  ["R4.2", "C3.1", "U2.3"], ["U2.1", "U1.17"],
  ["U1.16", "J2.2"],
  ["U1.10", "SW1.1", "SW1.2", "R8.2"],
  ["U1.11", "SW2.1", "SW2.2", "R9.2"],
  ["U1.3", "R5.1"], ["U1.4", "R6.1"], ["U1.5", "R7.1"],
  ["R5.2", "LED2.1"], ["R6.2", "LED3.1"], ["R7.2", "LED4.1"],
]
for (const pins of expected) {
  if (new Set(pins.map(net)).size !== 1) throw new Error(`Net mismatch: ${pins.join(", ")}`)
}
if (new Set(expected.map(pins => net(pins[0]))).size !== expected.length) throw new Error("Unintended merged nets")
const errors = circuit.filter((x: any) => x.type.endsWith("_error"))
if (errors.length) throw new Error(JSON.stringify(errors))
console.log(`PASS: ${expected.length} intended nets, ${expected.flat().length} physical pins; no unintended net merges or circuit errors.`)
console.log(`Routed PCB: ${circuit.filter((x: any) => x.type === "pcb_trace").length} traces, ${circuit.filter((x: any) => x.type === "pcb_via").length} vias.`)