/** * Pure measurement engine for the de:volt multimeter. * * The live sim store exposes node voltages (`netV`), per-element currents * (`elementI`) and the net topology (`nets[]`). This module turns a pair of * probe nets into a meter reading for each dial position, plus a resistor- * network solver for the resistance (Ω) mode. * * Modelling notes (deliberately explicit about the educational boundary): * - Voltage — differential: reading = V(red) − V(black). The probes are * ideal observers and do not stamp a real 10 MΩ / capacitive * input load back into the circuit. * - Resistance — a real DMM measures resistance on a *de-energized* network, * so Ω mode ignores sources entirely and computes the equivalent * resistance of the resistive sub-network (resistors) between the * two probed nets. Two probes on one net read 0 Ω (continuity); * two nets with no resistive path read OL. Series / parallel * resistor combinations solve exactly via the conductance * Laplacian of the network. * - Current — the probes must straddle one unambiguous two-terminal branch. * The meter reports that branch's solved current; it does not * insert a fuse/shunt burden into the topology. Anything else * reads "---" (cannot isolate a branch). * * This file is pure (no React, no stores) so it is unit-testable in isolation * and shared by any meter UI. */ import type { Circuit } from "../circuit/types.js"; import type { SimFailure } from "./engine/sim-engine.js"; import type { PhysicsTelemetrySnapshot } from "./messages.js"; export type MeterMode = "off" | "auto" | "voltage" | "resistance" | "current"; /** The concrete reading kind the LCD ends up showing (auto resolves to one). */ export type ResolvedMeterMode = "voltage" | "resistance" | "current"; export interface MeterReading { /** Concrete mode actually shown (auto resolves to voltage/resistance). */ mode: ResolvedMeterMode; /** Meter is idle — a lead is open or the dial is OFF; LCD shows dashes. */ idle: boolean; /** Main value in the base SI unit (V, Ω, A). NaN when idle / OL / undefined. */ value: number; /** Formatted numeric text for the LCD, e.g. "4.320", "OL", "0.00", "---". */ text: string; /** Unit suffix, e.g. "V", "kΩ", "mA". Empty while idle. */ unit: string; /** Resistance mode, both probes on one net → continuity (drives the beep). */ continuity: boolean; /** Value out of range / no path → "OL". */ overload: boolean; /** Whether the numeric value is current, retained while paused, or unavailable. */ dataState?: "current" | "paused" | "unavailable"; } type NetPin = readonly [string, string]; interface NetLike { id: string; pins: ReadonlyArray; } interface ResistorEdge { a: string; b: string; r: number; } /** * Collect the resistive edges of the circuit, keyed by live net id. Only plain * resistors are modelled in v1 — every other element is treated as open for the * resistance measurement (a DMM with sources removed sees no path through a * reverse-biased junction or an unpowered IC). Wires and breadboard strips are * already collapsed into single nets upstream, so within-net resistance is 0. */ export declare function resistorEdges(circuit: Circuit, nets: ReadonlyArray, failures?: Readonly>): ResistorEdge[]; /** * Equivalent resistance between two nets over a resistor network, in ohms. * Returns 0 when the nets are identical and Infinity (OL) when no resistive * path connects them. Solves the network exactly by grounding `b`, injecting * 1 A at `a`, and reading back V(a) = R. */ export declare function effectiveResistance(edges: ResistorEdge[], a: string, b: string): number; /** * Find the single two-terminal component bridging the two probed nets, returning * its signed current (red→black). Null when no single element straddles the two * nets (current is then undefined — a real ammeter must be inserted in series * with exactly one branch). */ export declare function bridgingCurrent(circuit: Circuit, nets: ReadonlyArray, redNet: string, blackNet: string, elementI: Record, physicsTelemetry?: PhysicsTelemetrySnapshot | null): number | null; export interface ReadMeterParams { mode: MeterMode; /** Live net under the red lead, or null when the lead is open. */ redNet: string | null; /** Live net under the black lead, or null when the lead is open. */ blackNet: string | null; circuit: Circuit; nets: ReadonlyArray; netV: Record; elementI: Record; failures?: Readonly>; physicsTelemetry?: PhysicsTelemetrySnapshot | null; /** Applies to solved voltage/current only; resistance is a topology observer. */ dataState?: "current" | "paused" | "unavailable"; /** Memoised resistor edges (optional; rebuilt when omitted). */ edges?: ResistorEdge[]; } /** * Compute the meter reading for the current dial position and probe nets. * The single entry point the UI calls every refresh tick. */ export declare function readMeter(params: ReadMeterParams): MeterReading; export {};