imrishabh18/corne-keyboard

The code defines and renders two surface-mount chip components with SMT pads, silkscreen outlines, and 3D CAD models (OBJ and STEP) for PCB assembly.

Version
2.0.21
License
unset
Stars
1

scripts/verify-panel.py

import json,subprocess,sys,hashlib
from pathlib import Path
project=Path(__file__).resolve().parent.parent
path=project/'dist/index/circuit.json'
j=json.loads(path.read_text());boards=[e for e in j if e['type']=='pcb_board'];assert len(boards)==2
inputs=[]
for board in boards:
 sb=next(e for e in j if e['type']=='source_board' and e['source_board_id']==board['source_board_id'])
 side='right' if sb['title'].endswith('RIGHT') else 'left'
 group=next(e for e in j if e['type']=='source_group' and e['source_group_id']==sb['source_group_id'])
 sid=group['subcircuit_id'];c=[e for e in j if e.get('subcircuit_id')==sid]
 component_ids={e['pcb_component_id'] for e in c if e['type']=='pcb_component'}
 source_ids={e['source_component_id'] for e in c if e['type']=='source_port'}
 for e in j:
  if e in c:continue
  if e['type'] in ['source_component','source_component_internal_connection'] and e.get('source_component_id') in source_ids:c.append(e)
  elif e['type'].startswith('pcb_') and not e.get('subcircuit_id') and e['type'] not in ['pcb_board','pcb_panel']:
   if e.get('pcb_component_id') in component_ids:c.append(e)
   elif 'x' in e and min(boards,key=lambda b:abs(e['x']-b['center']['x'])) is board:c.append(e)
 for e in [board,sb,group]:
  if e not in c:c.append(e)
 folder=path.parent/side;folder.mkdir(exist_ok=True);f=folder/'circuit.json';f.write_text(json.dumps(c,indent=2));inputs.append(str(f))
subprocess.run([sys.executable,str(project/'scripts/verify-board.py'),*inputs],check=True,cwd=project)
summaries=[]
for p in inputs:
 folder=Path(p).parent/'validation';summaries.append(json.loads((folder/'summary.json').read_text()))
remaining=[e for e in j if e['type'].endswith('_error')]
# This is an exact copy of raw core output; no diagnostics are filtered.
(path.parent/'circuit.validated.json').write_text(json.dumps(j,indent=2))
(path.parent/'validation-summary.json').write_text(json.dumps({'input_sha256':hashlib.sha256(path.read_bytes()).hexdigest(),'boards':summaries,'remaining_panel_diagnostics':remaining},indent=2))
print('panel:',sum(s['trace_count'] for s in summaries),'traces;',sum(s['checked_nets'] for s in summaries),'nets checked;',len(remaining),'remaining panel diagnostics')
if remaining:sys.exit(1)