// These are the unique ids of the terminal P1 and P2
const anodeTerminalElementId = "9b43137e-5678-604b-097b-07055b46b0c6"; //P1
const cathodeTerminalElementId = "8d0d6e5c-9570-643c-7237-cd6c714368b5"; //P2
const anodeTerminalElement = flux.getNodeById(anodeTerminalElementId, "elementTerminal");
const cathodeTerminalElement = flux.getNodeById(cathodeTerminalElementId, "elementTerminal");
const peakVoltage = Number(flux.properties.find((prop) => prop.name === "Peak Voltage")?.value) || 5;
const dcOffset = Number(flux.properties.find((prop) => prop.name === "DC Offset")?.value) || 0;
const pi = Math.PI;
var typeActive = "A"; // Set default waveform type to Sinusoid
flux.on("setup", (event) => {
const voltage = 0;
flux.simulationModel = simModel(voltage);
const currentWaveformType = flux.controls.find(control => control.name === "Waveform Type");
switch (currentWaveformType?.value) {
case 'Sinusoid': typeActive = "A"; flux.currentSymbol = "sine"; break;
case 'Square': typeActive = "B"; flux.currentSymbol = "square"; break;
case 'Triangle': typeActive = "C"; flux.currentSymbol = "triangle"; break;
case 'Sawtooth': typeActive = "D" ; flux.currentSymbol = "sawtooth"; break;
};
});
flux.on("beforeStep", (event) => {
const frequency = Number(flux.properties.find((prop) => prop.name === "Frequency")?.value) || 800;
const phaseShift = Number(flux.properties.find((prop) => prop.name === "Phase Offset")?.value) || 0;
const dutyCycle = (Number(flux.properties.find((prop) => prop.name === "Duty Cycle")?.value || 0.5)) / 100;