mohan-bee/flight-controller-v2
A 64 mm STM32F405 flight-controller PCB with ICM-42688 IMU, SPI flash, USB-C/ESD, battery buck and 3.3 V regulation, four motor outputs, service I/O, and PETG standoff mounting hardware.
- Version
- 0.1.0
- License
- ISC
- Stars
- 0
workarounds.mjs
import assert from "node:assert/strict";
import { readFileSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { Point } from "@flatten-js/core";
function patch(moduleName, before, after) {
const path = fileURLToPath(import.meta.resolve(moduleName));
const source = readFileSync(path, "utf8");
if (source.includes(after)) return;
assert.equal(
source.split(before).length,
2,
`Review workaround for ${moduleName} after upgrading`,
);
writeFileSync(path, source.replace(before, after));
}
patch(
"@tscircuit/core",
" updatePcbTraceRender() {\n",
' updatePcbTraceRender() {\n if (this.root?.pcbDisabled || this.root?.pcbRoutingDisabled || this.getInheritedProperty("routingDisabled")) return;\n',
);
// Excellon requires a slot's start coordinate and G85 endpoint in one block.
// Keep this export-only correction until circuit-json-to-gerber fixes it.
patch(
"./node_modules/@tscircuit/cli/dist/cli/main.js",
' return commands.map((c) => {\n const def = excellon_drill_command_map[c.command_code];\n return def.stringify(c);\n }).join(`\n`);',
' const blocks = [];\n for (const command of commands) {\n const block = excellon_drill_command_map[command.command_code].stringify(command);\n if (command.command_code === "G85") blocks[blocks.length - 1] += block;\n else blocks.push(block);\n }\n return blocks.join("\\n");',
);
const { getTraceSegmentPolygon } = await import("@tscircuit/circuit-json-util");
for (const length of [0, 1e-14, 1e-10]) {
const polygon = getTraceSegmentPolygon(
{ x: 10, y: 10 },
{ x: 10 + length, y: 10 },
0.2,
);
assert(Math.abs(polygon.area() - Math.PI * 0.1 ** 2) < 1e-8);
assert(polygon.contains(new Point(10, 10)));
}
const normal = getTraceSegmentPolygon({ x: 0, y: 0 }, { x: 1, y: 0 }, 0.2);
assert(Math.abs(normal.area() - (0.2 + Math.PI * 0.1 ** 2)) < 1e-8);
console.log(
"Pinned-tool workarounds applied; zero-length and normal copper segment geometry verified.",
);