From: Uwe Hermann Date: Thu, 11 May 2017 20:58:58 +0000 (+0200) Subject: Allow users to set initial pin states for decoders. X-Git-Tag: pulseview-0.4.0~33 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=407c9ebeb13200fb7f28a33cab00e996c018f8dc;p=pulseview.git Allow users to set initial pin states for decoders. This uses the new srd_inst_initial_pins_set_all() libsigrokdecode API which allows frontends to set the assumed initial pins (i.e., the assumed state of the pins before the first sample of a capture) to user-specified values. The assumed initial pins can be either low, or high, or "use same value as the first sample of the capture". --- diff --git a/pv/data/decode/decoder.cpp b/pv/data/decode/decoder.cpp index d7ec5e11..841d4fd7 100644 --- a/pv/data/decode/decoder.cpp +++ b/pv/data/decode/decoder.cpp @@ -37,7 +37,8 @@ namespace decode { Decoder::Decoder(const srd_decoder *const dec) : decoder_(dec), - shown_(true) + shown_(true), + initial_pins_(nullptr) { } @@ -74,6 +75,18 @@ void Decoder::set_channels(map& Decoder::options() const { return options_; @@ -142,6 +155,8 @@ srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session) const srd_inst_channel_set_all(decoder_inst, channels); + srd_inst_initial_pins_set_all(decoder_inst, initial_pins_); + return decoder_inst; } diff --git a/pv/data/decode/decoder.hpp b/pv/data/decode/decoder.hpp index 1b655662..eff2367f 100644 --- a/pv/data/decode/decoder.hpp +++ b/pv/data/decode/decoder.hpp @@ -62,6 +62,10 @@ public: void set_channels(map > channels); + void set_initial_pins(GArray *initial_pins); + + GArray *initial_pins() const; + const map& options() const; void set_option(const char *id, GVariant *value); @@ -78,6 +82,7 @@ private: bool shown_; map > channels_; + GArray *initial_pins_; map options_; }; diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 74d0dd65..9cc07d33 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -812,14 +812,24 @@ void DecodeTrace::create_decoder_form(int index, for (l = decoder->channels; l; l = l->next) { const struct srd_channel *const pdch = (struct srd_channel *)l->data; + QComboBox *const combo = create_channel_selector(parent, dec, pdch); + QComboBox *const combo_initial_pin = create_channel_selector_initial_pin(parent, dec, pdch); + connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_channel_selected(int))); + connect(combo_initial_pin, SIGNAL(currentIndexChanged(int)), + this, SLOT(on_initial_pin_selected(int))); + + QHBoxLayout *const hlayout = new QHBoxLayout; + hlayout->addWidget(combo); + hlayout->addWidget(combo_initial_pin); + decoder_form->addRow(tr("%1 (%2) *") .arg(QString::fromUtf8(pdch->name), - QString::fromUtf8(pdch->desc)), combo); + QString::fromUtf8(pdch->desc)), hlayout); - const ChannelSelector s = {combo, dec, pdch}; + const ChannelSelector s = {combo, combo_initial_pin, dec, pdch}; channel_selectors_.push_back(s); } @@ -827,14 +837,24 @@ void DecodeTrace::create_decoder_form(int index, for (l = decoder->opt_channels; l; l = l->next) { const struct srd_channel *const pdch = (struct srd_channel *)l->data; + QComboBox *const combo = create_channel_selector(parent, dec, pdch); + QComboBox *const combo_initial_pin = create_channel_selector_initial_pin(parent, dec, pdch); + connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_channel_selected(int))); + connect(combo_initial_pin, SIGNAL(currentIndexChanged(int)), + this, SLOT(on_initial_pin_selected(int))); + + QHBoxLayout *const hlayout = new QHBoxLayout; + hlayout->addWidget(combo); + hlayout->addWidget(combo_initial_pin); + decoder_form->addRow(tr("%1 (%2)") .arg(QString::fromUtf8(pdch->name), - QString::fromUtf8(pdch->desc)), combo); + QString::fromUtf8(pdch->desc)), hlayout); - const ChannelSelector s = {combo, dec, pdch}; + const ChannelSelector s = {combo, combo_initial_pin, dec, pdch}; channel_selectors_.push_back(s); } @@ -891,6 +911,24 @@ QComboBox* DecodeTrace::create_channel_selector( return selector; } +QComboBox* DecodeTrace::create_channel_selector_initial_pin(QWidget *parent, + const shared_ptr &dec, const srd_channel *const pdch) +{ + QComboBox *selector = new QComboBox(parent); + + selector->addItem("0", qVariantFromValue((int)SRD_INITIAL_PIN_LOW)); + selector->addItem("1", qVariantFromValue((int)SRD_INITIAL_PIN_HIGH)); + selector->addItem("?", qVariantFromValue((int)SRD_INITIAL_PIN_SAME_AS_SAMPLE0)); + + // Default to index 2 (SRD_INITIAL_PIN_SAME_AS_SAMPLE0). + const int idx = (!dec->initial_pins()) ? 2 : dec->initial_pins()->data[pdch->order]; + selector->setCurrentIndex(idx); + + selector->setToolTip("Initial (assumed) pin value before the first sample"); + + return selector; +} + void DecodeTrace::commit_decoder_channels(shared_ptr &dec) { assert(dec); @@ -900,6 +938,10 @@ void DecodeTrace::commit_decoder_channels(shared_ptr &dec const unordered_set< shared_ptr > sigs(session_.signalbases()); + GArray *const initial_pins = g_array_sized_new(FALSE, TRUE, + sizeof(uint8_t), channel_selectors_.size()); + g_array_set_size(initial_pins, channel_selectors_.size()); + for (const ChannelSelector &s : channel_selectors_) { if (s.decoder_ != dec) break; @@ -913,9 +955,15 @@ void DecodeTrace::commit_decoder_channels(shared_ptr &dec channel_map[s.pdch_] = sig; break; } + + int selection_initial_pin = s.combo_initial_pin_->itemData( + s.combo_initial_pin_->currentIndex()).value(); + + initial_pins->data[s.pdch_->order] = selection_initial_pin; } dec->set_channels(channel_map); + dec->set_initial_pins(initial_pins); } void DecodeTrace::commit_channels() @@ -950,6 +998,11 @@ void DecodeTrace::on_channel_selected(int) commit_channels(); } +void DecodeTrace::on_initial_pin_selected(int) +{ + commit_channels(); +} + void DecodeTrace::on_stack_decoder(srd_decoder *decoder) { shared_ptr decoder_stack = base_->decoder_stack(); diff --git a/pv/view/decodetrace.hpp b/pv/view/decodetrace.hpp index c4cb6fa5..619c7327 100644 --- a/pv/view/decodetrace.hpp +++ b/pv/view/decodetrace.hpp @@ -74,6 +74,7 @@ private: struct ChannelSelector { const QComboBox *combo_; + const QComboBox *combo_initial_pin_; const shared_ptr decoder_; const srd_channel *pdch_; }; @@ -182,6 +183,10 @@ private: const shared_ptr &dec, const srd_channel *const pdch); + QComboBox* create_channel_selector_initial_pin(QWidget *parent, + const shared_ptr &dec, + const srd_channel *const pdch); + void commit_decoder_channels(shared_ptr &dec); void commit_channels(); @@ -196,6 +201,8 @@ private Q_SLOTS: void on_channel_selected(int); + void on_initial_pin_selected(int); + void on_stack_decoder(srd_decoder *decoder); void on_delete_decoder(int index);