diff --git a/DSView/main.cpp b/DSView/main.cpp index 60ae81b0..4c149505 100644 --- a/DSView/main.cpp +++ b/DSView/main.cpp @@ -33,7 +33,7 @@ #include "pv/config/appconfig.h" #include "config.h" #include "pv/appcontrol.h" -#include "pv/log.h" +#include "pv/log.h" #ifdef _WIN32 #include @@ -208,7 +208,7 @@ bool bHighScale = true; //----------------------run dsv_info("----------------- version: %s-----------------", DS_VERSION_STRING); dsv_info("Qt:%s", QT_VERSION_STR); - + //init core if (!control->Init()){ dsv_err("%s", "init error!"); @@ -222,8 +222,8 @@ bool bHighScale = true; try { + pv::MainFrame w; control->Start(); - pv::MainFrame w; //Initialise the main frame w.show(); w.readSettings(); w.show_doc(); //to show the dailog for open help document diff --git a/DSView/pv/dock/triggerdock.cpp b/DSView/pv/dock/triggerdock.cpp index 9f3f2db4..980c716a 100644 --- a/DSView/pv/dock/triggerdock.cpp +++ b/DSView/pv/dock/triggerdock.cpp @@ -891,9 +891,9 @@ void TriggerDock::lineEdit_highlight(QLineEdit *dst) { } void TriggerDock::try_commit_trigger() -{ - int i; - AppConfig &app = AppConfig::Instance(); +{ + AppConfig &app = AppConfig::Instance(); + int num = 0; int mode = _session->get_device()->get_work_mode(); bool bInstant = _session->is_instant(); @@ -904,7 +904,7 @@ void TriggerDock::try_commit_trigger() return; } - if (this->commit_trigger() == false) + if (commit_trigger() == false) { /* simple trigger check trigger_enable */ for(auto &s : _session->get_signals()) @@ -913,11 +913,11 @@ void TriggerDock::try_commit_trigger() view::LogicSignal *logicSig = NULL; if ((logicSig = dynamic_cast(s))) { if (logicSig->commit_trig()) - i++; + num++; } } - if (app._appOptions.warnofMultiTrig && i > 1) { + if (app._appOptions.warnofMultiTrig && num > 1) { dialogs::DSMessageBox msg(this); msg.mBox()->setText(tr("Trigger")); msg.mBox()->setInformativeText(tr("Trigger setted on multiple channels! " diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 87fdc12e..4723a136 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -273,8 +273,22 @@ namespace pv connect(_dso_trigger_widget, SIGNAL(set_trig_pos(int)), _view, SLOT(set_trig_pos(int))); _logo_bar->set_mainform_callback(this); - - _session->set_default_device(); + + // Try load from file. + QString ldFileName(AppControl::Instance()->_open_file_name.c_str()); + if (ldFileName != ""){ + if (QFile::exists(ldFileName)){ + dsv_info("auto load file:%s", ldFileName.toUtf8().data()); + on_load_file(ldFileName); + } + else{ + dsv_err("file is not exists:%s", ldFileName.toUtf8().data()); + MsgBox::Show(tr("Open file error!"), ldFileName, NULL); + } + } + else{ + _session->set_default_device(); + } } void MainWindow::retranslateUi() @@ -322,10 +336,7 @@ namespace pv on_load_session(ses_name); } } - - - - + _trig_bar->restore_status(); //load specified file name from application startup param @@ -402,7 +413,7 @@ namespace pv break; case SigSession::Test_data_err: _session->stop_capture(); - _sampling_bar->set_sampling(false); + _sampling_bar->update_view_status(); title = tr("Data Error"); error_pattern = _session->get_error_pattern(); @@ -1329,6 +1340,20 @@ namespace pv _session->broadcast_msg(msg); } + void MainWindow::reset_all_view() + { + _sampling_bar->reload(); + _view->status_clear(); + _view->reload(); + _view->set_device(); + _trigger_widget->init(); + _trigger_widget->device_updated(); + _trig_bar->reload(); + _trig_bar->restore_status(); + _dso_trigger_widget->init(); + _measure_widget->reload(); + } + void MainWindow::OnMessage(int msg) { switch (msg) @@ -1343,12 +1368,16 @@ namespace pv break; case DSV_MSG_START_COLLECT_WORK: - _sampling_bar->set_sampling(false); + _sampling_bar->update_view_status(); + _file_bar->update_view_status(); + _trig_bar->update_view_status(); break; case DSV_MSG_END_COLLECT_WORK: _session->device_event_object()->device_updated(); - _sampling_bar->set_sampling(true); + _sampling_bar->update_view_status(); + _file_bar->update_view_status(); + _trig_bar->update_view_status(); break; case DSV_MSG_NEW_USB_DEVICE: @@ -1360,17 +1389,9 @@ namespace pv _msg->close(); _msg = NULL; } - + _sampling_bar->update_device_list(); - _view->reload(); - _view->set_device(); - _trig_bar->reload(); - _sampling_bar->reload(); - _view->status_clear(); - _trigger_widget->init(); - _dso_trigger_widget->init(); - _measure_widget->reload(); - _trigger_widget->device_updated(); + reset_all_view(); break; case DSV_MSG_CURRENT_DEVICE_CHANGE_PREV: @@ -1390,7 +1411,8 @@ namespace pv break; case DSV_MSG_DEVICE_MODE_CHANGED: - _view->mode_changed(); + _view->mode_changed(); + reset_all_view(); break; case DSV_MSG_CURRENT_DEVICE_DETACHED: diff --git a/DSView/pv/mainwindow.h b/DSView/pv/mainwindow.h index e7c981ea..e54372ad 100644 --- a/DSView/pv/mainwindow.h +++ b/DSView/pv/mainwindow.h @@ -143,6 +143,7 @@ public: private: void check_usb_device_speed(); + void reset_all_view(); private: //ISessionCallback diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index f2a608c1..6e01b2f8 100644 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -368,7 +368,8 @@ void SigSession::capture_init() _trigger_ch = 0; _hw_replied = false; - if (_device_agent.get_work_mode() != LOGIC) + int work_mode = _device_agent.get_work_mode(); + if (work_mode == DSO || work_mode == ANALOG) _feed_timer.Start(FeedInterval); else _feed_timer.Stop(); @@ -591,7 +592,8 @@ void SigSession::check_update() _data_updated = false; _noData_cnt = 0; data_auto_unlock(); - } else { + } + else { if (++_noData_cnt >= (WaitShowTime/FeedInterval)) nodata_timeout(); } @@ -1105,6 +1107,8 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, assert(packet); ds_lock_guard lock(_data_mutex); + + // dsv_info("%s", "Receive data."); if (_data_lock && packet->type != SR_DF_END) return; @@ -1156,9 +1160,8 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, break; } case SR_DF_END: - { - if (!_logic_data->snapshot()->empty()) - { + { + if (!_logic_data->snapshot()->empty()){ for (auto &g : _group_traces) { assert(g); @@ -1505,6 +1508,7 @@ void SigSession::nodata_timeout() void SigSession::feed_timeout() { data_unlock(); + if (!_data_updated) { if (++_noData_cnt >= (WaitShowTime/FeedInterval)) nodata_timeout(); @@ -1555,7 +1559,7 @@ void SigSession::set_repeat_intvl(double interval) } bool SigSession::repeat_check() -{ +{ if (!_is_working) { return false; } @@ -1819,14 +1823,28 @@ void SigSession::Close() void SigSession::on_device_lib_event(int event) { + if (_callback == NULL){ + dsv_info("%s", "The callback is null, so the device event was ignored."); + return; + } + switch (event) { case DS_EV_DEVICE_RUNNING: _device_status = ST_RUNNING; + receive_data(0); break; case DS_EV_DEVICE_STOPPED: _device_status = ST_STOPPED; + // Confirm that SR_DF_END was received + if (!_logic_data->snapshot()->last_ended() + || !_dso_data->snapshot()->last_ended() + || !_analog_data->snapshot()->last_ended()) + { + dsv_err("%s", "Error!The data is not completed."); + assert(false); + } break; case DS_EV_COLLECT_TASK_START: @@ -1967,5 +1985,10 @@ void SigSession::on_device_lib_event(int event) } + void SigSession::on_work_mode_changed() + { + init_signals(); + } + } // namespace pv diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index 6a90a69a..4be2bf39 100644 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -296,6 +296,7 @@ public: struct ds_device_info* get_device_list(int &out_count, int &actived_index); void add_msg_listener(IMessageListener *ln); void broadcast_msg(int msg); + void on_work_mode_changed(); private: bool exec_capture(); @@ -329,7 +330,7 @@ private: void repeat_update(); void container_init(); void init_signals(); - + //IMessageListener void OnMessage(int msg); diff --git a/DSView/pv/toolbars/filebar.cpp b/DSView/pv/toolbars/filebar.cpp index cc12c0cc..f826fe00 100644 --- a/DSView/pv/toolbars/filebar.cpp +++ b/DSView/pv/toolbars/filebar.cpp @@ -36,7 +36,6 @@ namespace toolbars { FileBar::FileBar(SigSession *session, QWidget *parent) : QToolBar("File Bar", parent), - _enable(true), _session(session), _file_button(this) { @@ -232,14 +231,11 @@ void FileBar::on_actionCapture_triggered() QTimer::singleShot(100, this, SIGNAL(sig_screenShot())); } -void FileBar::enable_toggle(bool enable) +void FileBar::update_view_status() { - _file_button.setDisabled(!enable); -} - -void FileBar::set_settings_en(bool enable) -{ - _menu_session->setDisabled(!enable); + bool bEnable = _session->is_working() == false; + _file_button.setEnabled(bEnable); + _menu_session->setEnabled(bEnable); } } // namespace toolbars diff --git a/DSView/pv/toolbars/filebar.h b/DSView/pv/toolbars/filebar.h index 5b3c435f..af758f65 100644 --- a/DSView/pv/toolbars/filebar.h +++ b/DSView/pv/toolbars/filebar.h @@ -42,14 +42,12 @@ class FileBar : public QToolBar public: explicit FileBar(SigSession *session, QWidget *parent = 0); - void enable_toggle(bool enable); - - void set_settings_en(bool enable); + void update_view_status(); private: void changeEvent(QEvent *event); void retranslateUi(); - void reStyle(); + void reStyle(); signals: void sig_load_file(QString); @@ -67,18 +65,14 @@ private slots: void on_actionCapture_triggered(); private: - bool _enable; SigSession* _session; QToolButton _file_button; - - QMenu *_menu; - - QMenu *_menu_session; //when the hardware device is connected,it will be enable + QMenu *_menu; + QMenu *_menu_session; //when the hardware device is connected,it will be enable QAction *_action_load; QAction *_action_store; QAction *_action_default; - QAction *_action_open; QAction *_action_save; QAction *_action_export; diff --git a/DSView/pv/toolbars/samplingbar.cpp b/DSView/pv/toolbars/samplingbar.cpp index 3269d5af..0ccdbb1e 100644 --- a/DSView/pv/toolbars/samplingbar.cpp +++ b/DSView/pv/toolbars/samplingbar.cpp @@ -20,7 +20,7 @@ */ #include "samplingbar.h" -#include +#include #include #include #include @@ -34,7 +34,7 @@ #include "../dialogs/interval.h" #include "../config/appconfig.h" #include "../dsvdef.h" -#include "../log.h" +#include "../log.h" #include "../deviceagent.h" using std::map; @@ -44,1016 +44,1114 @@ using std::string; using namespace pv::device; -namespace pv { -namespace toolbars { - -const QString SamplingBar::RLEString = tr("(RLE)"); -const QString SamplingBar::DIVString = tr(" / div"); - -SamplingBar::SamplingBar(SigSession *session, QWidget *parent) : - QToolBar("Sampling Bar", parent), - _device_type(this), - _device_selector(this), - _configure_button(this), - _sample_count(this), - _sample_rate(this), - _run_stop_button(this), - _instant_button(this), - _mode_button(this) +namespace pv { - _updating_device_list = false; - _updating_sample_rate = false; - _updating_sample_count = false; - - _last_device_handle = NULL_HANDLE; - - _session = session; - _device_agent = _session->get_device(); - - setMovable(false); - setContentsMargins(0,0,0,0); - layout()->setSpacing(0); - - _mode_button.setPopupMode(QToolButton::InstantPopup); - - _device_selector.setSizeAdjustPolicy(DsComboBox::AdjustToContents); - _sample_rate.setSizeAdjustPolicy(DsComboBox::AdjustToContents); - _sample_count.setSizeAdjustPolicy(DsComboBox::AdjustToContents); - _device_selector.setMaximumWidth(ComboBoxMaxWidth); - - _run_stop_button.setObjectName(tr("run_stop_button")); - - QWidget *leftMargin = new QWidget(this); - leftMargin->setFixedWidth(4); - addWidget(leftMargin); - - _device_type.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - addWidget(&_device_type); - addWidget(&_device_selector); - _configure_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - addWidget(&_configure_button); - - addWidget(&_sample_count); - addWidget(new QLabel(tr(" @ "))); - addWidget(&_sample_rate); - - _action_single = new QAction(this); - - _action_repeat = new QAction(this); - - _mode_menu = new QMenu(this); - _mode_menu->addAction(_action_single); - _mode_menu->addAction(_action_repeat); - _mode_button.setMenu(_mode_menu); - - _mode_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - _mode_action = addWidget(&_mode_button); - - _run_stop_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - _run_stop_action = addWidget(&_run_stop_button); - _instant_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - _instant_action = addWidget(&_instant_button); - - set_sampling(false); - - connect(&_device_selector, SIGNAL(currentIndexChanged (int)), this, SLOT(on_device_selected())); - connect(&_configure_button, SIGNAL(clicked()),this, SLOT(on_configure())); - connect(&_run_stop_button, SIGNAL(clicked()),this, SLOT(on_run_stop()), Qt::DirectConnection); - connect(&_instant_button, SIGNAL(clicked()), this, SLOT(on_instant_stop())); - connect(&_sample_count, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplecount_sel(int))); - connect(_action_single, SIGNAL(triggered()), this, SLOT(on_mode())); - connect(_action_repeat, SIGNAL(triggered()), this, SLOT(on_mode())); - connect(&_sample_rate, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplerate_sel(int))); -} - -void SamplingBar::changeEvent(QEvent *event) -{ - if (event->type() == QEvent::LanguageChange) - retranslateUi(); - else if (event->type() == QEvent::StyleChange) - reStyle(); - QToolBar::changeEvent(event); -} - -void SamplingBar::retranslateUi() -{ - bool bDev = _device_agent->have_instance(); - - if (bDev) { - if (_device_agent->is_demo()){ - _device_type.setText(tr("Demo")); - } - else if (_device_agent->is_file()){ - _device_type.setText(tr("File")); - } - else { - int usb_speed = LIBUSB_SPEED_HIGH; - GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_USB_SPEED); - - if (gvar != NULL) { - usb_speed = g_variant_get_int32(gvar); - g_variant_unref(gvar); - } - if (usb_speed == LIBUSB_SPEED_HIGH) - _device_type.setText(tr("USB 2.0")); - else if (usb_speed == LIBUSB_SPEED_SUPER) - _device_type.setText(tr("USB 3.0")); - else - _device_type.setText(tr("USB UNKNOWN")); - } - } - _configure_button.setText(tr("Options")); - _mode_button.setText(tr("Mode")); - - int mode = _device_agent->get_work_mode(); - - bool is_working = _session->is_working(); - - if (_session->is_instant()) { - if (bDev && mode == DSO) - _instant_button.setText(is_working ? tr("Stop") : tr("Single")); - else - _instant_button.setText(is_working ? tr("Stop") : tr("Instant")); - _run_stop_button.setText(tr("Start")); - } - else { - _run_stop_button.setText(is_working ? tr("Stop") : tr("Start")); - if (bDev && mode == DSO) - _instant_button.setText(tr("Single")); - else - _instant_button.setText(tr("Instant")); - } - - _action_single->setText(tr("&Single")); - _action_repeat->setText(tr("&Repetitive")); -} - -void SamplingBar::reStyle() -{ - bool bDev = _device_agent->have_instance(); - - if (bDev){ - if (_device_agent->is_demo()) - _device_type.setIcon(QIcon(":/icons/demo.svg")); - else if (_device_agent->is_file()) - _device_type.setIcon(QIcon(":/icons/data.svg")); - else { - int usb_speed = LIBUSB_SPEED_HIGH; - GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_USB_SPEED); - - if (gvar != NULL) { - usb_speed = g_variant_get_int32(gvar); - g_variant_unref(gvar); - } - if (usb_speed == LIBUSB_SPEED_SUPER) - _device_type.setIcon(QIcon(":/icons/usb3.svg")); - else - _device_type.setIcon(QIcon(":/icons/usb2.svg")); - - } - } - - if (true) { - QString iconPath = GetIconPath(); - _configure_button.setIcon(QIcon(iconPath+"/params.svg")); - QString icon1 = _session->is_repeat_mode() ? "moder.svg" : "modes.svg"; - _mode_button.setIcon(QIcon(iconPath+ "/" + icon1)); - QString icon2 = _session->is_working() ? "stop.svg" : "start.svg"; - _run_stop_button.setIcon(QIcon(iconPath + "/" + icon2)); - _instant_button.setIcon(QIcon(iconPath+"/single.svg")); - _action_single->setIcon(QIcon(iconPath+"/oneloop.svg")); - _action_repeat->setIcon(QIcon(iconPath+"/repeat.svg")); - } -} - -void SamplingBar::on_configure() -{ - int ret; - - if (_device_agent->have_instance() == false){ - dsv_info("%s", "Have no device, can't to set device config."); - return; - } - - _session->broadcast_msg(DSV_MSG_BEGIN_DEVICE_OPTIONS); - - pv::dialogs::DeviceOptions dlg(this); - connect(_session->device_event_object(), SIGNAL(device_updated()), &dlg, SLOT(reject())); - - ret = dlg.exec(); - - if (ret == QDialog::Accepted) - { - _session->broadcast_msg(DSV_MSG_DEVICE_OPTIONS_UPDATED); - - update_sample_rate_selector(); - - int mode = _device_agent->get_work_mode(); - GVariant* gvar; - - if (mode == DSO) { - gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ZERO); - if (gvar != NULL) { - bool zero = g_variant_get_boolean(gvar); - g_variant_unref(gvar); - if (zero) { - zero_adj(); - return; - } - } - } - gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TEST); - if (gvar != NULL) { - bool test = g_variant_get_boolean(gvar); - g_variant_unref(gvar); - if (test) { - update_sample_rate_selector_value(); - _sample_count.setDisabled(true); - _sample_rate.setDisabled(true); - } else { - _sample_count.setDisabled(false); - if (mode != DSO) - _sample_rate.setDisabled(false); - } - } - } - - _session->broadcast_msg(DSV_MSG_END_DEVICE_OPTIONS); -} - -void SamplingBar::zero_adj() -{ - view::DsoSignal *dsoSig = NULL; - - for(auto &s : _session->get_signals()) + namespace toolbars { - if ((dsoSig = dynamic_cast(s))) - dsoSig->set_enable(true); - } - - const int index_back = _sample_count.currentIndex(); - int i = 0; - for (i = 0; i < _sample_count.count(); i++) - if (_sample_count.itemData(i).value() == ZeroTimeBase) - break; + const QString SamplingBar::RLEString = tr("(RLE)"); + const QString SamplingBar::DIVString = tr(" / div"); - _sample_count.setCurrentIndex(i); - commit_hori_res(); - - if (_session->is_working() == false) - _session->start_capture(true); - - pv::dialogs::WaitingDialog wait(this, _session, SR_CONF_ZERO); - if (wait.start() == QDialog::Rejected) { - for(auto &s : _session->get_signals()) + SamplingBar::SamplingBar(SigSession *session, QWidget *parent) : QToolBar("Sampling Bar", parent), + _device_type(this), + _device_selector(this), + _configure_button(this), + _sample_count(this), + _sample_rate(this), + _run_stop_button(this), + _instant_button(this), + _mode_button(this) { - if ((dsoSig = dynamic_cast(s))) - dsoSig->commit_settings(); + _updating_device_list = false; + _updating_sample_rate = false; + _updating_sample_count = false; + _is_run_as_instant = false; + + _last_device_handle = NULL_HANDLE; + + _session = session; + _device_agent = _session->get_device(); + + setMovable(false); + setContentsMargins(0, 0, 0, 0); + layout()->setSpacing(0); + + _mode_button.setPopupMode(QToolButton::InstantPopup); + + _device_selector.setSizeAdjustPolicy(DsComboBox::AdjustToContents); + _sample_rate.setSizeAdjustPolicy(DsComboBox::AdjustToContents); + _sample_count.setSizeAdjustPolicy(DsComboBox::AdjustToContents); + _device_selector.setMaximumWidth(ComboBoxMaxWidth); + + _run_stop_button.setObjectName(tr("run_stop_button")); + + QWidget *leftMargin = new QWidget(this); + leftMargin->setFixedWidth(4); + addWidget(leftMargin); + + _device_type.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + addWidget(&_device_type); + addWidget(&_device_selector); + _configure_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + addWidget(&_configure_button); + + addWidget(&_sample_count); + addWidget(new QLabel(tr(" @ "))); + addWidget(&_sample_rate); + + _action_single = new QAction(this); + + _action_repeat = new QAction(this); + + _mode_menu = new QMenu(this); + _mode_menu->addAction(_action_single); + _mode_menu->addAction(_action_repeat); + _mode_button.setMenu(_mode_menu); + + _mode_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + _mode_action = addWidget(&_mode_button); + + _run_stop_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + _run_stop_action = addWidget(&_run_stop_button); + _instant_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + _instant_action = addWidget(&_instant_button); + + update_view_status(); + + connect(&_device_selector, SIGNAL(currentIndexChanged(int)), this, SLOT(on_device_selected())); + connect(&_configure_button, SIGNAL(clicked()), this, SLOT(on_configure())); + connect(&_run_stop_button, SIGNAL(clicked()), this, SLOT(on_run_stop()), Qt::DirectConnection); + connect(&_instant_button, SIGNAL(clicked()), this, SLOT(on_instant_stop())); + connect(&_sample_count, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplecount_sel(int))); + connect(_action_single, SIGNAL(triggered()), this, SLOT(on_mode())); + connect(_action_repeat, SIGNAL(triggered()), this, SLOT(on_mode())); + connect(&_sample_rate, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplerate_sel(int))); } - } - if (_session->is_working()) - _session->stop_capture(); - - _sample_count.setCurrentIndex(index_back); - commit_hori_res(); -} - -void SamplingBar::set_sampling(bool sampling) -{ - if (!sampling) { - enable_run_stop(true); - enable_instant(true); - } - else { - if (_session->is_instant()) - enable_instant(true); - else - enable_run_stop(true); - } - - _mode_button.setEnabled(!sampling); - _configure_button.setEnabled(!sampling); - _device_selector.setEnabled(!sampling); - - if (true) { - QString iconPath = GetIconPath(); - - if (_session->is_instant()) - _instant_button.setIcon(sampling ? QIcon(iconPath+"/stop.svg") : QIcon(iconPath+"/single.svg")); - else - _run_stop_button.setIcon(sampling ? QIcon(iconPath+"/stop.svg") : QIcon(iconPath+"/start.svg")); - - _mode_button.setIcon(_session->is_repeat_mode() == false ? QIcon(iconPath+"/modes.svg") : - QIcon(iconPath+"/moder.svg")); - } - - retranslateUi(); -} - -void SamplingBar::set_sample_rate(uint64_t sample_rate) -{ - for (int i = _sample_rate.count() - 1; i >= 0; i--) { - uint64_t cur_index_sample_rate = _sample_rate.itemData( - i).value(); - if (sample_rate >= cur_index_sample_rate) { - _sample_rate.setCurrentIndex(i); - break; + void SamplingBar::changeEvent(QEvent *event) + { + if (event->type() == QEvent::LanguageChange) + retranslateUi(); + else if (event->type() == QEvent::StyleChange) + reStyle(); + QToolBar::changeEvent(event); } - } - commit_settings(); -} -void SamplingBar::update_sample_rate_selector() -{ - GVariant *gvar_dict, *gvar_list; - const uint64_t *elements = NULL; - gsize num_elements; + void SamplingBar::retranslateUi() + { + bool bDev = _device_agent->have_instance(); - dsv_info("%s", "Update rate list."); + if (bDev) + { + if (_device_agent->is_demo()) + { + _device_type.setText(tr("Demo")); + } + else if (_device_agent->is_file()) + { + _device_type.setText(tr("File")); + } + else + { + int usb_speed = LIBUSB_SPEED_HIGH; + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_USB_SPEED); - if (_updating_sample_rate){ - dsv_err("%s", "Error! The rate list is updating."); - return; - } - - disconnect(&_sample_rate, SIGNAL(currentIndexChanged(int)), - this, SLOT(on_samplerate_sel(int))); - - if (_device_agent->have_instance() == false){ - dsv_info("%s", "SamplingBar::update_sample_rate_selector, have no device."); - return; - } - - _updating_sample_rate = true; - - gvar_dict = _device_agent->get_config_list(NULL, SR_CONF_SAMPLERATE); - if (gvar_dict == NULL) - { - _sample_rate.clear(); - _sample_rate.show(); - _updating_sample_rate = false; - return; - } - - if ((gvar_list = g_variant_lookup_value(gvar_dict, - "samplerates", G_VARIANT_TYPE("at")))) - { - elements = (const uint64_t *)g_variant_get_fixed_array( - gvar_list, &num_elements, sizeof(uint64_t)); - _sample_rate.clear(); - - for (unsigned int i = 0; i < num_elements; i++) - { - char *const s = sr_samplerate_string(elements[i]); - _sample_rate.addItem(QString(s), - QVariant::fromValue(elements[i])); - g_free(s); - } - - _sample_rate.show(); - g_variant_unref(gvar_list); - } - - _sample_rate.setMinimumWidth(_sample_rate.sizeHint().width()+15); - _sample_rate.view()->setMinimumWidth(_sample_rate.sizeHint().width()+30); - - _updating_sample_rate = false; - g_variant_unref(gvar_dict); - - update_sample_rate_selector_value(); - - connect(&_sample_rate, SIGNAL(currentIndexChanged(int)), - this, SLOT(on_samplerate_sel(int))); - - update_sample_count_selector(); -} - -void SamplingBar::update_sample_rate_selector_value() -{ - if (_updating_sample_rate) - return; - _updating_sample_rate = true; - - const uint64_t samplerate = _device_agent->get_sample_rate(); - uint64_t cur_value = _sample_rate.itemData(_sample_rate.currentIndex()).value(); - - if (samplerate != cur_value) { - for (int i = _sample_rate.count() - 1; i >= 0; i--) { - if (samplerate >= _sample_rate.itemData( - i).value()) { - _sample_rate.setCurrentIndex(i); - break; + if (gvar != NULL) + { + usb_speed = g_variant_get_int32(gvar); + g_variant_unref(gvar); + } + if (usb_speed == LIBUSB_SPEED_HIGH) + _device_type.setText(tr("USB 2.0")); + else if (usb_speed == LIBUSB_SPEED_SUPER) + _device_type.setText(tr("USB 3.0")); + else + _device_type.setText(tr("USB UNKNOWN")); + } } - } - } + _configure_button.setText(tr("Options")); + _mode_button.setText(tr("Mode")); - _updating_sample_rate = false; -} + int mode = _device_agent->get_work_mode(); -void SamplingBar::on_samplerate_sel(int index) -{ - (void)index; - if (_device_agent->get_work_mode() != DSO) - update_sample_count_selector(); -} + bool is_working = _session->is_working(); -void SamplingBar::update_sample_count_selector() -{ - bool stream_mode = false; - uint64_t hw_depth = 0; - uint64_t sw_depth; - uint64_t rle_depth = 0; - uint64_t max_timebase = 0; - uint64_t min_timebase = SR_NS(10); - double pre_duration = SR_SEC(1); - double duration; - bool rle_support = false; - - dsv_info("%s", "Update sample count list."); - - if (_updating_sample_count){ - dsv_err("%s", "Error! The sample count is updating."); - return; - } - - disconnect(&_sample_count, SIGNAL(currentIndexChanged(int)), - this, SLOT(on_samplecount_sel(int))); - - assert(!_updating_sample_count); - _updating_sample_count = true; - - GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_STREAM); - if (gvar != NULL) { - stream_mode = g_variant_get_boolean(gvar); - g_variant_unref(gvar); - } - - gvar = _device_agent->get_config(NULL, NULL, SR_CONF_HW_DEPTH); - if (gvar != NULL) { - hw_depth = g_variant_get_uint64(gvar); - g_variant_unref(gvar); - } - - int mode = _device_agent->get_work_mode(); - - if (mode == LOGIC) { - #if defined(__x86_64__) || defined(_M_X64) - sw_depth = LogicMaxSWDepth64; - #elif defined(__i386) || defined(_M_IX86) - int ch_num = _session->get_ch_num(SR_CHANNEL_LOGIC); - if (ch_num <= 0) - sw_depth = LogicMaxSWDepth32; + if (_session->is_instant()) + { + if (bDev && mode == DSO) + _instant_button.setText(is_working ? tr("Stop") : tr("Single")); + else + _instant_button.setText(is_working ? tr("Stop") : tr("Instant")); + _run_stop_button.setText(tr("Start")); + } else - sw_depth = LogicMaxSWDepth32 / ch_num; - #endif - } - else { - sw_depth = AnalogMaxSWDepth; - } - - if (mode == LOGIC) { - gvar = _device_agent->get_config(NULL, NULL, SR_CONF_RLE_SUPPORT); - if (gvar != NULL) { - rle_support = g_variant_get_boolean(gvar); - g_variant_unref(gvar); - } - if (rle_support) - rle_depth = min(hw_depth*SR_KB(1), sw_depth); - } - else if (mode == DSO) { - gvar = _device_agent->get_config(NULL, NULL, SR_CONF_MAX_TIMEBASE); - if (gvar != NULL) { - max_timebase = g_variant_get_uint64(gvar); - g_variant_unref(gvar); - } - gvar = _device_agent->get_config(NULL, NULL, SR_CONF_MIN_TIMEBASE); - if (gvar != NULL) { - min_timebase = g_variant_get_uint64(gvar); - g_variant_unref(gvar); - } - } - - if (0 != _sample_count.count()) - pre_duration = _sample_count.itemData( - _sample_count.currentIndex()).value(); - _sample_count.clear(); - const uint64_t samplerate = _sample_rate.itemData( - _sample_rate.currentIndex()).value(); - const double hw_duration = hw_depth / (samplerate * (1.0 / SR_SEC(1))); - - if (mode == DSO) - duration = max_timebase; - else if (stream_mode) - duration = sw_depth / (samplerate * (1.0 / SR_SEC(1))); - else if (rle_support) - duration = rle_depth / (samplerate * (1.0 / SR_SEC(1))); - else - duration = hw_duration; - - assert(duration > 0); - bool not_last = true; - - do { - QString suffix = (mode == DSO) ? DIVString : - (!stream_mode && duration > hw_duration) ? RLEString : ""; - char *const s = sr_time_string(duration); - _sample_count.addItem(QString(s) + suffix, QVariant::fromValue(duration)); - g_free(s); - - double unit; - if (duration >= SR_DAY(1)) - unit = SR_DAY(1); - else if (duration >= SR_HOUR(1)) - unit = SR_HOUR(1); - else if (duration >= SR_MIN(1)) - unit = SR_MIN(1); - else - unit = 1; - - const double log10_duration = pow(10, floor(log10(duration / unit))); - - if (duration > 5 * log10_duration * unit) - duration = 5 * log10_duration * unit; - else if (duration > 2 * log10_duration * unit) - duration = 2 * log10_duration * unit; - else if (duration > log10_duration * unit) - duration = log10_duration * unit; - else - duration = log10_duration > 1 ? duration * 0.5 : - (unit == SR_DAY(1) ? SR_HOUR(20) : - unit == SR_HOUR(1) ? SR_MIN(50) : - unit == SR_MIN(1) ? SR_SEC(50) : duration * 0.5); - - if (mode == DSO) - not_last = duration >= min_timebase; - else if (mode == ANALOG) - not_last = (duration >= SR_MS(100)) && - (duration / SR_SEC(1) * samplerate >= SR_KB(1)); - else - not_last = (duration / SR_SEC(1) * samplerate >= SR_KB(1)); - - } while(not_last); - - _updating_sample_count = true; - - if (pre_duration > _sample_count.itemData(0).value()){ - _sample_count.setCurrentIndex(0); - } - else if (pre_duration < _sample_count.itemData(_sample_count.count()-1).value()){ - _sample_count.setCurrentIndex(_sample_count.count()-1); - } - else { - for (int i = 0; i < _sample_count.count(); i++){ - if (pre_duration >= _sample_count.itemData(i).value()) { - _sample_count.setCurrentIndex(i); - break; + { + _run_stop_button.setText(is_working ? tr("Stop") : tr("Start")); + if (bDev && mode == DSO) + _instant_button.setText(tr("Single")); + else + _instant_button.setText(tr("Instant")); } + + _action_single->setText(tr("&Single")); + _action_repeat->setText(tr("&Repetitive")); } - } - _updating_sample_count = false; - update_sample_count_selector_value(); - on_samplecount_sel(_sample_count.currentIndex()); + void SamplingBar::reStyle() + { + bool bDev = _device_agent->have_instance(); - connect(&_sample_count, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplecount_sel(int))); -} + if (bDev) + { + if (_device_agent->is_demo()) + _device_type.setIcon(QIcon(":/icons/demo.svg")); + else if (_device_agent->is_file()) + _device_type.setIcon(QIcon(":/icons/data.svg")); + else + { + int usb_speed = LIBUSB_SPEED_HIGH; + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_USB_SPEED); -void SamplingBar::update_sample_count_selector_value() -{ - if (_updating_sample_count) - return; - - GVariant* gvar; - double duration; - - if (_device_agent->get_work_mode() == DSO) { - gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TIMEBASE); - if (gvar != NULL) { - duration = g_variant_get_uint64(gvar); - g_variant_unref(gvar); - } - else { - dsv_err("%s", "ERROR: config_get SR_CONF_TIMEBASE failed."); - return; - } - } - else { - gvar = _device_agent->get_config(NULL, NULL, SR_CONF_LIMIT_SAMPLES); - if (gvar != NULL) { - duration = g_variant_get_uint64(gvar); - g_variant_unref(gvar); - } - else { - dsv_err("%s", "ERROR: config_get SR_CONF_TIMEBASE failed."); - return; - } - const uint64_t samplerate = _device_agent->get_sample_rate(); - duration = duration / samplerate * SR_SEC(1); - } - assert(!_updating_sample_count); - _updating_sample_count = true; - - if (duration != _sample_count.itemData(_sample_count.currentIndex()).value()) - { - for (int i = 0; i < _sample_count.count(); i++) { - if (duration >= _sample_count.itemData( - i).value()) { - _sample_count.setCurrentIndex(i); - break; - } - } - } - - _updating_sample_count = false; -} - -void SamplingBar::on_samplecount_sel(int index) -{ - (void)index; - - if (_device_agent->get_work_mode() == DSO) - commit_hori_res(); - _session->broadcast_msg(DSV_MSG_DEVICE_DURATION_UPDATED); -} - -double SamplingBar::get_hori_res() -{ - return _sample_count.itemData(_sample_count.currentIndex()).value(); -} - -double SamplingBar::hori_knob(int dir) -{ - double hori_res = -1; - - disconnect(&_sample_count, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplecount_sel(int))); - - if (0 == dir) { - hori_res = commit_hori_res(); - } - else if ((dir > 0) && (_sample_count.currentIndex() > 0)) { - _sample_count.setCurrentIndex(_sample_count.currentIndex() - 1); - hori_res = commit_hori_res(); - } - else if ((dir < 0) && (_sample_count.currentIndex() < _sample_count.count() - 1)) { - _sample_count.setCurrentIndex(_sample_count.currentIndex() + 1); - hori_res = commit_hori_res(); - } - - connect(&_sample_count, SIGNAL(currentIndexChanged(int)), - this, SLOT(on_samplecount_sel(int))); - - return hori_res; -} - -double SamplingBar::commit_hori_res() -{ - const double hori_res = _sample_count.itemData( - _sample_count.currentIndex()).value(); - - const uint64_t sample_limit = _device_agent->get_sample_limit(); - GVariant* gvar; - uint64_t max_sample_rate; - gvar = _device_agent->get_config(NULL, NULL, SR_CONF_MAX_DSO_SAMPLERATE); - - if (gvar != NULL) { - max_sample_rate = g_variant_get_uint64(gvar); - g_variant_unref(gvar); - } - else { - dsv_err("%s", "ERROR: config_get SR_CONF_MAX_DSO_SAMPLERATE failed."); - return -1; - } - - const uint64_t sample_rate = min((uint64_t)(sample_limit * SR_SEC(1) / - (hori_res * DS_CONF_DSO_HDIVS)), - (uint64_t)(max_sample_rate / - (_session->get_ch_num(SR_CHANNEL_DSO) ? _session->get_ch_num(SR_CHANNEL_DSO) : 1))); - set_sample_rate(sample_rate); - - _device_agent->set_config(NULL, NULL, SR_CONF_TIMEBASE, - g_variant_new_uint64(hori_res)); - - return hori_res; -} - -void SamplingBar::commit_settings() -{ - bool test = false; - - if (_device_agent->have_instance()) { - GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TEST); - if (gvar != NULL) { - test = g_variant_get_boolean(gvar); - g_variant_unref(gvar); - } - } - - if (test) { - update_sample_rate_selector_value(); - update_sample_count_selector_value(); - } - else { - const double sample_duration = _sample_count.itemData( - _sample_count.currentIndex()).value(); - const uint64_t sample_rate = _sample_rate.itemData( - _sample_rate.currentIndex()).value(); - - - if (_device_agent->have_instance()) - { - if (sample_rate != _device_agent->get_sample_rate()) - _device_agent->set_config(NULL, NULL, - SR_CONF_SAMPLERATE, - g_variant_new_uint64(sample_rate)); - - if (_device_agent->get_work_mode() != DSO) { - const uint64_t sample_count = ((uint64_t)ceil(sample_duration / SR_SEC(1) * - sample_rate) + SAMPLES_ALIGN) & ~SAMPLES_ALIGN; - if (sample_count != _device_agent->get_sample_limit()) - _device_agent->set_config(NULL, NULL, - SR_CONF_LIMIT_SAMPLES, - g_variant_new_uint64(sample_count)); - - bool rle_mode = _sample_count.currentText().contains(RLEString); - _device_agent->set_config(NULL, NULL, - SR_CONF_RLE, - g_variant_new_boolean(rle_mode)); - } - } - } -} - -//start or stop capture -void SamplingBar::on_run_stop() -{ - if (_session->is_working()) { - _session->stop_capture(); - return; - } - - if (_device_agent->have_instance() == false) - { - dsv_info("%s", "Have no device, can't to collect data."); - return; - } - - commit_settings(); - - if (_device_agent->get_work_mode() == DSO) { - GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ZERO); - if (gvar != NULL) - { - bool zero = g_variant_get_boolean(gvar); - g_variant_unref(gvar); - - if (zero) { - dialogs::DSMessageBox msg(this); - msg.mBox()->setText(tr("Auto Calibration")); - msg.mBox()->setInformativeText(tr("Please adjust zero skew and save the result!")); - //msg.setStandardButtons(QMessageBox::Ok); - msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole); - msg.mBox()->addButton(tr("Skip"), QMessageBox::RejectRole); - msg.mBox()->setIcon(QMessageBox::Warning); - - if (msg.exec()) { - zero_adj(); - } - else { - _device_agent->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); - enable_run_stop(true); - enable_instant(true); + if (gvar != NULL) + { + usb_speed = g_variant_get_int32(gvar); + g_variant_unref(gvar); + } + if (usb_speed == LIBUSB_SPEED_SUPER) + _device_type.setIcon(QIcon(":/icons/usb3.svg")); + else + _device_type.setIcon(QIcon(":/icons/usb2.svg")); } + } + + if (true) + { + QString iconPath = GetIconPath(); + _configure_button.setIcon(QIcon(iconPath + "/params.svg")); + QString icon1 = _session->is_repeat_mode() ? "moder.svg" : "modes.svg"; + _mode_button.setIcon(QIcon(iconPath + "/" + icon1)); + QString icon2 = _session->is_working() ? "stop.svg" : "start.svg"; + _run_stop_button.setIcon(QIcon(iconPath + "/" + icon2)); + _instant_button.setIcon(QIcon(iconPath + "/single.svg")); + _action_single->setIcon(QIcon(iconPath + "/oneloop.svg")); + _action_repeat->setIcon(QIcon(iconPath + "/repeat.svg")); + } + } + + void SamplingBar::on_configure() + { + int ret; + + if (_device_agent->have_instance() == false) + { + dsv_info("%s", "Have no device, can't to set device config."); return; } + + _session->broadcast_msg(DSV_MSG_BEGIN_DEVICE_OPTIONS); + + pv::dialogs::DeviceOptions dlg(this); + connect(_session->device_event_object(), SIGNAL(device_updated()), &dlg, SLOT(reject())); + + ret = dlg.exec(); + + if (ret == QDialog::Accepted) + { + _session->broadcast_msg(DSV_MSG_DEVICE_OPTIONS_UPDATED); + + update_sample_rate_selector(); + + int mode = _device_agent->get_work_mode(); + GVariant *gvar; + + if (mode == DSO) + { + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ZERO); + if (gvar != NULL) + { + bool zero = g_variant_get_boolean(gvar); + g_variant_unref(gvar); + if (zero) + { + zero_adj(); + return; + } + } + } + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TEST); + if (gvar != NULL) + { + bool test = g_variant_get_boolean(gvar); + g_variant_unref(gvar); + if (test) + { + update_sample_rate_selector_value(); + _sample_count.setDisabled(true); + _sample_rate.setDisabled(true); + } + else + { + _sample_count.setDisabled(false); + if (mode != DSO) + _sample_rate.setDisabled(false); + } + } + } + + _session->broadcast_msg(DSV_MSG_END_DEVICE_OPTIONS); } - } - if (_session->start_capture(false)){ - enable_run_stop(false); - enable_instant(false); - } -} + void SamplingBar::zero_adj() + { + view::DsoSignal *dsoSig = NULL; -void SamplingBar::on_instant_stop() -{ - if (_session->is_working()) { - _session->set_repeat_mode(false); - bool wait_upload = false; + for (auto &s : _session->get_signals()) + { + if ((dsoSig = dynamic_cast(s))) + dsoSig->set_enable(true); + } - if (_session->is_repeat_mode() == false) { - GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_WAIT_UPLOAD); - if (gvar != NULL) { - wait_upload = g_variant_get_boolean(gvar); + const int index_back = _sample_count.currentIndex(); + int i = 0; + + for (i = 0; i < _sample_count.count(); i++) + if (_sample_count.itemData(i).value() == ZeroTimeBase) + break; + + _sample_count.setCurrentIndex(i); + commit_hori_res(); + + if (_session->is_working() == false) + _session->start_capture(true); + + pv::dialogs::WaitingDialog wait(this, _session, SR_CONF_ZERO); + if (wait.start() == QDialog::Rejected) + { + for (auto &s : _session->get_signals()) + { + if ((dsoSig = dynamic_cast(s))) + dsoSig->commit_settings(); + } + } + + if (_session->is_working()) + _session->stop_capture(); + + _sample_count.setCurrentIndex(index_back); + commit_hori_res(); + } + + void SamplingBar::set_sample_rate(uint64_t sample_rate) + { + for (int i = _sample_rate.count() - 1; i >= 0; i--) + { + uint64_t cur_index_sample_rate = _sample_rate.itemData( + i) + .value(); + if (sample_rate >= cur_index_sample_rate) + { + _sample_rate.setCurrentIndex(i); + break; + } + } + commit_settings(); + } + + void SamplingBar::update_sample_rate_selector() + { + GVariant *gvar_dict, *gvar_list; + const uint64_t *elements = NULL; + gsize num_elements; + + dsv_info("%s", "Update rate list."); + + if (_updating_sample_rate) + { + dsv_err("%s", "Error! The rate list is updating."); + return; + } + + disconnect(&_sample_rate, SIGNAL(currentIndexChanged(int)), + this, SLOT(on_samplerate_sel(int))); + + if (_device_agent->have_instance() == false) + { + dsv_info("%s", "SamplingBar::update_sample_rate_selector, have no device."); + return; + } + + _updating_sample_rate = true; + + gvar_dict = _device_agent->get_config_list(NULL, SR_CONF_SAMPLERATE); + if (gvar_dict == NULL) + { + _sample_rate.clear(); + _sample_rate.show(); + _updating_sample_rate = false; + return; + } + + if ((gvar_list = g_variant_lookup_value(gvar_dict, + "samplerates", G_VARIANT_TYPE("at")))) + { + elements = (const uint64_t *)g_variant_get_fixed_array( + gvar_list, &num_elements, sizeof(uint64_t)); + _sample_rate.clear(); + + for (unsigned int i = 0; i < num_elements; i++) + { + char *const s = sr_samplerate_string(elements[i]); + _sample_rate.addItem(QString(s), + QVariant::fromValue(elements[i])); + g_free(s); + } + + _sample_rate.show(); + g_variant_unref(gvar_list); + } + + _sample_rate.setMinimumWidth(_sample_rate.sizeHint().width() + 15); + _sample_rate.view()->setMinimumWidth(_sample_rate.sizeHint().width() + 30); + + _updating_sample_rate = false; + g_variant_unref(gvar_dict); + + update_sample_rate_selector_value(); + + connect(&_sample_rate, SIGNAL(currentIndexChanged(int)), + this, SLOT(on_samplerate_sel(int))); + + update_sample_count_selector(); + } + + void SamplingBar::update_sample_rate_selector_value() + { + if (_updating_sample_rate) + return; + _updating_sample_rate = true; + + const uint64_t samplerate = _device_agent->get_sample_rate(); + uint64_t cur_value = _sample_rate.itemData(_sample_rate.currentIndex()).value(); + + if (samplerate != cur_value) + { + for (int i = _sample_rate.count() - 1; i >= 0; i--) + { + if (samplerate >= _sample_rate.itemData( + i) + .value()) + { + _sample_rate.setCurrentIndex(i); + break; + } + } + } + + _updating_sample_rate = false; + } + + void SamplingBar::on_samplerate_sel(int index) + { + (void)index; + if (_device_agent->get_work_mode() != DSO) + update_sample_count_selector(); + } + + void SamplingBar::update_sample_count_selector() + { + bool stream_mode = false; + uint64_t hw_depth = 0; + uint64_t sw_depth; + uint64_t rle_depth = 0; + uint64_t max_timebase = 0; + uint64_t min_timebase = SR_NS(10); + double pre_duration = SR_SEC(1); + double duration; + bool rle_support = false; + + dsv_info("%s", "Update sample count list."); + + if (_updating_sample_count) + { + dsv_err("%s", "Error! The sample count is updating."); + return; + } + + disconnect(&_sample_count, SIGNAL(currentIndexChanged(int)), + this, SLOT(on_samplecount_sel(int))); + + assert(!_updating_sample_count); + _updating_sample_count = true; + + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_STREAM); + if (gvar != NULL) + { + stream_mode = g_variant_get_boolean(gvar); g_variant_unref(gvar); } - } - if (!wait_upload) { - _session->stop_capture(); - } - } - else { - if (_device_agent->have_instance() == false){ - dsv_info("%s", "Error! Have no device, can't to collect data."); - return; - } - - commit_settings(); - - if (_device_agent->get_work_mode() == DSO) { - GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ZERO); - - if (gvar != NULL) { - bool zero = g_variant_get_boolean(gvar); + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_HW_DEPTH); + if (gvar != NULL) + { + hw_depth = g_variant_get_uint64(gvar); g_variant_unref(gvar); + } - if (zero) { - dialogs::DSMessageBox msg(this); - msg.mBox()->setText(tr("Auto Calibration")); - msg.mBox()->setInformativeText(tr("Auto Calibration program will be started. Don't connect any probes. It can take a while!")); - - msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole); - msg.mBox()->addButton(tr("Skip"), QMessageBox::RejectRole); - msg.mBox()->setIcon(QMessageBox::Warning); + int mode = _device_agent->get_work_mode(); - if (msg.exec()) { - zero_adj(); - } - else { - _device_agent->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); - enable_run_stop(true); - enable_instant(true); + if (mode == LOGIC) + { +#if defined(__x86_64__) || defined(_M_X64) + sw_depth = LogicMaxSWDepth64; +#elif defined(__i386) || defined(_M_IX86) + int ch_num = _session->get_ch_num(SR_CHANNEL_LOGIC); + if (ch_num <= 0) + sw_depth = LogicMaxSWDepth32; + else + sw_depth = LogicMaxSWDepth32 / ch_num; +#endif + } + else + { + sw_depth = AnalogMaxSWDepth; + } + + if (mode == LOGIC) + { + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_RLE_SUPPORT); + if (gvar != NULL) + { + rle_support = g_variant_get_boolean(gvar); + g_variant_unref(gvar); + } + if (rle_support) + rle_depth = min(hw_depth * SR_KB(1), sw_depth); + } + else if (mode == DSO) + { + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_MAX_TIMEBASE); + if (gvar != NULL) + { + max_timebase = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + } + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_MIN_TIMEBASE); + if (gvar != NULL) + { + min_timebase = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + } + } + + if (0 != _sample_count.count()) + pre_duration = _sample_count.itemData( + _sample_count.currentIndex()) + .value(); + _sample_count.clear(); + const uint64_t samplerate = _sample_rate.itemData( + _sample_rate.currentIndex()) + .value(); + const double hw_duration = hw_depth / (samplerate * (1.0 / SR_SEC(1))); + + if (mode == DSO) + duration = max_timebase; + else if (stream_mode) + duration = sw_depth / (samplerate * (1.0 / SR_SEC(1))); + else if (rle_support) + duration = rle_depth / (samplerate * (1.0 / SR_SEC(1))); + else + duration = hw_duration; + + assert(duration > 0); + bool not_last = true; + + do + { + QString suffix = (mode == DSO) ? DIVString : (!stream_mode && duration > hw_duration) ? RLEString + : ""; + char *const s = sr_time_string(duration); + _sample_count.addItem(QString(s) + suffix, QVariant::fromValue(duration)); + g_free(s); + + double unit; + if (duration >= SR_DAY(1)) + unit = SR_DAY(1); + else if (duration >= SR_HOUR(1)) + unit = SR_HOUR(1); + else if (duration >= SR_MIN(1)) + unit = SR_MIN(1); + else + unit = 1; + + const double log10_duration = pow(10, floor(log10(duration / unit))); + + if (duration > 5 * log10_duration * unit) + duration = 5 * log10_duration * unit; + else if (duration > 2 * log10_duration * unit) + duration = 2 * log10_duration * unit; + else if (duration > log10_duration * unit) + duration = log10_duration * unit; + else + duration = log10_duration > 1 ? duration * 0.5 : (unit == SR_DAY(1) ? SR_HOUR(20) : unit == SR_HOUR(1) ? SR_MIN(50) + : unit == SR_MIN(1) ? SR_SEC(50) + : duration * 0.5); + + if (mode == DSO) + not_last = duration >= min_timebase; + else if (mode == ANALOG) + not_last = (duration >= SR_MS(100)) && + (duration / SR_SEC(1) * samplerate >= SR_KB(1)); + else + not_last = (duration / SR_SEC(1) * samplerate >= SR_KB(1)); + + } while (not_last); + + _updating_sample_count = true; + + if (pre_duration > _sample_count.itemData(0).value()) + { + _sample_count.setCurrentIndex(0); + } + else if (pre_duration < _sample_count.itemData(_sample_count.count() - 1).value()) + { + _sample_count.setCurrentIndex(_sample_count.count() - 1); + } + else + { + for (int i = 0; i < _sample_count.count(); i++) + { + if (pre_duration >= _sample_count.itemData(i).value()) + { + _sample_count.setCurrentIndex(i); + break; } + } + } + _updating_sample_count = false; + + update_sample_count_selector_value(); + on_samplecount_sel(_sample_count.currentIndex()); + + connect(&_sample_count, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplecount_sel(int))); + } + + void SamplingBar::update_sample_count_selector_value() + { + if (_updating_sample_count) + return; + + GVariant *gvar; + double duration; + + if (_device_agent->get_work_mode() == DSO) + { + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TIMEBASE); + if (gvar != NULL) + { + duration = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + } + else + { + dsv_err("%s", "ERROR: config_get SR_CONF_TIMEBASE failed."); return; } } + else + { + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_LIMIT_SAMPLES); + if (gvar != NULL) + { + duration = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + } + else + { + dsv_err("%s", "ERROR: config_get SR_CONF_TIMEBASE failed."); + return; + } + const uint64_t samplerate = _device_agent->get_sample_rate(); + duration = duration / samplerate * SR_SEC(1); + } + assert(!_updating_sample_count); + _updating_sample_count = true; + + if (duration != _sample_count.itemData(_sample_count.currentIndex()).value()) + { + for (int i = 0; i < _sample_count.count(); i++) + { + if (duration >= _sample_count.itemData( + i) + .value()) + { + _sample_count.setCurrentIndex(i); + break; + } + } + } + + _updating_sample_count = false; + } + + void SamplingBar::on_samplecount_sel(int index) + { + (void)index; + + if (_device_agent->get_work_mode() == DSO) + commit_hori_res(); + _session->broadcast_msg(DSV_MSG_DEVICE_DURATION_UPDATED); + } + + double SamplingBar::get_hori_res() + { + return _sample_count.itemData(_sample_count.currentIndex()).value(); + } + + double SamplingBar::hori_knob(int dir) + { + double hori_res = -1; + + disconnect(&_sample_count, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplecount_sel(int))); + + if (0 == dir) + { + hori_res = commit_hori_res(); + } + else if ((dir > 0) && (_sample_count.currentIndex() > 0)) + { + _sample_count.setCurrentIndex(_sample_count.currentIndex() - 1); + hori_res = commit_hori_res(); + } + else if ((dir < 0) && (_sample_count.currentIndex() < _sample_count.count() - 1)) + { + _sample_count.setCurrentIndex(_sample_count.currentIndex() + 1); + hori_res = commit_hori_res(); + } + + connect(&_sample_count, SIGNAL(currentIndexChanged(int)), + this, SLOT(on_samplecount_sel(int))); + + return hori_res; + } + + double SamplingBar::commit_hori_res() + { + const double hori_res = _sample_count.itemData( + _sample_count.currentIndex()) + .value(); + + const uint64_t sample_limit = _device_agent->get_sample_limit(); + GVariant *gvar; + uint64_t max_sample_rate; + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_MAX_DSO_SAMPLERATE); + + if (gvar != NULL) + { + max_sample_rate = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + } + else + { + dsv_err("%s", "ERROR: config_get SR_CONF_MAX_DSO_SAMPLERATE failed."); + return -1; + } + + const uint64_t sample_rate = min((uint64_t)(sample_limit * SR_SEC(1) / + (hori_res * DS_CONF_DSO_HDIVS)), + (uint64_t)(max_sample_rate / + (_session->get_ch_num(SR_CHANNEL_DSO) ? _session->get_ch_num(SR_CHANNEL_DSO) : 1))); + set_sample_rate(sample_rate); + + _device_agent->set_config(NULL, NULL, SR_CONF_TIMEBASE, + g_variant_new_uint64(hori_res)); + + return hori_res; + } + + void SamplingBar::commit_settings() + { + bool test = false; + + if (_device_agent->have_instance()) + { + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TEST); + if (gvar != NULL) + { + test = g_variant_get_boolean(gvar); + g_variant_unref(gvar); + } + } + + if (test) + { + update_sample_rate_selector_value(); + update_sample_count_selector_value(); + } + else + { + const double sample_duration = _sample_count.itemData( + _sample_count.currentIndex()) + .value(); + const uint64_t sample_rate = _sample_rate.itemData( + _sample_rate.currentIndex()) + .value(); + + if (_device_agent->have_instance()) + { + if (sample_rate != _device_agent->get_sample_rate()) + _device_agent->set_config(NULL, NULL, + SR_CONF_SAMPLERATE, + g_variant_new_uint64(sample_rate)); + + if (_device_agent->get_work_mode() != DSO) + { + const uint64_t sample_count = ((uint64_t)ceil(sample_duration / SR_SEC(1) * + sample_rate) + + SAMPLES_ALIGN) & + ~SAMPLES_ALIGN; + if (sample_count != _device_agent->get_sample_limit()) + _device_agent->set_config(NULL, NULL, + SR_CONF_LIMIT_SAMPLES, + g_variant_new_uint64(sample_count)); + + bool rle_mode = _sample_count.currentText().contains(RLEString); + _device_agent->set_config(NULL, NULL, + SR_CONF_RLE, + g_variant_new_boolean(rle_mode)); + } + } + } } - if (_session->start_capture(true)) + // start or stop capture + void SamplingBar::on_run_stop() { - enable_run_stop(false); - enable_instant(false); + if (_session->is_working()) + { + _session->stop_capture(); + return; + } + + if (_device_agent->have_instance() == false) + { + dsv_info("%s", "Have no device, can't to collect data."); + return; + } + + commit_settings(); + + if (_device_agent->get_work_mode() == DSO) + { + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ZERO); + if (gvar != NULL) + { + bool zero = g_variant_get_boolean(gvar); + g_variant_unref(gvar); + + if (zero) + { + dialogs::DSMessageBox msg(this); + msg.mBox()->setText(tr("Auto Calibration")); + msg.mBox()->setInformativeText(tr("Please adjust zero skew and save the result!")); + // msg.setStandardButtons(QMessageBox::Ok); + msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole); + msg.mBox()->addButton(tr("Skip"), QMessageBox::RejectRole); + msg.mBox()->setIcon(QMessageBox::Warning); + + if (msg.exec()) + { + zero_adj(); + } + else + { + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); + update_view_status(); + } + return; + } + } + } + + _is_run_as_instant = false; + _session->start_capture(false); } - } -} -void SamplingBar::on_device_selected() -{ - if (_updating_device_list){ - return; - } - if (_device_selector.currentIndex() == -1){ - dsv_err("%s", "Have no selected device."); - return; - } - _session->stop_capture(); - _session->session_save(); + void SamplingBar::on_instant_stop() + { + if (_session->is_working()) + { + bool wait_upload = false; - ds_device_handle devHandle = (ds_device_handle)_device_selector.currentData().toULongLong(); - _session->set_device(devHandle); -} + if (_session->is_repeat_mode() == false) + { + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_WAIT_UPLOAD); + if (gvar != NULL) + { + wait_upload = g_variant_get_boolean(gvar); + g_variant_unref(gvar); + } + } + if (!wait_upload) + { + _session->stop_capture(); + } + } + else + { + if (_device_agent->have_instance() == false) + { + dsv_info("%s", "Error! Have no device, can't to collect data."); + return; + } -void SamplingBar::enable_toggle(bool enable) -{ - bool test = false; - - if (_device_agent->have_instance()) { - GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TEST); - if (gvar != NULL) { - test = g_variant_get_boolean(gvar); - g_variant_unref(gvar); + commit_settings(); + + if (_device_agent->get_work_mode() == DSO) + { + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ZERO); + + if (gvar != NULL) + { + bool zero = g_variant_get_boolean(gvar); + g_variant_unref(gvar); + + if (zero) + { + dialogs::DSMessageBox msg(this); + msg.mBox()->setText(tr("Auto Calibration")); + msg.mBox()->setInformativeText(tr("Auto Calibration program will be started. Don't connect any probes. It can take a while!")); + + msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole); + msg.mBox()->addButton(tr("Skip"), QMessageBox::RejectRole); + msg.mBox()->setIcon(QMessageBox::Warning); + + if (msg.exec()) + { + zero_adj(); + } + else + { + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); + update_view_status(); + } + return; + } + } + } + + _is_run_as_instant = true; + _session->start_capture(true); + } } - } - if (!test) { - _sample_count.setDisabled(!enable); - if (_device_agent->get_work_mode() == DSO) - _sample_rate.setDisabled(true); - else - _sample_rate.setDisabled(!enable); - } - else { - _sample_count.setDisabled(true); - _sample_rate.setDisabled(true); - } + void SamplingBar::on_device_selected() + { + if (_updating_device_list) + { + return; + } + if (_device_selector.currentIndex() == -1) + { + dsv_err("%s", "Have no selected device."); + return; + } + _session->stop_capture(); + _session->session_save(); - if (_device_agent->name() == "virtual-session") { - _sample_count.setDisabled(true); - _sample_rate.setDisabled(true); - } -} - -void SamplingBar::enable_run_stop(bool enable) -{ - _run_stop_button.setDisabled(!enable); -} - -void SamplingBar::enable_instant(bool enable) -{ - _instant_button.setDisabled(!enable); -} - -void SamplingBar::reload() -{ - QString iconPath = GetIconPath(); - - if (_device_agent->get_work_mode() == LOGIC) { - if (_device_agent->name() == "virtual-session") { - _mode_action->setVisible(false); - } - else { - - QString icon = _session->is_repeat_mode() ? "/moder.svg" : "/modes.svg"; - _mode_button.setIcon(QIcon(iconPath + icon)); - _mode_action->setVisible(true); + ds_device_handle devHandle = (ds_device_handle)_device_selector.currentData().toULongLong(); + _session->set_device(devHandle); } - _run_stop_action->setVisible(true); - _instant_action->setVisible(true); - enable_toggle(true); - } - else if (_device_agent->get_work_mode() == ANALOG) { - _mode_action->setVisible(false); - _run_stop_action->setVisible(true); - _instant_action->setVisible(false); - enable_toggle(true); - } - else if (_device_agent->get_work_mode() == DSO) { - _mode_action->setVisible(false); - _run_stop_action->setVisible(true); - _instant_action->setVisible(true); - enable_toggle(true); - } - retranslateUi(); - reStyle(); - update(); -} + void SamplingBar::enable_toggle(bool enable) + { + bool test = false; -void SamplingBar::on_mode() -{ - QString iconPath = GetIconPath(); - QAction *act = qobject_cast(sender()); + if (_device_agent->have_instance()) + { + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TEST); + if (gvar != NULL) + { + test = g_variant_get_boolean(gvar); + g_variant_unref(gvar); + } + } + if (!test) + { + _sample_count.setDisabled(!enable); - if (act == _action_single) { - _mode_button.setIcon(QIcon(iconPath+"/modes.svg")); - _session->set_repeat_mode(false); - } - else if (act == _action_repeat) { - _mode_button.setIcon(QIcon(iconPath+"/moder.svg")); - pv::dialogs::Interval interval_dlg(this); + if (_device_agent->get_work_mode() == DSO) + _sample_rate.setDisabled(true); + else + _sample_rate.setDisabled(!enable); + } + else + { + _sample_count.setDisabled(true); + _sample_rate.setDisabled(true); + } - interval_dlg.set_interval(_session->get_repeat_intvl()); - interval_dlg.exec(); + if (_device_agent->name() == "virtual-session") + { + + } + } - if (interval_dlg.is_done()){ - _session->set_repeat_intvl(interval_dlg.get_interval()); - _session->set_repeat_mode(true); - } - } -} + void SamplingBar::reload() + { + QString iconPath = GetIconPath(); - void SamplingBar::update_device_list() - { - struct ds_device_info *array = NULL; - int dev_count = 0; - int select_index = 0; + if (_device_agent->get_work_mode() == LOGIC) + { + if (_device_agent->name() == "virtual-session") + { + _mode_action->setVisible(false); + } + else + { - dsv_info("%s", "Update device list."); + QString icon = _session->is_repeat_mode() ? "/moder.svg" : "/modes.svg"; + _mode_button.setIcon(QIcon(iconPath + icon)); + _mode_action->setVisible(true); + } + _run_stop_action->setVisible(true); + _instant_action->setVisible(true); + } + else if (_device_agent->get_work_mode() == ANALOG) + { + _mode_action->setVisible(false); + _run_stop_action->setVisible(true); + _instant_action->setVisible(false); + } + else if (_device_agent->get_work_mode() == DSO) + { + _mode_action->setVisible(false); + _run_stop_action->setVisible(true); + _instant_action->setVisible(true); + } + + retranslateUi(); + reStyle(); + update(); + } - array = _session->get_device_list(dev_count, select_index); + void SamplingBar::on_mode() + { + QString iconPath = GetIconPath(); + QAction *act = qobject_cast(sender()); - if (array == NULL){ - dsv_err("%s", "Get deivce list error!"); - return; - } + if (act == _action_single) + { + _mode_button.setIcon(QIcon(iconPath + "/modes.svg")); + _session->set_repeat_mode(false); + } + else if (act == _action_repeat) + { + _mode_button.setIcon(QIcon(iconPath + "/moder.svg")); + pv::dialogs::Interval interval_dlg(this); - _updating_device_list = true; - struct ds_device_info *p = NULL; + interval_dlg.set_interval(_session->get_repeat_intvl()); + interval_dlg.exec(); - _device_selector.clear(); + if (interval_dlg.is_done()) + { + _session->set_repeat_intvl(interval_dlg.get_interval()); + _session->set_repeat_mode(true); + } + } + } - for (int i=0; iname), QVariant::fromValue((unsigned long long)p->handle)); - } - free(array); + void SamplingBar::update_device_list() + { + struct ds_device_info *array = NULL; + int dev_count = 0; + int select_index = 0; - _device_selector.setCurrentIndex(select_index); - update_sample_rate_selector(); + dsv_info("%s", "Update device list."); - int width = _device_selector.sizeHint().width(); - _device_selector.setFixedWidth(min(width+15, _device_selector.maximumWidth())); - _device_selector.view()->setMinimumWidth(width+30); - - _updating_device_list = false; - } + array = _session->get_device_list(dev_count, select_index); - void SamplingBar::config_device() - { - on_configure(); - } + if (array == NULL) + { + dsv_err("%s", "Get deivce list error!"); + return; + } -} // namespace toolbars + _updating_device_list = true; + struct ds_device_info *p = NULL; + ds_device_handle cur_dev_handle = NULL_HANDLE; + + _device_selector.clear(); + + for (int i = 0; i < dev_count; i++) + { + p = (array + i); + _device_selector.addItem(QString(p->name), QVariant::fromValue((unsigned long long)p->handle)); + + if (i == select_index) + cur_dev_handle = p->handle; + } + free(array); + + _device_selector.setCurrentIndex(select_index); + + if (cur_dev_handle != _last_device_handle){ + update_sample_rate_selector(); + _last_device_handle = cur_dev_handle; + } + + + int width = _device_selector.sizeHint().width(); + _device_selector.setFixedWidth(min(width + 15, _device_selector.maximumWidth())); + _device_selector.view()->setMinimumWidth(width + 30); + + _updating_device_list = false; + } + + void SamplingBar::config_device() + { + on_configure(); + } + + void SamplingBar::update_view_status() + { + int bEnable = _session->is_working() == false; + + _device_type.setEnabled(bEnable); + _configure_button.setEnabled(bEnable); + _mode_button.setEnabled(bEnable); + _device_type.setEnabled(bEnable); + + _mode_button.setEnabled(bEnable); + _configure_button.setEnabled(bEnable); + _device_selector.setEnabled(bEnable); + _sample_rate.setEnabled(bEnable); + _sample_count.setEnabled(bEnable); + + + if (_session->is_working()){ + _run_stop_button.setEnabled(_is_run_as_instant ? false : true); + _instant_button.setEnabled(_is_run_as_instant ? true : false); + } + else{ + _run_stop_button.setEnabled(true); + _instant_button.setEnabled(true); + } + + QString iconPath = GetIconPath(); + + if (_is_run_as_instant) + _instant_button.setIcon(!bEnable ? QIcon(iconPath + "/stop.svg") : QIcon(iconPath + "/single.svg")); + else + _run_stop_button.setIcon(!bEnable ? QIcon(iconPath + "/stop.svg") : QIcon(iconPath + "/start.svg")); + + _mode_button.setIcon(_session->is_repeat_mode() == false ? QIcon(iconPath + "/modes.svg") : QIcon(iconPath + "/moder.svg")); + + retranslateUi(); + + if (bEnable){ + _is_run_as_instant = false; + } + } + + } // namespace toolbars } // namespace pv diff --git a/DSView/pv/toolbars/samplingbar.h b/DSView/pv/toolbars/samplingbar.h index 36182864..b9000262 100644 --- a/DSView/pv/toolbars/samplingbar.h +++ b/DSView/pv/toolbars/samplingbar.h @@ -76,23 +76,18 @@ namespace pv public: - SamplingBar(SigSession *session, QWidget *parent); - - void enable_toggle(bool enable); - void enable_instant(bool enable); + SamplingBar(SigSession *session, QWidget *parent); double hori_knob(int dir); double commit_hori_res(); double get_hori_res(); void set_sample_rate(uint64_t sample_rate); void update_device_list(); - void reload(); - void set_sampling(bool sampling); - + void reload(); + void update_view_status(); void config_device(); - private: - void enable_run_stop(bool enable); + private: void changeEvent(QEvent *event); void retranslateUi(); void reStyle(); @@ -103,6 +98,7 @@ namespace pv void update_sample_count_selector_value(); void commit_settings(); void setting_adj(); + void enable_toggle(bool enable); private slots: void on_mode(); @@ -116,32 +112,33 @@ namespace pv private: - SigSession *_session; - - QToolButton _device_type; - DsComboBox _device_selector; - - QToolButton _configure_button; - DsComboBox _sample_count; - DsComboBox _sample_rate; + SigSession *_session; + DsComboBox _device_selector; + DsComboBox _sample_count; + DsComboBox _sample_rate; bool _updating_sample_rate; bool _updating_sample_count; bool _updating_device_list; + QToolButton _device_type; + QToolButton _configure_button; QToolButton _run_stop_button; QToolButton _instant_button; + QToolButton _mode_button; + QAction *_run_stop_action; QAction *_instant_action; QAction *_mode_action; - QToolButton _mode_button; - + QMenu *_mode_menu; QAction *_action_repeat; QAction *_action_single; DeviceAgent *_device_agent; ds_device_handle _last_device_handle; + + bool _is_run_as_instant; }; } // namespace toolbars diff --git a/DSView/pv/toolbars/trigbar.cpp b/DSView/pv/toolbars/trigbar.cpp index 00a50a56..03edf1ae 100644 --- a/DSView/pv/toolbars/trigbar.cpp +++ b/DSView/pv/toolbars/trigbar.cpp @@ -241,21 +241,6 @@ void TrigBar::search_clicked() AppConfig::Instance().SaveFrame(); } -void TrigBar::enable_toggle(bool enable) -{ - _trig_button.setDisabled(!enable); - _protocol_button.setDisabled(!enable); - _measure_button.setDisabled(!enable); - _search_button.setDisabled(!enable); - _function_button.setDisabled(!enable); - _setting_button.setDisabled(!enable); -} - -void TrigBar::enable_protocol(bool enable) -{ - _protocol_button.setDisabled(!enable); -} - void TrigBar::close_all() { if (_trig_button.isChecked()) { @@ -310,8 +295,8 @@ void TrigBar::reload() _action_dispalyOptions->setVisible(false); } - enable_toggle(true); - update(); + update_view_status(); + update(); } void TrigBar::on_actionFft_triggered() @@ -384,7 +369,7 @@ void TrigBar::restore_status() AppConfig &app = AppConfig::Instance(); int mode = _session->get_device()->get_work_mode(); - if (mode == LOGIC) + if (mode == LOGIC) return &app._frameOptions._logicDock; else if (mode == DSO) return &app._frameOptions._dsoDock; @@ -392,5 +377,17 @@ void TrigBar::restore_status() return &app._frameOptions._analogDock; } + void TrigBar::update_view_status() + { + bool bEnable = _session->is_working() == false; + + _trig_button.setEnabled(bEnable); + _protocol_button.setEnabled(bEnable); + _measure_button.setEnabled(bEnable); + _search_button.setEnabled(bEnable); + _function_button.setEnabled(bEnable); + _setting_button.setEnabled(bEnable); + } + } // namespace toolbars } // namespace pv diff --git a/DSView/pv/toolbars/trigbar.h b/DSView/pv/toolbars/trigbar.h index 8728f1b6..b3f34673 100644 --- a/DSView/pv/toolbars/trigbar.h +++ b/DSView/pv/toolbars/trigbar.h @@ -46,16 +46,15 @@ class TrigBar : public QToolBar public: explicit TrigBar(SigSession *session, QWidget *parent = 0); - void enable_toggle(bool enable); - void enable_protocol(bool enable); void close_all(); void reload(); + void update_view_status(); private: void changeEvent(QEvent *event); void retranslateUi(); void reStyle(); - DockOptions* getDockOptions(); + DockOptions* getDockOptions(); signals: void sig_setTheme(QString style); diff --git a/DSView/pv/view/devmode.cpp b/DSView/pv/view/devmode.cpp index c5127bed..ba299d52 100644 --- a/DSView/pv/view/devmode.cpp +++ b/DSView/pv/view/devmode.cpp @@ -197,12 +197,14 @@ void DevMode::on_mode_change() { if ((*i).first == action) { if (_device_agent->get_work_mode() != (*i).second->mode) { - _session->stop_capture(); _session->set_repeat_mode(false); + _session->stop_capture(); _session->session_save(); _device_agent->set_config(NULL, NULL, SR_CONF_DEVICE_MODE, g_variant_new_int16((*i).second->mode)); + + _session->on_work_mode_changed(); auto *mode_name = get_mode_name((*i).second->mode); QString icon_fname = iconPath + "/" + QString::fromLocal8Bit(mode_name->_logo); diff --git a/DSView/pv/view/logicsignal.cpp b/DSView/pv/view/logicsignal.cpp index ef41d4c0..5b517c70 100644 --- a/DSView/pv/view/logicsignal.cpp +++ b/DSView/pv/view/logicsignal.cpp @@ -42,9 +42,9 @@ const int LogicSignal::StateRound = 5; LogicSignal::LogicSignal(data::Logic *data, sr_channel *probe) : Signal(probe), - _data(data), - _trig(NONTRIG) + _data(data) { + _trig = NONTRIG; } LogicSignal::LogicSignal(view::LogicSignal *s, @@ -96,7 +96,8 @@ bool LogicSignal::commit_trig() if (_trig == NONTRIG) { ds_trigger_probe_set(_index_list.front(), 'X', 'X'); return false; - } else { + } + else { ds_trigger_set_en(true); if (_trig == POSTRIG) ds_trigger_probe_set(_index_list.front(), 'R', 'X'); diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index ef865568..3507592f 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -479,8 +479,6 @@ void View::repeat_unshow() void View::frame_began() { -// if (_device_agent->get_work_mode() == LOGIC) -// _viewbottom->set_trig_time(_session->get_session_time()); _search_hit = false; _search_pos = 0; set_search_pos(_search_pos, _search_hit); @@ -866,6 +864,7 @@ void View::resizeEvent(QResizeEvent*) update_margins(); update_scroll(); signals_changed(); + if (_device_agent->get_work_mode() == DSO) _scale = _session->cur_view_time() / get_view_width(); diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index a753c5ed..5980b89f 100644 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -44,6 +44,7 @@ #include "../config/appconfig.h" #include "../dsvdef.h" #include "../appcontrol.h" +#include "../log.h" using namespace std; @@ -89,6 +90,7 @@ Viewport::Viewport(View &parent, View_type type) : transfer_started = false; timer_cnt = 0; _clickX = 0; + _sample_received = 0; // drag inertial _drag_strength = 0; @@ -1196,7 +1198,8 @@ void Viewport::set_receive_len(quint64 length) if (length == 0) { _sample_received = 0; start_trigger_timer(333); - } else { + } + else { stop_trigger_timer(); if (_sample_received + length > _view.session().cur_samplelimits()) _sample_received = _view.session().cur_samplelimits(); diff --git a/libsigrok4DSL/lib_main.c b/libsigrok4DSL/lib_main.c index f2f68a69..1d97e198 100644 --- a/libsigrok4DSL/lib_main.c +++ b/libsigrok4DSL/lib_main.c @@ -52,7 +52,6 @@ struct sr_lib_context struct libusb_device *attach_device_handle; struct libusb_device *detach_device_handle; struct sr_dev_inst *actived_device_instance; - int collect_stop_flag; GThread *hotplug_thread; GThread *collect_thread; ds_datafeed_callback_t data_forward_callback; @@ -84,7 +83,6 @@ static struct sr_lib_context lib_ctx = { .attach_device_handle = NULL, .detach_device_handle = NULL, .actived_device_instance = NULL, - .collect_stop_flag = 0, .data_forward_callback = NULL, .collect_thread = NULL, .callback_thread_count = 0, @@ -662,8 +660,6 @@ SR_API int ds_start_collect() return SR_ERR_CALL_STATUS; } - lib_ctx.collect_stop_flag = 0; - // Create new session. sr_session_new(); @@ -752,8 +748,6 @@ SR_API int ds_stop_collect() return SR_ERR_CALL_STATUS; } - lib_ctx.collect_stop_flag = 1; - // Stop current session. sr_session_stop(); @@ -1015,8 +1009,7 @@ SR_PRIV int ds_data_forward(const struct sr_dev_inst *sdi, return SR_ERR_ARG; } - if (lib_ctx.data_forward_callback != NULL && lib_ctx.collect_stop_flag == 0) - { + if (lib_ctx.data_forward_callback != NULL){ lib_ctx.data_forward_callback(sdi, packet); return SR_OK; } diff --git a/libsigrok4DSL/session.c b/libsigrok4DSL/session.c index d75f5736..7b06a1af 100644 --- a/libsigrok4DSL/session.c +++ b/libsigrok4DSL/session.c @@ -173,6 +173,7 @@ static int sr_session_iteration(gboolean block) */ g_mutex_lock(&session->stop_mutex); if (session->abort_session) { + sr_info("%s", "Collection task aborted."); current_device_acquisition_stop(); /* But once is enough. */ session->abort_session = FALSE;