AnasSarkiz/magnetic-shutter-remote-r8

A USB‑C rechargeable battery-powered ESP32‑C3 wireless controller with Li‑ion charging, protected 3.3‑V buck‑boost regulation, thermal/safety monitoring, status LEDs, buttons, programming UART, crystal clock, and 2.4‑GHz antenna matching network.

Version
0.4.0-prototype
License
unset
Stars
0

src/r9-ground-returns.ts

import type { FanoutTracePath } from "@tscircuit/core";
import { applyToPoint, translate } from "transformation-matrix";
import { z } from "zod";

// Short authored returns in board-world XY mm. Every barrel is0.30/0.45mm,
// top-to-bottom; SMT/NPTH/drill/other-net clearance is independently checked.
function groundReturn({
	connection,
	padMm,
	viaMm,
}: {
	connection: string;
	padMm: [number, number];
	viaMm: [number, number];
}): FanoutTracePath {
	return {
		connection,
		route: [
			{
				route_type: "wire",
				x: padMm[0],
				y: padMm[1],
				width: 0.3,
				layer: "top",
			},
			{
				route_type: "wire",
				x: viaMm[0],
				y: viaMm[1],
				width: 0.3,
				layer: "top",
			},
			{
				route_type: "via",
				x: viaMm[0],
				y: viaMm[1],
				from_layer: "top",
				to_layer: "bottom",
				via_diameter: 0.45,
				via_hole_diameter: 0.3,
			},
		],
	};
}
function inLocalFrame(
	paths: FanoutTracePath[],
	anchorMm: [number, number],
): FanoutTracePath[] {
	return paths.map((path) => ({
		...path,
		route: path.route.map((point) => {
			const moved = applyToPoint(translate(-anchorMm[0], -anchorMm[1]), {
				x: z.number().parse(point.x),
				y: z.number().parse(point.y),
			});
			return { ...point, x: moved.x, y: moved.y };
		}),
	}));
}
export const r9UsbSinkGroundPaths = [
	groundReturn({
		connection: "R1.pin2",
		padMm: [-3.246636, 19],
		viaMm: [-3.246636, 17.6],
	}),
];
export const r9InputCapGroundWorldPaths = [
	groundReturn({
		connection: "C1.pin2",
		padMm: [7.400024, 19.5],
		viaMm: [10, 19.5],
	}),
];
export const r9InputCapGroundPaths = inLocalFrame(
	r9InputCapGroundWorldPaths,
	[6.7, 19.5],
);
export const r9ShutterGroundPaths = [
	groundReturn({
		connection: "SW2.pin2",
		padMm: [19.0000401, -10.1999712],
		viaMm: [17.4, -10.1999712],
	}),
	groundReturn({
		connection: "SW2.pin3",
		padMm: [20.9499473, -10.6248878],
		viaMm: [20.6, -11.9],
	}),
	groundReturn({
		connection: "SW2.pin4",
		padMm: [20.9499473, -6.3751122],
		viaMm: [20.6, -5],
	}),
];
export const r9PairGroundWorldPaths = [
	groundReturn({
		connection: "SW3.pin2",
		padMm: [20.184908, -3],
		viaMm: [20.184908, -1.4],
	}),
];
export const r9PairGroundPaths = inLocalFrame(r9PairGroundWorldPaths, [18, -3]);
export const r9LedGroundWorldPaths = [
	groundReturn({
		connection: "LED2.pin2",
		padMm: [-19.750062, -5],
		viaMm: [-20.7, -6.2],
	}),
];
export const r9LedGroundPaths = inLocalFrame(r9LedGroundWorldPaths, [-19, -5]);
export const r9ProgramAdditionalGroundPaths = [
	groundReturn({
		connection: "J3.pin2",
		padMm: [16.500127, 17.3250037],
		viaMm: [16.500127, 19],
	}),
	groundReturn({
		connection: "J3.pin4",
		padMm: [18.799843, 14.8002437],
		viaMm: [20.3, 14.8002437],
	}),
];
export const r9BootGroundWorldPaths = [
	groundReturn({
		connection: "SW4.pin2",
		padMm: [-16.815092, -9],
		viaMm: [-15.6, -10],
	}),
];
export const r9BootGroundPaths = inLocalFrame(
	r9BootGroundWorldPaths,
	[-19, -9],
);
export const r9ResetGroundPaths = [
	groundReturn({
		connection: "SW5.pin2",
		padMm: [17.584908, 11.5],
		viaMm: [18.9, 11.5],
	}),
];
export const r9PowerSwitchGroundWorldPaths = [
	groundReturn({
		connection: "SW1.pin3",
		padMm: [17.50597835, 7.249932],
		viaMm: [16, 7.249932],
	}),
];
export const r9PowerSwitchGroundPaths = inLocalFrame(
	r9PowerSwitchGroundWorldPaths,
	[19, 5],
);
export const r9EnableCapGroundPaths = [
	groundReturn({
		connection: "C23.pin2",
		padMm: [7.2, -5.499976],
		viaMm: [8.6, -5.499976],
	}),
];