]> sigrok.org Git - pulseview.git/commitdiff
Implemented device probing
authorJoel Holdsworth <redacted>
Thu, 7 Mar 2013 21:23:11 +0000 (21:23 +0000)
committerUwe Hermann <redacted>
Sat, 9 Mar 2013 10:43:03 +0000 (11:43 +0100)
pv/dialogs/connect.cpp
pv/dialogs/connect.h

index 284ce07240c2a279d247252aac081cab66333d07..f7a75da0c6e081840ee9cd597c90a31d1605d4ac 100644 (file)
@@ -27,6 +27,8 @@ extern "C" {
 #include <libsigrok/libsigrok.h>
 }
 
+extern sr_context *sr_ctx;
+
 namespace pv {
 namespace dialogs {
 
@@ -37,6 +39,8 @@ Connect::Connect(QWidget *parent) :
        _form_layout(&_form),
        _drivers(&_form),
        _serial_device(&_form),
+       _scan_button(tr("Scan for Devices"), this),
+       _device_list(this),
        _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
                Qt::Horizontal, this)
 {
@@ -56,8 +60,13 @@ Connect::Connect(QWidget *parent) :
 
        unset_connection();
 
+       connect(&_scan_button, SIGNAL(pressed()),
+               this, SLOT(scan_pressed()));
+
        setLayout(&_layout);
        _layout.addWidget(&_form);
+       _layout.addWidget(&_scan_button);
+       _layout.addWidget(&_device_list);
        _layout.addWidget(&_button_box);
 }
 
@@ -89,10 +98,68 @@ void Connect::populate_drivers()
        }
 }
 
+void Connect::unset_connection()
+{
+       _device_list.clear();
+       _serial_device.hide();
+       _form_layout.labelForField(&_serial_device)->hide();
+}
+
+void Connect::set_serial_connection()
+{
+       _serial_device.show();
+       _form_layout.labelForField(&_serial_device)->show();
+}
+
+void Connect::scan_pressed()
+{
+       _device_list.clear();
+
+       const int index = _drivers.currentIndex();
+       if(index == -1)
+               return;
+
+       sr_dev_driver *const driver = (sr_dev_driver*)_drivers.itemData(
+               index).value<void*>();
+
+       GSList *drvopts = NULL;
+
+       if (_serial_device.isVisible()) {
+               sr_config *const src = (sr_config*)g_try_malloc(sizeof(sr_config));
+               src->key = SR_CONF_CONN;
+               const QByteArray byteArray = _serial_device.text().toUtf8();
+               src->value = g_strdup((const gchar*)byteArray.constData());
+               drvopts = g_slist_append(drvopts, src);
+       }
+
+       GSList *const devices = sr_driver_scan(driver, drvopts);
+
+       for (GSList *l = devices; l; l = l->next) {
+
+               sr_dev_inst *const sdi = (sr_dev_inst*)l->data;
+
+               QString text;
+               if (sdi->vendor && sdi->vendor[0])
+                       text += QString("%1 ").arg(sdi->vendor);
+               if (sdi->model && sdi->model[0])
+                       text += QString("%1 ").arg(sdi->model);
+               if (sdi->version && sdi->version[0])
+                       text += QString("%1 ").arg(sdi->version);
+               if (sdi->probes) {
+                       text += QString("with %1 probes").arg(
+                               g_slist_length(sdi->probes));
+               }
+
+               _device_list.addItem(text);
+       }
+
+       g_slist_free(devices);
+       g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
+}
+
 void Connect::device_selected(int index)
 {
        const int *hwopts;
-       const struct sr_hwcap_option *hwo;
        sr_dev_driver *const driver = (sr_dev_driver*)_drivers.itemData(
                index).value<void*>();
 
@@ -116,18 +183,11 @@ void Connect::device_selected(int index)
        }
 }
 
-void Connect::unset_connection()
-{
-       _serial_device.hide();
-       _form_layout.labelForField(&_serial_device)->hide();
-}
-
-void Connect::set_serial_connection()
+void Connect::free_drvopts(struct sr_config *src)
 {
-       _serial_device.show();
-       _form_layout.labelForField(&_serial_device)->show();
+       g_free((void *)src->value);
+       g_free(src);
 }
 
-
 } // namespace dialogs
 } // namespace pv
index 443f6e07fde6c3a94dca2e28f8ac563aece77898..862184b87326566415b2a142f59baef523dc6b6b 100644 (file)
 #include <QDialogButtonBox>
 #include <QFormLayout>
 #include <QLineEdit>
+#include <QListWidget>
+#include <QPushButton>
 #include <QVBoxLayout>
 
+struct sr_config;
+
 namespace pv {
 namespace dialogs {
 
@@ -41,12 +45,17 @@ public:
 private:
        void populate_drivers();
 
+       void unset_connection();
+
+       void set_serial_connection();
+
 private slots:
        void device_selected(int index);
 
-       void unset_connection();
+       void scan_pressed();
 
-       void set_serial_connection();
+private:
+       static void free_drvopts(sr_config *src);
 
 private:
        QVBoxLayout _layout;
@@ -58,6 +67,9 @@ private:
 
        QLineEdit _serial_device;
 
+       QPushButton _scan_button;
+       QListWidget _device_list;
+
        QDialogButtonBox _button_box;
 };