shibosoftwaredev/f1c100s-linux-nema17-stepper-controller

A four-layer NEMA 17 motor-controller PCB combining an Allwinner F1C100S Linux computer, USB‑PD/buck power system, W5500 Ethernet, STM32 real-time motion control, DRV8825 stepper driver, protection/temperature/current telemetry, USB interfaces, and local LED/buzzer diagnostics.

Version
0.4.56
License
unset
Stars
0

scripts/remove-buck-enable-tie.mjs

// One-time migration of the saved replay after removing the unsafe EN-VIN tie.
// Refuse unexpected inputs; all other emitted paths and footprints stay intact.
import fs from "node:fs"
import assert from "node:assert/strict"
const read = path => JSON.parse(fs.readFileSync(path, "utf8"))
const write = (path, value) => fs.writeFileSync(path, JSON.stringify(value, null, 2) + "\n")
const baseline = "../../checkpoints/nema17-round12-pre-fix-20261020-Md2v1O/restore-verified"
const old = read(`${baseline}/dist/index/circuit.json`)
const tie = old.find(e => e.type === "source_trace" && e.name === "BUCK_ENABLE")
assert.equal(tie.source_trace_id, "source_trace_104")
assert.deepEqual(tie.connected_source_port_ids, ["source_port_255", "source_port_253"])
const remapId = id => {
  if (!/^source_trace_\d+$/.test(id)) return id
  const n = Number(id.slice(13))
  assert.notEqual(n, 104, "deleted trace must not survive the migration")
  return `source_trace_${n > 104 ? n - 1 : n}`
}
const remap = value => {
  if (Array.isArray(value)) return value.map(remap)
  if (value && typeof value === "object") return Object.fromEntries(Object.entries(value)
    .map(([key, v]) => [remapId(key), remap(v)]))
  return typeof value === "string" ? remapId(value) : value
}
const routes = read(`${baseline}/routing/complete-routes.json`)
const deleted = routes.filter(t => t.source_trace_id === tie.source_trace_id)
assert.equal(deleted.length, 2)
// The 0.50 mm VIN trunk is duplicated by BUCK_INPUT_BYPASS, so deleting the
// tie's two source paths removes only the three-segment 0.15 mm EN branch.
for (const t of deleted) for (let i = 1; i < t.route.length; i++) {
  const a = t.route[i-1], b = t.route[i]
  if (a.route_type !== "wire" || b.route_type !== "wire" || Math.hypot(a.x-b.x,a.y-b.y) < 1e-8 || a.width < .5) continue
  assert.ok(routes.some(other => other.source_trace_id !== tie.source_trace_id && other.route.some((p,j) => {
    if (!j) return false
    const q = other.route[j-1]
    return Math.hypot(p.x-b.x,p.y-b.y) < 1e-6 && Math.hypot(q.x-a.x,q.y-a.y) < 1e-6 ||
      Math.hypot(p.x-a.x,p.y-a.y) < 1e-6 && Math.hypot(q.x-b.x,q.y-b.y) < 1e-6
  })), "shared VIN trunk must remain")
}
write("routing/complete-routes.json", remap(routes.filter(t => t.source_trace_id !== tie.source_trace_id)))
const constraints = read(`${baseline}/routing/trace-constraints.json`)
delete constraints[tie.source_trace_id]
write("routing/trace-constraints.json", remap(constraints))
write("routing/native-features.json", remap(read(`${baseline}/routing/native-features.json`)))
console.log("Removed EN copper branch; retained all other paths, VIN trunk and thermal vias; shifted trace identities explicitly.")