forked from Ivasoft/DSView
Improve measure @ OSC mode; add Vrms and Vmean
This commit is contained in:
@@ -24,8 +24,8 @@
|
||||
<file>icons/start.png</file>
|
||||
<file>icons/dsl_logo.png</file>
|
||||
<file>icons/logo.png</file>
|
||||
<file>icons/decoder-hidden.png</file>
|
||||
<file>icons/decoder-shown.png</file>
|
||||
<file>icons/hidden.png</file>
|
||||
<file>icons/shown.png</file>
|
||||
<file>icons/instant.png</file>
|
||||
<file>icons/trigger_dis.png</file>
|
||||
<file>icons/file_dis.png</file>
|
||||
@@ -55,5 +55,6 @@
|
||||
<file>icons/instant_dis_cn.png</file>
|
||||
<file>icons/start_dis.png</file>
|
||||
<file>icons/start_dis_cn.png</file>
|
||||
<file>icons/settings.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
BIN
DSView/icons/settings.png
Executable file
BIN
DSView/icons/settings.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 883 B After Width: | Height: | Size: 883 B |
@@ -45,6 +45,8 @@ const float DsoSnapshot::LogEnvelopeScaleFactor =
|
||||
logf(EnvelopeScaleFactor);
|
||||
const uint64_t DsoSnapshot::EnvelopeDataUnit = 4*1024; // bytes
|
||||
|
||||
const int DsoSnapshot::VrmsScaleFactor = 1 << 8;
|
||||
|
||||
DsoSnapshot::DsoSnapshot(const sr_datafeed_dso &dso, uint64_t _total_sample_len, unsigned int channel_num, bool instant) :
|
||||
Snapshot(sizeof(uint16_t), _total_sample_len, channel_num),
|
||||
_envelope_en(false),
|
||||
@@ -79,7 +81,7 @@ void DsoSnapshot::append_payload(const sr_datafeed_dso &dso)
|
||||
|
||||
void DsoSnapshot::enable_envelope(bool enable)
|
||||
{
|
||||
if (!_envelope_done & enable)
|
||||
if (!_envelope_done && enable)
|
||||
append_payload_to_envelope_levels();
|
||||
_envelope_en = enable;
|
||||
}
|
||||
@@ -146,24 +148,20 @@ void DsoSnapshot::reallocate_envelope(Envelope &e)
|
||||
|
||||
void DsoSnapshot::append_payload_to_envelope_levels()
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < _channel_num; i++) {
|
||||
for (int i = 0; i < _channel_num; i++) {
|
||||
Envelope &e0 = _envelope_levels[i][0];
|
||||
uint64_t prev_length;
|
||||
EnvelopeSample *dest_ptr;
|
||||
|
||||
// Expand the data buffer to fit the new samples
|
||||
prev_length = e0.length;
|
||||
e0.length = get_sample_count() / EnvelopeScaleFactor;
|
||||
e0.length = _sample_count / EnvelopeScaleFactor;
|
||||
|
||||
// Break off if there are no new samples to compute
|
||||
// if (e0.length == prev_length)
|
||||
// return;
|
||||
if (e0.length == 0)
|
||||
return;
|
||||
if (e0.length == prev_length)
|
||||
prev_length = 0;
|
||||
|
||||
// Expand the data buffer to fit the new samples
|
||||
reallocate_envelope(e0);
|
||||
|
||||
dest_ptr = e0.samples + prev_length;
|
||||
@@ -171,17 +169,6 @@ void DsoSnapshot::append_payload_to_envelope_levels()
|
||||
// Iterate through the samples to populate the first level mipmap
|
||||
const uint8_t *const stop_src_ptr = (uint8_t*)_data +
|
||||
e0.length * EnvelopeScaleFactor * _channel_num;
|
||||
// for (const uint16_t *src_ptr = (uint16_t*)_data +
|
||||
// prev_length * EnvelopeScaleFactor;
|
||||
// src_ptr < end_src_ptr; src_ptr += EnvelopeScaleFactor)
|
||||
// {
|
||||
// const EnvelopeSample sub_sample = {
|
||||
// *min_element(src_ptr, src_ptr + EnvelopeScaleFactor),
|
||||
// *max_element(src_ptr, src_ptr + EnvelopeScaleFactor),
|
||||
// };
|
||||
|
||||
// *dest_ptr++ = sub_sample;
|
||||
// }
|
||||
for (const uint8_t *src_ptr = (uint8_t*)_data +
|
||||
prev_length * EnvelopeScaleFactor * _channel_num + i;
|
||||
src_ptr < stop_src_ptr; src_ptr += EnvelopeScaleFactor * _channel_num)
|
||||
@@ -194,14 +181,13 @@ void DsoSnapshot::append_payload_to_envelope_levels()
|
||||
EnvelopeSample sub_sample;
|
||||
sub_sample.min = *begin_src_ptr;
|
||||
sub_sample.max = *begin_src_ptr;
|
||||
begin_src_ptr += _channel_num;
|
||||
//begin_src_ptr += _channel_num;
|
||||
while (begin_src_ptr < end_src_ptr)
|
||||
{
|
||||
sub_sample.min = min(sub_sample.min, *begin_src_ptr);
|
||||
sub_sample.max = max(sub_sample.max, *begin_src_ptr);
|
||||
begin_src_ptr += _channel_num;
|
||||
}
|
||||
|
||||
*dest_ptr++ = sub_sample;
|
||||
}
|
||||
|
||||
@@ -248,5 +234,72 @@ void DsoSnapshot::append_payload_to_envelope_levels()
|
||||
_envelope_done = true;
|
||||
}
|
||||
|
||||
double DsoSnapshot::cal_vrms(double zero_off, int index) const
|
||||
{
|
||||
assert(index >= 0);
|
||||
assert(index < _channel_num);
|
||||
|
||||
// root-meam-squart value
|
||||
double vrms_pre = 0;
|
||||
double vrms = 0;
|
||||
double tmp;
|
||||
|
||||
// Iterate through the samples to populate the first level mipmap
|
||||
const uint8_t *const stop_src_ptr = (uint8_t*)_data +
|
||||
_sample_count * _channel_num;
|
||||
for (const uint8_t *src_ptr = (uint8_t*)_data + index;
|
||||
src_ptr < stop_src_ptr; src_ptr += VrmsScaleFactor * _channel_num)
|
||||
{
|
||||
const uint8_t * begin_src_ptr =
|
||||
src_ptr;
|
||||
const uint8_t *const end_src_ptr =
|
||||
src_ptr + VrmsScaleFactor * _channel_num;
|
||||
|
||||
while (begin_src_ptr < end_src_ptr)
|
||||
{
|
||||
tmp = (zero_off - *begin_src_ptr);
|
||||
vrms += tmp * tmp;
|
||||
begin_src_ptr += _channel_num;
|
||||
}
|
||||
vrms = vrms_pre + vrms / _sample_count;
|
||||
vrms_pre = vrms;
|
||||
}
|
||||
vrms = std::pow(vrms, 0.5);
|
||||
|
||||
return vrms;
|
||||
}
|
||||
|
||||
double DsoSnapshot::cal_vmean(int index) const
|
||||
{
|
||||
assert(index >= 0);
|
||||
assert(index < _channel_num);
|
||||
|
||||
// mean value
|
||||
double vmean_pre = 0;
|
||||
double vmean = 0;
|
||||
|
||||
// Iterate through the samples to populate the first level mipmap
|
||||
const uint8_t *const stop_src_ptr = (uint8_t*)_data +
|
||||
_sample_count * _channel_num;
|
||||
for (const uint8_t *src_ptr = (uint8_t*)_data + index;
|
||||
src_ptr < stop_src_ptr; src_ptr += VrmsScaleFactor * _channel_num)
|
||||
{
|
||||
const uint8_t * begin_src_ptr =
|
||||
src_ptr;
|
||||
const uint8_t *const end_src_ptr =
|
||||
src_ptr + VrmsScaleFactor * _channel_num;
|
||||
|
||||
while (begin_src_ptr < end_src_ptr)
|
||||
{
|
||||
vmean += *begin_src_ptr;
|
||||
begin_src_ptr += _channel_num;
|
||||
}
|
||||
vmean = vmean_pre + vmean / _sample_count;
|
||||
vmean_pre = vmean;
|
||||
}
|
||||
|
||||
return vmean;
|
||||
}
|
||||
|
||||
} // namespace data
|
||||
} // namespace pv
|
||||
|
||||
@@ -67,6 +67,8 @@ private:
|
||||
static const float LogEnvelopeScaleFactor;
|
||||
static const uint64_t EnvelopeDataUnit;
|
||||
|
||||
static const int VrmsScaleFactor;
|
||||
|
||||
public:
|
||||
DsoSnapshot(const sr_datafeed_dso &dso, uint64_t _total_sample_len, unsigned int channel_num, bool instant);
|
||||
|
||||
@@ -82,6 +84,9 @@ public:
|
||||
|
||||
void enable_envelope(bool enable);
|
||||
|
||||
double cal_vrms(double zero_off, int index) const;
|
||||
double cal_vmean(int index) const;
|
||||
|
||||
private:
|
||||
void reallocate_envelope(Envelope &l);
|
||||
|
||||
|
||||
84
DSView/pv/dialogs/dsomeasure.cpp
Normal file
84
DSView/pv/dialogs/dsomeasure.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of the DSView project.
|
||||
* DSView 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 "dsomeasure.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QVariant>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
using namespace boost;
|
||||
using namespace std;
|
||||
using namespace pv::view;
|
||||
|
||||
namespace pv {
|
||||
namespace dialogs {
|
||||
|
||||
DsoMeasure::DsoMeasure(QWidget *parent, boost::shared_ptr<DsoSignal> dsoSig) :
|
||||
QDialog(parent),
|
||||
_dsoSig(dsoSig),
|
||||
_layout(this),
|
||||
_button_box(QDialogButtonBox::Ok,
|
||||
Qt::Horizontal, this)
|
||||
{
|
||||
setWindowTitle(tr("DSO Measure Options"));
|
||||
setLayout(&_layout);
|
||||
|
||||
for (int i=DsoSignal::DSO_MS_BEGIN+1; i<DsoSignal::DSO_MS_END; i++) {
|
||||
QCheckBox *checkBox = new QCheckBox(_dsoSig->get_ms_string(i), this);
|
||||
checkBox->setProperty("id", QVariant(i));
|
||||
checkBox->setChecked(dsoSig->get_ms_en(i));
|
||||
_layout.addWidget(checkBox);
|
||||
connect(checkBox, SIGNAL(toggled(bool)), this, SLOT(set_measure(bool)));
|
||||
}
|
||||
|
||||
_layout.addWidget(&_button_box);
|
||||
|
||||
connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(&_button_box, SIGNAL(rejected()), this, SLOT(accept()));
|
||||
}
|
||||
|
||||
void DsoMeasure::set_measure(bool en)
|
||||
{
|
||||
QCheckBox* sc=dynamic_cast<QCheckBox*>(sender());
|
||||
if(sc != NULL) {
|
||||
QVariant id = sc->property("id");
|
||||
_dsoSig->set_ms_en(id.toInt(), sc->isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
void DsoMeasure::accept()
|
||||
{
|
||||
using namespace Qt;
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void DsoMeasure::reject()
|
||||
{
|
||||
accept();
|
||||
}
|
||||
|
||||
} // namespace dialogs
|
||||
} // namespace pv
|
||||
67
DSView/pv/dialogs/dsomeasure.h
Normal file
67
DSView/pv/dialogs/dsomeasure.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of the DSView project.
|
||||
* DSView 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
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DSVIEW_PV_DSOMEASURE_H
|
||||
#define DSVIEW_PV_DSOMEASURE_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <pv/view/dsosignal.h>
|
||||
|
||||
namespace pv {
|
||||
|
||||
namespace view {
|
||||
class DsoSignal;
|
||||
}
|
||||
|
||||
namespace dialogs {
|
||||
|
||||
class DsoMeasure : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DsoMeasure(QWidget *parent, boost::shared_ptr<pv::view::DsoSignal> dsoSig);
|
||||
|
||||
private slots:
|
||||
void set_measure(bool en);
|
||||
|
||||
protected:
|
||||
void accept();
|
||||
void reject();
|
||||
|
||||
private:
|
||||
boost::shared_ptr<pv::view::DsoSignal> _dsoSig;
|
||||
|
||||
QVBoxLayout _layout;
|
||||
QDialogButtonBox _button_box;
|
||||
};
|
||||
|
||||
} // namespace dialogs
|
||||
} // namespace pv
|
||||
|
||||
#endif // DSVIEW_PV_DSOMEASURE_H
|
||||
@@ -127,7 +127,10 @@ DsoSignal::DsoSignal(boost::shared_ptr<pv::device::DevInst> dev_inst,
|
||||
_hover_en(false),
|
||||
_hover_index(0),
|
||||
_hover_point(QPointF(0, 0)),
|
||||
_hover_value(0)
|
||||
_hover_value(0),
|
||||
_ms_gear_hover(false),
|
||||
_ms_show_hover(false),
|
||||
_ms_show(false)
|
||||
{
|
||||
QVector<uint64_t> vValue;
|
||||
QVector<QString> vUnit;
|
||||
@@ -148,31 +151,12 @@ DsoSignal::DsoSignal(boost::shared_ptr<pv::device::DevInst> dev_inst,
|
||||
|
||||
_colour = SignalColours[probe->index % countof(SignalColours)];
|
||||
|
||||
// GVariant* gvar;
|
||||
for (int i = DSO_MS_BEGIN; i < DSO_MS_END; i++)
|
||||
_ms_en[i] = false;
|
||||
_ms_en[DSO_MS_FREQ] = true;
|
||||
_ms_en[DSO_MS_VMAX] = true;
|
||||
_ms_en[DSO_MS_VMIN] = true;
|
||||
|
||||
// gvar = dev_inst->get_config(probe, NULL, SR_CONF_VDIV);
|
||||
// if (gvar != NULL) {
|
||||
// _vDial->set_value(g_variant_get_uint64(gvar));
|
||||
// g_variant_unref(gvar);
|
||||
// } else {
|
||||
// qDebug() << "ERROR: config_get SR_CONF_VDIV failed.";
|
||||
// }
|
||||
|
||||
// gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TIMEBASE);
|
||||
// if (gvar != NULL) {
|
||||
// _hDial->set_value(g_variant_get_uint64(gvar));
|
||||
// g_variant_unref(gvar);
|
||||
// } else {
|
||||
// qDebug() << "ERROR: config_get SR_CONF_TIMEBASE failed.";
|
||||
// }
|
||||
|
||||
// gvar = dev_inst->get_config(probe, NULL, SR_CONF_COUPLING);
|
||||
// if (gvar != NULL) {
|
||||
// _acCoupling = g_variant_get_byte(gvar);
|
||||
// g_variant_unref(gvar);
|
||||
// } else {
|
||||
// qDebug() << "ERROR: config_get SR_CONF_COUPLING failed.";
|
||||
// }
|
||||
update_vDial();
|
||||
update_hDial();
|
||||
update_acCoupling();
|
||||
@@ -191,6 +175,14 @@ void DsoSignal::set_view(pv::view::View *view)
|
||||
{
|
||||
Trace::set_view(view);
|
||||
update_zeroPos();
|
||||
|
||||
const double ms_left = get_view_rect().right() - (MS_RectWidth + MS_RectMargin) * (get_index() + 1);
|
||||
const double ms_top = get_view_rect().top() + 5;
|
||||
for (int i = DSO_MS_BEGIN; i < DSO_MS_END; i++)
|
||||
_ms_rect[i] = QRect(ms_left, ms_top + MS_RectHeight * i, MS_RectWidth, MS_RectHeight);
|
||||
_ms_gear_rect = QRect(ms_left+MS_RectRad, ms_top+MS_RectRad, MS_IconSize, MS_IconSize);
|
||||
_ms_show_rect = QRect(ms_left+MS_RectWidth-MS_RectRad-MS_IconSize, ms_top+MS_RectRad, MS_IconSize, MS_IconSize);
|
||||
|
||||
}
|
||||
|
||||
void DsoSignal::set_scale(float scale)
|
||||
@@ -648,6 +640,59 @@ uint64_t DsoSignal::get_factor()
|
||||
}
|
||||
}
|
||||
|
||||
void DsoSignal::set_ms_show(bool show)
|
||||
{
|
||||
_ms_show = show;
|
||||
}
|
||||
|
||||
bool DsoSignal::get_ms_show() const
|
||||
{
|
||||
return _ms_show;
|
||||
}
|
||||
|
||||
bool DsoSignal::get_ms_show_hover() const
|
||||
{
|
||||
return _ms_show_hover;
|
||||
}
|
||||
|
||||
bool DsoSignal::get_ms_gear_hover() const
|
||||
{
|
||||
return _ms_gear_hover;
|
||||
}
|
||||
|
||||
void DsoSignal::set_ms_en(int index, bool en)
|
||||
{
|
||||
assert(index > DSO_MS_BEGIN);
|
||||
assert(index < DSO_MS_END);
|
||||
|
||||
_ms_en[index] = en;
|
||||
}
|
||||
|
||||
bool DsoSignal::get_ms_en(int index) const
|
||||
{
|
||||
assert(index > DSO_MS_BEGIN);
|
||||
assert(index < DSO_MS_END);
|
||||
|
||||
return _ms_en[index];
|
||||
}
|
||||
|
||||
QString DsoSignal::get_ms_string(int index) const
|
||||
{
|
||||
assert(index > DSO_MS_BEGIN);
|
||||
assert(index < DSO_MS_END);
|
||||
|
||||
switch(index) {
|
||||
case DSO_MS_FREQ: return "Frequency";
|
||||
case DSO_MS_PERD: return "Period";
|
||||
case DSO_MS_VMAX: return "Vmax";
|
||||
case DSO_MS_VMIN: return "Vmin";
|
||||
case DSO_MS_VRMS: return "Vrms";
|
||||
case DSO_MS_VMEA: return "Vmean";
|
||||
case DSO_MS_VP2P: return "Vp-p";
|
||||
default: return "Error: Out of Bound";
|
||||
}
|
||||
}
|
||||
|
||||
void DsoSignal::update_zeroPos()
|
||||
{
|
||||
if (strcmp(_dev_inst->dev_inst()->driver->name, "DSCope") == 0) {
|
||||
@@ -1020,24 +1065,90 @@ void DsoSignal::paint_measure(QPainter &p)
|
||||
const uint32_t count = (index == 0) ? status.ch0_pcnt : status.ch1_pcnt;
|
||||
double value_max = (_zero_off - _min) * _scale * _vDial->get_value() * _vDial->get_factor() * DS_CONF_DSO_VDIVS / get_view_rect().height();
|
||||
double value_min = (_zero_off - _max) * _scale * _vDial->get_value() * _vDial->get_factor() * DS_CONF_DSO_VDIVS / get_view_rect().height();
|
||||
double value_p2p = value_max - value_min;
|
||||
_period = (count == 0) ? period * 10.0 : period * 10.0 / count;
|
||||
const int channel_count = _view->session().get_ch_num(SR_CHANNEL_DSO);
|
||||
uint64_t sample_rate = _dev_inst->get_sample_rate();
|
||||
_period = _period * 200.0 / (channel_count * sample_rate * 1.0 / SR_MHZ(1));
|
||||
QString max_string = abs(value_max) > 1000 ? QString::number(value_max/1000.0, 'f', 2) + "V" : QString::number(value_max, 'f', 2) + "mV";
|
||||
QString min_string = abs(value_min) > 1000 ? QString::number(value_min/1000.0, 'f', 2) + "V" : QString::number(value_min, 'f', 2) + "mV";
|
||||
QString period_string = abs(_period) > 1000000000 ? QString::number(_period/1000000000, 'f', 2) + "S" :
|
||||
_ms_string[DSO_MS_VMAX] = "Vmax: " + (abs(value_max) > 1000 ? QString::number(value_max/1000.0, 'f', 2) + "V" : QString::number(value_max, 'f', 2) + "mV");
|
||||
_ms_string[DSO_MS_VMIN] = "Vmin: " + (abs(value_min) > 1000 ? QString::number(value_min/1000.0, 'f', 2) + "V" : QString::number(value_min, 'f', 2) + "mV");
|
||||
_ms_string[DSO_MS_PERD] = "Perd: " + (abs(_period) > 1000000000 ? QString::number(_period/1000000000, 'f', 2) + "S" :
|
||||
abs(_period) > 1000000 ? QString::number(_period/1000000, 'f', 2) + "mS" :
|
||||
abs(_period) > 1000 ? QString::number(_period/1000, 'f', 2) + "uS" : QString::number(_period, 'f', 2) + "nS";
|
||||
QString freq_string = abs(_period) > 1000000 ? QString::number(1000000000/_period, 'f', 2) + "Hz" :
|
||||
abs(_period) > 1000 ? QString::number(1000000/_period, 'f', 2) + "kHz" : QString::number(1000/_period, 'f', 2) + "MHz";
|
||||
abs(_period) > 1000 ? QString::number(_period/1000, 'f', 2) + "uS" : QString::number(_period, 'f', 2) + "nS");
|
||||
_ms_string[DSO_MS_FREQ] = "Freq: " + (abs(_period) > 1000000 ? QString::number(1000000000/_period, 'f', 2) + "Hz" :
|
||||
abs(_period) > 1000 ? QString::number(1000000/_period, 'f', 2) + "kHz" : QString::number(1000/_period, 'f', 2) + "MHz");
|
||||
_ms_string[DSO_MS_VP2P] = "Vp-p: " + (abs(value_p2p) > 1000 ? QString::number(value_p2p/1000.0, 'f', 2) + "V" : QString::number(value_p2p, 'f', 2) + "mV");
|
||||
|
||||
if (_ms_show && _ms_en[DSO_MS_VRMS]) {
|
||||
const deque< boost::shared_ptr<pv::data::DsoSnapshot> > &snapshots =
|
||||
_data->get_snapshots();
|
||||
if (!snapshots.empty()) {
|
||||
const boost::shared_ptr<pv::data::DsoSnapshot> &snapshot =
|
||||
snapshots.front();
|
||||
const double vrms = snapshot->cal_vrms(_zero_off, get_index());
|
||||
const double value_vrms = vrms * _scale * _vDial->get_value() * _vDial->get_factor() * DS_CONF_DSO_VDIVS / get_view_rect().height();
|
||||
_ms_string[DSO_MS_VRMS] = "Vrms: " + (abs(value_vrms) > 1000 ? QString::number(value_vrms/1000.0, 'f', 2) + "V" : QString::number(value_vrms, 'f', 2) + "mV");
|
||||
}
|
||||
}
|
||||
|
||||
if (_ms_show && _ms_en[DSO_MS_VMEA]) {
|
||||
const deque< boost::shared_ptr<pv::data::DsoSnapshot> > &snapshots =
|
||||
_data->get_snapshots();
|
||||
if (!snapshots.empty()) {
|
||||
const boost::shared_ptr<pv::data::DsoSnapshot> &snapshot =
|
||||
snapshots.front();
|
||||
const double vmean = snapshot->cal_vmean(get_index());
|
||||
const double value_vmean = (_zero_off - vmean) * _scale * _vDial->get_value() * _vDial->get_factor() * DS_CONF_DSO_VDIVS / get_view_rect().height();
|
||||
_ms_string[DSO_MS_VMEA] = "Vmean: " + (abs(value_vmean) > 1000 ? QString::number(value_vmean/1000.0, 'f', 2) + "V" : QString::number(value_vmean, 'f', 2) + "mV");
|
||||
}
|
||||
}
|
||||
|
||||
QColor measure_colour = _colour;
|
||||
measure_colour.setAlpha(180);
|
||||
p.setPen(measure_colour);
|
||||
p.drawText(QRectF(0, 100*index + UpMargin, get_view_rect().width()*0.9, 20), Qt::AlignRight | Qt::AlignVCenter, tr("Max: ")+max_string+" ");
|
||||
p.drawText(QRectF(0, 100*index + UpMargin + 20, get_view_rect().width()*0.9, 20), Qt::AlignRight | Qt::AlignVCenter, tr("Min: ")+min_string+" ");
|
||||
p.drawText(QRectF(0, 100*index + UpMargin + 40, get_view_rect().width()*0.9, 20), Qt::AlignRight | Qt::AlignVCenter, tr("Period: ")+period_string+" ");
|
||||
p.drawText(QRectF(0, 100*index + UpMargin + 60, get_view_rect().width()*0.9, 20), Qt::AlignRight | Qt::AlignVCenter, tr("Frequency: ")+freq_string+" ");
|
||||
QColor back_colour = Qt::white;
|
||||
back_colour.setAlpha(100);
|
||||
//p.setPen(measure_colour);
|
||||
//p.drawText(QRectF(0, 100*index + UpMargin, get_view_rect().width()*0.9, 20), Qt::AlignRight | Qt::AlignVCenter, tr("Max: ")+max_string+" ");
|
||||
//p.drawText(QRectF(0, 100*index + UpMargin + 20, get_view_rect().width()*0.9, 20), Qt::AlignRight | Qt::AlignVCenter, tr("Min: ")+min_string+" ");
|
||||
//p.drawText(QRectF(0, 100*index + UpMargin + 40, get_view_rect().width()*0.9, 20), Qt::AlignRight | Qt::AlignVCenter, tr("Period: ")+period_string+" ");
|
||||
//p.drawText(QRectF(0, 100*index + UpMargin + 60, get_view_rect().width()*0.9, 20), Qt::AlignRight | Qt::AlignVCenter, tr("Frequency: ")+freq_string+" ");
|
||||
|
||||
bool antialiasing = p.Antialiasing;
|
||||
p.setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(measure_colour);
|
||||
p.drawRoundedRect(_ms_rect[DSO_MS_BEGIN], MS_RectRad, MS_RectRad);
|
||||
const QPixmap gear_pix(":/icons/settings.png");
|
||||
const QPixmap show_pix(_ms_show ? ":/icons/shown.png" : ":/icons/hidden.png");
|
||||
if (_ms_gear_hover) {
|
||||
p.setBrush(back_colour);
|
||||
p.drawRoundedRect(_ms_gear_rect, MS_RectRad, MS_RectRad);
|
||||
} else if (_ms_show_hover) {
|
||||
p.setBrush(back_colour);
|
||||
p.drawRoundedRect(_ms_show_rect, MS_RectRad, MS_RectRad);
|
||||
}
|
||||
p.drawPixmap(_ms_gear_rect, gear_pix);
|
||||
p.drawPixmap(_ms_show_rect, show_pix);
|
||||
p.setPen(Qt::white);
|
||||
p.drawText(_ms_rect[DSO_MS_BEGIN], Qt::AlignCenter | Qt::AlignVCenter, "CH"+QString::number(index));
|
||||
|
||||
if (_ms_show) {
|
||||
p.setBrush(back_colour);
|
||||
int j = DSO_MS_BEGIN+1;
|
||||
for (int i=DSO_MS_BEGIN+1; i<DSO_MS_END; i++) {
|
||||
if (_ms_en[i]) {
|
||||
p.setPen(_colour);
|
||||
p.drawText(_ms_rect[j], Qt::AlignLeft | Qt::AlignVCenter, _ms_string[i]);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.drawRoundedRect(_ms_rect[j], MS_RectRad, MS_RectRad);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
p.setRenderHint(QPainter::Antialiasing, antialiasing);
|
||||
|
||||
if (_autoV) {
|
||||
const uint8_t vscale = abs(_max - _min);
|
||||
@@ -1092,6 +1203,19 @@ void DsoSignal::auto_set()
|
||||
|
||||
bool DsoSignal::measure(const QPointF &p)
|
||||
{
|
||||
if (_ms_gear_rect.contains(QPoint(p.x(), p.y()))) {
|
||||
_ms_gear_hover = true;
|
||||
return false;
|
||||
} else {
|
||||
_ms_gear_hover = false;
|
||||
}
|
||||
if (_ms_show_rect.contains(QPoint(p.x(), p.y()))) {
|
||||
_ms_show_hover = true;
|
||||
return false;
|
||||
} else {
|
||||
_ms_show_hover = false;
|
||||
}
|
||||
|
||||
_hover_en = false;
|
||||
if (!enabled())
|
||||
return false;
|
||||
|
||||
@@ -62,6 +62,26 @@ private:
|
||||
static const int DownMargin;
|
||||
static const int RightMargin;
|
||||
|
||||
public:
|
||||
enum DSO_MEASURE_TYPE {
|
||||
DSO_MS_BEGIN = 0,
|
||||
DSO_MS_FREQ,
|
||||
DSO_MS_PERD,
|
||||
DSO_MS_VMAX,
|
||||
DSO_MS_VMIN,
|
||||
DSO_MS_VRMS,
|
||||
DSO_MS_VMEA,
|
||||
DSO_MS_VP2P,
|
||||
DSO_MS_END,
|
||||
};
|
||||
|
||||
private:
|
||||
static const uint16_t MS_RectRad = 5;
|
||||
static const uint16_t MS_IconSize = 16;
|
||||
static const uint16_t MS_RectWidth = 120;
|
||||
static const uint16_t MS_RectMargin = 10;
|
||||
static const uint16_t MS_RectHeight = 25;
|
||||
|
||||
public:
|
||||
DsoSignal(boost::shared_ptr<pv::device::DevInst> dev_inst,
|
||||
boost::shared_ptr<pv::data::Dso> data,
|
||||
@@ -158,6 +178,14 @@ public:
|
||||
|
||||
QRectF get_trig_rect(int left, int right) const;
|
||||
|
||||
void set_ms_show(bool show);
|
||||
bool get_ms_show() const;
|
||||
bool get_ms_show_hover() const;
|
||||
bool get_ms_gear_hover() const;
|
||||
void set_ms_en(int index, bool en);
|
||||
bool get_ms_en(int index) const;
|
||||
QString get_ms_string(int index) const;
|
||||
|
||||
protected:
|
||||
void paint_type_options(QPainter &p, int right, bool hover, int action);
|
||||
|
||||
@@ -200,6 +228,15 @@ private:
|
||||
uint64_t _hover_index;
|
||||
QPointF _hover_point;
|
||||
double _hover_value;
|
||||
|
||||
QRect _ms_gear_rect;
|
||||
QRect _ms_show_rect;
|
||||
QRect _ms_rect[DSO_MS_END-DSO_MS_BEGIN];
|
||||
bool _ms_gear_hover;
|
||||
bool _ms_show_hover;
|
||||
bool _ms_show;
|
||||
bool _ms_en[DSO_MS_END-DSO_MS_BEGIN];
|
||||
QString _ms_string[DSO_MS_END-DSO_MS_BEGIN];
|
||||
};
|
||||
|
||||
} // namespace view
|
||||
|
||||
@@ -32,10 +32,12 @@
|
||||
#include "../data/logic.h"
|
||||
#include "../data/logicsnapshot.h"
|
||||
#include "../sigsession.h"
|
||||
#include <../dialogs/dsomeasure.h>
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QStyleOption>
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
@@ -396,10 +398,18 @@ void Viewport::mousePressEvent(QMouseEvent *event)
|
||||
if (!s->enabled())
|
||||
continue;
|
||||
boost::shared_ptr<DsoSignal> dsoSig;
|
||||
if ((dsoSig = dynamic_pointer_cast<DsoSignal>(s)) &&
|
||||
dsoSig->get_trig_rect(0, _view.get_view_width()).contains(_mouse_point)) {
|
||||
_drag_sig = s;
|
||||
break;
|
||||
if (dsoSig = dynamic_pointer_cast<DsoSignal>(s)) {
|
||||
if (dsoSig->get_trig_rect(0, _view.get_view_width()).contains(_mouse_point)) {
|
||||
_drag_sig = s;
|
||||
break;
|
||||
} else if (dsoSig->get_ms_show_hover()) {
|
||||
dsoSig->set_ms_show(!dsoSig->get_ms_show());
|
||||
break;
|
||||
} else if (dsoSig->get_ms_gear_hover()) {
|
||||
pv::dialogs::DsoMeasure dsoMeasureDialog(this, dsoSig);
|
||||
dsoMeasureDialog.exec();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,7 +521,8 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
|
||||
if(_drag_sig)
|
||||
_drag_sig.reset();
|
||||
|
||||
if (_mouse_down_point.x() == event->pos().x() &&
|
||||
if (_view.session().get_device()->dev_inst()->mode == LOGIC &&
|
||||
_mouse_down_point.x() == event->pos().x() &&
|
||||
event->button() & Qt::LeftButton) {
|
||||
if (_measure_type == LOGIC_EDGE) {
|
||||
_measure_type = NO_MEASURE;
|
||||
@@ -524,7 +535,8 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
if (_measure_type != LOGIC_EDGE) {
|
||||
if (_view.session().get_device()->dev_inst()->mode == LOGIC &&
|
||||
_measure_type != LOGIC_EDGE) {
|
||||
const double strength = _drag_strength*DragTimerInterval*1.0/_time.elapsed();
|
||||
if (abs(_drag_strength) < MinorDragOffsetUp && abs(strength) > MinorDragRateUp) {
|
||||
_drag_strength = _drag_strength;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace widgets {
|
||||
DecoderGroupBox::DecoderGroupBox(QString title, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
_layout(new QGridLayout),
|
||||
_show_hide_button(QIcon(":/icons/decoder-shown.png"), QString(), this)
|
||||
_show_hide_button(QIcon(":/icons/shown.png"), QString(), this)
|
||||
{
|
||||
_layout->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(_layout);
|
||||
@@ -61,8 +61,8 @@ void DecoderGroupBox::add_layout(QLayout *layout)
|
||||
void DecoderGroupBox::set_decoder_visible(bool visible)
|
||||
{
|
||||
_show_hide_button.setIcon(QIcon(visible ?
|
||||
":/icons/decoder-shown.png" :
|
||||
":/icons/decoder-hidden.png"));
|
||||
":/icons/shown.png" :
|
||||
":/icons/hidden.png"));
|
||||
}
|
||||
|
||||
} // widgets
|
||||
|
||||
Reference in New Issue
Block a user