Commit 51cb900c authored by DreamSourceLab's avatar DreamSourceLab

Improve measure @ OSC mode; add Vrms and Vmean

parent c1555897
......@@ -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>
......@@ -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);
......
/*
* 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
/*
* 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
This diff is collapsed.
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment