diff --git a/include-gpl/dsp/scopevis.h b/include-gpl/dsp/scopevis.h index 7f4605fcc..7a44a3482 100644 --- a/include-gpl/dsp/scopevis.h +++ b/include-gpl/dsp/scopevis.h @@ -70,10 +70,11 @@ private: uint m_fill; TriggerState m_triggerState; TriggerChannel m_triggerChannel; - FixReal m_triggerLevelHigh; - FixReal m_triggerLevelLow; + Real m_triggerLevel; bool m_triggerPositiveEdge; int m_sampleRate; + + bool triggerCondition(SampleVector::const_iterator& it); }; #endif // INCLUDE_SCOPEVIS_H diff --git a/sdrbase/dsp/scopevis.cpp b/sdrbase/dsp/scopevis.cpp index 4603062d8..87f9ad69e 100644 --- a/sdrbase/dsp/scopevis.cpp +++ b/sdrbase/dsp/scopevis.cpp @@ -4,6 +4,7 @@ #include "util/messagequeue.h" #include +#include MESSAGE_CLASS_DEFINITION(ScopeVis::MsgConfigureScopeVis, Message) @@ -13,8 +14,7 @@ ScopeVis::ScopeVis(GLScope* glScope) : m_fill(0), m_triggerState(Untriggered), m_triggerChannel(TriggerFreeRun), - m_triggerLevelHigh(0.01 * 32768), - m_triggerLevelLow(0.01 * 32768 - 1024), + m_triggerLevel(0.0), m_triggerPositiveEdge(true), m_sampleRate(0) { @@ -46,11 +46,11 @@ void ScopeVis::feed(SampleVector::const_iterator begin, SampleVector::const_iter m_fill = 0; } } - else if (m_triggerChannel == TriggerChannelI) + else { if(m_triggerState == Untriggered) { while(begin < end) { - if(begin->real() >= m_triggerLevelHigh) { + if (triggerCondition(begin)) { m_triggerState = Triggered; break; } @@ -70,53 +70,7 @@ void ScopeVis::feed(SampleVector::const_iterator begin, SampleVector::const_iter if(m_fill >= m_trace.size()) { m_glScope->newTrace(m_trace, m_sampleRate); m_fill = 0; - m_triggerState = WaitForReset; - } - } - if(m_triggerState == WaitForReset) { - while(begin < end) { - if(begin->real() < m_triggerLevelLow) { - m_triggerState = Untriggered; - break; - } - ++begin; - } - } - } - else if (m_triggerChannel == TriggerChannelQ) - { - if(m_triggerState == Untriggered) { - while(begin < end) { - if(begin->imag() >= m_triggerLevelHigh) { - m_triggerState = Triggered; - break; - } - ++begin; - } - } - if(m_triggerState == Triggered) { - int count = end - begin; - if(count > (int)(m_trace.size() - m_fill)) - count = m_trace.size() - m_fill; - std::vector::iterator it = m_trace.begin() + m_fill; - for(int i = 0; i < count; ++i) { - *it++ = Complex(begin->real() / 32768.0, begin->imag() / 32768.0); - ++begin; - } - m_fill += count; - if(m_fill >= m_trace.size()) { - m_glScope->newTrace(m_trace, m_sampleRate); - m_fill = 0; - m_triggerState = WaitForReset; - } - } - if(m_triggerState == WaitForReset) { - while(begin < end) { - if(begin->imag() < m_triggerLevelLow) { - m_triggerState = Untriggered; - break; - } - ++begin; + m_triggerState = Untriggered; } } } @@ -142,8 +96,12 @@ bool ScopeVis::handleMessageKeep(Message* message) MsgConfigureScopeVis* conf = (MsgConfigureScopeVis*)message; m_triggerState = Untriggered; m_triggerChannel = (TriggerChannel) conf->getTriggerChannel(); - m_triggerLevelHigh = conf->getTriggerLevel() * 32767; + m_triggerLevel = conf->getTriggerLevel(); m_triggerPositiveEdge = conf->getTriggerPositiveEdge(); + std::cerr << "ScopeVis::handleMessageKeep:" + << " m_triggerChannel: " << m_triggerChannel + << " m_triggerLevel: " << m_triggerLevel + << " m_triggerPositiveEdge: " << (m_triggerPositiveEdge ? "edge+" : "edge-") << std::endl; return true; /* } else if(DSPConfigureScopeVis::match(message)) { @@ -174,3 +132,29 @@ void ScopeVis::setSampleRate(int sampleRate) { m_sampleRate = sampleRate; } + +bool ScopeVis::triggerCondition(SampleVector::const_iterator& it) +{ + Complex c(it->real()/32768.0, it->imag()/32768.0); + + if (m_triggerChannel == TriggerChannelI) { + return c.real() > m_triggerLevel; + } + else if (m_triggerChannel == TriggerChannelQ) { + return c.imag() > m_triggerLevel; + } + else if (m_triggerChannel == TriggerMagLin) { + return abs(c) > m_triggerLevel; + } + else if (m_triggerChannel == TriggerMagDb) { + Real mult = (10.0f / log2f(10.0f)); + Real v = c.real() * c.real() + c.imag() * c.imag(); + return mult * log2f(v) > m_triggerLevel; + } + else if (m_triggerChannel == TriggerPhase) { + return arg(c) / M_PI > m_triggerLevel; + } + else { + return false; + } +} diff --git a/sdrbase/gui/glscopegui.cpp b/sdrbase/gui/glscopegui.cpp index 60d1e4feb..65b1d1106 100644 --- a/sdrbase/gui/glscopegui.cpp +++ b/sdrbase/gui/glscopegui.cpp @@ -165,6 +165,16 @@ void GLScopeGUI::applySettings() void GLScopeGUI::applyTriggerSettings() { + Real triggerLevel; + + if (m_triggerChannel == ScopeVis::TriggerMagDb) { + triggerLevel = m_triggerLevel - 100.0; + } + else { + triggerLevel = m_triggerLevel / 100.0; + } + + m_scopeVis->configure(m_messageQueue, (ScopeVis::TriggerChannel) m_triggerChannel, triggerLevel, m_triggerPositiveEdge); } void GLScopeGUI::setTrigLevelDisplay()