* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <extdef.h>
+
#include <assert.h>
#include <boost/foreach.hpp>
-extern "C" {
#include <libsigrok/libsigrok.h>
-}
#include <QAction>
+#include <QDebug>
#include "samplingbar.h"
-#include <pv/dialogs/hwcap.h>
+#include <pv/dialogs/deviceoptions.h>
namespace pv {
-const uint64_t SamplingBar::RecordLengths[11] = {
+const uint64_t SamplingBar::RecordLengths[20] = {
+ 1000,
+ 2500,
+ 5000,
+ 10000,
+ 25000,
+ 50000,
+ 100000,
+ 250000,
+ 500000,
1000000,
2000000,
5000000,
250000000,
500000000,
1000000000,
- 10000000000
+ 10000000000ULL,
};
+const uint64_t SamplingBar::DefaultRecordLength = 1000000;
+
SamplingBar::SamplingBar(QWidget *parent) :
QToolBar("Sampling Bar", parent),
_device_selector(this),
_configure_button(this),
_record_length_selector(this),
_sample_rate_list(this),
+ _icon_green(":/icons/status-green.svg"),
+ _icon_grey(":/icons/status-grey.svg"),
_run_stop_button(this)
{
connect(&_run_stop_button, SIGNAL(clicked()),
_sample_rate_value.setDecimals(0);
_sample_rate_value.setSuffix("Hz");
- BOOST_FOREACH(uint64_t l, RecordLengths)
+ for (size_t i = 0; i < countof(RecordLengths); i++)
{
+ const uint64_t &l = RecordLengths[i];
char *const text = sr_si_string_u64(l, " samples");
_record_length_selector.addItem(QString(text),
qVariantFromValue(l));
g_free(text);
+
+ if (l == DefaultRecordLength)
+ _record_length_selector.setCurrentIndex(i);
}
set_sampling(false);
- _configure_button.setIcon(QIcon::fromTheme("configure"));
+ _configure_button.setIcon(QIcon::fromTheme("configure",
+ QIcon(":/icons/configure.png")));
+
+ _run_stop_button.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
addWidget(&_device_selector);
addWidget(&_configure_button);
_sample_rate_value_action = addWidget(&_sample_rate_value);
addWidget(&_run_stop_button);
- update_device_selector();
+ connect(&_sample_rate_list, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(on_sample_rate_changed()));
+ connect(&_sample_rate_value, SIGNAL(editingFinished()),
+ this, SLOT(on_sample_rate_changed()));
+}
+
+void SamplingBar::set_device_list(
+ const std::list<struct sr_dev_inst*> &devices)
+{
+ _device_selector.clear();
+
+ BOOST_FOREACH (sr_dev_inst *sdi, devices) {
+ QString title;
+ if (sdi->vendor && sdi->vendor[0])
+ title += sdi->vendor + QString(" ");
+ if (sdi->model && sdi->model[0])
+ title += sdi->model + QString(" ");
+ if (sdi->version && sdi->version[0])
+ title += sdi->version + QString(" ");
+
+ _device_selector.addItem(title, qVariantFromValue(
+ (void*)sdi));
+ }
+
update_sample_rate_selector();
}
return _record_length_selector.itemData(index).value<uint64_t>();
}
-uint64_t SamplingBar::get_sample_rate() const
-{
- assert(_sample_rate_value_action);
- assert(_sample_rate_list_action);
-
- if (_sample_rate_value_action->isVisible())
- return (uint64_t)_sample_rate_value.value();
- else if (_sample_rate_list_action->isVisible())
- {
- const int index = _sample_rate_list.currentIndex();
- if (index < 0)
- return 0;
-
- return _sample_rate_list.itemData(index).value<uint64_t>();
- }
-
- return 0;
-}
-
void SamplingBar::set_sampling(bool sampling)
{
+ _run_stop_button.setIcon(sampling ? _icon_green : _icon_grey);
_run_stop_button.setText(sampling ? "Stop" : "Run");
}
-void SamplingBar::update_device_selector()
-{
- GSList *devices = NULL;
-
- /* Scan all drivers for all devices. */
- struct sr_dev_driver **const drivers = sr_driver_list();
- for (struct sr_dev_driver **driver = drivers; *driver; driver++) {
- GSList *tmpdevs = sr_driver_scan(*driver, NULL);
- for (GSList *l = tmpdevs; l; l = l->next)
- devices = g_slist_append(devices, l->data);
- g_slist_free(tmpdevs);
- }
-
- for (GSList *l = devices; l; l = l->next) {
- sr_dev_inst *const sdi = (sr_dev_inst*)l->data;
-
- QString title;
- if (sdi->vendor && sdi->vendor[0])
- title += sdi->vendor + QString(" ");
- if (sdi->model && sdi->model[0])
- title += sdi->model + QString(" ");
- if (sdi->version && sdi->version[0])
- title += sdi->version + QString(" ");
-
- _device_selector.addItem(title, qVariantFromValue(
- (void*)sdi));
- }
-
- g_slist_free(devices);
-}
-
void SamplingBar::update_sample_rate_selector()
{
const sr_dev_inst *const sdi = get_selected_device();
assert(_sample_rate_value_action);
assert(_sample_rate_list_action);
- if (sr_info_get(sdi->driver, SR_DI_SAMPLERATES,
+ if (!sdi)
+ return;
+
+ if (sr_config_list(sdi->driver, SR_CONF_SAMPLERATE,
(const void **)&samplerates, sdi) != SR_OK)
return;
_sample_rate_list.show();
_sample_rate_list_action->setVisible(true);
}
+
+ update_sample_rate_selector_value();
+}
+
+void SamplingBar::update_sample_rate_selector_value()
+{
+ sr_dev_inst *const sdi = get_selected_device();
+ assert(sdi);
+
+ uint64_t *samplerate = NULL;
+ if(sr_config_get(sdi->driver, SR_CONF_SAMPLERATE,
+ (const void**)&samplerate, sdi) != SR_OK) {
+ qDebug() <<
+ "WARNING: Failed to get value of sample rate";
+ return;
+ }
+
+ assert(_sample_rate_value_action);
+ assert(_sample_rate_list_action);
+
+ if (_sample_rate_value_action->isVisible())
+ _sample_rate_value.setValue(*samplerate);
+ else if (_sample_rate_list_action->isVisible())
+ {
+ for(int i = 0; i < _sample_rate_list.count(); i++)
+ if(*samplerate == _sample_rate_list.itemData(
+ i).value<uint64_t>())
+ _sample_rate_list.setCurrentIndex(i);
+ }
+}
+
+void SamplingBar::commit_sample_rate()
+{
+ uint64_t sample_rate = 0;
+
+ sr_dev_inst *const sdi = get_selected_device();
+ assert(sdi);
+
+ assert(_sample_rate_value_action);
+ assert(_sample_rate_list_action);
+
+ if (_sample_rate_value_action->isVisible())
+ sample_rate = (uint64_t)_sample_rate_value.value();
+ else if (_sample_rate_list_action->isVisible())
+ {
+ const int index = _sample_rate_list.currentIndex();
+ if (index >= 0)
+ sample_rate = _sample_rate_list.itemData(
+ index).value<uint64_t>();
+ }
+
+ // Set the samplerate
+ if (sr_config_set(sdi, SR_CONF_SAMPLERATE,
+ &sample_rate) != SR_OK) {
+ qDebug() << "Failed to configure samplerate.";
+ return;
+ }
}
void SamplingBar::on_device_selected()
update_sample_rate_selector();
}
+void SamplingBar::on_sample_rate_changed()
+{
+ commit_sample_rate();
+}
+
void SamplingBar::configure()
{
+ commit_sample_rate();
+
sr_dev_inst *const sdi = get_selected_device();
assert(sdi);
- pv::dialogs::HwCap dlg(this, sdi);
+ pv::dialogs::DeviceOptions dlg(this, sdi);
dlg.exec();
+
+ update_sample_rate_selector_value();
}
} // namespace pv