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-keyboardIn 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/seed-existing-routing.py
"""Preserve verified copper unaffected by a footprint correction before rerouting.
Run generate-routing-input.py first, then this helper with a prior routes JSON.
Copper is retained only if it clears every
current pad and non-plated drill. All retained geometry is saved in seed.json.
"""
from pathlib import Path
import json,sys
from shapely.geometry import Point,LineString
from routing_model import BoardModel,LAYERS,DSN
root=Path(__file__).resolve().parents[1]
half=sys.argv[1];old=json.loads(Path(sys.argv[2]).read_text());m=BoardModel(root/f'outputs/{half}/keyboard.circuit.json')
folder=root/f'.cache/routing/{half}'
seed=json.loads((folder/'seed.json').read_text());wires=[];vias=[];seen=set();removed=0
holes=[Point(h['x'],h['y']).buffer(h['hole_diameter']/2,quad_segs=24) for h in m.bytype['pcb_hole']]
def valid(g,net,layers,via=False):
if any(g.distance(h)<.2001 for h in holes):return False
for p in m.pads:
if p['net']!=net and set(p['layers'])&set(layers) and g.distance(p['shape'])<.1001:return False
return True
for path in old['paths']:
net=path['net']
route=path['route'];run=[];layer=None;width=None
def flush():
global run
if len(run)>1 and any(a!=b for a,b in zip(run,run[1:])):wires.append({'net':net,'layer':layer,'width':width,'points':run})
run=[]
for a,b in zip(route,route[1:]):
if a['route_type']!='wire' or b['route_type']!='wire' or a['layer']!=b['layer']:
flush();continue
g=LineString([(a['x'],a['y']),(b['x'],b['y'])]).buffer(a['width']/2,quad_segs=8)
if valid(g,net,[a['layer']]):
if layer!=a['layer'] or width!=a['width'] or (run and run[-1]!={'x':a['x'],'y':a['y']}):flush()
layer=a['layer'];width=a['width']
if not run:run=[{'x':a['x'],'y':a['y']}]
run.append({'x':b['x'],'y':b['y']})
else:removed+=1;flush()
flush()
for p in route:
if p['route_type']!='via':continue
key=(round(p['x'],5),round(p['y'],5),p['from_layer'],p['to_layer'])
if key in seen:continue
seen.add(key);lo,hi=sorted([LAYERS.index(p['from_layer']),LAYERS.index(p['to_layer'])])
d=p.get('via_diameter',.5);h=p.get('via_hole_diameter',.25)
if not valid(Point(p['x'],p['y']).buffer(d/2,quad_segs=16),net,LAYERS[lo:hi+1],True):removed+=1;continue
kind='Micro_B_L3' if p['from_layer']=='bottom' and p['to_layer']=='inner2' else 'Thermal_600_300' if h==.3 else 'Through_500_250'
vias.append({'net':net,'x':p['x'],'y':p['y'],'from_layer':p['from_layer'],'to_layer':p['to_layer'],'diameter':d,'hole':h,'kind':kind})
seed['traces']=wires;seed['vias']=vias
(folder/'seed.json').write_text(json.dumps(seed,indent=2)+'\n')
def n(v):return f'{v*1000:.5f}'.rstrip('0').rstrip('.')
lines=[' (wiring']
for w in wires:
xy=' '.join(f'{n(p["x"])} {n(p["y"])}' for p in w['points'])
lines.append(f' (wire (path {DSN[w["layer"]]} {n(w["width"])} {xy}) (net {json.dumps(w["net"])}) (type protect))')
for v in vias:lines.append(f' (via {v["kind"]} {n(v["x"])} {n(v["y"])} (net {json.dumps(v["net"])}) (type protect))')
lines.append(' ))')
p=folder/'input.dsn';text=p.read_text();text=text[:text.rindex(' (wiring')]+ '\n'.join(lines)+'\n';p.write_text(text)
print(half,'preserved',len(wires),'wires',len(vias),'vias; removed',removed,'conflicting pieces; current pads and drills checked')