From ec3b38b8cf524466e313ca68bee7149bd3bf7922 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Mon, 3 Apr 2023 17:50:34 +0800 Subject: [PATCH] fix: Able to use the disabled channel for trigger --- DSView/pv/deviceagent.cpp | 12 ++++++++ DSView/pv/deviceagent.h | 2 ++ DSView/pv/dock/dsotriggerdock.cpp | 50 +++++++++++++++++++++++++++++++ DSView/pv/dock/dsotriggerdock.h | 4 +-- DSView/pv/mainwindow.cpp | 6 +++- lang/cn/msg.json | 4 +++ lang/en/msg.json | 4 +++ libsigrok4DSL/libsigrok.h | 14 ++++----- 8 files changed, 86 insertions(+), 10 deletions(-) diff --git a/DSView/pv/deviceagent.cpp b/DSView/pv/deviceagent.cpp index 94ee03fc..49bd9c96 100644 --- a/DSView/pv/deviceagent.cpp +++ b/DSView/pv/deviceagent.cpp @@ -291,6 +291,18 @@ void DeviceAgent::config_changed() _callback->DeviceConfigChanged(); } } + +bool DeviceAgent::channel_is_enable(int index) +{ + for (const GSList *l = get_channels(); l; l = l->next) + { + const sr_channel *const probe = (const sr_channel *)l->data; + if (probe->index == index) + return probe->enabled; + } + + return false; +} //---------------device config-----------/ diff --git a/DSView/pv/deviceagent.h b/DSView/pv/deviceagent.h index 629118d2..4fbe52dc 100644 --- a/DSView/pv/deviceagent.h +++ b/DSView/pv/deviceagent.h @@ -177,6 +177,8 @@ public: return _is_new_device; } + bool channel_is_enable(int index); + private: void config_changed(); bool is_in_history(ds_device_handle dev_handle); diff --git a/DSView/pv/dock/dsotriggerdock.cpp b/DSView/pv/dock/dsotriggerdock.cpp index d1a92c5b..d48d1173 100644 --- a/DSView/pv/dock/dsotriggerdock.cpp +++ b/DSView/pv/dock/dsotriggerdock.cpp @@ -37,6 +37,8 @@ #include #include "../ui/langresource.h" +#include "../log.h" +#include "../ui/msgbox.h" using namespace boost; using namespace std; @@ -289,9 +291,21 @@ void DsoTriggerDock::margin_changed(int margin) void DsoTriggerDock::source_changed() { + if (check_trig_channel() == false){ + _auto_radioButton->setChecked(true); + _ch1_radioButton->setChecked(false); + _ch0a1_radioButton->setChecked(false); + _ch0o1_radioButton->setChecked(false); + + QString msg(L_S(STR_PAGE_MSG, S_ID(IDS_MSG_DISABLED_CHANNEL_TRIG), "Disabled channels cannot be used for triggering!")); + MsgBox::Show("", msg); + } + int id = _source_group->checkedId(); int ret; + dsv_info("Set DSO trig type:%d", id); + ret = _session->get_device()->set_config(NULL, NULL, SR_CONF_TRIGGER_SOURCE, g_variant_new_byte(id)); @@ -306,6 +320,42 @@ void DsoTriggerDock::source_changed() } } +void DsoTriggerDock::check_setting() +{ + if (check_trig_channel() == false){ + _auto_radioButton->setChecked(true); + _ch1_radioButton->setChecked(false); + _ch0a1_radioButton->setChecked(false); + _ch0o1_radioButton->setChecked(false); + + _session->get_device()->set_config(NULL, NULL, + SR_CONF_TRIGGER_SOURCE, + g_variant_new_byte(DSO_TRIGGER_AUTO)); + } +} + +bool DsoTriggerDock::check_trig_channel() +{ + int id = _source_group->checkedId(); + bool b0 = _session->get_device()->channel_is_enable(0); + bool b1 = _session->get_device()->channel_is_enable(1); + + if (DSO_TRIGGER_CH0 == id && !b0){ + dsv_err("ERROR: The trigger channel is disabled"); + return false; + } + else if (DSO_TRIGGER_CH1 == id && !b1){ + dsv_err("ERROR: The trigger channel is disabled"); + return false; + } + else if (DSO_TRIGGER_CH0A1 == id && (!b0 || !b1)){ + dsv_err("ERROR: The trigger channel is disabled"); + return false; + } + + return true; +} + void DsoTriggerDock::channel_changed(int ch) { (void)ch; diff --git a/DSView/pv/dock/dsotriggerdock.h b/DSView/pv/dock/dsotriggerdock.h index 3454601b..0f3c9cb8 100644 --- a/DSView/pv/dock/dsotriggerdock.h +++ b/DSView/pv/dock/dsotriggerdock.h @@ -50,12 +50,14 @@ public: void device_change(); void update_view(); + void check_setting(); private: void paintEvent(QPaintEvent *e); void changeEvent(QEvent *event); void retranslateUi(); void reStyle(); + bool check_trig_channel(); signals: void set_trig_pos(int percent); @@ -71,8 +73,6 @@ private slots: void type_changed(); void channel_changed(int ch); -private: - private: SigSession *_session; diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 3d38e012..17611108 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -1647,7 +1647,11 @@ namespace pv break; case DSV_MSG_START_COLLECT_WORK_PREV: - _trigger_widget->try_commit_trigger(); + if (_device_agent->get_work_mode() == LOGIC) + _trigger_widget->try_commit_trigger(); + else if (_device_agent->get_work_mode() == DSO) + _dso_trigger_widget->check_setting(); + _view->capture_init(); _view->on_state_changed(false); break; diff --git a/lang/cn/msg.json b/lang/cn/msg.json index be47e228..d64d07d6 100644 --- a/lang/cn/msg.json +++ b/lang/cn/msg.json @@ -358,5 +358,9 @@ { "id": "IDS_MSG_TO_SWITCH_DEVICE", "text": "要切换到新设备?" + }, + { + "id": "IDS_MSG_DISABLED_CHANNEL_TRIG", + "text": "禁用通道不能用于触发!" } ] \ No newline at end of file diff --git a/lang/en/msg.json b/lang/en/msg.json index 8e56d108..6708bbd5 100644 --- a/lang/en/msg.json +++ b/lang/en/msg.json @@ -359,5 +359,9 @@ { "id": "IDS_MSG_TO_SWITCH_DEVICE", "text": "To switch the new device?" + }, + { + "id": "IDS_MSG_DISABLED_CHANNEL_TRIG", + "text": "Disabled channels cannot be used for triggering!" } ] \ No newline at end of file diff --git a/libsigrok4DSL/libsigrok.h b/libsigrok4DSL/libsigrok.h index b606c152..11394d18 100644 --- a/libsigrok4DSL/libsigrok.h +++ b/libsigrok4DSL/libsigrok.h @@ -1142,20 +1142,20 @@ struct sr_dev_mode { enum { SIMPLE_TRIGGER = 0, - ADV_TRIGGER, - SERIAL_TRIGGER, + ADV_TRIGGER = 1, + SERIAL_TRIGGER = 2, }; enum { DSO_TRIGGER_AUTO = 0, - DSO_TRIGGER_CH0, - DSO_TRIGGER_CH1, - DSO_TRIGGER_CH0A1, - DSO_TRIGGER_CH0O1, + DSO_TRIGGER_CH0 = 1, + DSO_TRIGGER_CH1 = 2, + DSO_TRIGGER_CH0A1 = 3, + DSO_TRIGGER_CH0O1 = 4, }; enum { DSO_TRIGGER_RISING = 0, - DSO_TRIGGER_FALLING, + DSO_TRIGGER_FALLING = 1, }; struct ds_trigger_pos {