imrishabh18/rp2040-motor-controller

An RP2040-based NEMA17 stepper-motor controller with USB-C programming and PD motor-power negotiation, DRV8825 dual H-bridge drive, current/temperature telemetry, protected power filtering, status RGB LED, buzzer alarm, and optional magnetic encoder.

Version
1.0.42
License
unset
Stars
3

tests/temperature-telemetry.test.tsx

import { expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { Circuit } from "tscircuit";
import type { CircuitJson } from "circuit-json";
import Board from "../index.circuit";
import { assertTemperatureTelemetry } from "./helpers/assertTemperatureTelemetry";

async function buildJson(): Promise<CircuitJson> {
  if (process.env.CIRCUIT_JSON_PATH) return JSON.parse(readFileSync(process.env.CIRCUIT_JSON_PATH, "utf8"));
  const circuit = new Circuit({ platform: { pcbDisabled: true } });
  circuit.add(<Board routingDisabled />);
  await circuit.renderUntilSettled();
  return circuit.getCircuitJson();
}

test("temperature uses I2C only; ALERT/GPIO24 are disconnected and MCU/PD enable is retained", async () => {
  const json = await buildJson();
  expect(assertTemperatureTelemetry(json).status).toBe("pass");
  const disconnect = json.filter(e => !(e.type === "source_trace" && e.name === "PD_ENABLE_OUTPUT"));
  expect(() => assertTemperatureTelemetry(disconnect)).toThrow("Disconnected");
  const port = (part: string, label: string) => {
    const c = json.find(e => e.type === "source_component" && e.name === part)!;
    if (c.type !== "source_component") throw Error("component");
    const p = json.find(e => e.type === "source_port" && e.source_component_id === c.source_component_id && e.port_hints?.includes(label));
    if (p?.type !== "source_port") throw Error("port");
    return p.source_port_id;
  };
  const bypass: CircuitJson = [...json, { type: "source_trace", source_trace_id: "test_bypass",
    connected_source_port_ids: [port("U_TEMP", "ALERT"), port("DRIVER", "nSleep")], connected_source_net_ids: [] }];
  expect(() => assertTemperatureTelemetry(bypass)).toThrow("Unused temperature ALERT/GPIO24 is connected");
  const gpioReconnected: CircuitJson = [...json, { type: "source_trace", source_trace_id: "test_gpio24_reconnected",
    connected_source_port_ids: [port("U1", "GPIO24"), port("U_TEMP", "SDA")], connected_source_net_ids: [] }];
  expect(() => assertTemperatureTelemetry(gpioReconnected)).toThrow("Unused temperature ALERT/GPIO24 is connected");
}, 60_000);