Set trigger buttons as checked depending on the trigger type
[pulseview.git] / pv / view / logicsignal.cpp
index 813bb29eedd94b5af04b3a73a297e3ef2e41f8d8..c8713114fbf1a8bea4e785a0e49b83958578da16 100644 (file)
@@ -80,6 +80,30 @@ LogicSignal::LogicSignal(pv::SigSession &session, const sr_probe *const probe,
        _colour = SignalColours[probe->index % countof(SignalColours)];
 
        _separator.setSeparator(true);
+
+       _trigger_none.setCheckable(true);
+       connect(&_trigger_none, SIGNAL(triggered()),
+               this, SLOT(on_trigger_none()));
+
+       _trigger_rising.setCheckable(true);
+       connect(&_trigger_rising, SIGNAL(triggered()),
+               this, SLOT(on_trigger_rising()));
+
+       _trigger_high.setCheckable(true);
+       connect(&_trigger_high, SIGNAL(triggered()),
+               this, SLOT(on_trigger_high()));
+
+       _trigger_falling.setCheckable(true);
+       connect(&_trigger_falling, SIGNAL(triggered()),
+               this, SLOT(on_trigger_falling()));
+
+       _trigger_low.setCheckable(true);
+       connect(&_trigger_low, SIGNAL(triggered()),
+               this, SLOT(on_trigger_low()));
+
+       _trigger_change.setCheckable(true);
+       connect(&_trigger_change, SIGNAL(triggered()),
+               this, SLOT(on_trigger_change()));
 }
 
 LogicSignal::~LogicSignal()
@@ -115,6 +139,8 @@ const list<QAction*> LogicSignal::get_context_bar_actions()
                                &_trigger_low, actions);
                        add_trigger_action(trig_types, 'c',
                                &_trigger_change, actions);
+               
+                       update_trigger_actions();
                }
 
                g_variant_unref(gvar);
@@ -233,5 +259,67 @@ void LogicSignal::add_trigger_action(const char *trig_types, char type,
                }
 }
 
+void LogicSignal::update_trigger_actions()
+{
+       const char cur_trigger = _probe->trigger ?
+               _probe->trigger[0] : '\0';
+       _trigger_none.setChecked(cur_trigger == '\0');
+       _trigger_rising.setChecked(cur_trigger == 'r');
+       _trigger_high.setChecked(cur_trigger == '1');
+       _trigger_falling.setChecked(cur_trigger == 'f');
+       _trigger_low.setChecked(cur_trigger == '0');
+       _trigger_change.setChecked(cur_trigger == 'c');
+}
+
+void LogicSignal::set_trigger(char type)
+{
+       const char trigger_type_string[2] = {type, 0};
+       const char *const trigger_string =
+               (type != 0) ? trigger_type_string : NULL;
+
+       const sr_dev_inst *const sdi = _session.get_device();
+       const int probe_count = g_slist_length(sdi->probes);
+       assert(probe_count > 0);
+
+       assert(_probe && _probe->index < probe_count);
+
+       for (int i = 0; i < probe_count; i++) {
+               sr_dev_trigger_set(sdi, i, (i == _probe->index) ?
+                       trigger_string : NULL);
+       }
+
+       update_trigger_actions();
+}
+
+void LogicSignal::on_trigger_none()
+{
+       set_trigger('\0');      
+}
+
+void LogicSignal::on_trigger_rising()
+{
+       set_trigger('r');       
+}
+
+void LogicSignal::on_trigger_high()
+{
+       set_trigger('1');       
+}
+
+void LogicSignal::on_trigger_falling()
+{
+       set_trigger('f');       
+}
+
+void LogicSignal::on_trigger_low()
+{
+       set_trigger('0');       
+}
+
+void LogicSignal::on_trigger_change()
+{
+       set_trigger('c');       
+}
+
 } // namespace view
 } // namespace pv