mohan-bee/mic-tx

Pocket-sized ESP32-S3 wireless microphone transmitter with digital I²S microphone, RF antenna and flash, USB interface, Li‑ion charging/power management, buck-boost regulation, status LED, power key, and protective enclosure with clip, gasket, lid, and battery pack.

Version
0.0.4
License
unset
Stars
0

Use with the tscircuit CLI

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

tsci clone mohan-bee/mic-tx  # download the package files into ./mic-tx
tsci add mohan-bee/mic-tx    # add it to your project as @tsci/mohan-bee.mic-tx

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.

source/compose-assembly.mts

import assert from "node:assert/strict"
import { readFileSync, writeFileSync } from "node:fs"
import { resolve } from "node:path"

type Entry = { type: string; [key: string]: unknown }

const [pcbPath, mechanicsPath, outputPath, assetDirectory] = process.argv.slice(2)
assert(pcbPath && mechanicsPath && outputPath, "Expected PCB Circuit JSON, built mechanical Circuit JSON, and output path")
const read = (path: string): Entry[] => JSON.parse(readFileSync(path, "utf8"))
const pcb = read(pcbPath)
const mechanics = read(mechanicsPath)
assert.equal(pcb.filter((entry) => entry.type === "pcb_board").length, 1, "Expected one C5 PCB")
assert(!mechanics.some((entry) => entry.type === "pcb_board"), "Build the native assembly without a PCB before merging")

const assemblyIds = new Map<string, string>()
for (const entry of mechanics) {
  const id = entry[`${entry.type}_id`]
  if (typeof id === "string") assemblyIds.set(id, `enclosure_${id}`)

  const model = entry.model_glb_url
  const localModel = typeof model === "string" ? /^\.\/(?:source\/)?(models\/[\w-]+\.glb)$/.exec(model)?.[1] : undefined
  if (localModel) {
    assert(assetDirectory, `Missing asset directory for ${model}`)
    const bytes = readFileSync(resolve(assetDirectory, localModel))
    assert.equal(bytes.toString("ascii", 0, 4), "glTF", `${model} is not a GLB model`)
    entry.model_glb_url = `data:model/gltf-binary;base64,${bytes.toString("base64")}`
  }
}

// The JSON board inflater reconstructs the netlist and omits some existing PCB
// geometry. Compose the two compiled documents instead, preserving C5 verbatim.
const distinctMechanics: Entry[] = JSON.parse(JSON.stringify(mechanics, (_key, value) =>
  typeof value === "string" ? assemblyIds.get(value) ?? value : value))
writeFileSync(outputPath, `${JSON.stringify([...pcb, ...distinctMechanics])}\n`)