diff --git a/DSView/dsapplication.cpp b/DSView/dsapplication.cpp index 1a8df330..6ac6f80d 100644 --- a/DSView/dsapplication.cpp +++ b/DSView/dsapplication.cpp @@ -2,7 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2016 DreamSourceLab + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/dsapplication.h b/DSView/dsapplication.h index 7e0b3922..7e804745 100644 --- a/DSView/dsapplication.h +++ b/DSView/dsapplication.h @@ -2,7 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2016 DreamSourceLab + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/extdef.h b/DSView/extdef.h index 192bb8f3..7fc608fe 100644 --- a/DSView/extdef.h +++ b/DSView/extdef.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/analog.cpp b/DSView/pv/data/analog.cpp index e5c85b39..790c12a5 100644 --- a/DSView/pv/data/analog.cpp +++ b/DSView/pv/data/analog.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/analog.h b/DSView/pv/data/analog.h index b53aff6e..dc2a8571 100644 --- a/DSView/pv/data/analog.h +++ b/DSView/pv/data/analog.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/analogsnapshot.cpp b/DSView/pv/data/analogsnapshot.cpp index 66bf5833..4b8c1719 100644 --- a/DSView/pv/data/analogsnapshot.cpp +++ b/DSView/pv/data/analogsnapshot.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/analogsnapshot.h b/DSView/pv/data/analogsnapshot.h index 7df1e111..b7a8813d 100644 --- a/DSView/pv/data/analogsnapshot.h +++ b/DSView/pv/data/analogsnapshot.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/decode/annotation.cpp b/DSView/pv/data/decode/annotation.cpp index 652dc1b9..1cf20090 100644 --- a/DSView/pv/data/decode/annotation.cpp +++ b/DSView/pv/data/decode/annotation.cpp @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/data/decode/annotation.h b/DSView/pv/data/decode/annotation.h index 9ed39bf9..cba04c99 100644 --- a/DSView/pv/data/decode/annotation.h +++ b/DSView/pv/data/decode/annotation.h @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2013 Joel Holdsworth + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/data/decode/decoder.cpp b/DSView/pv/data/decode/decoder.cpp index 5c27c085..8d54d7f6 100644 --- a/DSView/pv/data/decode/decoder.cpp +++ b/DSView/pv/data/decode/decoder.cpp @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2013 Joel Holdsworth + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/data/decode/decoder.h b/DSView/pv/data/decode/decoder.h index 607bc0b8..40fde4e6 100644 --- a/DSView/pv/data/decode/decoder.h +++ b/DSView/pv/data/decode/decoder.h @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2013 Joel Holdsworth + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/data/decode/rowdata.cpp b/DSView/pv/data/decode/rowdata.cpp index 1fbd31a5..8d3e41e0 100644 --- a/DSView/pv/data/decode/rowdata.cpp +++ b/DSView/pv/data/decode/rowdata.cpp @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2014 Joel Holdsworth + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/data/decode/rowdata.h b/DSView/pv/data/decode/rowdata.h index 11b88420..e2a84f31 100644 --- a/DSView/pv/data/decode/rowdata.h +++ b/DSView/pv/data/decode/rowdata.h @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2014 Joel Holdsworth + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/data/decodermodel.cpp b/DSView/pv/data/decodermodel.cpp index 9e2c071f..078111a4 100644 --- a/DSView/pv/data/decodermodel.cpp +++ b/DSView/pv/data/decodermodel.cpp @@ -1,7 +1,7 @@ /* * This file is part of the DSView project. * - * Copyright (C) 2016 Andy Deng + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/data/decodermodel.h b/DSView/pv/data/decodermodel.h index a0eac14b..4616e250 100644 --- a/DSView/pv/data/decodermodel.h +++ b/DSView/pv/data/decodermodel.h @@ -1,7 +1,7 @@ /* * This file is part of the DSView project. * - * Copyright (C) 2016 Andy Deng + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index 7615e0e2..c480a006 100644 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/data/decoderstack.h b/DSView/pv/data/decoderstack.h index 143ad01d..7516c907 100644 --- a/DSView/pv/data/decoderstack.h +++ b/DSView/pv/data/decoderstack.h @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/data/dso.cpp b/DSView/pv/data/dso.cpp index fa4cf4a5..fe3ce699 100644 --- a/DSView/pv/data/dso.cpp +++ b/DSView/pv/data/dso.cpp @@ -2,7 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/dso.h b/DSView/pv/data/dso.h index be987821..0e724ed6 100644 --- a/DSView/pv/data/dso.h +++ b/DSView/pv/data/dso.h @@ -2,7 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/dsosnapshot.cpp b/DSView/pv/data/dsosnapshot.cpp index 7fdd78f8..b4f93c91 100644 --- a/DSView/pv/data/dsosnapshot.cpp +++ b/DSView/pv/data/dsosnapshot.cpp @@ -2,7 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/dsosnapshot.h b/DSView/pv/data/dsosnapshot.h index fbbdf849..e1488374 100644 --- a/DSView/pv/data/dsosnapshot.h +++ b/DSView/pv/data/dsosnapshot.h @@ -2,7 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/group.cpp b/DSView/pv/data/group.cpp index e0aab57f..3d086e08 100644 --- a/DSView/pv/data/group.cpp +++ b/DSView/pv/data/group.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/group.h b/DSView/pv/data/group.h index 25f9fb29..f166bf94 100644 --- a/DSView/pv/data/group.h +++ b/DSView/pv/data/group.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/groupsnapshot.cpp b/DSView/pv/data/groupsnapshot.cpp index 69a18f1a..6f0026dd 100644 --- a/DSView/pv/data/groupsnapshot.cpp +++ b/DSView/pv/data/groupsnapshot.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/groupsnapshot.h b/DSView/pv/data/groupsnapshot.h index ed475b3a..6ad65522 100644 --- a/DSView/pv/data/groupsnapshot.h +++ b/DSView/pv/data/groupsnapshot.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/logic.cpp b/DSView/pv/data/logic.cpp index a249eda8..f2a7cee4 100644 --- a/DSView/pv/data/logic.cpp +++ b/DSView/pv/data/logic.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/logic.h b/DSView/pv/data/logic.h index c7a97158..fe815264 100644 --- a/DSView/pv/data/logic.h +++ b/DSView/pv/data/logic.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/logicsnapshot.cpp b/DSView/pv/data/logicsnapshot.cpp index edea2467..17da83c7 100644 --- a/DSView/pv/data/logicsnapshot.cpp +++ b/DSView/pv/data/logicsnapshot.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/logicsnapshot.h b/DSView/pv/data/logicsnapshot.h index ecaab06b..475d8bf0 100644 --- a/DSView/pv/data/logicsnapshot.h +++ b/DSView/pv/data/logicsnapshot.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/mathstack.cpp b/DSView/pv/data/mathstack.cpp index 6494351c..13aa18d6 100644 --- a/DSView/pv/data/mathstack.cpp +++ b/DSView/pv/data/mathstack.cpp @@ -1,7 +1,7 @@ /* * This file is part of the PulseView project. * - * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/data/mathstack.h b/DSView/pv/data/mathstack.h index dbbe21bc..6616ac44 100644 --- a/DSView/pv/data/mathstack.h +++ b/DSView/pv/data/mathstack.h @@ -1,7 +1,7 @@ /* * This file is part of the PulseView project. * - * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/data/signaldata.cpp b/DSView/pv/data/signaldata.cpp index b97e026a..afb7f240 100644 --- a/DSView/pv/data/signaldata.cpp +++ b/DSView/pv/data/signaldata.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/signaldata.h b/DSView/pv/data/signaldata.h index 86279376..464215da 100644 --- a/DSView/pv/data/signaldata.h +++ b/DSView/pv/data/signaldata.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/snapshot.cpp b/DSView/pv/data/snapshot.cpp index c68d03ae..37eb9acf 100644 --- a/DSView/pv/data/snapshot.cpp +++ b/DSView/pv/data/snapshot.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/data/snapshot.h b/DSView/pv/data/snapshot.h index 9f2be22c..ca0e8831 100644 --- a/DSView/pv/data/snapshot.h +++ b/DSView/pv/data/snapshot.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/devicemanager.cpp b/DSView/pv/devicemanager.cpp index 066af640..474db42b 100644 --- a/DSView/pv/devicemanager.cpp +++ b/DSView/pv/devicemanager.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/devicemanager.h b/DSView/pv/devicemanager.h index fde8ad1e..3f0b313a 100644 --- a/DSView/pv/devicemanager.h +++ b/DSView/pv/devicemanager.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/about.cpp b/DSView/pv/dialogs/about.cpp index 6809fd70..b402cb52 100644 --- a/DSView/pv/dialogs/about.cpp +++ b/DSView/pv/dialogs/about.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/about.h b/DSView/pv/dialogs/about.h index 6d140472..d31b7607 100644 --- a/DSView/pv/dialogs/about.h +++ b/DSView/pv/dialogs/about.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/calibration.cpp b/DSView/pv/dialogs/calibration.cpp new file mode 100755 index 00000000..fe2572aa --- /dev/null +++ b/DSView/pv/dialogs/calibration.cpp @@ -0,0 +1,302 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2016 DreamSourceLab + * + * 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 "calibration.h" + +#include + +#include +#include +#include +#include +#include + +#include "libsigrok4DSL/libsigrok.h" +#include "../view/trace.h" + +using namespace boost; +using namespace std; + +namespace pv { +namespace dialogs { + +const QString Calibration::VGAIN = tr(" VGAIN"); +const QString Calibration::VOFF = tr(" VOFF"); + +Calibration::Calibration(QWidget *parent) : + QDialog(parent) +{ + this->setFixedSize(400, 200); + this->setWindowOpacity(0.7); + this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + this->setModal(false); + + _dev_inst = NULL; + _save_btn = new QPushButton(tr("Save"), this); + _reset_btn = new QPushButton(tr("Reset"), this); + _exit_btn = new QPushButton(tr("Exit"), this); + + _flayout = new QFormLayout(); + QGridLayout *glayout = new QGridLayout(this); + glayout->addLayout(_flayout, 0, 0, 1, 5); + glayout->addWidget(_save_btn, 1, 0); + glayout->addWidget(new QWidget(this), 1, 1); + glayout->setColumnStretch(1, 1); + glayout->addWidget(_reset_btn, 1, 2); + glayout->addWidget(new QWidget(this), 1, 3); + glayout->setColumnStretch(3, 1); + glayout->addWidget(_exit_btn, 1, 4); + setLayout(glayout); + + connect(_save_btn, SIGNAL(clicked()), this, SLOT(on_save())); + connect(_reset_btn, SIGNAL(clicked()), this, SLOT(on_reset())); + connect(_exit_btn, SIGNAL(clicked()), this, SLOT(reject())); +} + +void Calibration::set_device(boost::shared_ptr dev_inst) +{ + assert(dev_inst); + _dev_inst = dev_inst; + + for(std::list::const_iterator i = _slider_list.begin(); + i != _slider_list.end(); i++) { + (*i)->setParent(NULL); + _flayout->removeWidget((*i)); + delete (*i); + } + _slider_list.clear(); + for(std::list::const_iterator i = _label_list.begin(); + i != _label_list.end(); i++) { + (*i)->setParent(NULL); + _flayout->removeWidget((*i)); + delete (*i); + } + _label_list.clear(); + + for (const GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { + sr_channel *const probe = (sr_channel*)l->data; + assert(probe); + + uint64_t vgain, vgain_default; + uint16_t vgain_range; + GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN); + if (gvar != NULL) { + vgain = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + } + gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN_DEFAULT); + if (gvar != NULL) { + vgain_default = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + } + gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN_RANGE); + if (gvar != NULL) { + vgain_range = g_variant_get_uint16(gvar); + g_variant_unref(gvar); + } + + QSlider *gain_slider = new QSlider(Qt::Horizontal, this); + gain_slider->setRange(-vgain_range/2, vgain_range/2); + gain_slider->setValue(vgain - vgain_default); + gain_slider->setObjectName(VGAIN+probe->index); + QString gain_string = "Channel" + QString::number(probe->index) + VGAIN; + QLabel *gain_label = new QLabel(gain_string, this); + _flayout->addRow(gain_label, gain_slider); + _slider_list.push_back(gain_slider); + _label_list.push_back(gain_label); + + uint64_t voff, voff_default; + uint16_t voff_range; + gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VOFF); + if (gvar != NULL) { + voff = g_variant_get_uint16(gvar); + g_variant_unref(gvar); + } + gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VOFF_DEFAULT); + if (gvar != NULL) { + voff_default = g_variant_get_uint16(gvar); + g_variant_unref(gvar); + } + gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VOFF_RANGE); + if (gvar != NULL) { + voff_range = g_variant_get_uint16(gvar); + g_variant_unref(gvar); + } + QSlider *off_slider = new QSlider(Qt::Horizontal, this); + off_slider->setRange(0, voff_range); + off_slider->setValue(voff); + off_slider->setObjectName(VOFF+probe->index); + QString off_string = "Channel" + QString::number(probe->index) + VOFF; + QLabel *off_label = new QLabel(off_string, this); + _flayout->addRow(off_label, off_slider); + _slider_list.push_back(off_slider); + _label_list.push_back(off_label); + + connect(gain_slider, SIGNAL(valueChanged(int)), this, SLOT(set_value(int))); + connect(off_slider, SIGNAL(valueChanged(int)), this, SLOT(set_value(int))); + } + + update(); +} + +void Calibration::accept() +{ + using namespace Qt; + _dev_inst->set_config(NULL, NULL, SR_CONF_CALI, g_variant_new_boolean(false)); + QDialog::accept(); +} + +void Calibration::reject() +{ + using namespace Qt; + _dev_inst->set_config(NULL, NULL, SR_CONF_CALI, g_variant_new_boolean(false)); + QDialog::reject(); +} + +void Calibration::set_value(int value) +{ + QSlider* sc = dynamic_cast(sender()); + + for (const GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { + sr_channel *const probe = (sr_channel*)l->data; + assert(probe); + if (sc->objectName() == VGAIN+probe->index) { + uint64_t vgain_default; + GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN_DEFAULT); + if (gvar != NULL) { + vgain_default = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + _dev_inst->set_config(probe, NULL, SR_CONF_VGAIN, + g_variant_new_uint64(value+vgain_default)); + } + break; + } else if (sc->objectName() == VOFF+probe->index) { + _dev_inst->set_config(probe, NULL, SR_CONF_VOFF, + g_variant_new_uint16(value)); + break; + } + } +} + +void Calibration::on_save() +{ + this->hide(); + QFuture future; + future = QtConcurrent::run([&]{ + QTime dieTime = QTime::currentTime().addSecs(1); + _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_SET, + g_variant_new_boolean(true)); + while( QTime::currentTime() < dieTime ); + }); + Qt::WindowFlags flags = Qt::CustomizeWindowHint; + QProgressDialog dlg(tr("Save Calibration Result... It can take a while."), + tr("Cancel"),0,0,this,flags); + dlg.setWindowModality(Qt::WindowModal); + dlg.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); + dlg.setCancelButton(NULL); + + QFutureWatcher watcher; + connect(&watcher,SIGNAL(finished()),&dlg,SLOT(cancel())); + watcher.setFuture(future); + + dlg.exec(); + this->show(); +} + +void Calibration::on_reset() +{ + this->hide(); + QFuture future; + future = QtConcurrent::run([&]{ + QTime dieTime = QTime::currentTime().addSecs(1); + _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_LOAD, + g_variant_new_boolean(true)); + reload_value(); + while( QTime::currentTime() < dieTime ); + }); + Qt::WindowFlags flags = Qt::CustomizeWindowHint; + QProgressDialog dlg(tr("Reset Calibration Result... It can take a while."), + tr("Cancel"),0,0,this,flags); + dlg.setWindowModality(Qt::WindowModal); + dlg.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); + dlg.setCancelButton(NULL); + + QFutureWatcher watcher; + connect(&watcher,SIGNAL(finished()),&dlg,SLOT(cancel())); + watcher.setFuture(future); + + dlg.exec(); + this->show(); +} + +void Calibration::reload_value() +{ + for (const GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { + sr_channel *const probe = (sr_channel*)l->data; + assert(probe); + + uint64_t vgain, vgain_default; + uint16_t vgain_range; + GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN); + if (gvar != NULL) { + vgain = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + } + gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN_DEFAULT); + if (gvar != NULL) { + vgain_default = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + } + gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VGAIN_RANGE); + if (gvar != NULL) { + vgain_range = g_variant_get_uint16(gvar); + g_variant_unref(gvar); + } + + uint64_t voff; + uint16_t voff_range; + gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VOFF); + if (gvar != NULL) { + voff = g_variant_get_uint16(gvar); + g_variant_unref(gvar); + } + gvar = _dev_inst->get_config(probe, NULL, SR_CONF_VOFF_RANGE); + if (gvar != NULL) { + voff_range = g_variant_get_uint16(gvar); + g_variant_unref(gvar); + } + + for(std::list::iterator i = _slider_list.begin(); + i != _slider_list.end(); i++) { + if ((*i)->objectName() == VGAIN+probe->index) { + (*i)->setRange(-vgain_range/2, vgain_range/2); + (*i)->setValue(vgain - vgain_default); + } else if ((*i)->objectName() == VOFF+probe->index) { + (*i)->setRange(0, voff_range); + (*i)->setValue(voff); + } + } + } +} + +} // namespace dialogs +} // namespace pv diff --git a/DSView/pv/dialogs/calibration.h b/DSView/pv/dialogs/calibration.h new file mode 100755 index 00000000..3cc49827 --- /dev/null +++ b/DSView/pv/dialogs/calibration.h @@ -0,0 +1,77 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2016 DreamSourceLab + * + * 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_CALIBRATION_H +#define DSVIEW_PV_CALIBRATION_H + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace pv { +namespace dialogs { + +class Calibration : public QDialog +{ + Q_OBJECT + +private: + static const QString VGAIN; + static const QString VOFF; + +public: + Calibration(QWidget *parent); + + void set_device(boost::shared_ptr dev_inst); +protected: + void accept(); + void reject(); + +private slots: + void set_value(int value); + void on_save(); + void on_reset(); + void reload_value(); + +private: + boost::shared_ptr _dev_inst; + + QPushButton *_save_btn; + QPushButton *_reset_btn; + QPushButton *_exit_btn; + QFormLayout *_flayout; + std::list _slider_list; + std::list _label_list; +}; + +} // namespace dialogs +} // namespace pv + +#endif // DSVIEW_PV_CALIBRATION_H diff --git a/DSView/pv/dialogs/deviceoptions.cpp b/DSView/pv/dialogs/deviceoptions.cpp index f6a7874e..b2c8db05 100644 --- a/DSView/pv/dialogs/deviceoptions.cpp +++ b/DSView/pv/dialogs/deviceoptions.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -62,6 +62,10 @@ DeviceOptions::DeviceOptions(QWidget *parent, boost::shared_ptrset_config(NULL, NULL, SR_CONF_CALI, g_variant_new_boolean(true)); +} + void DeviceOptions::mode_check() { bool test; diff --git a/DSView/pv/dialogs/deviceoptions.h b/DSView/pv/dialogs/deviceoptions.h index e8cc4ce7..e1c3c6a3 100644 --- a/DSView/pv/dialogs/deviceoptions.h +++ b/DSView/pv/dialogs/deviceoptions.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -71,6 +71,7 @@ private slots: void zero_adj(); void mode_check(); void channel_check(); + void on_calibration(); private: boost::shared_ptr _dev_inst; @@ -85,6 +86,7 @@ private: QVBoxLayout _props_box_layout; QPushButton *_config_button; + QPushButton *_cali_button; QDialogButtonBox _button_box; QTimer _mode_check; diff --git a/DSView/pv/dialogs/dsomeasure.cpp b/DSView/pv/dialogs/dsomeasure.cpp index 9bb36909..6f5921fd 100644 --- a/DSView/pv/dialogs/dsomeasure.cpp +++ b/DSView/pv/dialogs/dsomeasure.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2015 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/dsomeasure.h b/DSView/pv/dialogs/dsomeasure.h index 05a1ba1a..178b0732 100644 --- a/DSView/pv/dialogs/dsomeasure.h +++ b/DSView/pv/dialogs/dsomeasure.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2015 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/fftoptions.cpp b/DSView/pv/dialogs/fftoptions.cpp index b73ac46e..ed7280b8 100644 --- a/DSView/pv/dialogs/fftoptions.cpp +++ b/DSView/pv/dialogs/fftoptions.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/fftoptions.h b/DSView/pv/dialogs/fftoptions.h index 534ef3e0..2ef9a8e9 100644 --- a/DSView/pv/dialogs/fftoptions.h +++ b/DSView/pv/dialogs/fftoptions.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/protocolexp.cpp b/DSView/pv/dialogs/protocolexp.cpp index c3baf6bb..ab79796b 100644 --- a/DSView/pv/dialogs/protocolexp.cpp +++ b/DSView/pv/dialogs/protocolexp.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/protocolexp.h b/DSView/pv/dialogs/protocolexp.h index c793a75c..0323082d 100644 --- a/DSView/pv/dialogs/protocolexp.h +++ b/DSView/pv/dialogs/protocolexp.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/protocollist.cpp b/DSView/pv/dialogs/protocollist.cpp index 6f6e090c..eb605476 100644 --- a/DSView/pv/dialogs/protocollist.cpp +++ b/DSView/pv/dialogs/protocollist.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/protocollist.h b/DSView/pv/dialogs/protocollist.h index 6d315322..0f116f7a 100644 --- a/DSView/pv/dialogs/protocollist.h +++ b/DSView/pv/dialogs/protocollist.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/search.cpp b/DSView/pv/dialogs/search.cpp index aeaeb464..3f177f60 100644 --- a/DSView/pv/dialogs/search.cpp +++ b/DSView/pv/dialogs/search.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/search.h b/DSView/pv/dialogs/search.h index 79c7533a..9efd762d 100644 --- a/DSView/pv/dialogs/search.h +++ b/DSView/pv/dialogs/search.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/streamoptions.cpp b/DSView/pv/dialogs/streamoptions.cpp index 610c5beb..7c0432dd 100644 --- a/DSView/pv/dialogs/streamoptions.cpp +++ b/DSView/pv/dialogs/streamoptions.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/streamoptions.h b/DSView/pv/dialogs/streamoptions.h index 03fdcc5b..1c9c148d 100644 --- a/DSView/pv/dialogs/streamoptions.h +++ b/DSView/pv/dialogs/streamoptions.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dialogs/waitingdialog.cpp b/DSView/pv/dialogs/waitingdialog.cpp index 8e2b0e52..cb0c742d 100644 --- a/DSView/pv/dialogs/waitingdialog.cpp +++ b/DSView/pv/dialogs/waitingdialog.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -27,6 +26,9 @@ #include #include +#include +#include +#include #include "libsigrok4DSL/libsigrok.h" #include "../view/trace.h" @@ -37,7 +39,8 @@ using namespace std; namespace pv { namespace dialogs { -const QString WaitingDialog::TIPS_INFO = tr("Waiting"); +const QString WaitingDialog::TIPS_WAIT = tr("Waiting"); +const QString WaitingDialog::TIPS_FINISHED = tr("Finished!"); WaitingDialog::WaitingDialog(QWidget *parent, boost::shared_ptr dev_inst) : QDialog(parent), @@ -58,7 +61,7 @@ WaitingDialog::WaitingDialog(QWidget *parent, boost::shared_ptrsetMovie(movie); tips = new QLabel(this); - tips->setText(TIPS_INFO); + tips->setText(TIPS_WAIT); QFont font; font.setPointSize(10); font.setBold(true); @@ -79,12 +82,29 @@ WaitingDialog::WaitingDialog(QWidget *parent, boost::shared_ptrstop(); timer->stop(); + QDialog::accept(); - _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_SET, g_variant_new_boolean(true)); - QDialog::accept(); + QFuture future; + future = QtConcurrent::run([&]{ + QTime dieTime = QTime::currentTime().addSecs(1); + _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_SET, + g_variant_new_boolean(true)); + while( QTime::currentTime() < dieTime ); + }); + Qt::WindowFlags flags = Qt::CustomizeWindowHint; + QProgressDialog dlg(tr("Save Auto Zero Result... It can take a while."), + tr("Cancel"),0,0,this,flags); + dlg.setWindowModality(Qt::WindowModal); + dlg.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); + dlg.setCancelButton(NULL); + + QFutureWatcher watcher; + watcher.setFuture(future); + connect(&watcher,SIGNAL(finished()),&dlg,SLOT(cancel())); + + dlg.exec(); } void WaitingDialog::reject() @@ -94,6 +114,27 @@ void WaitingDialog::reject() movie->stop(); timer->stop(); QDialog::reject(); + + QFuture future; + future = QtConcurrent::run([&]{ + QTime dieTime = QTime::currentTime().addSecs(1); + _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); + _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_LOAD, + g_variant_new_boolean(true)); + while( QTime::currentTime() < dieTime ); + }); + Qt::WindowFlags flags = Qt::CustomizeWindowHint; + QProgressDialog dlg(tr("Load Current Setting... It can take a while."), + tr("Cancel"),0,0,this,flags); + dlg.setWindowModality(Qt::WindowModal); + dlg.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); + dlg.setCancelButton(NULL); + + QFutureWatcher watcher; + connect(&watcher,SIGNAL(finished()),&dlg,SLOT(cancel())); + watcher.setFuture(future); + + dlg.exec(); } void WaitingDialog::start() @@ -105,19 +146,24 @@ void WaitingDialog::start() void WaitingDialog::changeText() { - sr_status status; index++; if(index == WPOINTS_NUM + 1) { - tips->setText(TIPS_INFO); + tips->setText(TIPS_WAIT); index = 0; - sr_status_get(_dev_inst->dev_inst(), &status, 0, 0); - if (!status.zeroing) { - movie->stop(); - movie->jumpToFrame(0); - timer->stop(); - tips->setText(""); - _button_box.buttons().front()->setVisible(true); + + GVariant* gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_ZERO); + if (gvar != NULL) { + bool zero = g_variant_get_boolean(gvar); + g_variant_unref(gvar); + if (!zero) { + movie->stop(); + movie->jumpToFrame(0); + timer->stop(); + tips->setAlignment(Qt::AlignHCenter); + tips->setText(TIPS_FINISHED); + _button_box.buttons().front()->setVisible(true); + } } } else { tips->setText(tips->text()+"."); diff --git a/DSView/pv/dialogs/waitingdialog.h b/DSView/pv/dialogs/waitingdialog.h index a214b45d..4b3480f6 100644 --- a/DSView/pv/dialogs/waitingdialog.h +++ b/DSView/pv/dialogs/waitingdialog.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -46,7 +45,8 @@ private: static const int TIP_WIDTH = 100; static const int TIP_HEIGHT = 40; static const int WPOINTS_NUM = 6; - static const QString TIPS_INFO; + static const QString TIPS_WAIT; + static const QString TIPS_FINISHED; public: WaitingDialog(QWidget *parent, boost::shared_ptr dev_inst); diff --git a/DSView/pv/dock/dsotriggerdock.cpp b/DSView/pv/dock/dsotriggerdock.cpp index a6d99456..346b7ea4 100644 --- a/DSView/pv/dock/dsotriggerdock.cpp +++ b/DSView/pv/dock/dsotriggerdock.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dock/dsotriggerdock.h b/DSView/pv/dock/dsotriggerdock.h index f5c4ac17..a35521ed 100644 --- a/DSView/pv/dock/dsotriggerdock.h +++ b/DSView/pv/dock/dsotriggerdock.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dock/measuredock.cpp b/DSView/pv/dock/measuredock.cpp index 67a7e2fe..1bac919a 100644 --- a/DSView/pv/dock/measuredock.cpp +++ b/DSView/pv/dock/measuredock.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dock/measuredock.h b/DSView/pv/dock/measuredock.h index 8cf455fa..bb941b0c 100644 --- a/DSView/pv/dock/measuredock.h +++ b/DSView/pv/dock/measuredock.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dock/protocoldock.cpp b/DSView/pv/dock/protocoldock.cpp index e57ea47a..b93a13a6 100644 --- a/DSView/pv/dock/protocoldock.cpp +++ b/DSView/pv/dock/protocoldock.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dock/protocoldock.h b/DSView/pv/dock/protocoldock.h index dcd1dfd8..71f68db6 100644 --- a/DSView/pv/dock/protocoldock.h +++ b/DSView/pv/dock/protocoldock.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dock/searchdock.cpp b/DSView/pv/dock/searchdock.cpp index 90b1bbab..c3801a31 100644 --- a/DSView/pv/dock/searchdock.cpp +++ b/DSView/pv/dock/searchdock.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dock/searchdock.h b/DSView/pv/dock/searchdock.h index 2477dcb4..2583cf1a 100644 --- a/DSView/pv/dock/searchdock.h +++ b/DSView/pv/dock/searchdock.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dock/triggerdock.cpp b/DSView/pv/dock/triggerdock.cpp index a16eb34e..26fbdfa9 100644 --- a/DSView/pv/dock/triggerdock.cpp +++ b/DSView/pv/dock/triggerdock.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/dock/triggerdock.h b/DSView/pv/dock/triggerdock.h index ece32316..6533b03e 100644 --- a/DSView/pv/dock/triggerdock.h +++ b/DSView/pv/dock/triggerdock.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 42e81399..fccd54af 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -194,6 +194,10 @@ void MainWindow::setup_ui() SLOT(instant_stop())); connect(_sampling_bar, SIGNAL(sample_count_changed()), _trigger_widget, SLOT(device_change())); + connect(_sampling_bar, SIGNAL(show_calibration()), _view, + SLOT(show_calibration())); + connect(_sampling_bar, SIGNAL(hide_calibration()), _view, + SLOT(hide_calibration())); connect(_dso_trigger_widget, SIGNAL(set_trig_pos(quint64)), _view, SLOT(set_trig_pos(quint64))); connect(_protocol_widget, SIGNAL(protocol_updated()), _view, SLOT(signals_changed())); @@ -421,11 +425,7 @@ void MainWindow::run_stop() void MainWindow::instant_stop() { -#ifdef TEST_MODE - disconnect(&test_timer, SIGNAL(timeout()), - this, SLOT(run_stop())); - test_timer_linked = false; -#else + switch(_session.get_capture_state()) { case SigSession::Init: case SigSession::Stopped: @@ -441,16 +441,12 @@ void MainWindow::instant_stop() _session.stop_capture(); break; } -#endif + } void MainWindow::test_data_error() { -#ifdef TEST_MODE - disconnect(&test_timer, SIGNAL(timeout()), - this, SLOT(run_stop())); - test_timer_linked = false; -#endif + _session.stop_capture(); QMessageBox msg(this); msg.setText(tr("Data Error")); @@ -511,11 +507,7 @@ void MainWindow::capture_state_changed(int state) } } } -#ifdef TEST_MODE - if (state == SigSession::Stopped) { - test_timer.start(100); - } -#endif + } } diff --git a/DSView/pv/mainwindow.h b/DSView/pv/mainwindow.h index 36abdf6f..1b96a375 100644 --- a/DSView/pv/mainwindow.h +++ b/DSView/pv/mainwindow.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -59,6 +59,10 @@ class MeasureDock; class SearchDock; } +namespace dialogs{ +class Calibration; +} + namespace view { class View; } diff --git a/DSView/pv/prop/binding/binding.cpp b/DSView/pv/prop/binding/binding.cpp index 95c9ca3b..2470ba21 100644 --- a/DSView/pv/prop/binding/binding.cpp +++ b/DSView/pv/prop/binding/binding.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/binding/binding.h b/DSView/pv/prop/binding/binding.h index ab7758b5..ca1462c2 100644 --- a/DSView/pv/prop/binding/binding.h +++ b/DSView/pv/prop/binding/binding.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/binding/binding_deviceoptions.cpp b/DSView/pv/prop/binding/binding_deviceoptions.cpp index c8c1e9a0..ea9a3c99 100644 --- a/DSView/pv/prop/binding/binding_deviceoptions.cpp +++ b/DSView/pv/prop/binding/binding_deviceoptions.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/binding/deviceoptions.h b/DSView/pv/prop/binding/deviceoptions.h index a4b99744..f9f8d42b 100644 --- a/DSView/pv/prop/binding/deviceoptions.h +++ b/DSView/pv/prop/binding/deviceoptions.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/bool.cpp b/DSView/pv/prop/bool.cpp index 9d7e4961..2dd84890 100644 --- a/DSView/pv/prop/bool.cpp +++ b/DSView/pv/prop/bool.cpp @@ -3,7 +3,6 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/bool.h b/DSView/pv/prop/bool.h index 3976606d..a1b3e2f6 100644 --- a/DSView/pv/prop/bool.h +++ b/DSView/pv/prop/bool.h @@ -3,7 +3,6 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/double.cpp b/DSView/pv/prop/double.cpp index 2bd4a9ff..73a174bb 100644 --- a/DSView/pv/prop/double.cpp +++ b/DSView/pv/prop/double.cpp @@ -3,7 +3,6 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/double.h b/DSView/pv/prop/double.h index e26d5d04..7eb4493d 100644 --- a/DSView/pv/prop/double.h +++ b/DSView/pv/prop/double.h @@ -3,7 +3,6 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/enum.cpp b/DSView/pv/prop/enum.cpp index 8c51f554..2aee897f 100644 --- a/DSView/pv/prop/enum.cpp +++ b/DSView/pv/prop/enum.cpp @@ -3,7 +3,6 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/enum.h b/DSView/pv/prop/enum.h index dbeb1cf2..a223565a 100644 --- a/DSView/pv/prop/enum.h +++ b/DSView/pv/prop/enum.h @@ -3,7 +3,6 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/int.cpp b/DSView/pv/prop/int.cpp index 1c9e79cd..b3ea0c69 100644 --- a/DSView/pv/prop/int.cpp +++ b/DSView/pv/prop/int.cpp @@ -3,7 +3,6 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/int.h b/DSView/pv/prop/int.h index 776b4f98..daa4c1d3 100644 --- a/DSView/pv/prop/int.h +++ b/DSView/pv/prop/int.h @@ -3,7 +3,6 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/property.cpp b/DSView/pv/prop/property.cpp index 48ca4a2c..af793309 100644 --- a/DSView/pv/prop/property.cpp +++ b/DSView/pv/prop/property.cpp @@ -3,7 +3,6 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/prop/property.h b/DSView/pv/prop/property.h index 6ef784d5..3a1b165f 100644 --- a/DSView/pv/prop/property.h +++ b/DSView/pv/prop/property.h @@ -3,7 +3,6 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index 51141f24..6584c09b 100644 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index 5092b19b..95769fe6 100644 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/toolbars/filebar.cpp b/DSView/pv/toolbars/filebar.cpp index 3c5efd30..ecf93a5a 100644 --- a/DSView/pv/toolbars/filebar.cpp +++ b/DSView/pv/toolbars/filebar.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/toolbars/filebar.h b/DSView/pv/toolbars/filebar.h index 6f4c2c40..a77f3928 100644 --- a/DSView/pv/toolbars/filebar.h +++ b/DSView/pv/toolbars/filebar.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/toolbars/logobar.cpp b/DSView/pv/toolbars/logobar.cpp index 00063406..8f19e614 100644 --- a/DSView/pv/toolbars/logobar.cpp +++ b/DSView/pv/toolbars/logobar.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/toolbars/logobar.h b/DSView/pv/toolbars/logobar.h index 7e8ac9bc..ad486b9e 100644 --- a/DSView/pv/toolbars/logobar.h +++ b/DSView/pv/toolbars/logobar.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/toolbars/samplingbar.cpp b/DSView/pv/toolbars/samplingbar.cpp index 05616ca3..fd3c3129 100644 --- a/DSView/pv/toolbars/samplingbar.cpp +++ b/DSView/pv/toolbars/samplingbar.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -204,6 +203,8 @@ shared_ptr SamplingBar::get_selected_device() const void SamplingBar::on_configure() { + hide_calibration(); + int ret; shared_ptr dev_inst = get_selected_device(); assert(dev_inst); @@ -215,17 +216,29 @@ void SamplingBar::on_configure() update_sample_count_selector(); update_sample_rate_selector(); commit_sample_rate(); + + GVariant* gvar; + if (dev_inst->dev_inst()->mode == DSO) { + gvar = dev_inst->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(); + } + + gvar = dev_inst->get_config(NULL, NULL, SR_CONF_CALI); + if (gvar != NULL) { + bool cali = g_variant_get_boolean(gvar); + g_variant_unref(gvar); + if (cali) { + show_calibration(); + } + } + } } - GVariant* gvar = dev_inst->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(); - } - - gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TEST); + GVariant* gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TEST); if (gvar != NULL) { bool test = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -316,17 +329,6 @@ void SamplingBar::set_sampling(bool sampling) _run_stop_button.setEnabled(true); _instant_button.setEnabled(true); } else { -// bool running = false; -// boost::shared_ptr dev_inst = get_selected_device(); -// assert(dev_inst); -// while (!running) { -// GVariant* gvar = dev_inst->get_config(NULL, NULL, SR_CONF_STATUS); -// if (gvar != NULL) { -// running = g_variant_get_boolean(gvar); -// g_variant_unref(gvar); -// } -// g_usleep(10000); -// } g_usleep(100000); if (_instant) _instant_button.setEnabled(true); @@ -667,10 +669,18 @@ void SamplingBar::on_run_stop() QMessageBox msg(this); msg.setText(tr("Zero Adjustment")); msg.setInformativeText(tr("Please adjust zero skew and save the result!")); - msg.setStandardButtons(QMessageBox::Ok); + //msg.setStandardButtons(QMessageBox::Ok); + msg.addButton(tr("Ok"), QMessageBox::AcceptRole); + msg.addButton(tr("Skip"), QMessageBox::RejectRole); msg.setIcon(QMessageBox::Warning); - msg.exec(); - zero_adj(); + int ret = msg.exec(); + if ( ret == QMessageBox::AcceptRole) { + zero_adj(); + } else { + dev_inst->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); + enable_run_stop(true); + enable_instant(true); + } return; } } @@ -696,14 +706,19 @@ void SamplingBar::on_instant_stop() if (zero) { QMessageBox msg(this); msg.setText(tr("Zero Adjustment")); - if(strcmp(dev_inst->dev_inst()->driver->name, "DSLogic") == 0) - msg.setInformativeText(tr("Please adjust zero skew and save the result!\nPlease left both of channels unconnect for zero adjustment!")); - else - msg.setInformativeText(tr("Please adjust zero skew and save the result!")); - msg.setStandardButtons(QMessageBox::Ok); + msg.setInformativeText(tr("Zero adjustment program will be started. Please keep all channels out of singal input. It can take a while!")); + //msg.setStandardButtons(QMessageBox::Ok); + msg.addButton(tr("Ok"), QMessageBox::AcceptRole); + msg.addButton(tr("Skip"), QMessageBox::RejectRole); msg.setIcon(QMessageBox::Warning); - msg.exec(); - zero_adj(); + int ret = msg.exec(); + if ( ret == QMessageBox::AcceptRole) { + zero_adj(); + } else { + dev_inst->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); + enable_run_stop(true); + enable_instant(true); + } return; } } diff --git a/DSView/pv/toolbars/samplingbar.h b/DSView/pv/toolbars/samplingbar.h index 377246e4..7c9fa4bb 100644 --- a/DSView/pv/toolbars/samplingbar.h +++ b/DSView/pv/toolbars/samplingbar.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -52,6 +51,7 @@ class DevInst; namespace dialogs { class deviceoptions; +class Calibration; } namespace toolbars { @@ -96,6 +96,8 @@ signals: void device_selected(); void device_updated(); void sample_count_changed(); + void show_calibration(); + void hide_calibration(); private: void update_sample_rate_selector(); diff --git a/DSView/pv/toolbars/trigbar.cpp b/DSView/pv/toolbars/trigbar.cpp index bbd580a2..50207684 100644 --- a/DSView/pv/toolbars/trigbar.cpp +++ b/DSView/pv/toolbars/trigbar.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/toolbars/trigbar.h b/DSView/pv/toolbars/trigbar.h index 7100799e..53faf1d3 100644 --- a/DSView/pv/toolbars/trigbar.h +++ b/DSView/pv/toolbars/trigbar.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/analogsignal.cpp b/DSView/pv/view/analogsignal.cpp index d9cc46b2..d9726117 100644 --- a/DSView/pv/view/analogsignal.cpp +++ b/DSView/pv/view/analogsignal.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/analogsignal.h b/DSView/pv/view/analogsignal.h index b241e848..b8810fdb 100644 --- a/DSView/pv/view/analogsignal.h +++ b/DSView/pv/view/analogsignal.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/cursor.cpp b/DSView/pv/view/cursor.cpp index 9f108e9a..aaa24582 100644 --- a/DSView/pv/view/cursor.cpp +++ b/DSView/pv/view/cursor.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/cursor.h b/DSView/pv/view/cursor.h index d1b284b7..b1205874 100644 --- a/DSView/pv/view/cursor.h +++ b/DSView/pv/view/cursor.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/decodetrace.cpp b/DSView/pv/view/decodetrace.cpp index e16c0f8b..8d20ddca 100644 --- a/DSView/pv/view/decodetrace.cpp +++ b/DSView/pv/view/decodetrace.cpp @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/view/decodetrace.h b/DSView/pv/view/decodetrace.h index 39db68e6..12269b8c 100644 --- a/DSView/pv/view/decodetrace.h +++ b/DSView/pv/view/decodetrace.h @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/view/devmode.cpp b/DSView/pv/view/devmode.cpp index 2fb0a2b7..b782a11c 100644 --- a/DSView/pv/view/devmode.cpp +++ b/DSView/pv/view/devmode.cpp @@ -2,7 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2014 DreamSourceLab + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/view/devmode.h b/DSView/pv/view/devmode.h index 3e114fbb..033f55ac 100644 --- a/DSView/pv/view/devmode.h +++ b/DSView/pv/view/devmode.h @@ -2,7 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2014 DreamSourceLab + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/view/dsldial.cpp b/DSView/pv/view/dsldial.cpp index 454dc620..3d0b1300 100644 --- a/DSView/pv/view/dsldial.cpp +++ b/DSView/pv/view/dsldial.cpp @@ -1,3 +1,24 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2014 DreamSourceLab + * + * 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 "dsldial.h" #include diff --git a/DSView/pv/view/dsldial.h b/DSView/pv/view/dsldial.h index ddb7ea61..392cf89e 100644 --- a/DSView/pv/view/dsldial.h +++ b/DSView/pv/view/dsldial.h @@ -1,3 +1,24 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2013 DreamSourceLab + * + * 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_VIEW_DSLDIAL_H #define DSVIEW_PV_VIEW_DSLDIAL_H diff --git a/DSView/pv/view/dsosignal.cpp b/DSView/pv/view/dsosignal.cpp index 4113c65f..7ee1befd 100644 --- a/DSView/pv/view/dsosignal.cpp +++ b/DSView/pv/view/dsosignal.cpp @@ -2,7 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -263,6 +263,7 @@ bool DsoSignal::go_vDialPre() if (_view->session().get_capture_state() == SigSession::Stopped) _scale *= pre_vdiv/_vDial->get_value(); update_zeroPos(); + _view->update_calibration(); _view->set_update(_viewport, true); _view->update(); return true; @@ -282,6 +283,7 @@ bool DsoSignal::go_vDialNext() if (_view->session().get_capture_state() == SigSession::Stopped) _scale *= pre_vdiv/_vDial->get_value(); update_zeroPos(); + _view->update_calibration(); _view->set_update(_viewport, true); _view->update(); return true; @@ -469,7 +471,7 @@ bool DsoSignal::load_settings() vdiv = g_variant_get_uint64(gvar); g_variant_unref(gvar); } else { - qDebug() << "ERROR: config_get SR_CONF_TIMEBASE failed."; + qDebug() << "ERROR: config_get SR_CONF_VDIV failed."; return false; } gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_FACTOR); @@ -477,7 +479,7 @@ bool DsoSignal::load_settings() vfactor = g_variant_get_uint64(gvar); g_variant_unref(gvar); } else { - qDebug() << "ERROR: config_get SR_CONF_TIMEBASE failed."; + qDebug() << "ERROR: config_get SR_CONF_FACTOR failed."; return false; } @@ -506,12 +508,29 @@ bool DsoSignal::load_settings() vpos = g_variant_get_double(gvar); g_variant_unref(gvar); } else { - qDebug() << "ERROR: config_get SR_CONF_COUPLING failed."; + qDebug() << "ERROR: config_get SR_CONF_VPOS failed."; return false; } _zeroPos = min(max((0.5 - vpos / (_vDial->get_value() * DS_CONF_DSO_VDIVS)), 0.0), 1.0); _zero_off = _zeroPos * 255; + // -- trig_value + uint8_t trigger_value; + gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_TRIGGER_VALUE); + if (gvar != NULL) { + trigger_value = g_variant_get_byte(gvar); + g_variant_unref(gvar); + } else { + qDebug() << "ERROR: config_get SR_CONF_TRIGGER_VALUE failed."; + return false; + } + bool isDSCope = (strcmp(_dev_inst->dev_inst()->driver->name, "DSCope") == 0); + if (isDSCope) { + _trig_vpos = min(max(trigger_value/255.0, 0+TrigMargin), 1-TrigMargin); + } else { + _trig_vpos = min(max(_zeroPos + ((trigger_value - 0x80) / 255.0), 0+TrigMargin), 1-TrigMargin); + } + if (_view) { _view->set_update(_viewport, true); _view->update(); @@ -519,6 +538,35 @@ bool DsoSignal::load_settings() return true; } +int DsoSignal::commit_settings() +{ + int ret; + // -- enable + ret = _dev_inst->set_config(_probe, NULL, SR_CONF_EN_CH, + g_variant_new_boolean(enabled())); + + // -- hdiv + ret = _dev_inst->set_config(_probe, NULL, SR_CONF_TIMEBASE, + g_variant_new_uint64(_hDial->get_value())); + + // -- vdiv + ret = _dev_inst->set_config(_probe, NULL, SR_CONF_VDIV, + g_variant_new_uint64(_vDial->get_value())); + ret = _dev_inst->set_config(_probe, NULL, SR_CONF_FACTOR, + g_variant_new_uint64(_vDial->get_factor())); + + // -- coupling + ret = _dev_inst->set_config(_probe, NULL, SR_CONF_COUPLING, + g_variant_new_byte(_acCoupling)); + + // -- vpos + double vpos_off = (0.5 - (get_zeroPos() - UpMargin) * 1.0/get_view_rect().height()) * _vDial->get_value() * DS_CONF_DSO_VDIVS; + ret = _dev_inst->set_config(_probe, NULL, SR_CONF_VPOS, + g_variant_new_double(vpos_off)); + + return ret; +} + uint64_t DsoSignal::get_vDialValue() const { return _vDial->get_value(); @@ -571,14 +619,14 @@ void DsoSignal::set_trig_vpos(int pos) double delta = min((double)max(pos - UpMargin, 0), get_view_rect().height()) * 1.0 / get_view_rect().height(); bool isDSCope = (strcmp(_dev_inst->dev_inst()->driver->name, "DSCope") == 0); if (isDSCope) { - _trig_vpos = min(max(delta, 0+TrigMargin), 1-TrigMargin); - trig_value = delta * 255; + trig_value = delta * 255.0 + 0.5; + _trig_vpos = min(max(trig_value/255.0, 0+TrigMargin), 1-TrigMargin); } else { delta = delta - _zeroPos; delta = min(delta, 0.5); delta = max(delta, -0.5); - _trig_vpos = min(max(_zeroPos + delta, 0+TrigMargin), 1-TrigMargin); trig_value = (delta * 255.0f + 0x80); + _trig_vpos = min(max(_zeroPos + (trig_value - 0x80) / 255.0, 0+TrigMargin), 1-TrigMargin); } _dev_inst->set_config(_probe, NULL, SR_CONF_TRIGGER_VALUE, g_variant_new_byte(trig_value)); @@ -591,14 +639,15 @@ void DsoSignal::set_trigRate(double rate) double delta = rate; bool isDSCope = (strcmp(_dev_inst->dev_inst()->driver->name, "DSCope") == 0); if (isDSCope) { - _trig_vpos = min(max(delta, 0+TrigMargin), 1-TrigMargin); - trig_value = delta * 255; + trig_value = delta * 255.0 + 0.5; + _trig_vpos = min(max(trig_value/255.0, 0+TrigMargin), 1-TrigMargin); + } else { delta = delta - _zeroPos; delta = min(delta, 0.5); delta = max(delta, -0.5); - _trig_vpos = min(max(_zeroPos + delta, 0+TrigMargin), 1-TrigMargin); trig_value = (delta * 255.0f + 0x80); + _trig_vpos = min(max(_zeroPos + (trig_value - 0x80) / 255.0, 0+TrigMargin), 1-TrigMargin); } _dev_inst->set_config(_probe, NULL, SR_CONF_TRIGGER_VALUE, g_variant_new_byte(trig_value)); @@ -764,8 +813,8 @@ void DsoSignal::paint_back(QPainter &p, int left, int right) p.setPen(Trace::dsLightBlue); p.drawLine(left, UpMargin/2, left + width, UpMargin/2); - const uint64_t sample_len = _view->session().get_device()->get_sample_limit(); - const double samplerate = _view->session().get_device()->get_sample_rate(); + const uint64_t sample_len = _dev_inst->get_sample_limit(); + const double samplerate = _dev_inst->get_sample_rate(); const double samples_per_pixel = samplerate * _view->scale(); const double shown_rate = min(samples_per_pixel * width * 1.0 / sample_len, 1.0); const double start_time = _data->get_start_time(); @@ -845,7 +894,7 @@ void DsoSignal::paint_mid(QPainter &p, int left, int right) const double pixels_offset = offset / scale; //const double samplerate = _data->samplerate(); - const double samplerate = _view->session().get_device()->get_sample_rate(); + const double samplerate = _dev_inst->get_sample_rate(); const double start_time = _data->get_start_time(); const int64_t last_sample = max((int64_t)(snapshot->get_sample_count() - 1), (int64_t)0); const double samples_per_pixel = samplerate * scale; @@ -1153,7 +1202,7 @@ bool DsoSignal::mouse_press(int right, const QPoint pt) if (strcmp(_view->session().get_device()->dev_inst()->driver->name, "DSLogic") == 0) set_acCoupling((get_acCoupling()+1)%2); else - set_acCoupling((get_acCoupling()+1)%3); + set_acCoupling((get_acCoupling()+1)%2); } else if (x1_rect.contains(pt)) { set_factor(1); } else if (x10_rect.contains(pt)) { @@ -1282,7 +1331,7 @@ void DsoSignal::paint_measure(QPainter &p) 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 = _view->session().get_device()->get_sample_rate(); + uint64_t sample_rate = _dev_inst->get_sample_rate(); _period = _period * 200.0 / (channel_count * sample_rate * 1.0 / SR_MHZ(1)); _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"); @@ -1457,7 +1506,7 @@ bool DsoSignal::measure(const QPointF &p) assert(scale > 0); const double offset = _view->offset(); const double pixels_offset = offset / scale; - const double samplerate = _view->session().get_device()->get_sample_rate(); + const double samplerate = _dev_inst->get_sample_rate(); const double samples_per_pixel = samplerate * scale; _hover_index = floor((p.x() + pixels_offset) * samples_per_pixel+0.5); diff --git a/DSView/pv/view/dsosignal.h b/DSView/pv/view/dsosignal.h index 032287e6..67c67da7 100644 --- a/DSView/pv/view/dsosignal.h +++ b/DSView/pv/view/dsosignal.h @@ -2,7 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -138,6 +138,7 @@ public: uint64_t get_factor(); bool load_settings(); + int commit_settings(); /** * diff --git a/DSView/pv/view/groupsignal.cpp b/DSView/pv/view/groupsignal.cpp index aec24c5b..b48eefe5 100644 --- a/DSView/pv/view/groupsignal.cpp +++ b/DSView/pv/view/groupsignal.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/groupsignal.h b/DSView/pv/view/groupsignal.h index 0aa18282..711382ca 100644 --- a/DSView/pv/view/groupsignal.h +++ b/DSView/pv/view/groupsignal.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/header.cpp b/DSView/pv/view/header.cpp index 2eb1d5fb..3b46006b 100644 --- a/DSView/pv/view/header.cpp +++ b/DSView/pv/view/header.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/header.h b/DSView/pv/view/header.h index 89d637ef..6d11b2fd 100644 --- a/DSView/pv/view/header.h +++ b/DSView/pv/view/header.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/logicsignal.cpp b/DSView/pv/view/logicsignal.cpp index 09a43232..cff3801c 100644 --- a/DSView/pv/view/logicsignal.cpp +++ b/DSView/pv/view/logicsignal.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/logicsignal.h b/DSView/pv/view/logicsignal.h index 3daa567b..ac64b1b8 100644 --- a/DSView/pv/view/logicsignal.h +++ b/DSView/pv/view/logicsignal.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/mathtrace.cpp b/DSView/pv/view/mathtrace.cpp index 459c15a9..0abafb18 100644 --- a/DSView/pv/view/mathtrace.cpp +++ b/DSView/pv/view/mathtrace.cpp @@ -1,7 +1,7 @@ /* * This file is part of the PulseView project. * - * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/view/mathtrace.h b/DSView/pv/view/mathtrace.h index 7a39babb..7fac9552 100644 --- a/DSView/pv/view/mathtrace.h +++ b/DSView/pv/view/mathtrace.h @@ -1,7 +1,7 @@ /* * This file is part of the PulseView project. * - * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/view/ruler.cpp b/DSView/pv/view/ruler.cpp index 209a75a1..f6050a73 100644 --- a/DSView/pv/view/ruler.cpp +++ b/DSView/pv/view/ruler.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/ruler.h b/DSView/pv/view/ruler.h index d3389bdc..41f415a6 100644 --- a/DSView/pv/view/ruler.h +++ b/DSView/pv/view/ruler.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/selectableitem.cpp b/DSView/pv/view/selectableitem.cpp index 2b4b4059..1c4d987e 100644 --- a/DSView/pv/view/selectableitem.cpp +++ b/DSView/pv/view/selectableitem.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2013 Joel Holdsworth - * Copyright (C) 2014 DreamSourceLab + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/view/selectableitem.h b/DSView/pv/view/selectableitem.h index 28004a2d..de9998a9 100644 --- a/DSView/pv/view/selectableitem.h +++ b/DSView/pv/view/selectableitem.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2013 Joel Holdsworth - * Copyright (C) 2014 DreamSourceLab + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/view/signal.cpp b/DSView/pv/view/signal.cpp index 04a4e6ed..9abd0ce9 100644 --- a/DSView/pv/view/signal.cpp +++ b/DSView/pv/view/signal.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/signal.h b/DSView/pv/view/signal.h index 632f1e37..01fabb25 100644 --- a/DSView/pv/view/signal.h +++ b/DSView/pv/view/signal.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/timemarker.cpp b/DSView/pv/view/timemarker.cpp index bf4f9c87..1956f013 100644 --- a/DSView/pv/view/timemarker.cpp +++ b/DSView/pv/view/timemarker.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/timemarker.h b/DSView/pv/view/timemarker.h index b6de934f..71ee4cfe 100644 --- a/DSView/pv/view/timemarker.h +++ b/DSView/pv/view/timemarker.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/trace.cpp b/DSView/pv/view/trace.cpp index 661f59f5..c9971bc8 100644 --- a/DSView/pv/view/trace.cpp +++ b/DSView/pv/view/trace.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2013 Joel Holdsworth - * Copyright (C) 2014 DreamSourceLab + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/view/trace.h b/DSView/pv/view/trace.h index 1c30de77..2dd9662c 100644 --- a/DSView/pv/view/trace.h +++ b/DSView/pv/view/trace.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2013 Joel Holdsworth - * Copyright (C) 2014 DreamSourceLab + * Copyright (C) 2014 DreamSourceLab * * 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 diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index d97d4759..c3e2193d 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -47,6 +47,7 @@ #include "pv/sigsession.h" #include "pv/data/logic.h" #include "pv/data/logicsnapshot.h" +#include "pv/dialogs/calibration.h" using namespace boost; using namespace std; @@ -179,6 +180,9 @@ View::View(SigSession &session, pv::toolbars::SamplingBar *sampling_bar, QWidget _show_search_cursor = false; _search_pos = 0; _search_cursor = new Cursor(*this, Trace::dsLightBlue, _search_pos); + + _cali = new pv::dialogs::Calibration(this); + _cali->hide(); } SigSession& View::session() @@ -972,6 +976,25 @@ double View::get_max_offset() - _scale * (get_view_width() * MaxViewRate); } +// -- calibration dialog +void View::show_calibration() +{ + _cali->set_device(_session.get_device()); + _cali->show(); +} + +void View::hide_calibration() +{ + _cali->hide(); +} + +void View::update_calibration() +{ + if (_cali->isVisible()) { + _cali->set_device(_session.get_device()); + } +} + QString View::trigger_time() { return _trigger_time.toString("yyyy-MM-dd hh:mm:ss ddd"); diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index 028eee48..55f8ae91 100644 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -231,6 +231,8 @@ public slots: void data_updated(); void update_scale_offset(); void show_region(uint64_t start, uint64_t end); + // -- calibration + void update_calibration(); private slots: @@ -245,6 +247,9 @@ private slots: void set_trig_pos(quint64 trig_pos); + // calibration for oscilloscope + void show_calibration(); + void hide_calibration(); void on_measure_updated(); void splitterMoved(int pos, int index); @@ -292,7 +297,7 @@ private: uint64_t _search_pos; QPointF _hover_point; - + dialogs::Calibration *_cali; QDateTime _trigger_time; }; diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index 9197f0ce..07f0dee8 100644 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/view/viewport.h b/DSView/pv/view/viewport.h index 33ed45b2..cee1e9eb 100644 --- a/DSView/pv/view/viewport.h +++ b/DSView/pv/view/viewport.h @@ -3,7 +3,7 @@ * DSView is based on PulseView. * * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/widgets/decodergroupbox.cpp b/DSView/pv/widgets/decodergroupbox.cpp index d03082e6..4be51822 100644 --- a/DSView/pv/widgets/decodergroupbox.cpp +++ b/DSView/pv/widgets/decodergroupbox.cpp @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2013 Joel Holdsworth + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/widgets/decodergroupbox.h b/DSView/pv/widgets/decodergroupbox.h index c69543d5..d780241b 100644 --- a/DSView/pv/widgets/decodergroupbox.h +++ b/DSView/pv/widgets/decodergroupbox.h @@ -2,6 +2,7 @@ * This file is part of the PulseView project. * * Copyright (C) 2013 Joel Holdsworth + * Copyright (C) 2016 DreamSourceLab * * 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 diff --git a/DSView/pv/widgets/fakelineedit.cpp b/DSView/pv/widgets/fakelineedit.cpp index 84e0c278..d8a2930a 100644 --- a/DSView/pv/widgets/fakelineedit.cpp +++ b/DSView/pv/widgets/fakelineedit.cpp @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/DSView/pv/widgets/fakelineedit.h b/DSView/pv/widgets/fakelineedit.h index a274f990..071c59e4 100644 --- a/DSView/pv/widgets/fakelineedit.h +++ b/DSView/pv/widgets/fakelineedit.h @@ -2,8 +2,7 @@ * This file is part of the DSView project. * DSView is based on PulseView. * - * Copyright (C) 2012 Joel Holdsworth - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 diff --git a/libsigrok4DSL/hardware/DSL/command.c b/libsigrok4DSL/hardware/DSL/command.c index accf2f15..e65741ed 100644 --- a/libsigrok4DSL/hardware/DSL/command.c +++ b/libsigrok4DSL/hardware/DSL/command.c @@ -234,19 +234,19 @@ SR_PRIV int command_get_status(libusb_device_handle *devhdl, return SR_OK; } -SR_PRIV int command_vth(libusb_device_handle *devhdl, double vth) +SR_PRIV int command_wr_reg(libusb_device_handle *devhdl, uint8_t value, uint8_t addr) { int ret; - uint8_t cmd; + uint16_t cmd; - cmd = vth/5.0 * 255; + cmd = value + (addr << 8); /* Send the control command. */ ret = libusb_control_transfer(devhdl, LIBUSB_REQUEST_TYPE_VENDOR | - LIBUSB_ENDPOINT_OUT, CMD_VTH, 0x0000, 0x0000, + LIBUSB_ENDPOINT_OUT, CMD_WR_REG, 0x0000, 0x0000, (unsigned char *)&cmd, sizeof(cmd), 3000); if (ret < 0) { - sr_err("Unable to send VTH command: %s.", - libusb_error_name(ret)); + sr_err("Unable to write REG @ address %d : %s.", + addr, libusb_error_name(ret)); return SR_ERR; } @@ -276,7 +276,7 @@ SR_PRIV int command_rd_nvm(libusb_device_handle *devhdl, unsigned char *ctx, uin int ret; struct cmd_nvm_info nvm_info; - assert(len <= 8); + assert(len <= 32); nvm_info.addr = addr; nvm_info.len = len; diff --git a/libsigrok4DSL/hardware/DSL/command.h b/libsigrok4DSL/hardware/DSL/command.h index 5f9735a0..44485e24 100644 --- a/libsigrok4DSL/hardware/DSL/command.h +++ b/libsigrok4DSL/hardware/DSL/command.h @@ -33,7 +33,7 @@ #define CMD_CONTROL 0xb5 #define CMD_STATUS 0xb6 #define CMD_STATUS_INFO 0xb7 -#define CMD_VTH 0xb8 +#define CMD_WR_REG 0xb8 #define CMD_WR_NVM 0xb9 #define CMD_RD_NVM 0xba #define CMD_RD_NVM_PRE 0xbb @@ -55,6 +55,10 @@ #define CMD_STATUS_CNT 32 +#define VTH_ADDR 0x78 +#define EEWP_ADDR 0x70 +#define COMB_ADDR 0x68 + #pragma pack(push, 1) struct version_info { @@ -98,22 +102,38 @@ struct cmd_status_info { struct cmd_zero_info { uint8_t zero_addr; - uint8_t vpos_l; - uint8_t vpos_h; - uint8_t voff_l; - uint8_t voff_h; - uint8_t vcntr_l; - uint8_t vcntr_h; - uint8_t adc_off; + uint8_t voff0; + uint8_t voff1; + uint8_t voff2; + uint8_t voff3; + uint8_t voff4; + uint8_t voff5; + uint8_t voff6; + uint8_t voff7; + uint8_t voff8; + uint8_t voff9; + uint8_t voff10; + uint8_t voff11; + uint8_t voff12; + uint8_t voff13; + uint8_t voff14; + uint8_t voff15; + uint8_t diff0; + uint8_t diff1; + uint8_t trans0; + uint8_t trans1; }; -struct cmd_comb_info { - uint8_t comb_addr; - uint8_t comb0_low_off; - uint8_t comb0_hig_off; - uint8_t comb1_low_off; - uint8_t comb1_hig_off; - uint8_t comb_sign; +struct cmd_vga_info { + uint8_t vga_addr; + uint16_t vga0; + uint16_t vga1; + uint16_t vga2; + uint16_t vga3; + uint16_t vga4; + uint16_t vga5; + uint16_t vga6; + uint16_t vga7; }; struct cmd_nvm_info { @@ -140,7 +160,7 @@ SR_PRIV int command_get_status(libusb_device_handle *devhdl, unsigned char *status, int begin, int end); -SR_PRIV int command_vth(libusb_device_handle *devhdl, double vth); +SR_PRIV int command_wr_reg(libusb_device_handle *devhdl, uint8_t value, uint8_t addr); SR_PRIV int command_wr_nvm(libusb_device_handle *devhdl, unsigned char *ctx, uint8_t len); SR_PRIV int command_rd_nvm(libusb_device_handle *devhdl, unsigned char *ctx, uint8_t addr, uint8_t len); diff --git a/libsigrok4DSL/hardware/DSL/dscope.c b/libsigrok4DSL/hardware/DSL/dscope.c index 26191168..ef4f8dd8 100644 --- a/libsigrok4DSL/hardware/DSL/dscope.c +++ b/libsigrok4DSL/hardware/DSL/dscope.c @@ -139,8 +139,7 @@ static const uint64_t samplecounts[] = { SR_MB(32), }; -static const uint8_t zero_base_addr = 0x80; -static const uint8_t comb_base_addr = 0xB0; +static const uint8_t zero_base_addr = 0x40; SR_PRIV struct sr_dev_driver DSCope_driver_info; static struct sr_dev_driver *di = &DSCope_driver_info; @@ -149,8 +148,51 @@ extern struct ds_trigger *trigger; gboolean mstatus_valid = FALSE; struct sr_status mstatus; -struct cmd_zero_info zero_info; -struct cmd_comb_info comb_info; + +static const uint64_t DSCOPE_DEFAULT_VGAIN[] = { + DSCOPE_DEFAULT_VGAIN0, + DSCOPE_DEFAULT_VGAIN1, + DSCOPE_DEFAULT_VGAIN2, + DSCOPE_DEFAULT_VGAIN3, + DSCOPE_DEFAULT_VGAIN4, + DSCOPE_DEFAULT_VGAIN5, + DSCOPE_DEFAULT_VGAIN6, + DSCOPE_DEFAULT_VGAIN7, +}; + +static const uint64_t DSCOPE20_DEFAULT_VGAIN[] = { + DSCOPE20_DEFAULT_VGAIN0, + DSCOPE20_DEFAULT_VGAIN1, + DSCOPE20_DEFAULT_VGAIN2, + DSCOPE20_DEFAULT_VGAIN3, + DSCOPE20_DEFAULT_VGAIN4, + DSCOPE20_DEFAULT_VGAIN5, + DSCOPE20_DEFAULT_VGAIN6, + DSCOPE20_DEFAULT_VGAIN7, +}; + +struct DSL_vga DSCope_vga[] = { + {10, DSCOPE_DEFAULT_VGAIN0, DSCOPE_DEFAULT_VGAIN0, DSCOPE_DEFAULT_VOFF, DSCOPE_DEFAULT_VOFF}, + {20, DSCOPE_DEFAULT_VGAIN1, DSCOPE_DEFAULT_VGAIN1, DSCOPE_DEFAULT_VOFF, DSCOPE_DEFAULT_VOFF}, + {50, DSCOPE_DEFAULT_VGAIN2, DSCOPE_DEFAULT_VGAIN2, DSCOPE_DEFAULT_VOFF, DSCOPE_DEFAULT_VOFF}, + {100, DSCOPE_DEFAULT_VGAIN3, DSCOPE_DEFAULT_VGAIN3, DSCOPE_DEFAULT_VOFF, DSCOPE_DEFAULT_VOFF}, + {200, DSCOPE_DEFAULT_VGAIN4, DSCOPE_DEFAULT_VGAIN4, DSCOPE_DEFAULT_VOFF, DSCOPE_DEFAULT_VOFF}, + {500, DSCOPE_DEFAULT_VGAIN5, DSCOPE_DEFAULT_VGAIN5, DSCOPE_DEFAULT_VOFF, DSCOPE_DEFAULT_VOFF}, + {1000,DSCOPE_DEFAULT_VGAIN6, DSCOPE_DEFAULT_VGAIN6, DSCOPE_DEFAULT_VOFF, DSCOPE_DEFAULT_VOFF}, + {2000,DSCOPE_DEFAULT_VGAIN7, DSCOPE_DEFAULT_VGAIN7, DSCOPE_DEFAULT_VOFF, DSCOPE_DEFAULT_VOFF}, + {0, 0, 0, 0}, +}; +struct DSL_vga DSCope20_vga[] = { + {10, DSCOPE20_DEFAULT_VGAIN0, DSCOPE20_DEFAULT_VGAIN0, DSCOPE20_DEFAULT_VOFF, CALI_VOFF_RANGE-DSCOPE20_DEFAULT_VOFF}, + {20, DSCOPE20_DEFAULT_VGAIN1, DSCOPE20_DEFAULT_VGAIN1, DSCOPE20_DEFAULT_VOFF, CALI_VOFF_RANGE-DSCOPE20_DEFAULT_VOFF}, + {50, DSCOPE20_DEFAULT_VGAIN2, DSCOPE20_DEFAULT_VGAIN2, DSCOPE20_DEFAULT_VOFF, CALI_VOFF_RANGE-DSCOPE20_DEFAULT_VOFF}, + {100, DSCOPE20_DEFAULT_VGAIN3, DSCOPE20_DEFAULT_VGAIN3, DSCOPE20_DEFAULT_VOFF, CALI_VOFF_RANGE-DSCOPE20_DEFAULT_VOFF}, + {200, DSCOPE20_DEFAULT_VGAIN4, DSCOPE20_DEFAULT_VGAIN4, DSCOPE20_DEFAULT_VOFF, CALI_VOFF_RANGE-DSCOPE20_DEFAULT_VOFF}, + {500, DSCOPE20_DEFAULT_VGAIN5, DSCOPE20_DEFAULT_VGAIN5, DSCOPE20_DEFAULT_VOFF, CALI_VOFF_RANGE-DSCOPE20_DEFAULT_VOFF}, + {1000,DSCOPE20_DEFAULT_VGAIN6, DSCOPE20_DEFAULT_VGAIN6, DSCOPE20_DEFAULT_VOFF, CALI_VOFF_RANGE-DSCOPE20_DEFAULT_VOFF}, + {2000,DSCOPE20_DEFAULT_VGAIN7, DSCOPE20_DEFAULT_VGAIN7, DSCOPE20_DEFAULT_VOFF, CALI_VOFF_RANGE-DSCOPE20_DEFAULT_VOFF}, + {0, 0, 0, 0}, +}; /** * Check the USB configuration to determine if this is an DSCope device. @@ -162,7 +204,7 @@ static gboolean check_conf_profile(libusb_device *dev) { struct libusb_device_descriptor des; struct libusb_device_handle *hdl; - gboolean ret; + gboolean ret; unsigned char strdesc[64]; hdl = NULL; @@ -184,7 +226,7 @@ static gboolean check_conf_profile(libusb_device *dev) if (libusb_get_string_descriptor_ascii(hdl, des.iProduct, strdesc, sizeof(strdesc)) < 0) break; - if (strncmp((const char *)strdesc, "DSCope", 6)) + if (strncmp((const char *)strdesc, "USB-based Instrument", 20)) break; /* If we made it here, it must be an DSCope. */ @@ -261,8 +303,8 @@ static int fpga_setting(const struct sr_dev_inst *sdi) ((devc->cur_samplerate == SR_MHZ(400)) << 6) + ((sdi->mode == ANALOG) << 7) + ((devc->filter == SR_FILTER_1T) << 8) + - (devc->instant << 9) + (devc->zero << 10); - setting.divider = devc->zero ? 0x1 : (uint32_t)ceil(DSCOPE_MAX_SAMPLERATE * 1.0 / devc->cur_samplerate / channel_en_cnt); + (devc->instant << 9); + setting.divider = (uint32_t)ceil(DSCOPE_MAX_SAMPLERATE * 1.0 / devc->cur_samplerate / channel_en_cnt); setting.count = (uint32_t)(devc->limit_samples / (channel_cnt / channel_en_cnt)); setting.trig_pos = (uint32_t)(trigger->trigger_pos / 100.0 * devc->limit_samples); setting.trig_glb = trigger->trigger_stages; @@ -592,6 +634,7 @@ static struct DSL_context *DSCope_dev_new(void) devc->trigger_hrate = 0; devc->zero = FALSE; devc->data_lock = FALSE; + devc->cali = FALSE; return devc; } @@ -606,6 +649,74 @@ static int init(struct sr_context *sr_ctx) return std_hw_init(sr_ctx, di, LOG_PREFIX); } + +static struct DSL_vga* get_vga_ptr(struct sr_dev_inst *sdi) +{ + struct DSL_vga *vga_ptr = NULL; + if (strcmp(sdi->model, "DSCope") == 0) + vga_ptr = DSCope_vga; + else if (strcmp(sdi->model, "DSCope20") == 0) + vga_ptr = DSCope20_vga; + + return vga_ptr; +} + +static uint16_t get_default_trans(struct sr_dev_inst *sdi) +{ + uint16_t trans = 1; + if (strcmp(sdi->model, "DSCope") == 0) + trans = DSCOPE_DEFAULT_TRANS; + else if (strcmp(sdi->model, "DSCope20") == 0) + trans = DSCOPE20_DEFAULT_TRANS; + + return trans; +} + +static uint16_t get_default_voff(struct sr_dev_inst *sdi, int ch_index) +{ + uint16_t voff = 0; + if (strcmp(sdi->model, "DSCope") == 0) + voff = DSCOPE_DEFAULT_VOFF; + else if (strcmp(sdi->model, "DSCope20") == 0) + if (ch_index == 1) + voff = CALI_VOFF_RANGE - DSCOPE20_DEFAULT_VOFF; + else + voff = DSCOPE20_DEFAULT_VOFF; + + return voff; +} + +static uint64_t get_default_vgain(struct sr_dev_inst *sdi, int num) +{ + uint64_t vgain = 0; + if (strcmp(sdi->model, "DSCope") == 0) { + assert(num < sizeof(DSCOPE_DEFAULT_VGAIN)); + vgain = DSCOPE_DEFAULT_VGAIN[num]; + } + else if (strcmp(sdi->model, "DSCope20") == 0) { + assert(num < sizeof(DSCOPE20_DEFAULT_VGAIN)); + vgain = DSCOPE20_DEFAULT_VGAIN[num]; + } + + return vgain; +} + +static int probe_init(struct sr_dev_inst *sdi) +{ + GList *l; + for (l = sdi->channels; l; l = l->next) { + struct sr_channel *probe = (struct sr_channel *)l->data; + if (sdi->mode == DSO) { + probe->vdiv = 1000; + probe->vfactor = 1; + probe->vpos = 0; + probe->coupling = SR_DC_COUPLING; + probe->trig_value = 0x80; + probe->vpos_trans = get_default_trans(sdi); + } + } +} + static int set_probes(struct sr_dev_inst *sdi, int num_probes) { uint16_t j; @@ -615,15 +726,9 @@ static int set_probes(struct sr_dev_inst *sdi, int num_probes) if (!(probe = sr_channel_new(j, (sdi->mode == LOGIC) ? SR_CHANNEL_LOGIC : ((sdi->mode == DSO) ? SR_CHANNEL_DSO : SR_CHANNEL_ANALOG), TRUE, probe_names[j]))) return SR_ERR; - if (sdi->mode == DSO) { - probe->vdiv = 1000; - probe->vfactor = 1; - probe->vpos = 0; - probe->coupling = SR_DC_COUPLING; - probe->trig_value = 0x80; - } sdi->channels = g_slist_append(sdi->channels, probe); } + probe_init(sdi); return SR_OK; } @@ -785,15 +890,66 @@ static GSList *dev_mode_list(const struct sr_dev_inst *sdi) return l; } +static uint64_t dso_vga(struct sr_dev_inst *sdi, struct sr_channel* ch) +{ + int i; + struct DSL_vga *vga_ptr = get_vga_ptr(sdi); + for (i = 0; vga_ptr && (vga_ptr+i)->key; i++) { + if ((vga_ptr+i)->key == ch->vdiv) + return (ch->index == 0) ? (vga_ptr+i)->vgain0 : (vga_ptr+i)->vgain1; + } + + return 0; +} + +static uint64_t dso_voff(struct sr_dev_inst *sdi, struct sr_channel* ch) +{ + int i; + struct DSL_vga *vga_ptr = get_vga_ptr(sdi); + for (i = 0; vga_ptr && (vga_ptr+i)->key; i++) { + if ((vga_ptr+i)->key == ch->vdiv) + return (ch->index == 0) ? (vga_ptr+i)->voff0 : (vga_ptr+i)->voff1; + } + return 0; +} + +static uint64_t dso_vpos(struct sr_dev_inst *sdi, struct sr_channel* ch) +{ + uint64_t vpos; + int vpos_coarse, vpos_fine; + int trans_coarse, trans_fine; + struct DSL_context *devc = sdi->priv; + const double voltage = (devc->zero && devc->zero_comb == -1) ? 0 : ch->vpos; + if (strcmp(sdi->model, "DSCope") == 0) { + trans_coarse = (ch->vpos_trans & 0xFF00) >> 8; + trans_fine = (ch->vpos_trans & 0x00FF); + if (ch->vdiv < 500) { + vpos_coarse = floor(-voltage*DSCOPE_TRANS_CMULTI/trans_coarse + 0.5); + vpos_fine = floor((voltage + vpos_coarse*trans_coarse/DSCOPE_TRANS_CMULTI)*1000.0/trans_fine + 0.5); + } else { + vpos_coarse = floor(-voltage/trans_coarse + 0.5); + vpos_fine = floor((voltage + vpos_coarse*trans_coarse)*DSCOPE_TRANS_FMULTI/trans_fine + 0.5); + } + //vpos = (vpos_coarse << 16) + vpos_fine; + } else if (strcmp(sdi->model, "DSCope20") == 0) { + vpos = ((ch->vdiv*5.0) - voltage)/(ch->vdiv*10.0)*ch->vpos_trans; + } + + const uint64_t voff = dso_voff(sdi, ch); + if (strcmp(sdi->model, "DSCope") == 0) + return ((vpos_coarse+DSCOPE_CONSTANT_BIAS+(voff>>10)) << 16)+vpos_fine+(voff&0x03ff); + else if (strcmp(sdi->model, "DSCope20") == 0) + return vpos+voff; + else + return 0; +} + static uint64_t dso_cmd_gen(struct sr_dev_inst *sdi, struct sr_channel* ch, int id) { struct DSL_context *devc; uint64_t cmd = 0; int channel_cnt = 0; - uint16_t vpos_coarse; - uint16_t vpos_fine; - gboolean vpos_coarse_neg; - gboolean vpos_fine_neg; + uint64_t vpos; GSList *l; const int ch_bit = 7; @@ -806,59 +962,36 @@ static uint64_t dso_cmd_gen(struct sr_dev_inst *sdi, struct sr_channel* ch, int struct sr_channel *probe = (struct sr_channel *)l->data; channel_cnt += probe->enabled; } - if (channel_cnt == 1) { + if (devc->zero || channel_cnt == 2) { + cmd += 0x0E00; + //cmd += 0x000; + } else if (channel_cnt == 1) { if (((ch->index == 0) && ch->enabled) || ((ch->index == 1) && !ch->enabled)) cmd += 0x1600; else if (((ch->index == 1) && ch->enabled) || ((ch->index == 0) && !ch->enabled)) cmd += 0x1A00; - } else if (channel_cnt == 2) { - cmd += 0x0E00; - //cmd += 0x000; } else { return 0x0; } cmd += ch->index << ch_bit; - if (ch->coupling == SR_GND_COUPLING) - cmd &= 0xFFFFFDFF; - else if (ch->coupling == SR_DC_COUPLING) + if (devc->zero || ch->coupling == SR_DC_COUPLING) cmd += 0x100; + else if (ch->coupling == SR_GND_COUPLING) + cmd &= 0xFFFFFDFF; break; case SR_CONF_VDIV: case SR_CONF_TIMEBASE: cmd += 0x8; cmd += ch->index << ch_bit; - // --VDBS - switch(ch->vdiv){ - case 5: cmd += 0x170000; break; - case 10: cmd += 0x162800; break; - case 20: cmd += 0x14D000; break; - case 50: cmd += 0x12E800; break; - case 100: cmd += 0x118000; break; - case 200: cmd += 0x101800; break; - case 500: cmd += 0x2E800; break; - case 1000: cmd += 0x18000; break; - case 2000: cmd += 0x01800; break; - case 5000: cmd += 0x00000; break; - default: cmd += 0x0; break; - } + // --VGAIN + cmd += dso_vga(sdi, ch); break; case SR_CONF_VPOS: cmd += 0x10; cmd += ch->index << ch_bit; - if (ch->vdiv < 500) { - vpos_coarse_neg = (ch->vpos < 0); - vpos_coarse = (uint16_t)(abs(ch->vpos)/(2*VPOS_STEP) + 0.5) * 4; - vpos_fine_neg = vpos_coarse_neg ^ ((abs(ch->vpos) < vpos_coarse*0.5*VPOS_STEP)); - vpos_fine = (uint16_t)(abs((abs(ch->vpos) - vpos_coarse*0.5*VPOS_STEP))/(2*VPOS_MINISTEP) + 0.5); - } else { - vpos_coarse_neg = (ch->vpos < 0); - vpos_coarse = (uint16_t)(abs(ch->vpos)/(20*VPOS_STEP) + 0.5) * 4; - vpos_fine_neg = vpos_coarse_neg ^ ((abs(ch->vpos) < vpos_coarse*5*VPOS_STEP)); - vpos_fine = (uint16_t)(abs((abs(ch->vpos) - vpos_coarse*5*VPOS_STEP))/(20*VPOS_MINISTEP) + 0.5); - } - cmd += (vpos_fine_neg << 31) + (vpos_fine << 20) + - (vpos_coarse_neg << 19) + (vpos_coarse << 8); + vpos = dso_vpos(sdi, ch); + cmd += (vpos << 8); break; case SR_CONF_SAMPLERATE: for (l = sdi->channels; l; l = l->next) { @@ -879,7 +1012,7 @@ static uint64_t dso_cmd_gen(struct sr_dev_inst *sdi, struct sr_channel* ch, int break; case SR_CONF_TRIGGER_SOURCE: cmd += 0x30; - cmd += devc->trigger_source << 8; + cmd += devc->zero ? 0x0 : devc->trigger_source << 8; break; case SR_CONF_TRIGGER_VALUE: cmd += 0x38; @@ -888,28 +1021,6 @@ static uint64_t dso_cmd_gen(struct sr_dev_inst *sdi, struct sr_channel* ch, int cmd += probe->trig_value << (8 * (probe->index + 1)); } break; - case SR_CONF_ZERO_SET: - cmd += 0x40; - cmd += ch->index << ch_bit; - cmd += ((uint64_t)zero_info.vpos_l << 8); - cmd += ((uint64_t)(zero_info.vpos_h & 0x3) << 16); - cmd += ((uint64_t)zero_info.voff_l << 24); - cmd += ((uint64_t)(zero_info.voff_h & 0x3) << 32); - cmd += ((uint64_t)zero_info.vcntr_l << 40); - cmd += ((uint64_t)(zero_info.vcntr_h & 0x3) << 48); - cmd += ((uint64_t)zero_info.adc_off << 56); - break; - case SR_CONF_COMB_SET: - cmd += 0x48; - cmd += ((uint64_t)comb_info.comb0_low_off << 8); - cmd += ((uint64_t)comb_info.comb0_hig_off << 16); - cmd += ((uint64_t)comb_info.comb1_low_off << 24); - cmd += ((uint64_t)comb_info.comb1_hig_off << 32); - cmd += ((uint64_t)comb_info.comb_sign << 40); - break; - case SR_CONF_ZERO_OVER: - cmd += 0x50; - break; case SR_CONF_TRIGGER_HOLDOFF: cmd += 0x58; cmd += ((uint64_t)devc->trigger_holdoff << 8); @@ -918,214 +1029,72 @@ static uint64_t dso_cmd_gen(struct sr_dev_inst *sdi, struct sr_channel* ch, int cmd = 0xa5a5a500; break; default: - cmd = 0x00000000; + cmd = 0xFFFFFFFF; } return cmd; } -static int dev_open(struct sr_dev_inst *sdi) +static gboolean dso_load_eep(struct sr_dev_inst *sdi, struct sr_channel *probe) { - struct sr_usb_dev_inst *usb; - struct DSL_context *devc; - int ret; - int64_t timediff_us, timediff_ms; - - devc = sdi->priv; - usb = sdi->conn; - - /* - * If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS - * milliseconds for the FX2 to renumerate. - */ - ret = SR_ERR; - if (devc->fw_updated > 0) { - sr_info("Waiting for device to reset."); - /* Takes >= 300ms for the FX2 to be gone from the USB bus. */ - g_usleep(300 * 1000); - timediff_ms = 0; - while (timediff_ms < MAX_RENUM_DELAY_MS) { - if ((ret = DSCope_dev_open(sdi)) == SR_OK) - break; - g_usleep(100 * 1000); - - timediff_us = g_get_monotonic_time() - devc->fw_updated; - timediff_ms = timediff_us / 1000; - sr_spew("Waited %" PRIi64 "ms.", timediff_ms); - } - if (ret != SR_OK) { - sr_err("Device failed to renumerate."); - return SR_ERR; - } - sr_info("Device came back after %" PRIi64 "ms.", timediff_ms); - } else { - sr_info("Firmware upload was not needed."); - ret = DSCope_dev_open(sdi); - } - - if (ret != SR_OK) { - sr_err("Unable to open device."); - return SR_ERR; - } - - ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE); - if (ret != 0) { - switch(ret) { - case LIBUSB_ERROR_BUSY: - sr_err("Unable to claim USB interface. Another " - "program or driver has already claimed it."); - break; - case LIBUSB_ERROR_NO_DEVICE: - sr_err("Device has been disconnected."); - break; - default: - sr_err("Unable to claim interface: %s.", - libusb_error_name(ret)); - break; - } - - return SR_ERR; - } - - if ((ret = command_fpga_config(usb->devhdl)) != SR_OK) { - sr_err("Send FPGA configure command failed!"); + int ret, i; + struct sr_usb_dev_inst *usb = sdi->conn; + struct cmd_zero_info zero_info; + uint8_t dst_addr = (zero_base_addr + + probe->index * (sizeof(struct cmd_zero_info) + sizeof(struct cmd_vga_info))); + zero_info.zero_addr = dst_addr; + if ((ret = command_rd_nvm(usb->devhdl, (unsigned char *)&zero_info, zero_info.zero_addr, sizeof(struct cmd_zero_info))) != SR_OK) { + return FALSE; + sr_err("Send Get Zero command failed!"); } else { - /* Takes >= 10ms for the FX2 to be ready for FPGA configure. */ - g_usleep(10 * 1000); - char *fpga_bit = malloc(strlen(config_path)+strlen(devc->profile->fpga_bit33)+1); - if (fpga_bit == NULL) - return SR_ERR_MALLOC; - strcpy(fpga_bit, config_path); - strcat(fpga_bit, devc->profile->fpga_bit33); - ret = fpga_config(usb->devhdl, fpga_bit); - if (ret != SR_OK) { - sr_err("Configure FPGA failed!"); - } - } - - if (sdi->mode == DSO) { - GSList *l; - for(l = sdi->channels; l; l = l->next) { - struct sr_channel *probe = (struct sr_channel *)l->data; - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe, SR_CONF_COUPLING)); - if (ret != SR_OK) { - sr_err("DSO set coupling of channel %d command failed!", probe->index); - return ret; - } - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe, SR_CONF_VDIV)); - if (ret != SR_OK) { - sr_err("Set VDIV of channel %d command failed!", probe->index); - return ret; - } - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe, SR_CONF_VPOS)); - if (ret != SR_OK) { - sr_err("Set VDIV of channel %d command failed!", probe->index); - return ret; - } - } - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, 0, SR_CONF_SAMPLERATE)); - if (ret != SR_OK) { - sr_err("Set Sample Rate command failed!"); - return ret; - } - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_HORIZ_TRIGGERPOS)); - if (ret != SR_OK) { - sr_err("Set Horiz Trigger Position command failed!"); - return ret; - } - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_TRIGGER_HOLDOFF)); - if (ret != SR_OK) { - sr_err("Set Trigger Holdoff Time command failed!"); - return ret; - } - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_TRIGGER_SLOPE)); - if (ret != SR_OK) { - sr_err("Set Trigger Slope command failed!"); - return ret; - } - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_TRIGGER_SOURCE)); - if (ret != SR_OK) { - sr_err("Set Trigger Source command failed!"); - return ret; - } - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_TRIGGER_VALUE)); - if (ret != SR_OK) { - sr_err("Set Trigger Value command failed!"); - return ret; - } - } - - GSList *l; - for(l = sdi->channels; l; l = l->next) { - struct sr_channel *probe = (struct sr_channel *)l->data; - zero_info.zero_addr = (zero_base_addr + probe->index * sizeof(struct cmd_zero_info)); - if ((ret = command_rd_nvm(usb->devhdl, (unsigned char *)&zero_info, zero_info.zero_addr, sizeof(struct cmd_zero_info))) != SR_OK) { - sr_err("Send Get Zero command failed!"); + if (zero_info.zero_addr == dst_addr) { + uint8_t* voff_ptr = &zero_info.zero_addr + 1; + struct DSL_vga *vga_ptr = get_vga_ptr(sdi); + for (i = 0; vga_ptr && (vga_ptr+i)->key; i++) { + if (probe->index == 0) + (vga_ptr+i)->voff0 = (*(voff_ptr + 2*i+1) << 8) + *(voff_ptr + 2*i); + else + (vga_ptr+i)->voff1 = (*(voff_ptr + 2*i+1) << 8) + *(voff_ptr + 2*i); + } + if (i != 0) { + probe->comb_diff_top = *(voff_ptr + 2*i); + probe->comb_diff_bom = *(voff_ptr + 2*i + 1); + probe->vpos_trans = *(voff_ptr + 2*i + 2) + (*(voff_ptr + 2*i + 3) << 8); + const double slope = (probe->comb_diff_bom - probe->comb_diff_top)/(2.0*255.0); + for (i = 0; i < 256; i++) { + ret = command_wr_reg(usb->devhdl, i, COMB_ADDR + probe->index*2); + int value = i+i*slope+probe->comb_diff_top*0.5+0.5; + value = (value < 0) ? 0 : + (value > 255) ? 255 : value; + ret = command_wr_reg(usb->devhdl, value, COMB_ADDR + probe->index*2 + 1); + } + } } else { - if (zero_info.zero_addr == (zero_base_addr + probe->index * sizeof(struct cmd_zero_info))) { - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe, SR_CONF_ZERO_SET)); - if (ret != SR_OK) { - sr_err("Set Zero command failed!"); - return ret; - } - } else { - devc->zero = TRUE; - sr_info("Zero have not been setted!"); - } + return FALSE; } } - comb_info.comb_addr = comb_base_addr; - if ((ret = command_rd_nvm(usb->devhdl, (unsigned char *)&comb_info, comb_info.comb_addr, sizeof(struct cmd_comb_info))) != SR_OK) { - sr_err("Send Get Comb Command Failed!"); + struct cmd_vga_info vga_info; + vga_info.vga_addr = dst_addr + sizeof(struct cmd_zero_info); + if ((ret = command_rd_nvm(usb->devhdl, (unsigned char *)&vga_info, vga_info.vga_addr, sizeof(struct cmd_vga_info))) != SR_OK) { + return FALSE; + sr_err("Send Get Zero command failed!"); } else { - if (comb_info.comb_addr == comb_base_addr) { - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_COMB_SET)); - if (ret != SR_OK) { - sr_err("Set Comb command failed!"); - return ret; - } + if (vga_info.vga_addr == dst_addr + sizeof(struct cmd_zero_info)) { + uint16_t* vgain_ptr = &vga_info.vga0; + struct DSL_vga *vga_ptr = get_vga_ptr(sdi); + for (i = 0; vga_ptr && (vga_ptr+i)->key; i++) { + if (probe->index == 0) + (vga_ptr+i)->vgain0 = *(vgain_ptr + i) << 8; + else + (vga_ptr+i)->vgain1 = *(vgain_ptr + i) << 8; + } } else { - devc->zero = TRUE; - sr_info("Comb have not been setted!"); + return FALSE; } } - return SR_OK; -} - -static int dev_close(struct sr_dev_inst *sdi) -{ - struct sr_usb_dev_inst *usb; - - usb = sdi->conn; - if (usb->devhdl == NULL) - return SR_ERR; - - sr_info("DSCope: Closing device %d on %d.%d interface %d.", - sdi->index, usb->bus, usb->address, USB_INTERFACE); - libusb_release_interface(usb->devhdl, USB_INTERFACE); - libusb_close(usb->devhdl); - usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; - - return SR_OK; -} - -static int cleanup(void) -{ - int ret; - struct drv_context *drvc; - - if (!(drvc = di->priv)) - return SR_OK; - - ret = dev_clear(); - - g_free(drvc); - di->priv = NULL; - - return ret; + return TRUE; } static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, @@ -1134,22 +1103,24 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, { struct DSL_context *devc; struct sr_usb_dev_inst *usb; - char str[128]; + char str[128]; + int i; + struct DSL_vga *vga_ptr; (void)cg; - switch (id) { + switch (id) { case SR_CONF_CONN: - if (!sdi || !sdi->conn) + if (!sdi || !sdi->conn) return SR_ERR_ARG; - usb = sdi->conn; - if (usb->address == 255) - /* Device still needs to re-enumerate after firmware - * upload, so we don't know its (future) address. */ + usb = sdi->conn; + if (usb->address == 255) + /* Device still needs to re-enumerate after firmware + * upload, so we don't know its (future) address. */ return SR_ERR; - snprintf(str, 128, "%d.%d", usb->bus, usb->address); + snprintf(str, 128, "%d.%d", usb->bus, usb->address); *data = g_variant_new_string(str); - break; + break; case SR_CONF_LIMIT_SAMPLES: if (!sdi) return SR_ERR; @@ -1157,11 +1128,11 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, *data = g_variant_new_uint64(devc->limit_samples); break; case SR_CONF_SAMPLERATE: - if (!sdi) + if (!sdi) return SR_ERR; - devc = sdi->priv; - *data = g_variant_new_uint64(devc->cur_samplerate); - break; + devc = sdi->priv; + *data = g_variant_new_uint64(devc->cur_samplerate); + break; case SR_CONF_CLOCK_TYPE: if (!sdi) return SR_ERR; @@ -1270,6 +1241,12 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, devc = sdi->priv; *data = g_variant_new_boolean(devc->zero); break; + case SR_CONF_CALI: + if (!sdi) + return SR_ERR; + devc = sdi->priv; + *data = g_variant_new_boolean(devc->cali); + break; case SR_CONF_STREAM: if (!sdi) return SR_ERR; @@ -1305,9 +1282,60 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, return SR_ERR; *data = g_variant_new_uint64(DSCOPE_MAX_DEPTH); break; + case SR_CONF_VGAIN: + if (!sdi || !ch) + return SR_ERR; + *data = g_variant_new_uint64(dso_vga(sdi, ch)>>8); + break; + case SR_CONF_VGAIN_DEFAULT: + if (!sdi || !ch) + return SR_ERR; + vga_ptr = get_vga_ptr(sdi); + for (i = 0; vga_ptr && (vga_ptr+i)->key; i++) { + if ((vga_ptr+i)->key == ch->vdiv) + break; + } + *data = g_variant_new_uint64(get_default_vgain(sdi, i)>>8); + break; + case SR_CONF_VGAIN_RANGE: + if (!sdi) + return SR_ERR; + vga_ptr = get_vga_ptr(sdi); + for (i = 0; vga_ptr && (vga_ptr+i)->key; i++) { + if ((vga_ptr+i)->key == ch->vdiv) + break; + } + uint16_t vgain_default= (get_default_vgain(sdi, i)>>8) & 0x0FFF; + *data = g_variant_new_uint16(min(CALI_VGAIN_RANGE, vgain_default*2)); + break; + case SR_CONF_VOFF: + if (!sdi || !ch) + return SR_ERR; + uint16_t voff = dso_voff(sdi, ch); + uint16_t voff_default = get_default_voff(sdi, ch->index); + if (strcmp(sdi->model, "DSCope") == 0) { + int voff_skew_coarse = (voff >> 10) - (voff_default >> 10); + int voff_skew_fine = (voff & 0x03ff) - (voff_default & 0x03ff); + double trans_coarse = (ch->vdiv < 500) ? (ch->vpos_trans >> 8)/DSCOPE_TRANS_CMULTI : (ch->vpos_trans >> 8); + double trans_fine = (ch->vdiv < 500) ? (ch->vpos_trans & 0x00ff) / 1000.0 : (ch->vpos_trans & 0x00ff) / DSCOPE_TRANS_FMULTI; + double voff_rate = (voff_skew_coarse*trans_coarse - voff_skew_fine*trans_fine) / ch->vdiv; + voff = (voff_rate * 0.5 + 0.5) * CALI_VOFF_RANGE; + } + *data = g_variant_new_uint16(voff); + break; + case SR_CONF_VOFF_DEFAULT: + if (!sdi || !ch) + return SR_ERR; + *data = g_variant_new_uint16(get_default_voff(sdi, ch->index)); + break; + case SR_CONF_VOFF_RANGE: + if (!sdi) + return SR_ERR; + *data = g_variant_new_uint16(CALI_VOFF_RANGE); + break; default: return SR_ERR_NA; - } + } return SR_OK; } @@ -1326,11 +1354,11 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, if (sdi->status != SR_ST_ACTIVE) return SR_ERR; - devc = sdi->priv; + devc = sdi->priv; usb = sdi->conn; if (id == SR_CONF_SAMPLERATE) { - devc->cur_samplerate = g_variant_get_uint64(data); + devc->cur_samplerate = g_variant_get_uint64(data); if (sdi->mode == LOGIC) { if (devc->cur_samplerate >= SR_MHZ(200)) { adjust_probes(sdi, SR_MHZ(1600)/devc->cur_samplerate); @@ -1364,7 +1392,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, } ret = SR_OK; } else if (id == SR_CONF_LIMIT_SAMPLES) { - devc->limit_samples = g_variant_get_uint64(data); + devc->limit_samples = g_variant_get_uint64(data); ret = SR_OK; } else if (id == SR_CONF_DEVICE_MODE) { sdi->mode = g_variant_get_int16(data); @@ -1572,62 +1600,162 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, __func__, devc->trigger_holdoff); } else if (id == SR_CONF_ZERO) { devc->zero = g_variant_get_boolean(data); - } else if (id == SR_CONF_ZERO_SET) { + if (devc->zero) { + devc->zero_stage = -1; + devc->zero_pcnt = 0; + devc->zero_comb = -1; + GList *l; + int i; + struct DSL_vga *vga_ptr = get_vga_ptr(sdi); + for(l = sdi->channels; l; l = l->next) { + struct sr_channel *probe = (struct sr_channel *)l->data; + probe->vpos_trans = get_default_trans(sdi); + } + for (i = 0; vga_ptr && (vga_ptr+i)->key; i++) { + (vga_ptr+i)->vgain0 = get_default_vgain(sdi, i); + (vga_ptr+i)->vgain1 = get_default_vgain(sdi, i); + (vga_ptr+i)->voff0 = get_default_voff(sdi, 0); + (vga_ptr+i)->voff1 = get_default_voff(sdi, 1); + } + } + } else if (id == SR_CONF_CALI) { + devc->cali = g_variant_get_boolean(data); + } else if (id == SR_CONF_ZERO_LOAD) { GSList *l; for(l = sdi->channels; l; l = l->next) { struct sr_channel *probe = (struct sr_channel *)l->data; - zero_info.zero_addr = zero_base_addr + probe->index * sizeof(struct cmd_zero_info); - zero_info.vpos_l = (probe->index == 0) ? mstatus.ch0_vpos_mid : mstatus.ch1_vpos_mid; - zero_info.vpos_h = (probe->index == 0) ? mstatus.ch0_vpos_mid >> 8 : mstatus.ch1_vpos_mid >> 8; - zero_info.voff_l = (probe->index == 0) ? mstatus.ch0_voff_mid : mstatus.ch1_voff_mid; - zero_info.voff_h = (probe->index == 0) ? mstatus.ch0_voff_mid >> 8 : mstatus.ch1_voff_mid >> 8; - zero_info.vcntr_l = (probe->index == 0) ? mstatus.ch0_vcntr : mstatus.ch1_vcntr; - zero_info.vcntr_h = (probe->index == 0) ? mstatus.ch0_vcntr >> 8 : mstatus.ch1_vcntr >> 8; - zero_info.adc_off = (probe->index == 0) ? mstatus.ch0_adc_off + (mstatus.ch0_adc_sign << 7) : mstatus.ch1_adc_off + (mstatus.ch1_adc_sign << 7); - ret = command_wr_nvm(usb->devhdl, (unsigned char *)&zero_info, sizeof(struct cmd_zero_info)); - if (ret != SR_OK) - sr_err("DSO channel %d Set Zero command failed!", probe->index); + if (!dso_load_eep(sdi, probe)) { + config_set(SR_CONF_ZERO, g_variant_new_boolean(TRUE), sdi, NULL, NULL); + sr_info("Zero have not been setted!"); + break; + } } - comb_info.comb_addr = comb_base_addr; - comb_info.comb0_low_off = mstatus.comb0_off; - comb_info.comb0_hig_off = mstatus.comb0_off >> 8; - comb_info.comb1_low_off = mstatus.comb1_off; - comb_info.comb1_hig_off = mstatus.comb1_off >> 8; - comb_info.comb_sign = mstatus.comb_sign; - ret = command_wr_nvm(usb->devhdl, (unsigned char *)&comb_info, sizeof(struct cmd_comb_info)); - if (ret != SR_OK) - sr_err("DSO Set Comb command failed!"); - else - devc->zero = FALSE; - } else { - ret = SR_ERR_NA; - } + } else if (id == SR_CONF_ZERO_SET) { + GSList *l; + struct cmd_zero_info zero_info; + struct cmd_vga_info vga_info; + for(l = sdi->channels; l; l = l->next) { + struct sr_channel *probe = (struct sr_channel *)l->data; + zero_info.zero_addr = zero_base_addr + + probe->index * (sizeof(struct cmd_zero_info) + sizeof(struct cmd_vga_info)); + int i; + struct DSL_vga *vga_ptr = get_vga_ptr(sdi); + uint8_t *voff_ptr = &zero_info.zero_addr + 1; + for (i = 0; vga_ptr && (vga_ptr+i)->key; i++) { + *(voff_ptr+2*i) = ((probe->index == 0) ? (vga_ptr+i)->voff0 : (vga_ptr+i)->voff1) & 0x00ff; + *(voff_ptr+2*i+1) = ((probe->index == 0) ? (vga_ptr+i)->voff0 : (vga_ptr+i)->voff1) >> 8; + } + if (i != 0) { + *(voff_ptr+2*i) = probe->comb_diff_top; + *(voff_ptr+2*i+1) = probe->comb_diff_bom; + *(voff_ptr+2*i+2) = (probe->vpos_trans&0x00FF); + *(voff_ptr+2*i+3) = (probe->vpos_trans>>8); - return ret; + vga_info.vga_addr = zero_info.zero_addr + sizeof(struct cmd_zero_info); + uint16_t *vgain_ptr = &vga_info.vga0; + for (i=0; vga_ptr && (vga_ptr+i)->key; i++){ + *(vgain_ptr+i) = ((probe->index == 0) ? (vga_ptr+i)->vgain0 : (vga_ptr+i)->vgain1) >> 8; + } + ret = command_wr_reg(usb->devhdl, 0, EEWP_ADDR); + if (ret == SR_OK) + ret = command_wr_nvm(usb->devhdl, (unsigned char *)&zero_info, sizeof(struct cmd_zero_info)); + if (ret == SR_OK) + ret = command_wr_nvm(usb->devhdl, (unsigned char *)&vga_info, sizeof(struct cmd_vga_info)); + if (ret == SR_OK) + ret = command_wr_reg(usb->devhdl, 1, EEWP_ADDR); + if (ret != SR_OK) + sr_err("DSO channel %d Set Zero command failed!", probe->index); + + const double slope = (probe->comb_diff_bom - probe->comb_diff_top)/(2.0*255.0); + for (i = 0; i < 256; i++) { + ret = command_wr_reg(usb->devhdl, i, COMB_ADDR + probe->index*2); + int value = i+i*slope+probe->comb_diff_top*0.5+0.5; + value = (value < 0) ? 0 : + (value > 255) ? 255 : value; + ret = command_wr_reg(usb->devhdl, value, COMB_ADDR + probe->index*2 + 1); + } + } + } + } else if (id == SR_CONF_VOCM) { + const uint8_t vocm = g_variant_get_byte(data); + ret = command_wr_reg(usb->devhdl, vocm, COMB_ADDR+4); + } else if (id == SR_CONF_VGAIN) { + const uint64_t vgain = g_variant_get_uint64(data) << 8; + int i; + struct DSL_vga *vga_ptr = get_vga_ptr(sdi); + for (i = 0; vga_ptr && (vga_ptr+i)->key; i++) { + if ((vga_ptr+i)->key == ch->vdiv) + if (ch->index == 0) + (vga_ptr+i)->vgain0 = vgain; + else if (ch->index == 1) + (vga_ptr+i)->vgain1 = vgain; + } + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, ch, SR_CONF_VDIV)); + if (ret == SR_OK) + sr_dbg("%s: setting VDIV of channel %d to %d mv", + __func__, ch->index, ch->vdiv); + else + sr_dbg("%s: setting VDIV of channel %d to %d mv failed", + __func__, ch->index, ch->vdiv); + } else if (id == SR_CONF_VOFF) { + uint16_t voff = g_variant_get_uint16(data); + if (strcmp(sdi->model, "DSCope") == 0) { + double voltage_off = (2.0 * voff / CALI_VOFF_RANGE - 1) * ch->vdiv; + double trans_coarse = (ch->vdiv < 500) ? (ch->vpos_trans >> 8)/DSCOPE_TRANS_CMULTI : (ch->vpos_trans >> 8); + double trans_fine = (ch->vdiv < 500) ? (ch->vpos_trans & 0x00ff) / 1000.0 : (ch->vpos_trans & 0x00ff) / DSCOPE_TRANS_FMULTI; + + uint16_t default_voff = get_default_voff(sdi, ch->index); + int voff_coarse = floor(voltage_off / trans_coarse + 0.5); + int voff_fine = floor(-(voltage_off - voff_coarse*trans_coarse)/trans_fine + 0.5); + voff_coarse = (default_voff >> 10) + voff_coarse; + voff_fine = (default_voff&0x03ff) + voff_fine; + voff = (voff_coarse << 10) + voff_fine; + } + int i; + struct DSL_vga *vga_ptr = get_vga_ptr(sdi); + for (i = 0; vga_ptr && (vga_ptr+i)->key; i++) { + if ((vga_ptr+i)->key == ch->vdiv) + if (ch->index == 0) + (vga_ptr+i)->voff0 = voff; + else if (ch->index == 1) + (vga_ptr+i)->voff1 = voff; + } + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, ch, SR_CONF_VPOS)); + if (ret == SR_OK) + sr_dbg("%s: setting VPOS of channel %d to %lf mv", + __func__, ch->index, ch->vpos); + else + sr_dbg("%s: setting VPOS of channel %d to %lf mv failed", + __func__, ch->index, ch->vpos); + }else { + ret = SR_ERR_NA; + } + + return ret; } static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - GVariant *gvar; - GVariantBuilder gvb; + GVariant *gvar; + GVariantBuilder gvb; - (void)sdi; + (void)sdi; (void)cg; - switch (key) { + switch (key) { case SR_CONF_SCAN_OPTIONS: // *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, // hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t)); *data = g_variant_new_from_data(G_VARIANT_TYPE("ai"), hwopts, ARRAY_SIZE(hwopts)*sizeof(int32_t), TRUE, NULL, NULL); - break; + break; case SR_CONF_DEVICE_OPTIONS: // *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, // hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); *data = g_variant_new_from_data(G_VARIANT_TYPE("ai"), hwcaps, ARRAY_SIZE(hwcaps)*sizeof(int32_t), TRUE, NULL, NULL); - break; + break; case SR_CONF_DEVICE_CONFIGS: // *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, // hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); @@ -1639,14 +1767,14 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, sessions, ARRAY_SIZE(sessions)*sizeof(int32_t), TRUE, NULL, NULL); break; case SR_CONF_SAMPLERATE: - g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); + g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); // gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates, // ARRAY_SIZE(samplerates), sizeof(uint64_t)); gvar = g_variant_new_from_data(G_VARIANT_TYPE("at"), samplerates, ARRAY_SIZE(samplerates)*sizeof(uint64_t), TRUE, NULL, NULL); g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); - *data = g_variant_builder_end(&gvb); - break; + *data = g_variant_builder_end(&gvb); + break; case SR_CONF_LIMIT_SAMPLES: g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); gvar = g_variant_new_from_data(G_VARIANT_TYPE("at"), @@ -1656,7 +1784,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, break; case SR_CONF_TRIGGER_TYPE: *data = g_variant_new_string(TRIGGER_TYPE); - break; + break; case SR_CONF_OPERATION_MODE: *data = g_variant_new_strv(opmodes, opmodes_show_count); break; @@ -1666,13 +1794,364 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, case SR_CONF_FILTER: *data = g_variant_new_strv(filters, ARRAY_SIZE(filters)); break; - default: + default: return SR_ERR_NA; - } + } return SR_OK; } +static int dso_init(struct sr_dev_inst *sdi, gboolean from_eep) +{ + int ret, i; + GSList *l; + struct sr_usb_dev_inst *usb = sdi->conn; + gboolean zeroed = TRUE; + + for(l = sdi->channels; l; l = l->next) { + struct sr_channel *probe = (struct sr_channel *)l->data; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe, SR_CONF_COUPLING)); + if (ret != SR_OK) { + sr_err("DSO set coupling of channel %d command failed!", probe->index); + return ret; + } + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe, SR_CONF_VDIV)); + if (ret != SR_OK) { + sr_err("Set VDIV of channel %d command failed!", probe->index); + return ret; + } + if (from_eep && zeroed) { + zeroed = dso_load_eep(sdi, probe); + } + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe, SR_CONF_VPOS)); + if (ret != SR_OK) { + sr_err("Set VPOS of channel %d command failed!", probe->index); + return ret; + } + } + if (!zeroed) { + for(l = sdi->channels; l; l = l->next) { + struct sr_channel *probe = (struct sr_channel *)l->data; + for (i = 0; i < 256; i++) { + ret = command_wr_reg(usb->devhdl, i, COMB_ADDR + probe->index*2); + ret = command_wr_reg(usb->devhdl, i, COMB_ADDR + probe->index*2 + 1); + } + } + config_set(SR_CONF_ZERO, g_variant_new_boolean(TRUE), sdi, NULL, NULL); + sr_info("Zero have not been setted!"); + } + + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, 0, SR_CONF_SAMPLERATE)); + if (ret != SR_OK) { + sr_err("Set Sample Rate command failed!"); + return ret; + } + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_HORIZ_TRIGGERPOS)); + if (ret != SR_OK) { + sr_err("Set Horiz Trigger Position command failed!"); + return ret; + } + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_TRIGGER_HOLDOFF)); + if (ret != SR_OK) { + sr_err("Set Trigger Holdoff Time command failed!"); + return ret; + } + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_TRIGGER_SLOPE)); + if (ret != SR_OK) { + sr_err("Set Trigger Slope command failed!"); + return ret; + } + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_TRIGGER_SOURCE)); + if (ret != SR_OK) { + sr_err("Set Trigger Source command failed!"); + return ret; + } + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_TRIGGER_VALUE)); + if (ret != SR_OK) { + sr_err("Set Trigger Value command failed!"); + return ret; + } + return ret; +} + +static int dso_zero(struct sr_dev_inst *sdi, struct sr_status mstatus) +{ + struct DSL_context *devc = sdi->priv; + struct sr_usb_dev_inst *usb = sdi->conn; + GSList *l; + int ret, i; + static double vpos_back[2]; + static uint64_t vdiv_back[2]; + struct DSL_vga *vga_ptr = get_vga_ptr(sdi); + struct sr_channel *probe0, *probe1; + for(l = sdi->channels; l; l = l->next) { + struct sr_channel *probe = (struct sr_channel *)l->data; + if (probe->index == 0) + probe0 = probe; + if (probe->index == 1) + probe1 = probe; + } + + if (devc->zero_stage == -1) { + // initialize before zero adjustment + if (dso_init(sdi, 0) == SR_OK) + devc->zero_stage = 0; + } else if ((vga_ptr+devc->zero_stage)->key == 0) { + ret = SR_OK; + if (strcmp(sdi->model, "DSCope20") == 0) { + if (devc->zero_pcnt == 0) { + devc->zero_comb = 0; + vpos_back[0] = probe0->vpos; + probe0->vpos = (vga_ptr+devc->zero_stage-1)->key * -4.8; + vdiv_back[0] = probe0->vdiv; + probe0->vdiv = (vga_ptr+devc->zero_stage-1)->key; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe0, SR_CONF_VPOS)); + } else if (devc->zero_pcnt == 4) { + const double voff = 255*0.98 - (mstatus.ch0_max + mstatus.ch0_min) / 2.0; + if (abs(voff) < 0.5) { + probe0->vpos = vpos_back[0]; + } else { + probe0->vpos_trans += voff; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe0, SR_CONF_VPOS)); + devc->zero_pcnt = 1; + } + } else if (devc->zero_pcnt == 5) { + devc->zero_comb = 0; + vpos_back[1] = probe1->vpos; + probe1->vpos = (vga_ptr+devc->zero_stage-1)->key * -4.8; + vdiv_back[1] = probe1->vdiv; + probe1->vdiv = (vga_ptr+devc->zero_stage-1)->key; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe1, SR_CONF_VPOS)); + } else if (devc->zero_pcnt == 9) { + const double voff = 255*0.98 - (mstatus.ch1_max + mstatus.ch1_min) / 2.0; + if (abs(voff) < 0.5) { + probe1->vpos = vpos_back[1]; + } else { + probe1->vpos_trans += voff; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe1, SR_CONF_VPOS)); + devc->zero_pcnt = 6; + } + } + } + + if (devc->zero_pcnt == 10) { + ret = command_wr_reg(usb->devhdl, 0b1101, COMB_ADDR+6); + devc->zero_comb = 0; + vpos_back[0] = probe0->vpos; + probe0->vpos = (vga_ptr+devc->zero_stage-1)->key * 4.5; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe0, SR_CONF_VPOS)); + } else if (devc->zero_pcnt == 15) { + probe0->comb_diff_top = (mstatus.ch0_max - mstatus.ch1_max) + + (mstatus.ch0_min - mstatus.ch1_min); + probe0->vpos = (vga_ptr+devc->zero_stage-1)->key * -4.5; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe0, SR_CONF_VPOS)); + } else if (devc->zero_pcnt == 20) { + probe0->comb_diff_bom = (mstatus.ch0_max - mstatus.ch1_max) + + (mstatus.ch0_min - mstatus.ch1_min); + probe0->vpos = vpos_back[0]; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe0, SR_CONF_VPOS)); + } + + if (devc->zero_pcnt == 25) { + ret = command_wr_reg(usb->devhdl, 0b1110, COMB_ADDR+6); + devc->zero_comb = 1; + vpos_back[1] = probe1->vpos; + probe1->vpos = (vga_ptr+devc->zero_stage-1)->key * 4.5; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe1, SR_CONF_VPOS)); + } else if (devc->zero_pcnt == 30) { + probe1->comb_diff_top = (mstatus.ch1_max - mstatus.ch0_max) + + (mstatus.ch1_min - mstatus.ch0_min); + probe1->vpos = (vga_ptr+devc->zero_stage-1)->key * -4.5; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe1, SR_CONF_VPOS)); + } else if (devc->zero_pcnt == 35) { + probe1->comb_diff_bom = (mstatus.ch1_max - mstatus.ch0_max) + + (mstatus.ch1_min - mstatus.ch0_min); + probe1->vpos = vpos_back[1]; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe1, SR_CONF_VPOS)); + } + + if (devc->zero_pcnt == 40) { + if (strcmp(sdi->model, "DSCope20") == 0) { + probe0->vdiv = vdiv_back[0]; + probe1->vdiv = vdiv_back[1]; + } + ret = command_wr_reg(usb->devhdl, 0b0011, COMB_ADDR+6); + devc->zero = FALSE; + dso_init(sdi, 0); + } + + if (ret == SR_OK) + devc->zero_pcnt++; + } else { + if (devc->zero_pcnt == 0) { + for(l = sdi->channels; l; l = l->next) { + struct sr_channel *probe = (struct sr_channel *)l->data; + uint64_t vdiv_back = probe->vdiv; + probe->vdiv = (vga_ptr+devc->zero_stage)->key; + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe, SR_CONF_VDIV)); + ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe, SR_CONF_VPOS)); + probe->vdiv = vdiv_back; + } + } + + if (devc->zero_pcnt == 4) { + const double voff0 = 255/2.0 - (mstatus.ch0_max + mstatus.ch0_min)/2.0; + const double voff1 = 255/2.0 - (mstatus.ch1_max + mstatus.ch1_min)/2.0; + if (abs(voff0) < 0.5 && abs(voff1) < 0.5) { + devc->zero_stage++; + } else { + if (strcmp(sdi->model, "DSCope") == 0) { + for(l = sdi->channels; l; l = l->next) { + struct sr_channel *probe = (struct sr_channel *)l->data; + double trans_coarse = ((vga_ptr+devc->zero_stage)->key < 500) ? (probe->vpos_trans >> 8)/DSCOPE_TRANS_CMULTI : (probe->vpos_trans >> 8); + double trans_fine = ((vga_ptr+devc->zero_stage)->key < 500) ? (probe->vpos_trans & 0x00ff) / 1000.0 : (probe->vpos_trans & 0x00ff) / DSCOPE_TRANS_FMULTI; + + double voltage_off = ((probe->index == 0) ? voff0 : voff1) * (vga_ptr+devc->zero_stage)->key * 10 / 255.0; + uint16_t last_voff = ((probe->index == 0) ? (vga_ptr+devc->zero_stage)->voff0 : (vga_ptr+devc->zero_stage)->voff1); + int voff_coarse = floor(voltage_off / trans_coarse + 0.5); + int voff_fine = floor(-(voltage_off - voff_coarse*trans_coarse)/trans_fine + 0.5); + voff_coarse = (last_voff >> 10) + voff_coarse; + voff_fine = (last_voff&0x03ff) + voff_fine; + if (probe->index == 0) + (vga_ptr+devc->zero_stage)->voff0 = (voff_coarse << 10) + voff_fine; + else if (probe->index == 1) + (vga_ptr+devc->zero_stage)->voff1 = (voff_coarse << 10) + voff_fine; + } + } else if (strcmp(sdi->model, "DSCope20") == 0) { + (vga_ptr+devc->zero_stage)->voff0 += voff0; + (vga_ptr+devc->zero_stage)->voff1 += voff1; + } + } + devc->zero_pcnt = 0; + } else { + devc->zero_pcnt++; + } + } + + return ret; +} + +static int dev_open(struct sr_dev_inst *sdi) +{ + struct sr_usb_dev_inst *usb; + struct DSL_context *devc; + int ret; + int64_t timediff_us, timediff_ms; + int i; + + devc = sdi->priv; + usb = sdi->conn; + + /* + * If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS + * milliseconds for the FX2 to renumerate. + */ + ret = SR_ERR; + if (devc->fw_updated > 0) { + sr_info("Waiting for device to reset."); + /* Takes >= 300ms for the FX2 to be gone from the USB bus. */ + g_usleep(300 * 1000); + timediff_ms = 0; + while (timediff_ms < MAX_RENUM_DELAY_MS) { + if ((ret = DSCope_dev_open(sdi)) == SR_OK) + break; + g_usleep(100 * 1000); + + timediff_us = g_get_monotonic_time() - devc->fw_updated; + timediff_ms = timediff_us / 1000; + sr_spew("Waited %" PRIi64 "ms.", timediff_ms); + } + if (ret != SR_OK) { + sr_err("Device failed to renumerate."); + return SR_ERR; + } + sr_info("Device came back after %" PRIi64 "ms.", timediff_ms); + } else { + sr_info("Firmware upload was not needed."); + ret = DSCope_dev_open(sdi); + } + + if (ret != SR_OK) { + sr_err("Unable to open device."); + return SR_ERR; + } + + ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE); + if (ret != 0) { + switch(ret) { + case LIBUSB_ERROR_BUSY: + sr_err("Unable to claim USB interface. Another " + "program or driver has already claimed it."); + break; + case LIBUSB_ERROR_NO_DEVICE: + sr_err("Device has been disconnected."); + break; + default: + sr_err("Unable to claim interface: %s.", + libusb_error_name(ret)); + break; + } + + return SR_ERR; + } + + if ((ret = command_fpga_config(usb->devhdl)) != SR_OK) { + sr_err("Send FPGA configure command failed!"); + } else { + /* Takes >= 10ms for the FX2 to be ready for FPGA configure. */ + g_usleep(10 * 1000); + char *fpga_bit = malloc(strlen(config_path)+strlen(devc->profile->fpga_bit33)+1); + if (fpga_bit == NULL) + return SR_ERR_MALLOC; + strcpy(fpga_bit, config_path); + strcat(fpga_bit, devc->profile->fpga_bit33); + ret = fpga_config(usb->devhdl, fpga_bit); + if (ret != SR_OK) { + sr_err("Configure FPGA failed!"); + } + } + + if (sdi->mode == DSO) + dso_init(sdi, 1); + + return SR_OK; +} + +static int dev_close(struct sr_dev_inst *sdi) +{ + struct sr_usb_dev_inst *usb; + + usb = sdi->conn; + if (usb->devhdl == NULL) + return SR_ERR; + + sr_info("DSCope: Closing device %d on %d.%d interface %d.", + sdi->index, usb->bus, usb->address, USB_INTERFACE); + libusb_release_interface(usb->devhdl, USB_INTERFACE); + libusb_close(usb->devhdl); + usb->devhdl = NULL; + sdi->status = SR_ST_INACTIVE; + + return SR_OK; +} + +static int cleanup(void) +{ + int ret; + struct drv_context *drvc; + + if (!(drvc = di->priv)) + return SR_OK; + + ret = dev_clear(); + + g_free(drvc); + di->priv = NULL; + + return ret; +} + + static void abort_acquisition(struct DSL_context *devc) { int i; @@ -1778,7 +2257,7 @@ static struct sr_config * new_config(int key, GVariant *data) static void receive_transfer(struct libusb_transfer *transfer) { - gboolean packet_has_error = FALSE; + gboolean packet_has_error = FALSE; struct sr_datafeed_packet packet; struct sr_datafeed_logic logic; struct sr_datafeed_dso dso; @@ -1920,6 +2399,7 @@ static void receive_transfer(struct libusb_transfer *transfer) uint16_t channel_cnt = 0; uint16_t channel_en_cnt = 0; GSList *l; + int ret; struct sr_dev_inst *sdi = devc->cb_data; for (l = sdi->channels; l; l = l->next) { struct sr_channel *probe = (struct sr_channel *)l->data; @@ -1945,24 +2425,14 @@ static void receive_transfer(struct libusb_transfer *transfer) mstatus.stream_mode = *((const uint32_t*)cur_buf + mstatus_offset/2 + 16/2) & 0x80000000; mstatus.sample_divider = *((const uint32_t*)cur_buf + mstatus_offset/2 + 18/2) & 0x7fffffff; mstatus.sample_divider_tog = *((const uint32_t*)cur_buf + mstatus_offset/2 + 18/2) & 0x80000000; - mstatus.zeroing = (*((const uint16_t*)cur_buf + mstatus_offset + 128) & 0x8000) != 0; - mstatus.ch0_vpos_mid = *((const uint16_t*)cur_buf + mstatus_offset + 128) & 0x7fff; - mstatus.ch0_voff_mid = *((const uint16_t*)cur_buf + mstatus_offset + 129); - mstatus.ch0_vcntr = *((const uint16_t*)cur_buf + mstatus_offset + 130); - mstatus.ch0_adc_off = *((const uint8_t*)cur_buf + mstatus_offset*2 + 131*2); - mstatus.ch0_adc_sign = *((const uint8_t*)cur_buf + mstatus_offset*2 + 131*2+1); - mstatus.ch1_vpos_mid = *((const uint16_t*)cur_buf + mstatus_offset + 132); - mstatus.ch1_voff_mid = *((const uint16_t*)cur_buf + mstatus_offset + 133); - mstatus.ch1_vcntr = *((const uint16_t*)cur_buf + mstatus_offset + 134); - mstatus.ch1_adc_off = *((const uint8_t*)cur_buf + mstatus_offset*2 + 135*2); - mstatus.ch1_adc_sign = *((const uint8_t*)cur_buf + mstatus_offset*2 + 135*2+1); - mstatus.comb0_off = *((const uint16_t*)cur_buf + mstatus_offset + 136); - mstatus.comb1_off = *((const uint16_t*)cur_buf + mstatus_offset + 137); - mstatus.comb_sign = *((const uint8_t*)cur_buf + mstatus_offset*2 + 138*2); } else { mstatus.vlen = instant_buffer_size; } + if (devc->zero) { + dso_zero(sdi, mstatus); + } + const uint32_t divider = devc->zero ? 0x1 : (uint32_t)ceil(DSCOPE_MAX_SAMPLERATE * 1.0 / devc->cur_samplerate / channel_en_cnt); if ((mstatus.sample_divider == divider && mstatus.vlen != 0 && @@ -2394,9 +2864,14 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc->transfers[0] = transfer; devc->submitted_transfers++; + if (devc->zero && devc->zero_stage == -1) { + // initialize before zero adjustment + if (dso_init(sdi, 0) == SR_OK) + devc->zero_stage = 0; + } + devc->status = DSL_START; mstatus_valid = FALSE; - mstatus.zeroing = devc->zero; /* Send header packet to the session bus. */ //std_session_send_df_header(cb_data, LOG_PREFIX); std_session_send_df_header(sdi, LOG_PREFIX); @@ -2447,10 +2922,7 @@ static int dev_status_get(struct sr_dev_inst *sdi, struct sr_status *status, int devc = sdi->priv; if (mstatus_valid) { *status = mstatus; - if (devc->zero) - return SR_ERR; - else - return SR_OK; + return SR_OK; } else { return SR_ERR; } diff --git a/libsigrok4DSL/hardware/DSL/dsl.h b/libsigrok4DSL/hardware/DSL/dsl.h index 2a693e70..1b3f3c4e 100644 --- a/libsigrok4DSL/hardware/DSL/dsl.h +++ b/libsigrok4DSL/hardware/DSL/dsl.h @@ -2,7 +2,7 @@ * This file is part of the libsigrok project. * * Copyright (C) 2013 Bert Vermeulen - * Copyright (C) 2013 DreamSourceLab + * Copyright (C) 2013 DreamSourceLab * * 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 @@ -78,6 +78,49 @@ #define DSCOPE_MAX_SAMPLERATE SR_MHZ(200) #define DSCOPE_INSTANT_DEPTH SR_MB(32) +/* + * for DSCope device + * trans: x << 8 + y + * x = vpos(coarse), each step(1024 total) indicate x(mv) at 1/20 attenuation, and x/10(mv) at 1/2 attenuation + * y = voff(fine), each step(1024 total) indicate y/100(mv) at 1/20 attenuation, adn y/1000(mv) at 1/2 attenuation + * voff: x << 10 + y + * x = vpos(coarse) default bias + * y = voff(fine) default bias + * the final offset: x+DSCOPE_CONSTANT_BIAS->vpos(coarse); y->voff(fine) + */ +#define DSCOPE_DEFAULT_TRANS (129<<8)+167 +#define DSCOPE_DEFAULT_VOFF (32<<10)+558 +#define DSCOPE_CONSTANT_BIAS 160 +#define DSCOPE_TRANS_CMULTI 10 +#define DSCOPE_TRANS_FMULTI 100.0 +#define DSCOPE_DEFAULT_VGAIN0 0x162400 +#define DSCOPE_DEFAULT_VGAIN1 0x14C000 +#define DSCOPE_DEFAULT_VGAIN2 0x12E800 +#define DSCOPE_DEFAULT_VGAIN3 0x118000 +#define DSCOPE_DEFAULT_VGAIN4 0x102400 +#define DSCOPE_DEFAULT_VGAIN5 0x2E800 +#define DSCOPE_DEFAULT_VGAIN6 0x18000 +#define DSCOPE_DEFAULT_VGAIN7 0x02400 + +/* + * for DSCope20 device + * trans: the whole windows offset map to the offset pwm(1024 total) + * voff: offset pwm constant bias to balance circuit offset + */ +#define DSCOPE20_DEFAULT_TRANS 920 +#define DSCOPE20_DEFAULT_VOFF 45 +#define DSCOPE20_DEFAULT_VGAIN0 0x1DA800 +#define DSCOPE20_DEFAULT_VGAIN1 0x1A7200 +#define DSCOPE20_DEFAULT_VGAIN2 0x164200 +#define DSCOPE20_DEFAULT_VGAIN3 0x131800 +#define DSCOPE20_DEFAULT_VGAIN4 0xBD000 +#define DSCOPE20_DEFAULT_VGAIN5 0x7AD00 +#define DSCOPE20_DEFAULT_VGAIN6 0x48800 +#define DSCOPE20_DEFAULT_VGAIN7 0x12000 + +#define CALI_VGAIN_RANGE 100 +#define CALI_VOFF_RANGE (1024-DSCOPE20_DEFAULT_TRANS) + struct DSL_profile { uint16_t vid; uint16_t pid; @@ -113,7 +156,7 @@ static const struct DSL_profile supported_DSLogic[3] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; -static const struct DSL_profile supported_DSCope[2] = { +static const struct DSL_profile supported_DSCope[3] = { /* * DSCope */ @@ -123,6 +166,12 @@ static const struct DSL_profile supported_DSCope[2] = { "DSCope.bin", DEV_CAPS_16BIT}, + {0x2A0E, 0x0004, NULL, "DSCope20", NULL, + "DSCope20.fw", + "DSCope20.bin", + "DSCope20.bin", + DEV_CAPS_16BIT}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; @@ -176,6 +225,10 @@ struct DSL_context { uint32_t trigger_hpos; uint32_t trigger_holdoff; gboolean zero; + gboolean cali; + int zero_stage; + int zero_pcnt; + int zero_comb; gboolean stream; gboolean data_lock; @@ -254,4 +307,12 @@ struct DSL_setting { uint32_t end_sync; }; +struct DSL_vga { + int key; + uint64_t vgain0; + uint64_t vgain1; + uint16_t voff0; + uint16_t voff1; +}; + #endif diff --git a/libsigrok4DSL/hardware/DSL/dslogic.c b/libsigrok4DSL/hardware/DSL/dslogic.c index bed14429..b08feda5 100644 --- a/libsigrok4DSL/hardware/DSL/dslogic.c +++ b/libsigrok4DSL/hardware/DSL/dslogic.c @@ -245,7 +245,6 @@ extern struct ds_trigger *trigger; struct sr_status mstatus; struct cmd_zero_info zero_info; -struct cmd_comb_info comb_info; /** * Check the USB configuration to determine if this is an DSLogic device. @@ -279,7 +278,7 @@ static gboolean check_conf_profile(libusb_device *dev) if (libusb_get_string_descriptor_ascii(hdl, des.iProduct, strdesc, sizeof(strdesc)) < 0) break; - if (strncmp((const char *)strdesc, "DSLogic", 7)) + if (strncmp((const char *)strdesc, "USB-based Instrument", 20)) break; /* If we made it here, it must be an DSLogic. */ @@ -1000,28 +999,6 @@ static uint64_t dso_cmd_gen(struct sr_dev_inst *sdi, struct sr_channel* ch, int cmd += probe->trig_value << (8 * (probe->index + 1)); } break; - case SR_CONF_ZERO_SET: - cmd += 0x40; - cmd += ch->index << ch_bit; - cmd += ((uint64_t)zero_info.vpos_l << 8); - cmd += ((uint64_t)(zero_info.vpos_h & 0x3) << 16); - cmd += ((uint64_t)zero_info.voff_l << 24); - cmd += ((uint64_t)(zero_info.voff_h & 0x3) << 32); - cmd += ((uint64_t)zero_info.vcntr_l << 40); - cmd += ((uint64_t)(zero_info.vcntr_h & 0x3) << 48); - cmd += ((uint64_t)zero_info.adc_off << 56); - break; - case SR_CONF_COMB_SET: - cmd += 0x48; - cmd += ((uint64_t)comb_info.comb0_low_off << 8); - cmd += ((uint64_t)comb_info.comb0_hig_off << 16); - cmd += ((uint64_t)comb_info.comb1_low_off << 24); - cmd += ((uint64_t)comb_info.comb1_hig_off << 32); - cmd += ((uint64_t)comb_info.comb_sign << 40); - break; - case SR_CONF_ZERO_OVER: - cmd += 0x50; - break; case SR_CONF_TRIGGER_HOLDOFF: cmd += 0x58; cmd += devc->trigger_holdoff << 8; @@ -1128,7 +1105,7 @@ static int dev_open(struct sr_dev_inst *sdi) g_free(fpga_bit); } - ret = command_vth(usb->devhdl, devc->vth); + ret = command_wr_reg(usb->devhdl, (uint8_t)(devc->vth/5.0*255), VTH_ADDR); if (ret == SR_OK) sr_dbg("%s: setting threshold voltage to %d", __func__, devc->vth); @@ -1401,12 +1378,6 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, devc = sdi->priv; *data = g_variant_new_uint64(DSLOGIC_MAX_LOGIC_DEPTH*ceil(samplerates[devc->samplerates_size-1] * 1.0 / DSLOGIC_MAX_LOGIC_SAMPLERATE)); break; - case SR_CONF_STATUS: - if (!sdi) - return SR_ERR; - devc = sdi->priv; - *data = g_variant_new_boolean(devc->status != DSL_INIT); - break; default: return SR_ERR_NA; } @@ -1510,22 +1481,6 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, } } - comb_info.comb_addr = comb_base_addr; - if ((ret = command_rd_nvm(usb->devhdl, (unsigned char *)&comb_info, comb_info.comb_addr, sizeof(struct cmd_comb_info))) != SR_OK) { - sr_err("Send Get Comb Command Failed!"); - } else { - if (comb_info.comb_addr == comb_base_addr) { - ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, NULL, SR_CONF_COMB_SET)); - if (ret != SR_OK) { - sr_err("Set Comb command failed!"); - return ret; - } - } else { - devc->zero = TRUE; - sr_info("Comb have not been setted!"); - } - } - for(l = sdi->channels; l; l = l->next) { struct sr_channel *probe = (struct sr_channel *)l->data; ret = command_dso_ctrl(usb->devhdl, dso_cmd_gen(sdi, probe, SR_CONF_COUPLING)); @@ -1695,7 +1650,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, __func__, devc->th_level); } else if (id == SR_CONF_VTH) { devc->vth = g_variant_get_double(data); - ret = command_vth(usb->devhdl, devc->vth); + ret = command_wr_reg(usb->devhdl, (uint8_t)(devc->vth/5.0*255), VTH_ADDR); if (ret == SR_OK) sr_dbg("%s: setting threshold voltage to %d", __func__, devc->vth); @@ -1851,18 +1806,10 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, for(l = sdi->channels; l; l = l->next) { struct sr_channel *probe = (struct sr_channel *)l->data; zero_info.zero_addr = zero_base_addr + probe->index * sizeof(struct cmd_zero_info); - zero_info.adc_off = (probe->index == 0) ? mstatus.ch0_adc_off + (mstatus.ch0_adc_sign << 7) : mstatus.ch1_adc_off + (mstatus.ch1_adc_sign << 7); ret = command_wr_nvm(usb->devhdl, (unsigned char *)&zero_info, sizeof(struct cmd_zero_info)); if (ret != SR_OK) sr_err("DSO channel %d Set Zero command failed!", probe->index); } - comb_info.comb_addr = comb_base_addr; - comb_info.comb0_low_off = mstatus.comb0_off; - comb_info.comb0_hig_off = mstatus.comb0_off >> 8; - comb_info.comb1_low_off = mstatus.comb1_off; - comb_info.comb1_hig_off = mstatus.comb1_off >> 8; - comb_info.comb_sign = mstatus.comb_sign; - ret = command_wr_nvm(usb->devhdl, (unsigned char *)&comb_info, sizeof(struct cmd_comb_info)); if (ret != SR_OK) sr_err("DSO Set Comb command failed!"); else @@ -2221,14 +2168,6 @@ static void receive_transfer(struct libusb_transfer *transfer) mstatus.stream_mode = *((const uint32_t*)cur_buf + mstatus_offset/2 + 16/2) & 0x80000000; mstatus.sample_divider = *((const uint32_t*)cur_buf + mstatus_offset/2 + 18/2) & 0x7fffffff; mstatus.sample_divider_tog = *((const uint32_t*)cur_buf + mstatus_offset/2 + 18/2) & 0x80000000; - mstatus.zeroing = (*((const uint16_t*)cur_buf + mstatus_offset + 128) & 0x8000) != 0; - mstatus.ch0_adc_off = *((const uint8_t*)cur_buf + mstatus_offset*2 + 131*2); - mstatus.ch0_adc_sign = *((const uint8_t*)cur_buf + mstatus_offset*2 + 131*2+1); - mstatus.ch1_adc_off = *((const uint8_t*)cur_buf + mstatus_offset*2 + 135*2); - mstatus.ch1_adc_sign = *((const uint8_t*)cur_buf + mstatus_offset*2 + 135*2+1); - mstatus.comb0_off = *((const uint16_t*)cur_buf + mstatus_offset + 136); - mstatus.comb1_off = *((const uint16_t*)cur_buf + mstatus_offset + 137); - mstatus.comb_sign = *((const uint8_t*)cur_buf + mstatus_offset*2 + 138*2); } else { mstatus.vlen = instant_buffer_size; } diff --git a/libsigrok4DSL/hardware/demo/demo.c b/libsigrok4DSL/hardware/demo/demo.c index d39aebf0..e9536f4d 100644 --- a/libsigrok4DSL/hardware/demo/demo.c +++ b/libsigrok4DSL/hardware/demo/demo.c @@ -278,6 +278,7 @@ static const char *probe_names[NUM_PROBES + 1] = { "CH8", "CH9", "CH10", "CH11", "CH12", "CH13", "CH14", "CH15", NULL, + }; /* Private, per-device-instance driver context. */ diff --git a/libsigrok4DSL/hwdriver.c b/libsigrok4DSL/hwdriver.c index 4e437dfd..da3bcd35 100644 --- a/libsigrok4DSL/hwdriver.c +++ b/libsigrok4DSL/hwdriver.c @@ -49,7 +49,6 @@ * * @{ */ - static struct sr_config_info sr_config_info_data[] = { {SR_CONF_CONN, SR_T_CHAR, "conn", "Connection", "Connection", NULL}, diff --git a/libsigrok4DSL/libsigrok.h b/libsigrok4DSL/libsigrok.h index c6c9e01e..12cf5eaa 100644 --- a/libsigrok4DSL/libsigrok.h +++ b/libsigrok4DSL/libsigrok.h @@ -568,10 +568,11 @@ struct sr_channel { uint64_t vdiv; uint16_t vfactor; double vpos; + uint16_t vpos_trans; uint8_t coupling; uint8_t trig_value; - uint16_t vpos_mid; - uint16_t voff_mid; + int8_t comb_diff_top; + int8_t comb_diff_bom; }; /** Structure for groups of channels that have common properties. */ @@ -629,22 +630,6 @@ struct sr_status { gboolean stream_mode; uint32_t sample_divider; gboolean sample_divider_tog; - - gboolean zeroing; - uint16_t ch0_vpos_mid; - uint16_t ch0_voff_mid; - uint16_t ch0_vcntr; - uint16_t ch1_vpos_mid; - uint16_t ch1_voff_mid; - uint16_t ch1_vcntr; - uint8_t ch0_adc_off; - uint8_t ch1_adc_off; - gboolean ch0_adc_sign; - gboolean ch1_adc_sign; - - uint16_t comb0_off; - uint16_t comb1_off; - uint8_t comb_sign; }; enum { @@ -754,9 +739,12 @@ enum { /** Zero */ SR_CONF_ZERO_SET, + SR_CONF_ZERO_LOAD, SR_CONF_COMB_SET, SR_CONF_ZERO, SR_CONF_ZERO_OVER, + SR_CONF_VOCM, + SR_CONF_CALI, /** status for dso channel */ SR_CONF_STATUS_PERIOD, @@ -778,6 +766,13 @@ enum { /** Vertical offset */ SR_CONF_VOFF, + SR_CONF_VOFF_DEFAULT, + SR_CONF_VOFF_RANGE, + + /** VGain */ + SR_CONF_VGAIN, + SR_CONF_VGAIN_DEFAULT, + SR_CONF_VGAIN_RANGE, /** Coupling for dso channel. */ SR_CONF_COUPLING,