Devesh36/usb-c-aqi-meter

A PETG-enclosed air-quality monitor assembly combining an AQI circuit board, Sensirion SPS30 particulate sensor, OLED display with bezel and glass, power slider, branding, and internal wiring harness.

Version
1.2.0
License
unset
Stars
0

Use with the tscircuit CLI

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

tsci clone Devesh36/usb-c-aqi-meter  # download the package files into ./usb-c-aqi-meter
tsci add Devesh36/usb-c-aqi-meter    # add it to your project as @tsci/Devesh36.usb-c-aqi-meter

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.

mechanics.tsx

import { jscad } from "tscircuit";
// Millimetres, PCB midplane Z=0. Purchased module models are dimensional envelopes.
export const OLED = { x: 0, y: -8, pcbZ: 19.5, glassZ: 22.5 };
function RoundedPlate({
	width,
	depth,
	height,
	z,
	radius = 5,
}: {
	width: number;
	depth: number;
	height: number;
	z: number;
	radius?: number;
}) {
	return (
		<jscad.hull>
			{[-1, 1].flatMap((x) =>
				[-1, 1].map((y) => (
					<jscad.cylinder
						key={`${x}:${y}`}
						radius={radius}
						height={height}
						center={[x * (width / 2 - radius), y * (depth / 2 - radius), z]}
					/>
				)),
			)}
		</jscad.hull>
	);
}
export function Base() {
	return (
		<jscad.subtract>
			<jscad.union>
				<jscad.subtract>
					<RoundedPlate width={86} depth={76} height={27.5} z={7.75} />
					<RoundedPlate width={82} depth={72} height={28} z={10} radius={3} />
				</jscad.subtract>
				{[-36, 36].flatMap((x) =>
					[-31, 31].map((y) => (
						<jscad.cylinder
							key={`${x}:${y}`}
							radius={3}
							height={3.2}
							center={[x, y, -2.4]}
						/>
					)),
				)}
				{[0, 34].flatMap((x) =>
					[-12, 24].map((y) => (
						<jscad.union key={`sensor:${x}:${y}`}>
							<jscad.cylinder radius={3} height={3.2} center={[x, y, -2.4]} />
							<jscad.cylinder radius={1.35} height={6.8} center={[x, y, 2.6]} />
							<jscad.cuboid size={[4, 4, 0.8]} center={[x, y, 5.6]} />
						</jscad.union>
					)),
				)}
				{/* Corner bosses retain the lid with M2 screws; bores require fit qualification. */}
				{[-36, 36].flatMap((x) =>
					[-31, 31].map((y) => (
						<jscad.union key={`lid:${x}:${y}`}>
							<jscad.cylinder radius={1.35} height={2.2} center={[x, y, 0.3]} />
							<jscad.cylinder
								radius={2.5}
								height={20.1}
								center={[x, y, 11.45]}
							/>
						</jscad.union>
					)),
				)}
			</jscad.union>
			<jscad.cuboid size={[12, 10, 7]} center={[0, -37, 2]} />
			<jscad.cuboid size={[12, 8, 7]} center={[28, -37, 3]} />
			<jscad.cuboid size={[12, 10, 7]} center={[-24, 37, 11.6]} />
			{/* Separate front/rear vent banks provide air access to the SPS30. */}
			{[-43, 43].flatMap((x) =>
				Array.from({ length: 7 }, (_, i) => (
					<jscad.cuboid
						key={`${x}:${i}`}
						size={[5, 3, 9]}
						center={[x, -12 + i * 6, 12]}
					/>
				)),
			)}
			{/* Ambient sensor has its own vent, remote from the USB power components. */}
			<jscad.cuboid size={[12, 5, 7]} center={[4, 37, 4]} />
			{[-36, 36].flatMap((x) =>
				[-31, 31].map((y) => (
					<jscad.cylinder
						key={`${x}:${y}`}
						radius={0.85}
						height={10}
						center={[x, y, -2]}
					/>
				)),
			)}
			{[-36, 36].flatMap((x) =>
				[-31, 31].map((y) => (
					<jscad.cylinder
						key={`lid:${x}:${y}`}
						radius={0.85}
						height={27}
						center={[x, y, 9]}
					/>
				)),
			)}
		</jscad.subtract>
	);
}
export function Lid() {
	return (
		<jscad.subtract>
			<jscad.union>
				<RoundedPlate width={86} depth={76} height={2} z={22.5} />
				{/* Display carrier clips retain the module edges, clear of the active panel. */}
				{[-1, 1].map((side) => (
					<jscad.cuboid
						key={side}
						size={[1.6, 40.3, 4]}
						center={[OLED.x + side * 31.55, OLED.y, 20.5]}
					/>
				))}
				{[-1, 1].map((side) => (
					<jscad.cuboid
						key={`ledge:${side}`}
						size={[2.4, 40.3, 0.8]}
						center={[OLED.x + side * 31.15, OLED.y, 18.6]}
					/>
				))}
			</jscad.union>
			<jscad.cuboid size={[56, 28.5, 6]} center={[OLED.x, OLED.y, 22.5]} />
			{Array.from({ length: 9 }, (_, i) => (
				<jscad.cuboid
					key={i}
					size={[2.4, 13, 6]}
					center={[-2 + i * 4, 24, 22.5]}
				/>
			))}

			{[-36, 36].flatMap((x) =>
				[-31, 31].map((y) => (
					<jscad.cylinder
						key={`${x}:${y}`}
						radius={1.2}
						height={6}
						center={[x, y, 22.5]}
					/>
				)),
			)}
		</jscad.subtract>
	);
}
export function Bezel() {
	return (
		<jscad.subtract>
			<jscad.cuboid size={[60, 32.5, 0.7]} center={[OLED.x, OLED.y, 23.65]} />
			<jscad.cuboid size={[55.6, 28.1, 3]} center={[OLED.x, OLED.y, 23.65]} />
		</jscad.subtract>
	);
}
export function SensorEnvelope() {
	return (
		<jscad.colorize color="#aeb7bd">
			<jscad.subtract>
				<jscad.cuboid size={[41, 41, 12]} center={[17, 6, 12]} />
				<jscad.cuboid size={[16, 3, 5]} center={[24, -14.5, 11]} />
				<jscad.cuboid size={[16, 3, 5]} center={[24, 26.5, 11]} />
				<jscad.cylinder radius={7} height={1} center={[23, 10, 18]} />
			</jscad.subtract>
		</jscad.colorize>
	);
}
export function DisplayEnvelope() {
	return (
		<jscad.colorize color="#153d36">
			<jscad.cuboid
				size={[61.5, 39.5, 1]}
				center={[OLED.x, OLED.y, OLED.pcbZ]}
			/>
		</jscad.colorize>
	);
}
export function DisplayGlass() {
	return (
		<jscad.colorize color="#071116">
			<jscad.cuboid
				size={[55.01, 27.49, 1.2]}
				center={[OLED.x, OLED.y, OLED.glassZ]}
			/>
		</jscad.colorize>
	);
}
// A physical startup-screen illustration, never a simulated or live AQI reading.
const font: Record<string, string[]> = {
	A: ["01110", "10001", "10001", "11111", "10001", "10001", "10001"],
	B: ["11110", "10001", "10001", "11110", "10001", "10001", "11110"],
	E: ["11111", "10000", "10000", "11110", "10000", "10000", "11111"],
	H: ["10001", "10001", "10001", "11111", "10001", "10001", "10001"],
	I: ["11111", "00100", "00100", "00100", "00100", "00100", "11111"],
	N: ["10001", "11001", "10101", "10011", "10001", "10001", "10001"],
	Q: ["01110", "10001", "10001", "10001", "10101", "10010", "01101"],
	R: ["11110", "10001", "10001", "11110", "10100", "10010", "10001"],
	S: ["01111", "10000", "10000", "01110", "00001", "00001", "11110"],
	T: ["11111", "00100", "00100", "00100", "00100", "00100", "00100"],
	G: ["01110", "10001", "10000", "10111", "10001", "10001", "01110"],
	c: ["00000", "00000", "01111", "10000", "10000", "10000", "01111"],
	i: ["00100", "00000", "01100", "00100", "00100", "00100", "01110"],
	r: ["00000", "00000", "10110", "11001", "10000", "10000", "10000"],
	s: ["00000", "00000", "01111", "10000", "01110", "00001", "11110"],
	t: ["00100", "00100", "11111", "00100", "00100", "00100", "00011"],
	u: ["00000", "00000", "10001", "10001", "10001", "10011", "01101"],
	O: ["01110", "10001", "10001", "10001", "10001", "10001", "01110"],
	F: ["11111", "10000", "10000", "11110", "10000", "10000", "10000"],

	"-": ["00000", "00000", "00000", "11111", "00000", "00000", "00000"],
	" ": Array(7).fill("00000"),
};
export function PixelText({
	text,
	x,
	y,
	z,
	pitch = 0.24,
}: { text: string; x: number; y: number; z: number; pitch?: number }) {
	return (
		<jscad.union>
			{text
				.split("")
				.flatMap((c, i) =>
					(font[c] ?? font[" "]).flatMap((row, j) =>
						row
							.split("")
							.flatMap((bit, k) =>
								bit === "1"
									? [
											<jscad.cuboid
												key={`${i}:${j}:${k}`}
												size={[pitch * 0.88, pitch * 0.88, 0.035]}
												center={[x + (i * 6 + k) * pitch, y - j * pitch, z]}
											/>,
										]
									: [],
							),
					),
				)}
		</jscad.union>
	);
}
export function ScreenReadout() {
	return (
		<jscad.colorize color="#d7f3ff">
			<jscad.union>
				<PixelText
					text="AQI --"
					x={OLED.x - 22}
					y={OLED.y + 8}
					z={23.14}
					pitch={1.1}
				/>
				<PixelText
					text="STARTING"
					x={OLED.x - 22}
					y={OLED.y - 6}
					z={23.14}
					pitch={0.55}
				/>
			</jscad.union>
		</jscad.colorize>
	);
}
export function Branding() {
	return (
		<PixelText text="tscircuit" x={-15.6} y={-29.5} z={23.55} pitch={0.6} />
	);
}
export function PowerLegend() {
	return <PixelText text="ON   OFF" x={18} y={-33.2} z={23.55} pitch={0.38} />;
}
// Slip-on extension of the native side-facing slide-switch actuator, not a second control.
export function PowerSlider() {
	return <jscad.cuboid size={[2.3, 5.5, 2.3]} center={[27, -38.3, 2.7]} />;
}
// Illustrative looms; connectors/cable lengths must be qualified on physical samples.
export function Harness() {
	const paths = [
		[
			[18, -17.5, 5],
			[18, -21, 7],
			[6, -21, 9],
			[6, -14.5, 11],
		],
		[
			[12, 28, 5],
			[0, 29, 9],
			[-29, 17, 15],
			[-29, 11, 19.5],
		],
	];
	return (
		<jscad.colorize color="#29343e">
			<jscad.union>
				{paths.flatMap((p, k) =>
					p.slice(1).map((q, i) => (
						<jscad.hull key={`${k}:${i}`}>
							<jscad.sphere
								radius={0.7}
								center={p[i] as [number, number, number]}
							/>
							<jscad.sphere
								radius={0.7}
								center={q as [number, number, number]}
							/>
						</jscad.hull>
					)),
				)}
			</jscad.union>
		</jscad.colorize>
	);
}