const int SignalBase::ColourBGAlpha = 8 * 256 / 100;
const uint64_t SignalBase::ConversionBlockSize = 4096;
+const uint32_t SignalBase::ConversionDelay = 1000; // 1 second
SignalBase::SignalBase(shared_ptr<sigrok::Channel> channel, ChannelType channel_type) :
channel_(channel),
{
if (channel_)
internal_name_ = QString::fromStdString(channel_->name());
+
+ connect(&delayed_conversion_starter_, SIGNAL(timeout()),
+ this, SLOT(on_delayed_conversion_start()));
+ delayed_conversion_starter_.setSingleShot(true);
+ delayed_conversion_starter_.setInterval(ConversionDelay);
}
SignalBase::~SignalBase()
} while (!conversion_interrupt_);
}
-void SignalBase::start_conversion()
+void SignalBase::start_conversion(bool delayed_start)
{
+ if (delayed_start) {
+ delayed_conversion_starter_.start();
+ return;
+ }
+
stop_conversion();
if (converted_data_)
// Notify the conversion thread since it's running
conversion_input_cond_.notify_one();
} else {
- // Start the conversion thread
- start_conversion();
+ // Start the conversion thread unless the delay timer is running
+ if (!delayed_conversion_starter_.isActive())
+ start_conversion();
}
}
// Restart conversion if one is enabled and uses a calculated threshold
if ((conversion_type_ != NoConversion) &&
(get_current_conversion_preset() == DynamicPreset))
- start_conversion();
+ start_conversion(true);
}
void SignalBase::on_capture_state_changed(int state)
}
}
+void SignalBase::on_delayed_conversion_start()
+{
+ start_conversion();
+}
+
} // namespace data
} // namespace pv
#include <QObject>
#include <QSettings>
#include <QString>
+#include <QTimer>
#include <QVariant>
#include <libsigrokcxx/libsigrokcxx.hpp>
private:
static const int ColourBGAlpha;
static const uint64_t ConversionBlockSize;
+ static const uint32_t ConversionDelay;
public:
SignalBase(shared_ptr<sigrok::Channel> channel, ChannelType channel_type);
virtual void restore_settings(QSettings &settings);
- void start_conversion();
+ void start_conversion(bool delayed_start=false);
private:
bool conversion_is_a2l() const;
void on_capture_state_changed(int state);
+ void on_delayed_conversion_start();
+
protected:
shared_ptr<sigrok::Channel> channel_;
ChannelType channel_type_;
atomic<bool> conversion_interrupt_;
mutex conversion_input_mutex_;
condition_variable conversion_input_cond_;
+ QTimer delayed_conversion_starter_;
QString internal_name_, name_;
QColor colour_, bgcolour_;
connect(analog_data, SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
this, SLOT(on_samples_added()));
- connect(&delayed_conversion_starter_, SIGNAL(timeout()),
- this, SLOT(on_delayed_conversion_starter()));
- delayed_conversion_starter_.setSingleShot(true);
- delayed_conversion_starter_.setInterval(1000); // 1s timeout
-
GlobalSettings gs;
div_height_ = gs.value(GlobalSettings::Key_View_DefaultDivHeight).toInt();
// For now, we simply assume that the unit is volt without modifiers
const double thr = tokens.at(1).toDouble();
- // Only restart the conversion if the threshold was updated
+ // Only restart the conversion if the threshold was updated.
+ // We're starting a delayed conversion because the user may still be
+ // typing and the UI would lag if we kept on restarting it immediately
if (base_->set_conversion_option("threshold_value", thr))
- delayed_conversion_starter_.start();
+ base_->start_conversion(true);
}
if (conv_type == SignalBase::A2LConversionBySchmittTrigger && use_custom_thr) {
const double low_thr = tokens.at(1).toDouble();
const double high_thr = tokens.at(3).toDouble();
- // Only restart the conversion if one of the options was updated
+ // Only restart the conversion if one of the options was updated.
+ // We're starting a delayed conversion because the user may still be
+ // typing and the UI would lag if we kept on restarting it immediately
bool o1 = base_->set_conversion_option("threshold_value_low", low_thr);
bool o2 = base_->set_conversion_option("threshold_value_high", high_thr);
if (o1 || o2)
- delayed_conversion_starter_.start();
+ base_->start_conversion(true); // Start delayed conversion
}
base_->set_conversion_preset((SignalBase::ConversionPreset)index);
- // Immediately start the conversion if we're not asking for a delayed reaction
- if (!delayed_conversion_starter_.isActive())
+ // Immediately start the conversion if we're not using custom values
+ // (i.e. we're using one of the presets)
+ if (!use_custom_thr)
base_->start_conversion();
}
#include <QComboBox>
#include <QSpinBox>
-#include <QTimer>
using std::pair;
using std::shared_ptr;
*display_type_cb_;
QSpinBox *pvdiv_sb_, *nvdiv_sb_, *div_height_sb_;
- QTimer delayed_conversion_starter_;
-
float scale_;
int scale_index_;
int scale_index_drag_offset_;