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

import { jscad } from "jscad-fiber/headless"
import {
  body,
  chargeLed,
  component,
  design as d,
  dpi,
  encoderCenter,
  keys,
  middle,
  mountingHoles,
  pcbBottom,
  pcbTop,
  power,
  range,
  roofInner,
  roofOuter,
  sensor,
  sideButtons,
  thtParts,
  usb,
  wheelAxis,
} from "./dimensions"
import { Box, Cylinder, RoundBox, Shell, Sloped, XCylinder, YCylinder } from "./geometry"
import { EngravedText, lidLabels } from "./labels"

const high = 40 // any Z above the whole mouse
const innerFront = body.front + d.wall
const leftWallInner = -body.halfWidth + d.wall

// ---------------------------------------------------------------- base
const bay = d.battery
const bayOuter = { w: bay.width + 2 * bay.wall, h: bay.depth + 2 * bay.wall }
const lipInset = d.wall + d.lipClearance

export function Base() {
  return (
    <jscad.subtract>
      <jscad.union>
        <jscad.subtract>
          <Shell inset={0} bottom={d.bottom} top={() => d.floorTop} />
          {/* Lens opening for the LM18-LSI under the PMW3610. */}
          <RoundBox x={sensor.x} y={sensor.y} w={d.lens.width} h={d.lens.depth} r={d.lens.radius} z0={d.bottom - 1} z1={d.floorTop + 1} />
          {/* Recesses for adhesive PTFE skates. */}
          {d.skates.map((s, i) => (
            <RoundBox key={i} x={s.x} y={s.y} w={s.w} h={s.d} r={1} z0={d.bottom - 1} z1={d.bottom + d.skate.recess} />
          ))}
          {/* Relief under through-hole leads. */}
          {thtParts.map((ref) => {
            const c = component(ref)
            return (
              <Box key={ref} x={c.center.x} y={c.center.y} w={c.width + 2 * d.thtRelief.margin} h={c.height + 2 * d.thtRelief.margin} z0={d.floorTop - d.thtRelief.depth} z1={d.floorTop + 1} />
            )
          })}
        </jscad.subtract>
        {/* PCB posts on the three existing 2.4 mm holes. */}
        {mountingHoles.map((h) => (
          <Cylinder key={h.pcb_hole_id} x={h.x} y={h.y} z0={d.floorTop - d.thtRelief.depth - 0.1} z1={pcbBottom} r={d.pcbMount.radius} />
        ))}
        {/* Locating lip inside the lid walls. */}
        <jscad.subtract>
          <Shell inset={lipInset} bottom={d.floorTop - 0.1} top={() => d.floorTop + d.lip.height} />
          <Shell inset={lipInset + d.lip.thickness} bottom={d.floorTop - 1} top={() => d.floorTop + d.lip.height + 1} />
        </jscad.subtract>
        {/* Battery bay behind the PCB. */}
        <jscad.subtract>
          <Box x={bay.x} y={bay.y} w={bayOuter.w} h={bayOuter.h} z0={d.floorTop - 0.1} z1={d.floorTop + bay.height} />
          <Box x={bay.x} y={bay.y} w={bay.width} h={bay.depth} z0={d.floorTop} z1={d.floorTop + bay.height + 1} />
          <Box x={bay.x - bay.width / 2 + bay.cableNotch / 2 + 1} y={bay.y - bay.depth / 2} w={bay.cableNotch} h={bay.wall * 4} z0={d.floorTop + 1.5} z1={d.floorTop + bay.height + 1} />
        </jscad.subtract>
      </jscad.union>
      {mountingHoles.map((h) => (
        <Cylinder key={h.pcb_hole_id} x={h.x} y={h.y} z0={d.pcbMount.holeBottom} z1={pcbBottom + 1} r={d.inserts.m2.holeDiameter / 2} />
      ))}
      {d.caseBolts.map(([x, y]) => (
        <jscad.union key={`${x}:${y}`}>
          <Cylinder x={x} y={y} z0={d.bottom - 1} z1={d.floorTop + d.lip.height + 1} r={d.flange.holeRadius} />
          <Cylinder x={x} y={y} z0={d.bottom - 1} z1={d.flange.headSeat} r={d.flange.headRadius} />
          {/* Lip clearance around the lid flanges. */}
          <Cylinder x={x} y={y} z0={d.floorTop - 0.05} z1={d.floorTop + d.lip.height + 1} r={d.flange.radius + d.lipClearance} />
        </jscad.union>
      ))}
    </jscad.subtract>
  )
}

// ---------------------------------------------------------------- lid features
const b = d.button
export const dpiPlunger = (() => {
  const tipBottom = pcbTop + d.tactHeight + b.tipGap
  const stop = range(roofInner, dpi.y - b.guideRadius, dpi.y + b.guideRadius, "min")
  const roofMax = range(roofInner, dpi.y - b.guideRadius, dpi.y + b.guideRadius, "max")
  const flangeTop = stop - 0.2
  const flangeBottom = flangeTop - b.flangeThickness
  const guideBottom = tipBottom + 1.4
  const top = range(roofOuter, dpi.y - b.boreRadius, dpi.y + b.boreRadius, "max") + b.proud
  return { tipBottom, stop, roofMax, flangeTop, flangeBottom, guideBottom, top }
})()

const y = d.yoke
const yokeBox = {
  x0: y.x0,
  x1: y.x1,
  y0: middle.y - y.halfDepth,
  y1: middle.y + y.halfDepth,
  z0: pcbTop + d.tactHeight + 0.05,
  z1: wheelAxis.z + y.topAboveAxis,
}
const guide = {
  x0: y.x0 - y.guideClearance - y.guideThickness,
  x1: d.wheelSlot.x0 - 0.2,
  yIn0: yokeBox.y0 - y.guideClearance,
  yIn1: yokeBox.y1 + y.guideClearance,
}
const ribs = [-6, 6]
const ribBottom = d.floorTop + bay.cell[2] + 0.5

export function Lid() {
  const p = power
  const flatTop = (z: number) => () => z
  return (
    <jscad.subtract>
      <jscad.union>
        <jscad.subtract>
          <Shell inset={0} bottom={d.seam + 0.15} top={roofOuter} />
          <Shell inset={d.wall} bottom={d.bottom - 1} top={roofInner} />
        </jscad.subtract>
        {/* Case-bolt flanges: same flange and taper as the BLDC lid. */}
        {d.caseBolts.map(([x, yy]) => (
          <jscad.union key={`${x}:${yy}`}>
            <Cylinder x={x} y={yy} z0={d.flange.bottom} z1={d.flange.top} r={d.flange.radius} />
            <jscad.hull>
              <Cylinder x={x} y={yy} z0={d.flange.top - 0.1} z1={d.flange.top} r={d.flange.radius} />
              <Cylinder x={x} y={yy} z0={d.flange.top + 3} z1={d.flange.top + 3.1} r={1.5} />
            </jscad.hull>
          </jscad.union>
        ))}
        {/* DPI plunger guide tube. */}
        <Cylinder x={dpi.x} y={dpi.y} z0={dpiPlunger.guideBottom} z1={dpiPlunger.roofMax + 0.1} r={b.guideRadius} />
        {/* Guides that keep the wheel yoke upright over SW_MIDDLE. */}
        {[
          [guide.yIn0 - y.guideThickness, guide.yIn0],
          [guide.yIn1, guide.yIn1 + y.guideThickness],
        ].map(([y0, y1]) => (
          <Sloped key={y0} x0={guide.x0} x1={guide.x1} y0={y0} y1={y1} bottom={flatTop(y.guideBottom)} top={(yy) => roofInner(yy) + 0.1} />
        ))}
        <Sloped x0={guide.x0} x1={guide.x0 + y.guideThickness} y0={guide.yIn0} y1={guide.yIn1} bottom={flatTop(y.guideBottom)} top={(yy) => roofInner(yy) + 0.1} />
        {/* POWER boss: guide floor and two M2 insert holes, as in the BLDC lid. */}
        <Sloped x0={p.x - p.outerWidth / 2 - 0.6} x1={p.x + p.outerWidth / 2 + 0.6} y0={p.y - p.outerDepth / 2 - 0.6} y1={p.y + p.outerDepth / 2 + 0.6} bottom={flatTop(p.floorBottom)} top={(yy) => roofOuter(yy) - 0.01} />
        {/* Battery hold-down ribs. */}
        {ribs.map((x) => (
          <Sloped key={x} x0={bay.x + x - 0.6} x1={bay.x + x + 0.6} y0={bay.y - bay.depth / 2 + 2} y1={bay.y + bay.depth / 2 - 2} bottom={flatTop(ribBottom)} top={(yy) => roofInner(yy) + 0.1} />
        ))}
      </jscad.union>

      {/* USB-C plug opening and charge-LED window in the front wall. */}
      <Box x={usb.x} y={body.front + d.wall / 2} w={d.usb.width} h={d.wall + 2} z0={usb.z - d.usb.height / 2} z1={usb.z + d.usb.height / 2} />
      <YCylinder x={chargeLed.x} z={chargeLed.z} y0={body.front - 1} y1={innerFront + 1} r={d.chargeLed.radius} />

      {/* Main-button key windows. */}
      {keys.map((k) => (
        <Box key={k.ref} x={(k.x0 + k.x1) / 2} y={(k.y0 + k.y1) / 2} w={k.x1 - k.x0} h={k.y1 - k.y0} z0={range(roofInner, k.y0, k.y1, "min") - 0.5} z1={high} />
      ))}

      {/* Wheel slot and a thinned roof over the encoder body. */}
      <Box x={(d.wheelSlot.x0 + d.wheelSlot.x1) / 2} y={wheelAxis.y} w={d.wheelSlot.x1 - d.wheelSlot.x0} h={2 * (d.wheel.radius + d.wheelSlot.margin)} z0={wheelAxis.z} z1={high} />
      <Sloped
        x0={d.encoderPocket.x0}
        x1={d.encoderPocket.x1}
        y0={encoderCenter.y - d.encoder.halfDepthY - d.encoderPocket.margin}
        y1={encoderCenter.y + d.encoder.halfDepthY + d.encoderPocket.margin}
        bottom={(yy) => roofInner(yy) - 0.5}
        top={(yy) => roofOuter(yy) - d.encoderPocket.skin}
      />

      {/* DPI plunger bore and flange pocket. */}
      <Cylinder x={dpi.x} y={dpi.y} r={b.boreRadius} z0={dpiPlunger.guideBottom - 1} z1={high} />
      <Cylinder x={dpi.x} y={dpi.y} r={b.pocketRadius} z0={dpiPlunger.guideBottom - 1} z1={dpiPlunger.stop} />

      {/* Side-button windows in the left wall. */}
      {sideButtons.map((s) => (
        <Box key={s.ref} x={-body.halfWidth + d.wall / 2} y={s.y} w={d.wall + 2} h={d.side.window.w} z0={d.side.axisZ - d.side.window.h / 2} z1={d.side.axisZ + d.side.window.h / 2} />
      ))}

      {/* POWER slider pocket, track, fork slot and insert holes. */}
      <RoundBox x={p.x} y={p.y} w={p.outerWidth + 0.4} h={p.outerDepth + 0.4} r={1} z0={p.retainerBottom} z1={high} />
      <Box x={p.x} y={p.y} w={p.innerWidth} h={p.innerDepth} z0={p.floorTop} z1={high} />
      <Box x={p.x} y={p.y} w={p.lowerSlotWidth} h={p.lowerSlotDepth} z0={p.floorBottom - 1} z1={high} />
      {[-1, 1].map((s) => (
        <Cylinder key={s} x={p.x} y={p.y + s * p.screwY} z0={p.insertTop - p.insertHoleDepth} z1={p.insertTop + 0.1} r={d.inserts.m2.holeDiameter / 2} />
      ))}

      {/* M2 x 3 inserts in the case-bolt flanges. */}
      {d.caseBolts.map(([x, yy]) => (
        <Cylinder key={`${x}:${yy}`} x={x} y={yy} r={d.inserts.m2.holeDiameter / 2} z0={d.flange.bottom - 1} z1={d.flange.bottom + d.inserts.m2.length + 0.6} />
      ))}

      {lidLabels.map((l) => (
        <EngravedText key={l.text} {...l} />
      ))}
    </jscad.subtract>
  )
}

// ---------------------------------------------------------------- moving parts
const kd = d.key
export function Key({ refName }: { refName: string }) {
  const k = keys.find((q) => q.ref === refName)!
  const c = kd.windowClearance
  const fx0 = k.x0 - (k.flangeX0 ?? kd.flangeMargin)
  const fx1 = k.x1 + (k.flangeX1 ?? kd.flangeMargin)
  const flangeTop = (yy: number) => roofInner(yy) - kd.flangeGap
  const flangeBottom = (yy: number) => flangeTop(yy) - kd.flangeThickness
  const actuatorTop = pcbTop + kd.actuatorHeight
  const padBottom = actuatorTop + kd.tipGap
  return (
    <jscad.union>
      <Sloped x0={k.x0 + c} x1={k.x1 - c} y0={k.y0 + c} y1={k.y1 - c} bottom={(yy) => flangeBottom(yy) + 0.05} top={(yy) => roofOuter(yy) + kd.capProud} />
      <Sloped x0={fx0} x1={fx1} y0={k.y0 - kd.flangeMargin} y1={k.y1 + kd.flangeMargin} bottom={flangeBottom} top={flangeTop} />
      <Cylinder x={k.x} y={k.y} r={kd.stemRadius} z0={padBottom + kd.pad.h - 0.01} z1={flangeBottom(k.y) + 0.1} />
      <Box x={k.x} y={k.y} w={kd.pad.w} h={kd.pad.d} z0={padBottom} z1={padBottom + kd.pad.h} />
    </jscad.union>
  )
}

export function DpiPlunger() {
  const q = dpiPlunger
  return (
    <jscad.union>
      <Cylinder x={dpi.x} y={dpi.y} r={b.tipRadius} z0={q.tipBottom} z1={q.flangeTop} />
      <Cylinder x={dpi.x} y={dpi.y} r={b.stemRadius} z0={q.guideBottom} z1={q.top} />
      <jscad.hull>
        <Cylinder x={dpi.x} y={dpi.y} r={b.stemRadius} z0={q.flangeBottom - 1} z1={q.flangeBottom - 0.99} />
        <Cylinder x={dpi.x} y={dpi.y} r={b.flangeRadius} z0={q.flangeBottom} z1={q.flangeBottom + 0.1} />
      </jscad.hull>
      <Cylinder x={dpi.x} y={dpi.y} r={b.flangeRadius} z0={q.flangeBottom} z1={q.flangeTop} />
    </jscad.union>
  )
}

const sd = d.side
export function SidePlunger({ refName }: { refName: string }) {
  const s = sideButtons.find((q) => q.ref === refName)!
  const outer = -body.halfWidth
  const flange0 = leftWallInner + sd.flange.gap
  const flange1 = flange0 + sd.flange.t
  const barStart = -22 - sd.boardGap
  const tip = s.tipX - sd.tipGap
  const z = sd.axisZ
  const seg = (x0: number, x1: number, w: number, z0: number, z1: number) => (
    <Box x={(x0 + x1) / 2} y={s.y} w={x1 - x0} h={w} z0={z0} z1={z1} />
  )
  return (
    <jscad.union>
      {seg(outer - sd.head.proud, flange0 + 0.05, sd.head.w, z - sd.head.h / 2, z + sd.head.h / 2)}
      {seg(flange0, flange1, sd.flange.w, z - sd.flange.h / 2, z + sd.flange.h / 2)}
      {seg(flange1 - 0.05, barStart + 0.05, sd.head.w, z - sd.head.h / 2, z + sd.head.h / 2)}
      {seg(barStart, tip, sd.bar.w, sd.bar.z0, sd.bar.z1)}
    </jscad.union>
  )
}

const w = d.wheel
export function ScrollWheel() {
  const width = w.x1 - w.x0
  return (
    <jscad.subtract>
      <jscad.union>
        <XCylinder y={wheelAxis.y} z={wheelAxis.z} x0={w.x0} x1={w.x1} r={w.radius} />
        <XCylinder y={wheelAxis.y} z={wheelAxis.z} x0={w.axleX0} x1={w.axleX1} r={w.axleRadius} />
      </jscad.union>
      {Array.from({ length: w.grooves }, (_, i) => (
        <jscad.translate key={i} offset={[(w.x0 + w.x1) / 2, wheelAxis.y, wheelAxis.z]}>
          <jscad.rotate angles={[(2 * Math.PI * i) / w.grooves, 0, 0]}>
            <jscad.cuboid size={[width + 1, 0.8, 1.2]} center={[0, 0, w.radius]} />
          </jscad.rotate>
        </jscad.translate>
      ))}
      {/* D flat on the axle end that enters the encoder rotor (verify against the EC10E drawing). */}
      <Box x={(7.2 + w.axleX1 + 1) / 2} y={wheelAxis.y} w={w.axleX1 + 1 - 7.2} h={2 * w.axleRadius + 1} z0={wheelAxis.z + 0.7 * w.axleRadius} z1={wheelAxis.z + 2} />
    </jscad.subtract>
  )
}

export function WheelYoke() {
  const q = yokeBox
  return (
    <jscad.subtract>
      <Box x={(q.x0 + q.x1) / 2} y={(q.y0 + q.y1) / 2} w={q.x1 - q.x0} h={q.y1 - q.y0} z0={q.z0} z1={q.z1} />
      <XCylinder y={wheelAxis.y} z={wheelAxis.z} x0={q.x0 - 1} x1={q.x1 + 1} r={y.boreRadius} />
    </jscad.subtract>
  )
}

// Jaws engage the SS-12D00 lever along X. Geometry is centred at mid-travel;
// the assembly places the slider at the start position (see enclosure.circuit.tsx).
export function PowerSlider() {
  const p = power
  return (
    <jscad.union>
      <Box x={p.x} y={p.y} w={p.flangeWidth} h={p.flangeDepth} z0={p.flangeBottom} z1={p.flangeTop} />
      <RoundBox x={p.x} y={p.y} w={p.gripWidth} h={p.gripDepth} z0={p.flangeTop - 0.1} z1={p.gripTop} r={0.6} />
      {[-1, 1].map((s) => (
        <Box key={s} x={p.x + (s * (p.forkGap + p.jawThickness)) / 2} y={p.y} w={p.jawThickness} h={p.forkWidth} z0={p.forkBottom} z1={p.flangeBottom + 0.2} />
      ))}
    </jscad.union>
  )
}
export function PowerRetainer() {
  const p = power
  return (
    <jscad.subtract>
      <RoundBox x={p.x} y={p.y} w={p.outerWidth} h={p.outerDepth} z0={p.retainerBottom} z1={p.retainerTop} r={1} />
      <Box x={p.x} y={p.y} w={p.windowWidth} h={p.windowDepth} z0={p.retainerBottom - 1} z1={p.retainerTop + 1} />
      {[-1, 1].map((s) => (
        <Cylinder key={s} x={p.x} y={p.y + s * p.screwY} z0={p.retainerBottom - 1} z1={p.retainerTop + 1} r={p.screwRadius} />
      ))}
    </jscad.subtract>
  )
}

/** Pose offsets from the modelled position to the assembled start position. */
export const poses: Record<string, [number, number, number]> = {
  // Lever at its -X end, jaws centred around it with equal clearance.
  "power-slider": [-(power.leverTravel / 2 + (power.forkGap - power.leverWidth) / 4), 0, 0],
}

export const printableParts = {
  base: { Part: Base, quantity: 1 },
  lid: { Part: Lid, quantity: 1 },
  "key-left": { Part: () => <Key refName="SW_LEFT" />, quantity: 1 },
  "key-right": { Part: () => <Key refName="SW_RIGHT" />, quantity: 1 },
  "dpi-plunger": { Part: DpiPlunger, quantity: 1 },
  "side-plunger-1": { Part: () => <SidePlunger refName="SW_SIDE1" />, quantity: 1 },
  "side-plunger-2": { Part: () => <SidePlunger refName="SW_SIDE2" />, quantity: 1 },
  "scroll-wheel": { Part: ScrollWheel, quantity: 1 },
  "wheel-yoke": { Part: WheelYoke, quantity: 1 },
  "power-slider": { Part: PowerSlider, quantity: 1 },
  "power-retainer": { Part: PowerRetainer, quantity: 1 },
}