Skip to content

Commit

Permalink
StreamBrowserDialog: properly cache channel / global enable status
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Oct 14, 2024
1 parent a74b988 commit 6349695
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib
5 changes: 5 additions & 0 deletions src/ngscopeclient/InstrumentThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,14 @@ void InstrumentThread(InstrumentThreadArgs args)
psustate->m_channelCurrent[i] = pchan->GetCurrentMeasured();
psustate->m_channelConstantCurrent[i] = psu->IsPowerConstantCurrent(i);
psustate->m_channelFuseTripped[i] = psu->GetPowerOvercurrentShutdownTripped(i);
psustate->m_channelOn[i] = psu->GetPowerChannelActive(i);

session->MarkChannelDirty(pchan);
}

if(psu->SupportsMasterOutputSwitching())
psustate->m_masterEnable = psu->GetMasterPowerEnable();

psustate->m_firstUpdateDone = true;
}
if(load)
Expand Down
7 changes: 7 additions & 0 deletions src/ngscopeclient/PowerSupplyState.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,21 @@ class PowerSupplyState

PowerSupplyState(size_t n = 0)
{
m_masterEnable = false;

m_channelVoltage = std::make_unique<std::atomic<float>[] >(n);
m_channelCurrent = std::make_unique<std::atomic<float>[] >(n);
m_channelConstantCurrent = std::make_unique<std::atomic<bool>[] >(n);
m_channelFuseTripped = std::make_unique<std::atomic<bool>[] >(n);
m_channelOn = std::make_unique<std::atomic<bool>[] >(n);

for(size_t i=0; i<n; i++)
{
m_channelVoltage[i] = 0;
m_channelCurrent[i] = 0;
m_channelConstantCurrent[i] = false;
m_channelFuseTripped[i] = false;
m_channelOn[i] = false;
}

m_firstUpdateDone = false;
Expand All @@ -64,8 +68,11 @@ class PowerSupplyState
std::unique_ptr<std::atomic<float>[]> m_channelCurrent;
std::unique_ptr<std::atomic<bool>[]> m_channelConstantCurrent;
std::unique_ptr<std::atomic<bool>[]> m_channelFuseTripped;
std::unique_ptr<std::atomic<bool>[]> m_channelOn;

std::atomic<bool> m_firstUpdateDone;

std::atomic<bool> m_masterEnable;
};

#endif
47 changes: 18 additions & 29 deletions src/ngscopeclient/StreamBrowserDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ bool StreamBrowserDialog::DoRender()
};

auto renderPsuRows = [this](bool isVoltage, bool cc, PowerSupplyChannel* chan,const char *setValue, const char *measuredValue, bool &clicked, bool &hovered)
{
{
auto& prefs = m_session.GetPreferences();
// Row 1
ImGui::TableNextRow();
Expand Down Expand Up @@ -321,7 +321,7 @@ bool StreamBrowserDialog::DoRender()

// Render ornaments for this scope: offline, trigger status, ...
auto scope = std::dynamic_pointer_cast<Oscilloscope>(inst);
if (scope)
if (scope)
{
if (scope->IsOffline())
renderBadge(ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_offline_badge_color")), "OFFLINE", "OFFL", NULL);
Expand Down Expand Up @@ -362,42 +362,40 @@ bool StreamBrowserDialog::DoRender()

// Render ornaments for this PSU: on/off status, ...
auto psu = std::dynamic_pointer_cast<SCPIPowerSupply>(inst);
if (psu)
if (psu)
{
//Get the state
auto psustate = m_session.GetPSUState(psu);

bool allOn = false;
bool someOn = false;
if(psu->SupportsMasterOutputSwitching())
{
allOn = psu->GetMasterPowerEnable();
}
allOn = psustate->m_masterEnable;
else
{
allOn = true;
for(size_t i = 0 ; i < channelCount ; i++)
{
if(psu->GetPowerChannelActive(i))
{
if(psustate->m_channelOn[i])
someOn = true;
}
else
{
allOn = false;
}
}
}
bool clicked;
if(allOn || someOn)
{
clicked = renderBadge(allOn ? ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_on_badge_color")) : ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_partial_badge_color")), "ON", "I", NULL);
clicked = renderBadge(allOn ?
ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_on_badge_color")) :
ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_partial_badge_color")), "ON", "I", NULL);
}
else
{
clicked = renderBadge(ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_off_badge_color")), "OFF", "O", NULL);
clicked = renderBadge(ImGui::ColorConvertU32ToFloat4(
prefs.GetColor("Appearance.Stream Browser.instrument_off_badge_color")), "OFF", "O", NULL);
}
if(clicked)
{
psu->SetMasterPowerEnable(!allOn);
}
}

if(instIsOpen)
Expand All @@ -421,9 +419,7 @@ bool StreamBrowserDialog::DoRender()
for(size_t i = 0; i<channelCount; i++)
{
if(scope->IsChannelEnabled(i))
{
lastEnabledChannelIndex = i;
}
}

ImGui::EndChild();
Expand Down Expand Up @@ -485,30 +481,23 @@ bool StreamBrowserDialog::DoRender()
if (scopechan)
{
if(!scopechan->IsEnabled())
{
renderBadge(ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_disabled_badge_color")), "DISABLED", "DISA","--", NULL);
}
else
{
renderDownloadProgress(inst, chan, (i == lastEnabledChannelIndex));
}
}
else if(psu)
{
//Get the state
auto psustate = m_session.GetPSUState(psu);

bool clicked;
bool active = psu->GetPowerChannelActive(i);
bool active = psustate->m_channelOn[i];
if(active)
{
clicked = renderBadge(ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_on_badge_color")), "ON", "I", NULL);
}
else
{
clicked = renderBadge(ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_off_badge_color")), "OFF", "O", NULL);
}
if(clicked)
{
psu->SetPowerChannelActive(i,!active);
}
}

if(open)
Expand Down Expand Up @@ -545,7 +534,7 @@ bool StreamBrowserDialog::DoRender()
}
if (hovered)
m_parent->AddStatusHelp("mouse_lmb", "Open channel properties");
}
}
ImGui::EndChild();
}
else
Expand Down

0 comments on commit 6349695

Please sign in to comment.