diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2020-05-31 06:38:00 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2020-05-31 06:38:00 +0200 |
commit | 58d857673ed0fdd801da53b7c7b6dec1dc26d60a (patch) | |
tree | dc7c523a2213bc6765a04b94d9eb50754255f498 /video-ps3eye | |
parent | 4c39f488136f79692d1b78da8772fd77e97d3c77 (diff) |
video/ps3eye: don't reset sensor that much
Diffstat (limited to 'video-ps3eye')
-rw-r--r-- | video-ps3eye/module.cpp | 19 | ||||
-rw-r--r-- | video-ps3eye/module.hpp | 11 |
2 files changed, 23 insertions, 7 deletions
diff --git a/video-ps3eye/module.cpp b/video-ps3eye/module.cpp index 73aaf114..97dd370e 100644 --- a/video-ps3eye/module.cpp +++ b/video-ps3eye/module.cpp @@ -237,16 +237,19 @@ OTR_REGISTER_CAMERA(ps3eye_camera_) dialog::dialog(QWidget* parent) : QWidget(parent) { ui.setupUi(this); + t.setSingleShot(true); + t.setInterval(500); tie_setting(s.exposure, ui.exposure_slider); tie_setting(s.gain, ui.gain_slider); ui.exposure_label->setValue((int)*s.exposure); ui.gain_label->setValue((int)*s.gain); - connect(&s.exposure, value_::value_changed<slider_value>(), this, [this](const slider_value&) { s.set_exposure(); }); - connect(&s.gain, value_::value_changed<slider_value>(), this, [this](const slider_value&) { s.set_gain(); }); + connect(&s.exposure, value_::value_changed<slider_value>(), this, [this](const slider_value&) { s.set_exposure(); t.stop(); t.start(); }); + connect(&s.gain, value_::value_changed<slider_value>(), this, [this](const slider_value&) { s.set_gain(); t.stop(); t.start(); }); connect(ui.exposure_slider, &QSlider::valueChanged, ui.exposure_label, &QSpinBox::setValue); connect(ui.gain_slider, &QSlider::valueChanged, ui.gain_label, &QSpinBox::setValue); connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &dialog::do_ok); connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &dialog::do_cancel); + connect(&t, &QTimer::timeout, this, [this]() { s.apply(); }); } // XXX copypasta -sh 20200329 @@ -257,7 +260,7 @@ void settings::set_gain() auto& ptr = *(ps3eye::shm volatile*)shm.ptr(); ptr.in.gain = (unsigned char)*gain; - ++ptr.in.settings_updated; + //++ptr.in.settings_updated; std::atomic_thread_fence(std::memory_order_seq_cst); } @@ -268,6 +271,16 @@ void settings::set_exposure() auto& ptr = *(ps3eye::shm volatile*)shm.ptr(); ptr.in.exposure = (unsigned char)*exposure; + //++ptr.in.settings_updated; + std::atomic_thread_fence(std::memory_order_seq_cst); +} + +void settings::apply() +{ + if (!shm.success()) + return; + + auto& ptr = *(ps3eye::shm volatile*)shm.ptr(); ++ptr.in.settings_updated; std::atomic_thread_fence(std::memory_order_seq_cst); } diff --git a/video-ps3eye/module.hpp b/video-ps3eye/module.hpp index 56ffe5df..955463d6 100644 --- a/video-ps3eye/module.hpp +++ b/video-ps3eye/module.hpp @@ -8,8 +8,8 @@ #include "compat/timer.hpp" #include "ui_dialog.h" -#include <QDialog> #include <QProcess> +#include <QTimer> using namespace options; @@ -27,6 +27,7 @@ struct settings final void set_exposure(); void set_gain(); + void apply(); }; class dialog final : public QWidget @@ -35,13 +36,15 @@ class dialog final : public QWidget Ui_Dialog ui; settings s; + QTimer t; + shm_wrapper shm { "ps3eye-driver-shm", nullptr, sizeof(ps3eye::shm) }; - void do_ok() { s.b->save(); close(); deleteLater(); } - void do_cancel() { s.b->reload(); close(); deleteLater(); } + void do_ok() { s.b->save(); s.apply(); close(); } + void do_cancel() { s.b->reload(); s.apply(); close(); } protected: - void closeEvent(QCloseEvent*) override { do_cancel(); } + void closeEvent(QCloseEvent*) override { do_cancel(); deleteLater(); } public: explicit dialog(QWidget* parent = nullptr); |