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/generate-tenting.py
"""Removable contour-matched tenting cradles; inner edges rise, desks stay flat."""
from pathlib import Path
import json,math
import numpy as np
import trimesh
from shapely.geometry import Polygon,Point,MultiPoint
from shapely.affinity import affine_transform
from shapely.ops import unary_union
ROOT=Path(__file__).resolve().parents[1]
geometry=json.loads((ROOT/'src/generated/mechanical-geometry.json').read_text())
OUT=ROOT/'outputs/enclosure';OUT.mkdir(exist_ok=True)
plan={'units':'mm','angles':[5,10,15],'defaultAngle':10,'halves':{}}
qa={'passed':True,'construction':'Lift-out PLA cradle; 0.5 mm contour clearance, 1.4 mm retaining lip; 1 mm adhesive rubber below frame','halves':{}}
def wedge(poly,top):
mesh=trimesh.creation.extrude_polygon(poly,1,engine='earcut')
z=mesh.vertices[:,2].copy()
mesh.vertices[:,2]=np.where(z>.5,top(mesh.vertices[:,0]),1.)
assert mesh.is_watertight and mesh.volume>0
return mesh
for half in ['left','right']:
g=geometry['halves'][half];sgn=1 if half=='left' else -1
outline=Polygon([(p['x'],p['y']) for p in g['outline']]).buffer(2.15,quad_segs=8)
plan['halves'][half]={};qa['halves'][half]={}
for degrees in plan['angles']:
a=math.radians(degrees);c=math.cos(a);sn=math.sin(a)
# R_y(-sign*a): x'=c*x-sign*sin(a)*z; z'=sign*sin(a)*x+c*z+lift.
contour=affine_transform(outline,[c,0,0,1,sgn*sn*10.8,0])
lo=min(sgn*x for x,y in contour.exterior.coords)
lift=3+10.8/c-lo*math.tan(a)
support=lambda x:sgn*math.tan(a)*x+lift-10.8/c
footprint=contour.buffer(2.5,quad_segs=8)
ring=footprint.difference(contour.buffer(-5,quad_segs=8))
retainer=footprint.difference(contour.buffer(.5,quad_segs=8))
mesh=trimesh.boolean.union([wedge(ring,support),wedge(retainer,lambda x:support(x)+1.4)],engine='manifold')
assert mesh.is_watertight and mesh.volume>0
mesh.export(OUT/f'{half}-tenting-{degrees}deg.stl')
# Desktops see a broad contour frame. Every switch-load center and the cell
# project inside its support hull; this is static geometry, not a load test.
hull=footprint.convex_hull
points=[(c*k['x']-sgn*sn*10,k['y']) for k in g['keys']]
points.append((c*(-8 if half=='left' else 8)-sgn*sn*(-6.625),5))
margins=[hull.exterior.distance(Point(x,y)) if hull.covers(Point(x,y)) else -hull.distance(Point(x,y)) for x,y in points]
assert min(margins)>2
name=f'TENTING_{half.upper()}_{degrees}'
plan['halves'][half][str(degrees)]={'name':name,'angleDegrees':degrees,'rotationYDegrees':-sgn*degrees,'liftZ':lift,'vertices':np.round(mesh.vertices,6).tolist(),'faces':mesh.faces.tolist()}
qa['halves'][half][str(degrees)]={'watertight':True,'volumeMm3':round(float(mesh.volume),3),'boundsMm':mesh.bounds.tolist(),'caseRotationYDegrees':-sgn*degrees,'caseLiftZMm':round(lift,4),'lowestCaseFloorAboveDeskMm':3,'retainerHeightMm':1.4,'contourClearanceMm':.5,'minimumKeyAndCellLoadProjectionMarginMm':round(min(margins),3),'portWindowAboveRetainerMm':3.4}
(ROOT/'src/generated/tenting.json').write_text(json.dumps(plan,separators=(',',':'))+'\n')
(OUT/'tenting-check.json').write_text(json.dumps(qa,indent=2)+'\n')
print(json.dumps(qa,indent=2))