diff --git a/.gitmodules b/.gitmodules index 5db1390..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "libsmu"] - path = libsmu - url = https://github.com/signalspec/libsmu diff --git a/Plot/FloatBuffer.cpp b/Plot/FloatBuffer.cpp index cbe9f62..39591b2 100644 --- a/Plot/FloatBuffer.cpp +++ b/Plot/FloatBuffer.cpp @@ -5,5 +5,6 @@ FloatBuffer::FloatBuffer(QObject *parent): m_secondsPerSample(0.00001), m_start(0), m_length(0), - m_first_samples_ignored(0) + m_first_samples_ignored(0), + m_start_test(0) {} diff --git a/Plot/FloatBuffer.h b/Plot/FloatBuffer.h index 00c43a3..ccfa710 100644 --- a/Plot/FloatBuffer.h +++ b/Plot/FloatBuffer.h @@ -36,14 +36,45 @@ public: return m_data[wrapIndex(i)]; } - void shift(float d) { - m_data[(m_start + m_length) % m_data.size()] = d; +// Not needed anymore +// void shift(float d) { +// m_data[(m_start + m_length) % m_data.size()] = d; - if (m_length < m_data.size()) { - m_length += 1; - } else { - m_start = (m_start + 1) % m_data.size(); +// if (m_length < m_data.size()) { +// m_length += 1; +// } else { +// m_start = (m_start + 1) % m_data.size(); +// } +// } + + void append_samples(const std::vector>& samples, int signal_index) + { + size_t free_buffer_space = m_data.size() - m_start_test; + int num_samples_to_add = std::min(samples.size(), free_buffer_space); + + for (int i = 0; i < num_samples_to_add; i++) { + m_data[(m_start_test + i) % m_data.size()] = samples[i][signal_index]; } + m_start_test += num_samples_to_add; + if (m_length < m_start_test) + m_length = m_start_test; + + emit dataChanged(); + } + + void append_samples_circular(const std::vector>& samples, int signal_index) + { + int num_samples_to_add = samples.size(); + + for (int i = 0; i < num_samples_to_add; i++) { + m_data[(m_start_test + i) % m_data.size()] = samples[i][signal_index]; + } + + m_start_test += num_samples_to_add; + if (m_length < m_start_test) + m_length = m_start_test; + + emit dataChanged(); } void toVertexData(double start, double end, QSGGeometry::Point2D *vertices, unsigned n_verticies) { @@ -89,20 +120,23 @@ public: m_length = 0; dataChanged(); } + m_start_test = 0; } - void sweepProgress(unsigned sample) { - if (m_length < sample) { - m_length = sample; - } - dataChanged(); - } +// Not needed anymore +// void sweepProgress(unsigned sample) { +// if (m_length < sample) { +// m_length = sample; +// } +// dataChanged(); +// } - void continuousProgress(unsigned sample) { - Q_UNUSED(sample); - // m_start and m_length are adjusted in shift() - dataChanged(); - } +// Not needed anymore +// void continuousProgress(unsigned sample) { +// Q_UNUSED(sample); +// // m_start and m_length are adjusted in shift() +// dataChanged(); +// } template @@ -152,6 +186,7 @@ private: size_t m_start; size_t m_length; size_t m_first_samples_ignored; + size_t m_start_test; unsigned unwrapIndex(unsigned index) { if (index >= m_start) { diff --git a/SMU.cpp b/SMU.cpp index 921693c..91a369d 100644 --- a/SMU.cpp +++ b/SMU.cpp @@ -5,12 +5,13 @@ #include "utils/bossac_wrap.h" #include "qdebug.h" +using namespace smu; + void registerTypes() { qmlRegisterType(); qmlRegisterType(); qmlRegisterType(); qmlRegisterType(); - qmlRegisterType(); qmlRegisterType(); qmlRegisterType("Plot", 1, 0, "PhosphorRender"); @@ -26,24 +27,20 @@ m_continuous(false), m_sample_rate(0), m_sample_count(0) { - connect(this, &SessionItem::progress, this, &SessionItem::onProgress, Qt::QueuedConnection); connect(this, &SessionItem::finished, this, &SessionItem::onFinished, Qt::QueuedConnection); connect(this, &SessionItem::attached, this, &SessionItem::onAttached, Qt::QueuedConnection); connect(this, &SessionItem::detached, this, &SessionItem::onDetached, Qt::QueuedConnection); - m_session->m_completion_callback = [this](unsigned status){ - emit finished(status); - }; + connect(&timer, SIGNAL(timeout()), this, SLOT(getSamples())); - m_session->m_progress_callback = [this](uint64_t n) { - emit progress(n); - }; - m_session->m_hotplug_attach_callback = [this](Device* device){ + m_session->hotplug_attach([this](Device* device, void* data){ + Q_UNUSED(data); emit attached(device); - }; - m_session->m_hotplug_detach_callback = [this](Device* device){ + }); + m_session->hotplug_detach([this](Device* device, void* data){ + Q_UNUSED(data); emit detached(device); - }; + }); } SessionItem::~SessionItem() { @@ -54,75 +51,60 @@ SessionItem::~SessionItem() { /// called on initialisation void SessionItem::openAllDevices() { - m_session->update_available_devices(); - for (auto i: m_session->m_available_devices) { - auto dev = m_session->add_device(&*i); - m_devices.append(new DeviceItem(this, dev)); - } + m_session->m_queue_size = 1000000; + m_session->add_all(); + for (auto i: m_session->m_available_devices) + m_devices.append(new DeviceItem(this, &*i)); devicesChanged(); } /// called at exit void SessionItem::closeAllDevices() { - qDebug() << "Closing devices"; - m_session->cancel(); - m_session->end(); - QList devices; - m_devices.swap(devices); - devicesChanged(); + m_session->cancel(); + m_session->end(); + QList devices; + m_devices.swap(devices); + devicesChanged(); - for (auto i: devices) { - m_session->remove_device(i->m_device); - delete i; - } + for (auto i: devices) + m_session->remove(i->m_device); } /// configure device, datapaths, and start streaming void SessionItem::start(bool continuous) { +qDebug() << "Session start(" << continuous << ")"; if (m_devices.size() == 0) return; - if (m_active) return; if (m_sample_rate == 0) return; - m_continuous = continuous; - m_active = true; - activeChanged(); m_session->configure(m_sample_rate); + m_continuous = continuous; // Configure buffers for (auto dev: m_devices) { + dev->setSamplesAdded(0); for (auto chan: dev->m_channels) { dev->m_device->set_mode(chan->m_index, chan->m_mode); + chan->buildTxBuffer(); for (auto sig: chan->m_signals) { sig->m_buffer->setRate(1.0/m_sample_rate); sig->m_buffer->allocate(m_sample_count); - - if (m_continuous) { - sig->m_signal->measure_callback([=](float d){ - sig->m_buffer->shift(d); - }); - - connect(sig->m_src, &SrcItem::changed, [=] { - dev->m_device->lock(); - sig->m_src->update(); - dev->m_device->unlock(); - }); - - sig->updateMeasurementMean(); - sig->updatePeakToPeak(); - sig->updateRms(); - } else { - sig->m_buffer->startSweep(); - sig->m_signal->measure_buffer(sig->m_buffer->data(), m_sample_count); - } - sig->m_src->update(); - + sig->m_buffer->startSweep(); } } + dev->write(); } - m_session->start(continuous ? 0 : m_sample_count); + m_session->flush(); + if (continuous) + m_session->start(0); + else + m_session->start(m_sample_count); + timer.start(0); + + m_active = true; + emit activeChanged(); } /// handles hotplug attach condition @@ -130,10 +112,17 @@ void SessionItem::start(bool continuous) /// triggered by libUSB callback over Queue void SessionItem::onAttached(Device *device) { - auto dev = m_session->add_device(device); - Q_UNUSED(dev); - m_devices.append(new DeviceItem(this, device)); - devicesChanged(); + if (m_active) { + this->cancel(); + } + + int err = m_session->add(device); + + if (!err) { + m_devices.append(new DeviceItem(this, device)); + devicesChanged(); + } +qDebug() << "Device attached"; } /// handles hotplug detach condition @@ -143,20 +132,15 @@ void SessionItem::onDetached(Device* device){ if (m_active) { this->cancel(); } - // wait for completion and teardown relevant state - // cut out the middleman, ensure completion is handled - // don't rely on nondeterministic race condition between Detached and Finished - onFinished(); - m_session->remove_device(device); - if ((int) m_session->m_devices.size() < m_devices.size()) { - for (auto dev: m_devices) { - if (dev->m_device == device) - m_devices.removeOne(dev); - } + m_session->remove(device, true); + for (auto dev: m_devices) { + if (dev->m_device == device) { + m_devices.removeOne(dev); + } } - // remove from list of available devices - m_session->destroy_available(device); + m_session->destroy(device); devicesChanged(); +qDebug() << "Device detached"; } void SessionItem::handleDownloadedFirmware() @@ -169,26 +153,36 @@ void SessionItem::handleDownloadedFirmware() m_firmware_fd = NULL; } -/// cancel obnoxious amount of redirection -/// SessionItem::cancel calls Session::cancel calls Device::cancel on each device void SessionItem::cancel() { - if (!m_active) { return; } + if (!m_active) + return; + + if (m_continuous) + timer.stop(); + m_session->cancel(); + m_session->end(); + qDebug() << "Session cancel" << "status:" << m_session->cancelled(); + + m_active = false; + emit activeChanged(); +} + +void SessionItem::restart() +{ + if (!m_active) + return; + + cancel(); + while(m_active); + start(m_continuous); } -/// completion event handler -/// runs on UI thread -/// waits for device to complete (paradoxically?), then tears down the output update connection void SessionItem::onFinished() { - m_session->end(); - m_active = false; - activeChanged(); - for (auto dev: m_devices) { for (auto chan: dev->m_channels) { for (auto sig: chan->m_signals) { - disconnect(sig->m_src, &SrcItem::changed, 0, 0); sig->updateMeasurementMean(); sig->updatePeakToPeak(); sig->updateRms(); @@ -197,30 +191,8 @@ void SessionItem::onFinished() } } -/// progress handler -/// called over Queue, updates BufferItem with new data as appropriate -void SessionItem::onProgress(uint64_t sample) { - - if (!m_continuous && sample > m_sample_count) { - // libsmu rounds up to the packet size and can report a sample count higher than requested, - // but the buffers only deal with requested samples. - sample = m_sample_count; - } - - for (auto dev: m_devices) { - for (auto chan: dev->m_channels) { - for (auto sig: chan->m_signals) { - if (m_continuous) { - sig->m_buffer->continuousProgress(sample); - } else { - sig->m_buffer->sweepProgress(sample); - } - } - } - } -} - void SessionItem::updateMeasurements() { +/* for (auto dev: m_devices) { for (auto chan: dev->m_channels) { for (auto sig: chan->m_signals) { @@ -228,6 +200,7 @@ void SessionItem::updateMeasurements() { } } } +*/ } void SessionItem::updateAllMeasurements() { @@ -244,15 +217,87 @@ void SessionItem::updateAllMeasurements() { void SessionItem::downloadFromUrl(QString url) { + /* + * this causes Error in `/home/dan/work/git/build-pixelpulse2-Desktop_Qt_5_5_1_GCC_64bit3-Debug/pixelpulse2': corrupted double-linked list: 0x0000000001bf9140 *** + * QUrl firmwareUrl(url); m_firmware_fd = new FileDownloader(firmwareUrl, this); connect(m_firmware_fd, SIGNAL (downloaded()), this, SLOT (handleDownloadedFirmware())); + */ +} + +void SessionItem::getSamples() +{ + if (!m_active) + return; + + for (auto dev: m_devices) { + std::vector> rxbuf; + int ret = 0; + + try { + ret = dev->m_device->read(rxbuf, 1000); + } catch (std::system_error& e) { + qDebug() << "exception:" << e.what(); + } catch (std::runtime_error& e) { + qDebug() << "exception:" << e.what(); + } + + qDebug() << ret; + + if (ret == 0) + return; + + dev->setSamplesAdded(dev->samplesAdded() + ret); + + int i = 0; + for (auto chan: dev->m_channels) { + int j = 0; + for (auto sig: chan->m_signals) { + if (m_continuous) + sig->m_buffer->append_samples_circular(rxbuf, i * 2 + j); + else + sig->m_buffer->append_samples(rxbuf, i * 2 + j); + j++; + } + i++; + } + + if (!m_continuous) { + if (dev->samplesAdded() == m_sample_count || !m_active) { + timer.stop(); + dev->setSamplesAdded(0); + emit finished(0); + QTimer::singleShot(100, this, SLOT(beginNewSweep())); + } + } + } +} + +void SessionItem::beginNewSweep() +{ + if (m_active) { + m_session->flush(); + for (auto dev: m_devices) { + dev->setSamplesAdded(0); + for (auto chan: dev->m_channels) { + chan->buildTxBuffer(); + for (auto sig: chan->m_signals) { + sig->m_buffer->startSweep(); + } + } + dev->write(); + } + m_session->start(m_sample_count); + timer.start(0); + } } /// DeviceItem constructor DeviceItem::DeviceItem(SessionItem* parent, Device* dev): QObject(parent), -m_device(dev) +m_device(dev), +m_samples_added(0) { auto dev_info = dev->info(); @@ -261,6 +306,16 @@ m_device(dev) } } +void DeviceItem::write() +{ + for (auto chn: m_channels) { + unsigned mode = chn->property("mode").toUInt(); + if (mode == SVMI || mode == SIMV) { + m_device->write(chn->m_tx_data, chn->m_index, true); + } + } +} + /// ChannelItem constructor ChannelItem::ChannelItem(DeviceItem* parent, Device* dev, unsigned ch_i): QObject(parent), m_device(dev), m_index(ch_i), m_mode(0) @@ -273,6 +328,44 @@ QObject(parent), m_device(dev), m_index(ch_i), m_mode(0) } } +void ChannelItem::buildTxBuffer() +{ + SignalItem *txSignal; + + switch (m_mode) { + case SVMI: + txSignal = m_signals[0]; + break; + case SIMV: + txSignal = m_signals[1]; + break; + default: + return; + } + + QString src = txSignal->getSrc()->property("src").toString(); + float v1 = txSignal->getSrc()->property("v1").toFloat(); + float v2 = txSignal->getSrc()->property("v2").toFloat(); + float period = txSignal->getSrc()->property("period").toFloat(); + float phase = txSignal->getSrc()->property("phase").toFloat(); + float duty = txSignal->getSrc()->property("duty").toFloat(); + + m_tx_data.resize(0); + + if (src == "constant") + txSignal->m_signal->constant(m_tx_data, 1, v1); + else if (src == "square") + txSignal->m_signal->square(m_tx_data, period, v1, v2, period, phase, duty); + else if (src == "sawtooth") + txSignal->m_signal->sawtooth(m_tx_data, period, v1, v2, period, phase); + else if (src == "stairstep") + txSignal->m_signal->stairstep(m_tx_data, period, v1, v2, period, phase); + else if (src == "sine") + txSignal->m_signal->sine(m_tx_data, period, v1, v2, period, phase); + else if (src == "triangle") + txSignal->m_signal->triangle(m_tx_data, period, v1, v2, period, phase); +} + /// SignalItem constructor SignalItem::SignalItem(ChannelItem* parent, int index, Signal* sig): QObject(parent), @@ -304,8 +397,10 @@ void SignalItem::updateMeasurementMean(){ } void SignalItem::updateMeasurementLatest(){ +/* m_measurement = m_signal->measure_instantaneous(); measurementChanged(m_measurement); +*/ } void SignalItem::updatePeakToPeak() { @@ -340,6 +435,7 @@ m_parent(parent) /// update output signal void SrcItem::update() { + /*time Src v = SRC_CONSTANT; if (m_src == "constant") v = SRC_CONSTANT; else if (m_src == "buffer") v = SRC_BUFFER; @@ -357,9 +453,5 @@ void SrcItem::update() { m_parent->m_signal->m_src_period = m_period; m_parent->m_signal->m_src_phase = m_phase; m_parent->m_signal->m_src_duty = m_duty; -} - -ModeItem::ModeItem() -{ - +*/ } diff --git a/SMU.h b/SMU.h index 5073a5b..b6e3f09 100644 --- a/SMU.h +++ b/SMU.h @@ -1,9 +1,11 @@ #pragma once #include -#include "libsmu/src/libsmu.hpp" +#include +#include #include #include "utils/filedownloader.h" #include +#include class SessionItem; class DeviceItem; @@ -33,6 +35,7 @@ public: Q_INVOKABLE void start(bool continuous); Q_INVOKABLE void cancel(); + Q_INVOKABLE void restart(); int getAvailableDevices() { return m_session->m_available_devices.size(); } int getActiveDevices() { return m_session->m_devices.size(); } @@ -49,26 +52,28 @@ signals: void activeChanged(); void sampleRateChanged(); void sampleCountChanged(); - void progress(uint64_t); void finished(unsigned status); - void attached(Device* device); - void detached(Device* device); + void attached(smu::Device* device); + void detached(smu::Device* device); protected slots: - void onProgress(uint64_t); void onFinished(); - void onAttached(Device* device); - void onDetached(Device* device); + void onAttached(smu::Device* device); + void onDetached(smu::Device* device); void handleDownloadedFirmware(); + void getSamples(); + void beginNewSweep(); + protected: - Session* m_session; + smu::Session* m_session; bool m_active; bool m_continuous; unsigned m_sample_rate; unsigned m_sample_count; FileDownloader *m_firmware_fd; QList m_devices; + QTimer timer; }; @@ -83,19 +88,24 @@ class DeviceItem : public QObject { Q_PROPERTY(QString UUID READ getDevSN CONSTANT); public: - DeviceItem(SessionItem*, Device*); + DeviceItem(SessionItem*, smu::Device*); QQmlListProperty getChannels() { return QQmlListProperty(this, m_channels); } QString getLabel() { return QString(m_device->info()->label); } - QString getFWVer() { return QString(m_device->fwver()); } - QString getHWVer() { return QString(m_device->hwver()); } - QString getDevSN() { return QString(m_device->serial()); } + QString getFWVer() { return QString::fromStdString(m_device->m_fwver); } + QString getHWVer() { return QString::fromStdString(m_device->m_hwver); } + QString getDevSN() { return QString::fromStdString(m_device->m_serial); } int getDefaultRate() { return m_device->get_default_rate(); } Q_INVOKABLE int ctrl_transfer( int x, int y, int z) { return m_device->ctrl_transfer(0x40, x, y, z, 0, 0, 100);} + size_t samplesAdded() { return m_samples_added; } + void setSamplesAdded(size_t count) { m_samples_added = count; } + void write(); + protected: - Device* const m_device; + smu::Device* const m_device; QList m_channels; friend class SessionItem; + size_t m_samples_added; }; class ChannelItem : public QObject { @@ -105,22 +115,27 @@ class ChannelItem : public QObject { Q_PROPERTY(unsigned mode MEMBER m_mode NOTIFY modeChanged); public: - ChannelItem(DeviceItem*, Device*, unsigned index); + ChannelItem(DeviceItem*, smu::Device*, unsigned index); QQmlListProperty getSignals() { return QQmlListProperty(this, m_signals); } QString getLabel() const { return QString(m_device->channel_info(m_index)->label); } + void buildTxBuffer(); + signals: void modeChanged(unsigned mode); protected: - Device* const m_device; + smu::Device* const m_device; const unsigned m_index; unsigned m_mode; QList m_modes; QList m_signals; + std::vector m_tx_data; + friend class SessionItem; + friend class DeviceItem; friend class SignalItem; }; @@ -141,7 +156,7 @@ class SignalItem : public QObject { Q_PROPERTY(double mean READ getMean NOTIFY meanChanged); public: - SignalItem(ChannelItem*, int index, Signal*); + SignalItem(ChannelItem*, int index, smu::Signal*); FloatBuffer* getBuffer() const { return m_buffer; } QString getLabel() const { return QString(m_signal->info()->label); } double getMin() const { return m_signal->info()->min; } @@ -181,7 +196,7 @@ protected slots: protected: int const m_index; ChannelItem* const m_channel; - Signal* const m_signal; + smu::Signal* const m_signal; FloatBuffer* m_buffer; SrcItem* m_src; double m_measurement; @@ -189,6 +204,7 @@ protected: double m_rms; double m_mean; friend class SessionItem; + friend class ChannelItem; friend class SrcItem; void updateMeasurementMean(); @@ -197,13 +213,6 @@ protected: void updateRms(); }; -/// Should be used for handling mode switches in continuous mode. -class ModeItem : public QObject { -Q_OBJECT -public: - ModeItem(); -}; - class SrcItem : public QObject { Q_OBJECT Q_PROPERTY(QString src MEMBER m_src NOTIFY srcChanged); diff --git a/libsmu b/libsmu deleted file mode 160000 index 80f7026..0000000 --- a/libsmu +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 80f7026ab2cdb1204fdc420a1dbc5b65a6b55646 diff --git a/pixelpulse2.pro b/pixelpulse2.pro index 67821a3..5888e44 100644 --- a/pixelpulse2.pro +++ b/pixelpulse2.pro @@ -4,12 +4,12 @@ QT += qml quick widgets QT += network CONFIG += c++11 -win32 { - CONFIG += release -} -unix { - CONFIG += release -} +#win32 { +# CONFIG += release +#} +#unix { +# CONFIG += release +#} QMAKE_CFLAGS_DEBUG += -ggdb QMAKE_CXXFLAGS_DEBUG += -ggdb @@ -23,8 +23,6 @@ SOURCES += main.cpp \ SMU.cpp \ Plot/PhosphorRender.cpp \ Plot/FloatBuffer.cpp \ - libsmu/src/device_m1000.cpp \ - libsmu/src/session.cpp \ utils/filedownloader.cpp RESOURCES += qml.qrc @@ -56,9 +54,6 @@ HEADERS += \ SMU.h \ Plot/PhosphorRender.h \ Plot/FloatBuffer.h \ - libsmu/src/device_m1000.hpp \ - libsmu/src/libsmu.hpp \ - libsmu/src/internal.hpp \ utils/fileio.h \ utils/bossac_wrap.h \ utils/filedownloader.h @@ -84,6 +79,7 @@ win32 { unix { CONFIG += link_pkgconfig +PKGCONFIG += libsmu # if we do not have a locally compiled static version of libusb-1.0 installed, use pkg-config !exists(/usr/local/lib/libusb-1.0.a) { PKGCONFIG += libusb-1.0 @@ -106,5 +102,3 @@ unix:!osx { QMAKE_CFLAGS_DEBUG += -rdynamic QMAKE_CXXFLAGS_DEBUG += -rdynamic } - - diff --git a/qml/Controller.qml b/qml/Controller.qml index 6170d51..16ae01b 100644 --- a/qml/Controller.qml +++ b/qml/Controller.qml @@ -2,7 +2,7 @@ import QtQuick 2.0 import "sesssave.js" as StateSave Item { - property bool enabled: false + property bool enabled: session.active property bool continuous: false property bool repeat: true property real sampleRate: session.devices.length ? session.devices[0].DefaultRate : 0 @@ -14,100 +14,111 @@ Item { property bool dlySmplCntChanged: false - function trigger() { - session.sampleRate = sampleRate - session.sampleCount = sampleCount +// function trigger() { +// session.sampleRate = sampleRate +// session.sampleCount = sampleCount - if (dlySmplCntChanged) { - for (var i = 0; i < session.devices.length; i++) { - for (var j = 0; j < session.devices[i].channels.length; j++) { - session.devices[i].channels[j].signals[0].buffer.setIgnoredFirstSamplesCount(delaySampleCount); - session.devices[i].channels[j].signals[1].buffer.setIgnoredFirstSamplesCount(delaySampleCount); - } - } - dlySmplCntChanged = false; - } +// if (dlySmplCntChanged) { +// for (var i = 0; i < session.devices.length; i++) { +// for (var j = 0; j < session.devices[i].channels.length; j++) { +// session.devices[i].channels[j].signals[0].buffer.setIgnoredFirstSamplesCount(delaySampleCount); +// session.devices[i].channels[j].signals[1].buffer.setIgnoredFirstSamplesCount(delaySampleCount); +// } +// } +// dlySmplCntChanged = false; +// } - session.start(continuous); - if ( session.devices.length > 0 ) { - lastConfig = StateSave.saveState(); - } - } +// session.start(continuous); +// if ( session.devices.length > 0 ) { +// lastConfig = StateSave.saveState(); +// } +// } - onSampleTimeChanged: { - if (continuous && enabled) { - enabled = false; - restartAfterStop = true; - session.cancel(); - enabled = true; - } - } +// onSampleTimeChanged: { +// if (continuous && enabled) { +// enabled = false; +// restartAfterStop = true; +// session.cancel(); +// enabled = true; +// } +// } - Timer { - id: timer - interval: 100 - onTriggered: { trigger() } - } +// Timer { +// id: timer +// interval: 100 +// onTriggered: { trigger() } +// } + +// function toggle() { +// if (!enabled) { +// trigger(); +// enabled = true; +// } else { +// enabled = false; +// if (continuous || sampleTime > 0.1) { +// session.cancel(); +// } +// } +// } function toggle() { - if (!enabled) { - trigger(); - enabled = true; - } else { - enabled = false; - if (continuous || sampleTime > 0.1) { - session.cancel(); + if (!session.active) { + session.sampleRate = sampleRate + session.sampleCount = sampleCount + session.start(continuous); + } else { + session.cancel(); } - } } - Timer { - id: updateMeasurementsTimer - interval: 50 - repeat: true - running: enabled && continuous - onTriggered: session.updateMeasurements() - } +// Timer { +// id: updateMeasurementsTimer +// interval: 50 +// repeat: true +// running: enabled && continuous +// onTriggered: session.updateMeasurements() +// } - Timer { - id: updateLabelsTimer - interval: 500 - repeat: true - running: enabled - onTriggered: session.updateAllMeasurements() - } +// Timer { +// id: updateLabelsTimer +// interval: 500 +// repeat: true +// running: enabled +// onTriggered: session.updateAllMeasurements() +// } - onContinuousChanged: { - // Restart the session so the new sampling mode takes effect - restartAfterStop = true; - session.cancel(); +// onContinuousChanged: { +// // Restart the session so the new sampling mode takes effect +// restartAfterStop = true; +// session.cancel(); - toolbar.acqusitionDialog.onContinuousModeChanged(continuous); - } +// toolbar.acqusitionDialog.onContinuousModeChanged(continuous); +// } - onDelaySampleCountChanged: { - dlySmplCntChanged = true; - } +// onDelaySampleCountChanged: { +// dlySmplCntChanged = true; +// } - Connections { - target: session - onFinished: { - if (enabled && restartAfterStop) { - restartAfterStop = false; - timer.start() - return; - } +// Connections { +// target: session - if (!continuous && repeat && enabled) { - timer.start(); - } - } +// onFinished: { +// if (enabled && restartAfterStop) { +// restartAfterStop = false; +// timer.start() +// return; +// } - onDetached: { - enabled = false; - continuous = false; - } - } +// if (!continuous && repeat && enabled) { +// timer.start(); +// } +// } + +// onDetached: { +// enabled = false; +// continuous = false; +// } +// } Repeater { model: session.devices @@ -118,10 +129,7 @@ Item { Connections { target: modelData onModeChanged: { - if (continuous) { - restartAfterStop = true; - session.cancel(); - } + session.restart(); } } }