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.

src/KeyboardAssembly.tsx

import * as React from 'react'
import { assembly, jscad } from 'tscircuit'
import { KeyboardModels } from './KeyboardModels'
import { KeyboardHalf } from './KeyboardHalf'
import { placement } from './componentPlacement'
import type { Half } from './mechanicalGeometry'
import enclosure from './generated/enclosure.json'

type PolygonPlan = { outer: number[][]; holes: number[][][] }
type SolidPlan = { z: number; height: number; polygons: PolygonPlan[] }
const points = (ring: number[][]): [number,number][] => ring.map(([x,y])=>[x,y])
function Outline({polygon}:{polygon:PolygonPlan}) {
  const outer=<jscad.polygon points={points(polygon.outer)}/>
  return polygon.holes.length ? <jscad.subtract>{outer}
    {polygon.holes.map((ring,i)=><React.Fragment key={i}><jscad.polygon points={points(ring)}/></React.Fragment>)}
  </jscad.subtract> : outer
}
function PrintedSolid({solids}:{solids:SolidPlan[]}) {
  return <jscad.union>{solids.map((solid,i)=><React.Fragment key={i}>
    <jscad.translate offset={[0,0,solid.z]}>
      <jscad.extrudeLinear height={solid.height}>
        <jscad.union>{solid.polygons.map((polygon,j)=><React.Fragment key={j}><Outline polygon={polygon}/></React.Fragment>)}</jscad.union>
      </jscad.extrudeLinear>
    </jscad.translate>
  </React.Fragment>)}</jscad.union>
}
export function KeyboardAssembly({half}:{half:Half}) {
  const plan=enclosure.halves[half]
  for (const [reference, expected] of [['SW_PWR',plan.switch],['J_USB',plan.usb]] as const) {
    const actual=placement(half,reference,{x:0,y:0,rotation:0,side:'bottom'})
    if(Math.hypot(actual.x-expected.x,actual.y-expected.y)>.001 || actual.rotation!==expected.rotation || actual.side!==expected.side) {
      throw new Error(`Enclosure access is stale; regenerate the enclosure plan after moving ${reference}`)
    }
  }
  return <assembly.device name={`WIRELESS_SPLIT_KEYBOARD_${half.toUpperCase()}`}>
    <KeyboardHalf half={half}/>
    {plan.parts.map(part=><React.Fragment key={part.name}>
      <assembly.printedpart name={part.name} displayName={part.label} color={part.color} material="pla"
        jscad={<PrintedSolid solids={part.solids}/>}/>
    </React.Fragment>)}
    <KeyboardModels half={half}/>
  </assembly.device>
}