krishnax12/usb-c-control-dial

USB-C control dial PCB with an EC11 push encoder and a 16-LED ring for volume and brightness controls. Work in progress; firmware not included and not fabrication-ready.

Version
0.0.3
License
unset
Stars
1

scripts/render.tsx

import { mkdir } from "node:fs/promises"
import { resolve } from "node:path"
import { Circuit } from "@tscircuit/core"

Bun.plugin({
  name: "local-cad-assets",
  setup(build) {
    build.onLoad({ filter: /\.(obj|step)$/ }, (asset) => ({
      contents: `export default ${JSON.stringify(asset.path)}`,
      loader: "js",
    }))
  },
})

const { default: UsbControlDial } = await import("../index.circuit")
const circuit = new Circuit({ platform: { partsEngineDisabled: true } })
const solverEvents: { solverName: string; startedAt: string }[] = []
circuit.on("solver:started", (event) => {
  solverEvents.push({
    solverName: event.solverName,
    startedAt: new Date().toISOString(),
  })
  console.log(`Solver: ${event.solverName}`)
})
circuit.on("solver:ended", (event) =>
  console.log(`Finished: ${event.solverName}`),
)
circuit.add(<UsbControlDial />)
await circuit.renderUntilSettled()
const circuitJson = circuit.getCircuitJson()
const outputDirectory = resolve(import.meta.dir, "../outputs")
await mkdir(outputDirectory, { recursive: true })
await Bun.write(
  resolve(outputDirectory, "circuit.json"),
  JSON.stringify(circuitJson, null, 2),
)
await Bun.write(
  resolve(outputDirectory, "solvers.json"),
  JSON.stringify(solverEvents, null, 2),
)
const diagnostics = circuitJson.filter((element) =>
  /error|warning/.test(element.type),
)
await Bun.write(
  resolve(outputDirectory, "diagnostics.json"),
  JSON.stringify(diagnostics, null, 2),
)
console.log(
  JSON.stringify(
    {
      diagnostics: Object.fromEntries(
        [...new Set(diagnostics.map((element) => element.type))].map((type) => [
          type,
          diagnostics.filter((element) => element.type === type).length,
        ]),
      ),
      components: circuit.db.source_component.list().length,
      traces: circuit.db.pcb_trace.list().length,
    },
    null,
    2,
  ),
)
if (diagnostics.length) process.exitCode = 1