Initialise Trace widgets when the trace is received by the View
[pulseview.git] / pv / sigsession.cpp
index 793a5e8a894147073f2d91fe5143690cd1e1e10d..6d8e09d6c231be69e4e9ec65f635b5e3c7c9fd1b 100644 (file)
@@ -79,7 +79,7 @@ void SigSession::set_device(struct sr_dev_inst *sdi)
        if (sdi)
                _device_manager.use_device(sdi, this);
        _sdi = sdi;
-       update_signals();
+       update_signals(sdi);
 }
 
 void SigSession::release_device(struct sr_dev_inst *sdi)
@@ -88,7 +88,7 @@ void SigSession::release_device(struct sr_dev_inst *sdi)
 
        assert(_capture_state == Stopped);
        _sdi = NULL;
-       update_signals();
+       update_signals(NULL);
 }
 
 void SigSession::load_file(const string &name,
@@ -164,8 +164,10 @@ boost::shared_ptr<data::Logic> SigSession::get_data()
 void SigSession::set_capture_state(capture_state state)
 {
        lock_guard<mutex> lock(_sampling_mutex);
+       const bool changed = _capture_state != state;
        _capture_state = state;
-       capture_state_changed(state);
+       if(changed)
+               capture_state_changed(state);
 }
 
 /**
@@ -244,7 +246,7 @@ sr_input* SigSession::load_input_file_format(const string &filename,
        return in;
 }
 
-void SigSession::update_signals()
+void SigSession::update_signals(const sr_dev_inst *const sdi)
 {
        assert(_capture_state == Stopped);
 
@@ -253,8 +255,8 @@ void SigSession::update_signals()
        unsigned int analog_probe_count = 0;
 
        // Detect what data types we will receive
-       if(_sdi) {
-               for (const GSList *l = _sdi->probes; l; l = l->next) {
+       if(sdi) {
+               for (const GSList *l = sdi->probes; l; l = l->next) {
                        const sr_probe *const probe = (const sr_probe *)l->data;
                        if (!probe->enabled)
                                continue;
@@ -295,8 +297,8 @@ void SigSession::update_signals()
 
                _signals.clear();
 
-               if(_sdi) {
-                       for (const GSList *l = _sdi->probes; l; l = l->next) {
+               if(sdi) {
+                       for (const GSList *l = sdi->probes; l; l = l->next) {
                                const sr_probe *const probe =
                                        (const sr_probe *)l->data;
                                assert(probe);
@@ -323,6 +325,19 @@ void SigSession::update_signals()
        signals_changed();
 }
 
+bool SigSession::is_trigger_enabled() const
+{
+       assert(_sdi);
+       for (const GSList *l = _sdi->probes; l; l = l->next) {
+               const sr_probe *const p = (const sr_probe *)l->data;
+               assert(p);
+               if (p->trigger && p->trigger[0] != '\0')
+                       return true;
+       }
+
+       return false;
+}
+
 void SigSession::load_thread_proc(const string name,
        function<void (const QString)> error_handler)
 {
@@ -387,7 +402,7 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
                return;
        }
 
-       set_capture_state(Running);
+       set_capture_state(is_trigger_enabled() ? AwaitingTrigger : Running);
 
        sr_session_run();
        sr_session_destroy();
@@ -455,6 +470,8 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic)
 
        if (!_cur_logic_snapshot)
        {
+               set_capture_state(Running);
+
                // Create a new data snapshot
                _cur_logic_snapshot = shared_ptr<data::LogicSnapshot>(
                        new data::LogicSnapshot(logic));
@@ -481,6 +498,8 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog)
 
        if (!_cur_analog_snapshot)
        {
+               set_capture_state(Running);
+
                // Create a new data snapshot
                _cur_analog_snapshot = shared_ptr<data::AnalogSnapshot>(
                        new data::AnalogSnapshot(analog));