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/check-assembly-models.py

"""Measure actual top switch/keycap meshes and connector contacts after GLB export."""
import json, sys, hashlib
from pathlib import Path
import numpy as np
from shapely.geometry import MultiPoint
from glb_geometry import GlbGeometry
from routing_model import BoardModel

root = Path(__file__).resolve().parents[1]
half = sys.argv[1]
folder = root / f'outputs/{half}'
model = GlbGeometry(folder / 'keyboard-placement.glb')
board = BoardModel(folder / 'keyboard.circuit.json')
keys = json.loads((root / 'src/generated/mechanical-geometry.json').read_text())['halves'][half]['keys']
catalog = json.loads((root / 'src/models/catalog.json').read_text())
measurements = []
caps = []
for key in keys:
    switch = model.vertices(key['reference'] + '_KEY')
    cap = model.vertices(key['reference'] + '_CAP')
    centers = [(vertices.min(axis=0) + vertices.max(axis=0))[:2] / 2 for vertices in [switch, cap]]
    error = np.linalg.norm(centers[0] - [key['x'], key['y']])
    assert error < .002, (key['reference'], error)
    assert np.linalg.norm(centers[1]-[key['x'],key['y']]) < .02
    assert abs(switch[:, 2].min() + 2.2) < .002
    assert abs(switch[:, 2].max() - 8.8) < .002
    flange = switch[abs(switch[:, 2] - 3.0) < .002, :2] - [key['x'], key['y']]
    angle = (key['rotation'] + 180) * np.pi / 180
    local = flange @ np.array([[np.cos(angle),-np.sin(angle)],[np.sin(angle),np.cos(angle)]])
    assert np.allclose(local.max(axis=0)-local.min(axis=0), [15,15], atol=.003)
    profile = 'thumb' if key['row']==4 else 'homing' if key['row']==2 and key['column']==3 else 'normal'
    color = 'blue' if key['row']==4 else 'ivory'
    bounds = np.array(catalog[f'keycap-{profile}-{color}']['bounds'])
    assert np.allclose([cap[:,2].min(),cap[:,2].max()],bounds[:,2]+6.12,atol=.002)
    angle = key['rotation']*np.pi/180
    stems = cap[cap[:,2]<7.37,:2]-[key['x'],key['y']]
    stems = stems @ np.array([[np.cos(angle),-np.sin(angle)],[np.sin(angle),np.cos(angle)]])
    for sign in [-1,1]:
        prong = stems[stems[:,0]*sign>0]
        assert np.allclose((prong.min(0)+prong.max(0))/2,[sign*2.85,0],atol=.03)
    caps.append(MultiPoint(cap[:, :2]).convex_hull)
    measurements.append({'ref': key['reference'], 'stemCenterErrorMm': round(float(error), 6)})
minimum_gap = min(a.distance(b) for i, a in enumerate(caps) for b in caps[i+1:])
assert minimum_gap > .1, minimum_gap
plate = model.vertices('CASE_PLATE')
assert np.any(abs(plate[:, 2] - 3.0) < .002)
glass = model.vertices('LCD_GLASS')
assert np.allclose(glass.max(axis=0) - glass.min(axis=0), [14, 32, .745], atol=.002)
for name in ['LCD_ACTIVE', 'LCD_FLEX', 'ENC1_KNOB', 'BATTERY_CELL', 'J_USB', 'J_LCD', 'J_NTC_WIRES', 'SW_PWR', 'SW_RESET']:
    model.vertices(name)
connector = model.vertices('J_BAT')
tips = connector[connector[:, 2] > connector[:, 2].max() - .001, :2]
holes = board.byref['J_BAT']
nearest = ((tips[:, None, :] - np.array([[p['x'], p['y']] for p in holes])[None, :, :])**2).sum(2).argmin(1)
lead_errors = []
for index, pad in enumerate(holes):
    points = tips[nearest == index]
    center = (points.min(axis=0) + points.max(axis=0)) / 2
    lead_errors.append(float(np.linalg.norm(center - [pad['x'], pad['y']])))
assert max(lead_errors) < .05, lead_errors
report = {'passed': True, 'topSwitches': measurements, 'keycaps': len(caps),
          'minimumKeycapGapMm': round(minimum_gap, 6), 'switchFlangeUndersideAndPlateTopZ': 3.0,
          'batteryConnectorMaximumLeadErrorMm': round(max(lead_errors), 6),
          'rawGlassEnvelopeMm': [14, 32, .745],
          'glbSha256': hashlib.sha256(model.raw).hexdigest(),
          'circuitJsonSha256': hashlib.sha256((folder / 'keyboard.circuit.json').read_bytes()).hexdigest(),
          'keycapSource':'KLP Lame Choc stem / Choc size, 6000 triangles, no scaling',
          'limitations': 'Sourced keycap/panel CAD and supplier switch/connector meshes; knob, cell and encoder remain nominal. Stem tolerances, FPC mating and printed fit need physical validation.'}
(folder / 'assembly-model-check.json').write_text(json.dumps(report, indent=2) + '\n')
print(half, 'assembly models passed:', len(keys), 'switches/caps, minimum cap gap', round(minimum_gap, 3), 'mm')