/** * Ammeter — probe component that reads the current through its body. * * Connected in SERIES with the circuit under test. `componentToSpice` * emits a `V__sense 0` voltage source plus a tiny shunt; ngspice * reports the branch current for that source, and we read it back here. * * Like a real bench DMM, the display switches to RMS/peak/DC when the * current has AC content (detected via `.tran` `timeWaveforms`). */ import { useMemo } from 'react'; import { useElectricalStore } from '../../store/useElectricalStore'; import { readAmmeter } from '../../simulation/spice/probes'; interface AmmeterProps { id: string; } export function Ammeter({ id }: AmmeterProps) { const branchCurrents = useElectricalStore((s) => s.branchCurrents); const converged = useElectricalStore((s) => s.converged); const error = useElectricalStore((s) => s.error); const timeWaveforms = useElectricalStore((s) => s.timeWaveforms); const reading = useMemo(() => { return readAmmeter( { id, metadataId: 'instr-ammeter', properties: {} }, { nodeVoltages: {}, branchCurrents, converged, error, solveMs: 0, submittedNetlist: '', pinNetMap: new Map(), analysisMode: timeWaveforms ? 'tran' : 'op', timeWaveforms, }, timeWaveforms, ); }, [branchCurrents, converged, error, id, timeWaveforms]); const color = reading.stale ? '#666' : '#4dd0e1'; const height = reading.ac ? 78 : 60; return (
A METER {reading.ac ? '~AC' : 'DC'}
{reading.display}
{reading.ac && (
{reading.ac.peakDisplay} {reading.ac.dcDisplay}
)}
); }