rushabhcodes/wireless-split-keyboard

Wireless Split Keyboard — custom routed nRF52840 split PCBs with a printable enclosure

Version
0.4.5
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone rushabhcodes/wireless-split-keyboard  # download the package files into ./wireless-split-keyboard
tsci add rushabhcodes/wireless-split-keyboard    # add it to your project as @tsci/rushabhcodes.wireless-split-keyboard

In a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.

scripts/inspect-clearances.py

"""Inspect built pad geometry against the fixed outline and RF reservation.
This is a placement check, not routed-copper DRC or a fabrication release."""
from pathlib import Path
import json,math
from shapely.geometry import Point,box,Polygon
from shapely.affinity import rotate
root=Path(__file__).resolve().parents[1]
report={}
def land(e):
 x,y=e['x'],e['y']
 if e.get('shape')=='circle':return Point(x,y).buffer(e.get('radius',e.get('outer_diameter',0)/2))
 w,h=e.get('width',e.get('outer_width',0)),e.get('height',e.get('outer_height',0))
 if not w:return Point(x,y).buffer(e.get('outer_diameter',e.get('hole_diameter',0))/2)
 return rotate(box(x-w/2,y-h/2,x+w/2,y+h/2),e.get('ccw_rotation',e.get('rotation',0)),origin=(x,y))
for half in ['left','right']:
 j=json.loads((root/f'outputs/{half}/keyboard.circuit.json').read_text())
 board=Polygon([(p['x'],p['y']) for p in next(e for e in j if e['type']=='pcb_board')['outline']])
 names={e['source_component_id']:e['name'] for e in j if e['type']=='source_component'}
 refs={e['pcb_component_id']:names.get(e.get('source_component_id')) for e in j if e['type']=='pcb_component'}
 zone=box((-61.5 if half=='right' else 47)-3.25,45.75,(-61.5 if half=='right' else 47)+3.25,52.25)
 outside=[];near=[];rf=[];minimum=math.inf
 for e in j:
  if e['type'] not in ['pcb_smtpad','pcb_plated_hole']:continue
  g=land(e);ref=refs.get(e.get('pcb_component_id'));ident=e.get('pcb_smtpad_id',e.get('pcb_plated_hole_id'))
  d=board.exterior.distance(g);minimum=min(minimum,d)
  record={'reference':ref,'id':ident,'edgeClearanceMm':round(d,6)}
  if not board.covers(g):outside.append(record)
  elif d<.2:near.append(record)
  if ref!='ANT1' and zone.intersects(g):rf.append(record)
 report[half]={'minimumLandToOutlineMm':minimum,'landsOutsideBoard':outside,'landsCloserThanPoint2Mm':near,'nonAntennaLandsInRfReservation':rf,'scope':'Unrouted pads only; no planes, RF traces or actual USB shell/case fit validation'}
(root/'outputs/clearance-inspection.json').write_text(json.dumps(report,indent=2)+'\n')
for h,v in report.items():print(h,'outside',len(v['landsOutsideBoard']),'near edge',len(v['landsCloserThanPoint2Mm']),'RF intrusions',len(v['nonAntennaLandsInRfReservation']))