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/geometry.tsx

import { jscad } from "jscad-fiber/headless"
import { body, design as d } from "./dimensions"

// Same primitive helpers as the BLDC enclosure, plus sloped and shell helpers
// for the mouse roof (piecewise-linear in Y, built from hull chains).
export function Box({ x, y, z0, z1, w, h }: { x: number; y: number; z0: number; z1: number; w: number; h: number }) {
  return <jscad.cuboid size={[w, h, z1 - z0]} center={[x, y, (z0 + z1) / 2]} />
}
export function Cylinder({ x, y, z0, z1, r }: { x: number; y: number; z0: number; z1: number; r: number }) {
  return <jscad.cylinder radius={r} height={z1 - z0} center={[x, y, (z0 + z1) / 2]} />
}
export function RoundBox({ x, y, z0, z1, w, h, r = 2 }: { x: number; y: number; z0: number; z1: number; w: number; h: number; r?: number }) {
  return (
    <jscad.hull>
      {[-1, 1].flatMap((dx) =>
        [-1, 1].map((dy) => (
          <Cylinder key={`${dx}:${dy}`} x={x + dx * (w / 2 - r)} y={y + dy * (h / 2 - r)} z0={z0} z1={z1} r={r} />
        )),
      )}
    </jscad.hull>
  )
}
/** Cylinder whose axis runs along X. */
export function XCylinder({ y, z, x0, x1, r }: { y: number; z: number; x0: number; x1: number; r: number }) {
  return (
    <jscad.translate offset={[(x0 + x1) / 2, y, z]}>
      <jscad.rotate angles={[0, Math.PI / 2, 0]}>
        <jscad.cylinder radius={r} height={x1 - x0} />
      </jscad.rotate>
    </jscad.translate>
  )
}
/** Cylinder whose axis runs along Y. */
export function YCylinder({ x, z, y0, y1, r }: { x: number; z: number; y0: number; y1: number; r: number }) {
  return (
    <jscad.translate offset={[x, (y0 + y1) / 2, z]}>
      <jscad.rotate angles={[Math.PI / 2, 0, 0]}>
        <jscad.cylinder radius={r} height={y1 - y0} />
      </jscad.rotate>
    </jscad.translate>
  )
}

const slab = 0.01
function stationYs(y0: number, y1: number, extra: number[] = []) {
  const ys = [y0, y1, ...extra, ...d.roofStations.map((s) => s[0])].filter((y) => y >= y0 && y <= y1)
  return [...new Set(ys.map((y) => Math.round(y * 1e4) / 1e4))].sort((a, b) => a - b)
}
function Slabs({ stations }: { stations: { y: number; x0: number; x1: number; z0: number; z1: number }[] }) {
  const n = stations.length
  return (
    <jscad.hullChain>
      {stations.map((s, i) => {
        const y = i === 0 ? s.y + slab / 2 : i === n - 1 ? s.y - slab / 2 : s.y
        return <jscad.cuboid key={i} size={[s.x1 - s.x0, slab, s.z1 - s.z0]} center={[(s.x0 + s.x1) / 2, y, (s.z0 + s.z1) / 2]} />
      })}
    </jscad.hullChain>
  )
}

/** Rectangular footprint whose top and bottom follow functions of Y. */
export function Sloped({ x0, x1, y0, y1, top, bottom }: { x0: number; x1: number; y0: number; y1: number; top: (y: number) => number; bottom: (y: number) => number }) {
  return <Slabs stations={stationYs(y0, y1).map((y) => ({ y, x0, x1, z0: bottom(y), z1: top(y) }))} />
}

/** Mouse body outline inset by `inset` in plan, from `bottom` to `top(y)`. */
export function Shell({ inset, bottom, top }: { inset: number; bottom: number; top: (y: number) => number }) {
  const hw = body.halfWidth - inset
  const yf = body.front + inset
  const yr = body.rear - inset
  const r = Math.max(d.cornerRadius - inset, 0.6)
  const corner = Array.from({ length: 7 }, (_, i) => r * (1 - Math.cos((i * Math.PI) / 12)))
  const half = (y: number) => {
    const e = Math.min(y - yf, yr - y)
    return e >= r ? hw : hw - r + Math.sqrt(Math.max(r * r - (r - e) ** 2, 0))
  }
  const ys = stationYs(yf, yr, [...corner.map((c) => yf + c), ...corner.map((c) => yr - c)])
  return <Slabs stations={ys.map((y) => ({ y, x0: -half(y), x1: half(y), z0: bottom, z1: top(y) }))} />
}