MustafaMulla29/wireless-mouse-pcb

A 3D-printed wireless mouse enclosure housing a 44×70 mm PCB with nRF52810 BLE control, optical sensor, USB-C LiPo charging/power circuitry, buttons, scroll encoder/wheel, and battery bay.

Version
1.0.18
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone MustafaMulla29/wireless-mouse-pcb  # download the package files into ./wireless-mouse-pcb
tsci add MustafaMulla29/wireless-mouse-pcb    # add it to your project as @tsci/MustafaMulla29.wireless-mouse-pcb

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.

enclosure/viewer-gen.ts

// Writes viewer.html with assembled-pose STLs embedded (no server needed).
import modeling from "@jscad/modeling"
import { renderToJscadPlan } from "jscad-fiber/headless"
import { executeJscadOperations } from "jscad-planner"
import { readFileSync, writeFileSync } from "node:fs"
import { poses } from "./parts"

process.chdir(import.meta.dir)
const report = JSON.parse(readFileSync("dist/build-report.json","utf8"))
const colors: Record<string,string> = { base:"#37454e", lid:"#dde4df", "key-left":"#c9d3cd", "key-right":"#c9d3cd", "power-retainer":"#c9d3cd", "scroll-wheel":"#37454e" }
const parts: any[] = []
for (const name of Object.keys(report.parts)) {
  const plan = JSON.parse(readFileSync(`dist/${name}.jscad.json`,"utf8"))
  let s = executeJscadOperations(modeling as any, plan) as any
  s = modeling.transforms.translate(poses[name] ?? [0,0,0], s)
  const pos: number[] = []
  for (const p of modeling.geometries.geom3.toPolygons(s)) for (let i=1;i<p.vertices.length-1;i++) pos.push(...p.vertices[0],...p.vertices[i],...p.vertices[i+1])
  parts.push({ name, color: colors[name] ?? "#e7a64f", pos: Buffer.from(new Float32Array(pos).buffer).toString("base64") })
}
// PCB slab + component envelopes for context
const html = `<!doctype html><html><head><meta charset="utf-8"><title>Mouse enclosure</title>
<style>body{margin:0;background:#f4f5f2;font:13px system-ui}#ui{position:fixed;top:8px;left:8px;background:#fff9;padding:6px 8px;border-radius:6px}label{display:block}</style>
<script type="importmap">{"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js","three/addons/":"https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"}}</script></head>
<body><div id="ui"></div><script type="module">
import * as THREE from "three"; import {OrbitControls} from "three/addons/controls/OrbitControls.js"
const parts=${JSON.stringify(parts)}
const r=new THREE.WebGLRenderer({antialias:true,preserveDrawingBuffer:true});r.setSize(innerWidth,innerHeight);document.body.appendChild(r.domElement)
const sc=new THREE.Scene();sc.background=new THREE.Color("#f4f5f2")
const cam=new THREE.PerspectiveCamera(35,innerWidth/innerHeight,1,2000);cam.up.set(0,0,1);cam.position.set(150,-170,140)
const ctl=new OrbitControls(cam,r.domElement);ctl.target.set(0,18,8);ctl.update()
sc.add(new THREE.HemisphereLight(0xffffff,0x667788,1.6));const dl=new THREE.DirectionalLight(0xffffff,1.6);dl.position.set(80,-120,200);sc.add(dl)
const pcb=new THREE.Mesh(new THREE.BoxGeometry(44,70,1.4),new THREE.MeshStandardMaterial({color:"#1f6b3a"}));sc.add(pcb)
window.meshes={};const ui=document.getElementById("ui")
for(const p of parts){const b=Uint8Array.from(atob(p.pos),c=>c.charCodeAt(0));const g=new THREE.BufferGeometry();g.setAttribute("position",new THREE.BufferAttribute(new Float32Array(b.buffer),3));g.computeVertexNormals()
const m=new THREE.Mesh(g,new THREE.MeshStandardMaterial({color:p.color,flatShading:true,side:THREE.DoubleSide}));sc.add(m);meshes[p.name]=m
const l=document.createElement("label");l.innerHTML='<input type=checkbox checked> '+p.name;l.querySelector("input").onchange=e=>m.visible=e.target.checked;ui.appendChild(l)}
window.view=(pos,tgt)=>{cam.position.set(...pos);if(tgt)ctl.target.set(...tgt);ctl.update()}
;function fit(){const w=innerWidth||1024,h=innerHeight||768;r.setSize(w,h);cam.aspect=w/h;cam.updateProjectionMatrix()};addEventListener("resize",fit);fit();(function loop(){requestAnimationFrame(loop);if(r.domElement.width<2)fit();r.render(sc,cam)})()
</script></body></html>`
writeFileSync("viewer.html", html)
console.log("viewer.html", (html.length/1e6).toFixed(1), "MB")