// see https://docs.flux.ai/simulator/analogswitch2
const terminals: Array<any> = [];
terminals[0] = flux.getNodeById("ba26450a-7aa7-ad28-82b1-1fdd1da67669");
terminals[1] = flux.getNodeById("1e5938e6-2cc6-769c-77e2-e9c7848615ee");
flux.on("setup", () => {
flux.simulationModel = {
type: "analogSwitch2",
map_input_to_terminal_uid: terminals[0]?.uid,
map_output_to_terminal_uid: terminals[1]?.uid
}
})
const v0 = flux.createOutputNode({ name: "VP0", value: 0, unit: "V" });
const v1 = flux.createOutputNode({ name: "VP1", value: 0, unit: "V" });
const vdrop = flux.createOutputNode({ name: "Vdrop", value: 0, unit: "V" });
const current = flux.createOutputNode({ name: "Current", value: 0, unit: "A" });
flux.on("afterStep", () => {
v0.value = Number(terminals[0]?.voltage);
v1.value = Number(terminals[1]?.voltage);
vdrop.value = v1.value - v0.value
current.value = Number(terminals[0]?.current);
flux.outputs = [v0, v1, current, vdrop];
})