1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-22 17:45:48 -05:00

Scope trigger #1

This commit is contained in:
f4exb 2015-07-13 23:38:10 +02:00
parent d67e4e0b82
commit e696e4f8a2
3 changed files with 49 additions and 54 deletions

View File

@ -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

View File

@ -4,6 +4,7 @@
#include "util/messagequeue.h"
#include <cstdio>
#include <iostream>
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<Complex>::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;
}
}
}
@ -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;
}
}

View File

@ -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()