imrishabh18/fitness_watch
This circuit integrates an ESP-12E microcontroller with various sensors, relays, and power management components, including an AO3400A transistor for switching loads, to enable wireless control and sensing functions.
- Version
- 1.0.11
- License
- unset
- Stars
- 0
reviewed-routing.ts
import routes from "./reviewed-routes.json"
import anchors from "./routing-anchors.json"
// Replays reviewed copper without discarding per-segment widths or via sizes.
// Any pad-position or net-membership change requires regenerating these routes.
export const replayReviewedRoutes = async (input: any) => {
const points = new Map<string, any>()
const parent = new Map<string, string>()
const find = (id: string): string => {
if (!parent.has(id)) parent.set(id, id)
const p = parent.get(id)!
if (p !== id) parent.set(id, find(p))
return parent.get(id)!
}
for (const connection of input.connections) {
const ids: string[] = []
for (const point of connection.pointsToConnect) {
const id = point.pcb_port_id ?? point.pointId
if (!id) throw new Error("Routing input has an unnamed endpoint")
points.set(id, point)
ids.push(id)
}
for (const id of ids.slice(1)) parent.set(find(id), find(ids[0]))
}
const covered = new Set<string>()
for (const [id, point] of points) {
const saved = (anchors as Record<string, any>)[id]
if (!saved || Math.hypot(point.x - saved.x, point.y - saved.y) > 0.0001 ||
(point.layer && !saved.layers.includes(point.layer)))
throw new Error(`Saved copper is stale at ${id}; reroute the board`)
}
for (const trace of routes) {
const first = trace.route[0] as any
const last = trace.route[trace.route.length - 1] as any
const endpoints = [[first.start_pcb_port_id, first], [last.end_pcb_port_id, last]]
for (const [id, saved] of endpoints) {
if (!id) continue
const point = points.get(id)
if (!point || Math.hypot(point.x - saved.x, point.y - saved.y) > 0.0001)
throw new Error(`Saved copper is stale at ${id}; reroute the board`)
covered.add(id)
}
// The router can emit a joining segment without endpoint markers.
// Its connectsTo membership still identifies the net it belongs to.
const ids = [...new Set([...(trace.connectsTo ?? []), first.start_pcb_port_id, last.end_pcb_port_id].filter(Boolean))] as string[]
if (!ids.length || ids.some(id => !points.has(id)))
throw new Error("Saved copper has an unknown net endpoint; reroute the board")
for (const id of ids) covered.add(id)
if (ids.some(id => find(id) !== find(ids[0])))
throw new Error(`Saved copper joins different nets: ${ids.join(", ")}`)
}
for (const id of points.keys()) if (!covered.has(id))
throw new Error(`No saved copper for ${id}; reroute the board`)
const handlers = new Map<string, (event: any) => void>()
return {
on(event: string, callback: (event: any) => void) { handlers.set(event, callback) },
start() { handlers.get("complete")?.({ traces: structuredClone(routes) }) },
stop() {},
}
}