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/componentPlacement.ts

import type { Half } from './mechanicalGeometry'
export type Placement = {x:number;y:number;rotation:number;side:'top'|'bottom'}
/** Right positions in board-centered mm. All individual references can be overridden.
 * Left and right are separate physical boards; never mirror a physical IC pad map.
 */
const base:Record<string,Placement> = {
 U1:{x:-54,y:33,rotation:0,side:'bottom'},
 U_CHG:{x:-53,y:22,rotation:0,side:'bottom'},
 U_REG:{x:-60,y:-28,rotation:0,side:'bottom'},
 J_USB:{x:-61.7,y:20,rotation:270,side:'bottom'},
 LCD_SUPPORT:{x:-53,y:13,rotation:0,side:'bottom'},
 J_LCD:{x:-53.3,y:.5,rotation:180,side:'top'},
 J_BAT:{x:-24,y:14,rotation:0,side:'bottom'},
 SW_PWR:{x:-63,y:4,rotation:270,side:'bottom'},
 SW_RESET:{x:-60,y:7,rotation:0,side:'bottom'},
}
export const placementOverrides:Record<Half,Record<string,Partial<Placement>>>={
 left:{
  J_BAT:{y:12},
  U_ESD:{y:17},
  R_CC1:{x:58},
  R_CC2:{x:58},
  SW_RESET_BODY:{x:57,y:-.5},
 },
 right:{
  J_NTC:{x:-46,y:22},
  J_BAT:{x:-27,y:16},
  C_REG_OUT1:{x:-60.25},
  U_ESD:{y:17},
  R_CC1:{x:-58},
  R_CC2:{x:-58},
  SW_RESET_BODY:{x:-57,y:-.5},
 },
}
export function placement(half:Half,ref:string,fallback:Placement):Placement {
 const p=base[ref]??fallback
 return {...p,x:half==='left'?-p.x:p.x,rotation:half==='left'?(-p.rotation+360)%360:p.rotation,...placementOverrides[half][ref]}
}
export function offsetPlacement(half:Half,ref:string,anchor:string,dx:number,dy:number,rotation=0):Placement {
 const b=placement(half,anchor,{x:0,y:0,rotation:0,side:'bottom'})
 // Follow the anchor's rotation as a rigid cluster; individual overrides remain available.
 const a=b.rotation*Math.PI/180
 const mdx=half==='left'&&anchor!=='U1'?-dx:dx
 const x=b.x+mdx*Math.cos(a)-dy*Math.sin(a), y=b.y+mdx*Math.sin(a)+dy*Math.cos(a)
 return {...b,x,y,rotation:(b.rotation+(half==='left'&&anchor!=='U1'?-rotation:rotation)+360)%360,...placementOverrides[half][ref]}
}
export const pcbProps=(p:Placement)=>({pcbX:p.x,pcbY:p.y,pcbRotation:p.rotation,layer:p.side})