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/render-socket-comparison.ts

/** Actual native GLB renders, cropped to a regular key and a rotated thumb. */
import {readFile,writeFile,mkdir} from 'node:fs/promises'
import {renderGLTFToPNGFromGLB} from 'poppygl'
import {Resvg} from '@resvg/resvg-js'
import geometry from '../src/generated/mechanical-geometry.json'
const beforeModel=process.argv[2],beforeCircuit=process.argv[3]
if(!beforeModel||!beforeCircuit)throw new Error('Usage: bun scripts/render-socket-comparison.ts BEFORE.glb BEFORE.circuit.json')
const afterModel='outputs/left/keyboard-placement.glb'
const documents=await Promise.all([beforeCircuit,'outputs/left/keyboard.circuit.json'].map(async file=>JSON.parse(await readFile(file,'utf8'))))
const models=await Promise.all([beforeModel,afterModel].map(file=>readFile(file)))
function selectedGlb(bytes:Buffer,ref:string){
 const n=bytes.readUInt32LE(12),json=JSON.parse(bytes.subarray(20,20+n).toString())
 json.scenes[json.scene??0].nodes=json.nodes.flatMap((node:any,i:number)=>['Box0','Via Plating',ref,ref.replace('SW','D')].includes(node.name)?[i]:[])
 const raw=Buffer.from(JSON.stringify(json)),padded=Buffer.alloc(Math.ceil(raw.length/4)*4,32);raw.copy(padded)
 const binary=bytes.subarray(20+n),header=Buffer.alloc(20)
 header.write('glTF');header.writeUInt32LE(2,4);header.writeUInt32LE(20+padded.length+binary.length,8);header.writeUInt32LE(padded.length,12);header.write('JSON',16)
 return Buffer.concat([header,padded,binary])
}
const panels:string[]=[]
for(const [row,ref] of ['SW1','SW26'].entries()){
 const key=geometry.halves.left.keys.find(k=>k.reference===ref)!
 const cad=documents.map(json=>{
  const source=json.find((e:any)=>e.type==='source_component'&&e.name===ref)
  return json.find((e:any)=>e.type==='cad_component'&&e.source_component_id===source.source_component_id)
 })
 const x=-(cad[0].position.x+cad[1].position.x)/2,z=(cad[0].position.y+cad[1].position.y)/2
 for(const col of [0,1]){
  const png=await renderGLTFToPNGFromGLB(selectedGlb(models[col],ref),{
   width:860,height:510,backgroundColor:'#edf1f5',projection:'orthographic',orthographicHeight:22,
   camPos:row===0?[x,-35,z]:[x+13,-26,z-13],lookAt:[x,-.8,z],up:'z+',ambient:.65,cull:false,
   debugPoints:[{label:`${ref} stem`,position:{x:-key.x,y:-.8,z:key.y}}],debugFontSize:14,
   debugPointColor:[.1,.4,.9],debugLabelColor:[.1,.15,.2],
  })
  panels.push(`<image x="${30+col*890}" y="${155+row*580}" width="860" height="510" href="data:image/png;base64,${Buffer.from(png).toString('base64')}"/>`)
 }
 panels.push(`<text x="40" y="${700+row*580}" font-size="22">${ref}: ${row===0?'bottom view':'oblique thumb view'} · PCB rotation ${key.rotation}° · fixed stem (${key.x.toFixed(3)}, ${key.y.toFixed(3)}) mm</text>`)
}
const svg=`<svg xmlns="http://www.w3.org/2000/svg" width="1800" height="1410"><rect width="1800" height="1410" fill="#fff"/><g font-family="DejaVu Sans, sans-serif" fill="#172333"><text x="35" y="48" font-size="31" font-weight="bold">Bottom-side Choc sockets — actual exported 3D geometry</text><text x="35" y="84" font-size="21">Enclosure hidden for inspection · same camera in each pair · blue marker: unchanged switch stem</text><text x="35" y="132" font-size="25" fill="#a62d36">Before: footprint mirror suppressed</text><text x="925" y="132" font-size="25" fill="#18794e">Corrected: footprint and CAD share the bottom frame</text>${panels.join('')}<text x="35" y="1340" font-size="23">All 58 sockets measured: locating-post error 2.200 mm before → below 0.001 mm after.</text><text x="35" y="1380" font-size="21">Both metal legs fully covered by their pads; minimum measured land margin 0.150 mm. CAD verification; physical fit untested.</text></g></svg>`
await mkdir('outputs',{recursive:true});await writeFile('outputs/socket-alignment-comparison.png',new Resvg(svg).render().asPng())
console.log('Wrote outputs/socket-alignment-comparison.png')