1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
/*
* This file is part of the DSLogic-gui project.
* DSLogic-gui is based on PulseView.
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
* Copyright (C) 2013 DreamSourceLab <dreamsourcelab@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "dsotriggerdock.h"
#include "../sigsession.h"
#include <QObject>
#include <QLabel>
#include <QRadioButton>
#include <QPainter>
#include <QStyleOption>
#include <QMessageBox>
#include <QVector>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include "libsigrok4DSLogic/libsigrok.h"
namespace pv {
namespace dock {
DsoTriggerDock::DsoTriggerDock(QWidget *parent, SigSession &session) :
QWidget(parent),
_session(session)
{
QLabel *position_label = new QLabel("Trigger Position: ", this);
position_spinBox = new QSpinBox(this);
position_spinBox->setRange(0, 99);
position_spinBox->setButtonSymbols(QAbstractSpinBox::NoButtons);
position_slider = new QSlider(Qt::Horizontal, this);
position_slider->setRange(0, 99);
connect(position_slider, SIGNAL(valueChanged(int)), position_spinBox, SLOT(setValue(int)));
connect(position_spinBox, SIGNAL(valueChanged(int)), position_slider, SLOT(setValue(int)));
connect(position_slider, SIGNAL(valueChanged(int)), this, SLOT(pos_changed(int)));
QLabel *tSource_labe = new QLabel("Trigger Sources: ", this);
QRadioButton *auto_radioButton = new QRadioButton("Auto");
auto_radioButton->setChecked(true);
QRadioButton *ch0_radioButton = new QRadioButton("Channel 0");
QRadioButton *ch1_radioButton = new QRadioButton("Channel 1");
QRadioButton *ch0a1_radioButton = new QRadioButton("Channel 0 && Channel 1");
QRadioButton *ch0o1_radioButton = new QRadioButton("Channel 0 | Channel 1");
connect(auto_radioButton, SIGNAL(clicked()), this, SLOT(source_changed()));
connect(ch0_radioButton, SIGNAL(clicked()), this, SLOT(source_changed()));
connect(ch1_radioButton, SIGNAL(clicked()), this, SLOT(source_changed()));
connect(ch0a1_radioButton, SIGNAL(clicked()), this, SLOT(source_changed()));
connect(ch0o1_radioButton, SIGNAL(clicked()), this, SLOT(source_changed()));
QLabel *tType_labe = new QLabel("Trigger Types: ", this);
QRadioButton *rising_radioButton = new QRadioButton("Rising Edge");
rising_radioButton->setChecked(true);
QRadioButton *falling_radioButton = new QRadioButton("Falling Edge");
connect(rising_radioButton, SIGNAL(clicked()), this, SLOT(type_changed()));
connect(falling_radioButton, SIGNAL(clicked()), this, SLOT(type_changed()));
source_group=new QButtonGroup(this);
type_group=new QButtonGroup(this);
source_group->addButton(auto_radioButton);
source_group->addButton(ch0_radioButton);
source_group->addButton(ch1_radioButton);
source_group->addButton(ch0a1_radioButton);
source_group->addButton(ch0o1_radioButton);
source_group->setId(auto_radioButton, DSO_TRIGGER_AUTO);
source_group->setId(ch0_radioButton, DSO_TRIGGER_CH0);
source_group->setId(ch1_radioButton, DSO_TRIGGER_CH1);
source_group->setId(ch0a1_radioButton, DSO_TRIGGER_CH0A1);
source_group->setId(ch0o1_radioButton, DSO_TRIGGER_CH0O1);
type_group->addButton(rising_radioButton);
type_group->addButton(falling_radioButton);
type_group->setId(rising_radioButton, DSO_TRIGGER_RISING);
type_group->setId(falling_radioButton, DSO_TRIGGER_FALLING);
QVBoxLayout *layout = new QVBoxLayout(this);
QGridLayout *gLayout = new QGridLayout();
gLayout->addWidget(position_label, 0, 0);
gLayout->addWidget(position_spinBox, 0, 1);
gLayout->addWidget(new QLabel(this), 0, 2);
gLayout->addWidget(position_slider, 1, 0, 1, 3);
gLayout->addWidget(new QLabel(this), 2, 0);
gLayout->addWidget(tSource_labe, 3, 0);
gLayout->addWidget(auto_radioButton, 4, 0);
gLayout->addWidget(ch0_radioButton, 5, 0);
gLayout->addWidget(ch1_radioButton, 5, 1);
gLayout->addWidget(ch0a1_radioButton, 6, 0);
gLayout->addWidget(ch0o1_radioButton, 6, 1);
gLayout->addWidget(new QLabel(this), 7, 0);
gLayout->addWidget(tType_labe, 8, 0);
gLayout->addWidget(rising_radioButton, 9, 0);
gLayout->addWidget(falling_radioButton, 10, 0);
gLayout->setColumnStretch(3, 1);
layout->addLayout(gLayout);
layout->addStretch(1);
setLayout(layout);
}
DsoTriggerDock::~DsoTriggerDock()
{
}
void DsoTriggerDock::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
void DsoTriggerDock::pos_changed(int pos)
{
int ret;
quint32 real_pos;
real_pos = pos*_session.get_total_sample_len()/100.0f;
real_pos = (_session.get_last_sample_rate() > SR_MHZ(100)) ? real_pos/2 : real_pos;
ret = sr_config_set(_session.get_device(), SR_CONF_HORIZ_TRIGGERPOS, g_variant_new_uint32(real_pos));
if (ret != SR_OK) {
QMessageBox msg(this);
msg.setText("Trigger Setting Issue");
msg.setInformativeText("Change horiz trigger position failed!");
msg.setStandardButtons(QMessageBox::Ok);
msg.setIcon(QMessageBox::Warning);
msg.exec();
}
}
void DsoTriggerDock::source_changed()
{
int id = source_group->checkedId();
int ret;
ret = sr_config_set(_session.get_device(), SR_CONF_TRIGGER_SOURCE, g_variant_new_byte(id));
if (ret != SR_OK) {
QMessageBox msg(this);
msg.setText("Trigger Setting Issue");
msg.setInformativeText("Change trigger source failed!");
msg.setStandardButtons(QMessageBox::Ok);
msg.setIcon(QMessageBox::Warning);
msg.exec();
}
}
void DsoTriggerDock::type_changed()
{
int id = type_group->checkedId();
int ret;
ret = sr_config_set(_session.get_device(), SR_CONF_TRIGGER_SLOPE, g_variant_new_byte(id));
if (ret != SR_OK) {
QMessageBox msg(this);
msg.setText("Trigger Setting Issue");
msg.setInformativeText("Change trigger type failed!");
msg.setStandardButtons(QMessageBox::Ok);
msg.setIcon(QMessageBox::Warning);
msg.exec();
}
}
void DsoTriggerDock::device_change()
{
if (strcmp(_session.get_device()->driver->name, "DSLogic") != 0) {
position_spinBox->setDisabled(true);
position_slider->setDisabled(true);
} else {
position_spinBox->setDisabled(false);
position_slider->setDisabled(false);
}
}
} // namespace dock
} // namespace pv
|