MustafaMulla29/rp2040-bldc-motor-controller

Hardware assembly metadata and PCB geometry for a controller board with a snap-off rotary-encoder section, plus four parallel 150 µF/50 V bulk electrolytic capacitors filtering the motor supply.

Version
2.0.40
License
unset
Stars
0

Use with the tscircuit CLI

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

tsci clone MustafaMulla29/rp2040-bldc-motor-controller  # download the package files into ./rp2040-bldc-motor-controller
tsci add MustafaMulla29/rp2040-bldc-motor-controller    # add it to your project as @tsci/MustafaMulla29.rp2040-bldc-motor-controller

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.

scripts/push-package.mjs

/** Publish a portable copy; keep local assembly authoring and audit caches. */
import { cpSync, existsSync, mkdtempSync, readFileSync, readdirSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
import { dirname, join, resolve } from "node:path"
import { fileURLToPath } from "node:url"

const root = resolve(dirname(fileURLToPath(import.meta.url)), "..")
const config = JSON.parse(readFileSync(join(root, "tscircuit.config.json"), "utf8"))
const patterns = [...(config.ignoredFiles ?? []), "**/__pycache__/**", "**/*.pyc"]
const ignored = patterns.map(pattern => new Bun.Glob(pattern))
const stage = mkdtempSync(join(tmpdir(), "motor-controller-publish-"))
const originalPackage = readFileSync(join(root, "package.json"), "utf8")
let files = 0
function copyDirectory(relative = "") {
  for (const entry of readdirSync(join(root, relative), { withFileTypes: true })) {
    if (entry.name.startsWith(".")) continue
    const path = relative ? `${relative}/${entry.name}` : entry.name
    if (ignored.some(glob => glob.match(path) || entry.isDirectory() && glob.match(`${path}/`))) continue
    if (entry.isDirectory()) copyDirectory(path)
    else if (entry.isFile()) {
      cpSync(join(root, path), join(stage, path))
      files++
    }
  }
}
copyDirectory()
for (const path of [config.mainEntrypoint, "system.circuit.tsx", "index.circuit.tsx", "assets/connected-system.glb", "circuit/route-plan.json.gz", "scripts/large-files.json",
  "enclosure/parts.tsx", "enclosure/dimensions.ts", "enclosure/oled-mechanics.ts", "enclosure/labels.tsx", "enclosure/reference-board.json",
  ...["base", "lid", "button-plunger", "speed-knob", "screen-holder"].map(name => `assets/enclosure/${name}.stl`),
  "assets/enclosure/README.md"]) {
  if (!existsSync(join(stage, path))) throw new Error(`Publish copy is missing ${path}`)
}
console.log(`Prepared ${files} files, including the assembly model, in ${stage}`)
if (!process.argv.includes("--prepare-only")) {
  const cli = fileURLToPath(import.meta.resolve("@tscircuit/cli"))
  // Use the Node runtime declared by the CLI's own shebang.
  const child = Bun.spawn(["node", cli, "push", "--compress"], {
    cwd: stage, stdin: "inherit", stdout: "inherit", stderr: "pipe",
  })
  const [code, stderr] = await Promise.all([child.exited, new Response(child.stderr).text()])
  // Uncaught CLI request errors can include Authorization headers.
  process.stderr.write(stderr.replace(/Bearer\s+[^"'\s,}]+/g, "Bearer [REDACTED]"))
  const published = JSON.parse(readFileSync(join(stage, "package.json"), "utf8"))
  // Retain the CLI's consumed version even if its upload fails; preserve other edits.
  if (readFileSync(join(root, "package.json"), "utf8") === originalPackage) {
    const local = JSON.parse(originalPackage)
    local.version = published.version
    writeFileSync(join(root, "package.json"), JSON.stringify(local, null, 2))
  } else console.log("Local package.json changed during upload; its version was left untouched.")
  process.exitCode = code
}