Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions libdp100/PowerSupply.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public class PowerSupply
/// </summary>
private bool[] presetsValid = new bool[NumPresets];

/// <summary>
/// Indicates that the "Presets" object has been applied to the volatile preset's state.
/// </summary>
private bool[] presetsLoaded = new bool[NumPresets];

/// <summary>
/// Indicates that the "SystemParams" object has been populated with valid data.
/// </summary>
Expand Down Expand Up @@ -525,8 +530,14 @@ public PowerSupplyResult SetOutput(bool outputOn, ushort millivolts, ushort mill
Output.Setpoint.Voltage = millivolts;
Output.Setpoint.Current = milliamps;

if (Presets[Output.Preset] == null)
{
Presets[Output.Preset] = new PowerSupplySetpoint(Output.Preset);
}

// Output state affects the volatile state of a preset (group).
Presets[Output.Preset].Copy(Output.Setpoint);
presetsValid[Output.Preset] = true;
}

return result;
Expand Down Expand Up @@ -894,6 +905,14 @@ public PowerSupplyResult UsePreset(byte preset)
}
}

if (result == PowerSupplyResult.OK)
{
if (!presetsLoaded[preset])
{
result = SetOutput(Presets[preset]);
}
}

if (result == PowerSupplyResult.OK)
{
Output.Setpoint.Copy(Presets[preset]);
Expand Down Expand Up @@ -1042,18 +1061,6 @@ public PowerSupplyResult Reload()
{
return result;
}

result = UsePreset(i);
if (result != PowerSupplyResult.OK)
{
return result;
}

result = SetOutput(Presets[i]);
if (result != PowerSupplyResult.OK)
{
return result;
}
}

return result;
Expand Down
Loading