]> sigrok.org Git - pulseview.git/commitdiff
Allow users to set initial pin states for decoders.
authorUwe Hermann <redacted>
Thu, 11 May 2017 20:58:58 +0000 (22:58 +0200)
committerUwe Hermann <redacted>
Mon, 5 Jun 2017 16:15:26 +0000 (18:15 +0200)
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".

pv/data/decode/decoder.cpp
pv/data/decode/decoder.hpp
pv/view/decodetrace.cpp
pv/view/decodetrace.hpp

index d7ec5e11bc3525102d073b7d171fb5be6f478d2c..841d4fd7b874cdf4ba30227beaf862f361d60627 100644 (file)
@@ -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<const srd_channel*,
        channels_ = channels;
 }
 
+void Decoder::set_initial_pins(GArray *initial_pins)
+{
+       if (initial_pins_)
+               g_array_free(initial_pins_, TRUE);
+       initial_pins_ = initial_pins;
+}
+
+GArray *Decoder::initial_pins() const
+{
+       return initial_pins_;
+}
+
 const map<string, GVariant*>& 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;
 }
 
index 1b655662bcb707dfe5fd83dbc847164e81bc04a2..eff2367fb3604cf4c76e7e9ca7c9887cf0e741c4 100644 (file)
@@ -62,6 +62,10 @@ public:
        void set_channels(map<const srd_channel*,
                shared_ptr<data::SignalBase> > channels);
 
+       void set_initial_pins(GArray *initial_pins);
+
+       GArray *initial_pins() const;
+
        const map<string, GVariant*>& options() const;
 
        void set_option(const char *id, GVariant *value);
@@ -78,6 +82,7 @@ private:
        bool shown_;
 
        map<const srd_channel*, shared_ptr<pv::data::SignalBase> > channels_;
+       GArray *initial_pins_;
        map<string, GVariant*> options_;
 };
 
index 74d0dd6511b623a4c41aba5b66bd6cf13194f830..9cc07d3377e5646c6191635714aa9dbc1420afc9 100644 (file)
@@ -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("<b>%1</b> (%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("<b>%1</b> (%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<data::decode::Decoder> &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<data::decode::Decoder> &dec)
 {
        assert(dec);
@@ -900,6 +938,10 @@ void DecodeTrace::commit_decoder_channels(shared_ptr<data::decode::Decoder> &dec
        const unordered_set< shared_ptr<data::SignalBase> >
                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<data::decode::Decoder> &dec
                                channel_map[s.pdch_] = sig;
                                break;
                        }
+
+               int selection_initial_pin = s.combo_initial_pin_->itemData(
+                       s.combo_initial_pin_->currentIndex()).value<int>();
+
+               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<pv::data::DecoderStack> decoder_stack = base_->decoder_stack();
index c4cb6fa553015b48a3f977d49629a3fe8b08830e..619c7327b7ba838663340e270f5e61dbb7012234 100644 (file)
@@ -74,6 +74,7 @@ private:
        struct ChannelSelector
        {
                const QComboBox *combo_;
+               const QComboBox *combo_initial_pin_;
                const shared_ptr<pv::data::decode::Decoder> decoder_;
                const srd_channel *pdch_;
        };
@@ -182,6 +183,10 @@ private:
                const shared_ptr<pv::data::decode::Decoder> &dec,
                const srd_channel *const pdch);
 
+       QComboBox* create_channel_selector_initial_pin(QWidget *parent,
+               const shared_ptr<pv::data::decode::Decoder> &dec,
+               const srd_channel *const pdch);
+
        void commit_decoder_channels(shared_ptr<data::decode::Decoder> &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);