Showing with 39 additions and 15 deletions.
  1. +24 −11 scopehal/Filter.cpp
  2. +12 −2 scopehal/Filter.h
  3. +1 −1 scopehal/Unit.cpp
  4. +2 −1 scopeprotocols/ClockRecoveryFilter.cpp
@@ -441,24 +441,37 @@ Filter* Filter::CreateFilter(string protocol, string color)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Input verification helpers

/**
@brief Returns true if a given input to the filter is non-NULL (and, optionally has a non-empty waveform present)
*/
bool Filter::VerifyInputOK(size_t i, bool allowEmpty)
{
auto p = m_inputs[i];

if(p.m_channel == NULL)
return false;
auto data = p.GetData();
if(data == NULL)
return false;

if(!allowEmpty)
{
if(data->m_offsets.size() == 0)
return false;
}

return true;
}

/**
@brief Returns true if every input to the filter is non-NULL (and, optionally has a non-empty waveform present)
*/
bool Filter::VerifyAllInputsOK(bool allowEmpty)
{
for(auto p : m_inputs)
for(size_t i=0; i<m_inputs.size(); i++)
{
if(p.m_channel == NULL)
if(!VerifyInputOK(i, allowEmpty))
return false;
auto data = p.m_channel->GetData(p.m_stream);
if(data == NULL)
return false;

if(!allowEmpty)
{
if(data->m_offsets.size() == 0)
return false;
}
}

return true;
@@ -269,11 +269,21 @@ class Filter : public OscilloscopeChannel
bool m_dirty;

bool VerifyAllInputsOK(bool allowEmpty = false);
bool VerifyInputOK(size_t i, bool allowEmpty = false);
bool VerifyAllInputsOKAndAnalog();

///Gets the waveform attached to the specified input
/**
@brief Gets the waveform attached to the specified input.
This function is safe to call on a NULL input and will return NULL in that case.
*/
WaveformBase* GetInputWaveform(size_t i)
{ return m_inputs[i].m_channel->GetData(m_inputs[i].m_stream); }
{
auto chan = m_inputs[i].m_channel;
if(chan == NULL)
return NULL;
return chan->GetData(m_inputs[i].m_stream);
}

///Gets the analog waveform attached to the specified input
AnalogWaveform* GetAnalogInputWaveform(size_t i)
@@ -194,7 +194,7 @@ string Unit::PrettyPrint(double value)
break;

default:
snprintf(tmp, sizeof(tmp), "%.3f %s%s", value_rescaled, scale, unit);
snprintf(tmp, sizeof(tmp), "%.4f %s%s", value_rescaled, scale, unit);
break;
}
return string(tmp);
@@ -119,7 +119,8 @@ double ClockRecoveryFilter::GetVoltageRange()

void ClockRecoveryFilter::Refresh()
{
if(!VerifyAllInputsOK())
//Require a data signal, but not necessarily a gate
if(!VerifyInputOK(0))
{
SetData(NULL, 0);
return;