seveibar/nema17-stepper-motor-driver-tmc2209-usb-pd
RP2040-based USB-C PD stepper-motor controller with TMC2209 drive, AS5600 position feedback, TMP102 thermal shutdown, current/voltage telemetry, RGB status LED, and protected buzzer alarm circuitry.
- Version
- 0.2.0
- License
- unset
- Stars
- 0
scripts/repair-routes.py
"""Apply reviewed local route edits only to their exact original circuit input."""
import json, hashlib
from pathlib import Path
p=Path('routing/route-plan.json');plan=json.loads(p.read_text())
patch=json.loads(Path('routing/trace-overrides.json').read_text())
fingerprint=hashlib.sha256(json.dumps(plan['expectedInput'],sort_keys=True,separators=(',',':')).encode()).hexdigest()
if fingerprint!=patch['expected_input_sha256']:
raise ValueError('Circuit input changed: review/reroute these local edits instead of replaying them')
found=set()
for t in plan['traces']:
id=t['pcb_trace_id']
if id in patch['routes']:
route=patch['routes'][id]
def endpoints(r):return sorted((round(p['x'],6),round(p['y'],6)) for p in [r[0],r[-1]])
if endpoints(t['route'])!=endpoints(route):raise ValueError('Trace endpoints changed: '+id)
t['route']=route;found.add(id)
assert found==set(patch['routes']), 'Missing route IDs'
p.write_text(json.dumps(plan,indent=2)+'\n')
print(f'Applied {len(found)} guarded route overrides; run the full build and DRC.')