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-inspection-views.ts

/** Native exported meshes, with removable assembly parts hidden for PCB inspection. */
import { readFile, writeFile } from 'node:fs/promises'
import { renderGLTFToPNGFromGLB } from 'poppygl'
import { Resvg } from '@resvg/resvg-js'

function bareBoard(bytes: Buffer) {
  const length = bytes.readUInt32LE(12)
  const document = JSON.parse(bytes.subarray(20, 20 + length).toString())
  const removable = /^(CASE_|SPACER_|MOUNT_SCREW_|SW\d+_(KEY|CAP)$|LCD_|BATTERY_|ENC1_KNOB$)/
  const scene = document.scenes[document.scene ?? 0]
  scene.nodes = scene.nodes.filter((index: number) => !removable.test(document.nodes[index].name ?? ''))
  const json = Buffer.from(JSON.stringify(document))
  const padded = Buffer.alloc(Math.ceil(json.length / 4) * 4, 32)
  json.copy(padded)
  const binary = bytes.subarray(20 + length)
  const 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 gallery: string[] = []
for (const [index, half] of ['left', 'right'].entries()) {
  const folder = `outputs/${half}`
  const bytes = await readFile(`${folder}/keyboard-placement.glb`)
  await writeFile(`${folder}/board-bottom-3d.png`, await renderGLTFToPNGFromGLB(bareBoard(bytes), {
    width: 1200, height: 1000, projection: 'orthographic', orthographicHeight: 118,
    camPos: [0,-180,0], lookAt: [0,0,0], up: 'z+', backgroundColor: '#edf1f5', ambient: .65,
  }))
  const preview = (await readFile(`${folder}/3d.png`)).toString('base64')
  gallery.push(`<image x="${index*1200}" y="55" width="1200" height="900" href="data:image/png;base64,${preview}"/>`)
  gallery.push(`<text x="${index*1200+45}" y="48" font-size="30">${half === 'left' ? 'Left' : 'Right'} · native PCB and enclosure assembly</text>`)
}
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="2400" height="970"><rect width="2400" height="970" fill="#edf1f5"/><g font-family="DejaVu Sans" fill="#263b4d">${gallery.join('')}</g></svg>`
await writeFile('outputs/keyboard-assembly.png', new Resvg(svg).render().asPng())

const tentingGallery: string[]=[]
for(const [index,half] of ['left','right'].entries()) {
  const png=(await readFile(`outputs/${half}/tenting-10deg.png`)).toString('base64')
  tentingGallery.push(`<image x="${index*1200}" y="55" width="1200" height="900" href="data:image/png;base64,${png}"/>`)
  tentingGallery.push(`<text x="${index*1200+45}" y="48" font-size="30">${half} · 10° inner-edge tenting · native meshes</text>`)
}
await writeFile('outputs/keyboard-tenting.png',new Resvg(`<svg xmlns="http://www.w3.org/2000/svg" width="2400" height="970"><rect width="2400" height="970" fill="#edf1f5"/><g font-family="DejaVu Sans" fill="#263b4d">${tentingGallery.join('')}</g></svg>`).render().asPng())