diff options
Diffstat (limited to 'video-ps3eye')
-rw-r--r-- | video-ps3eye/dialog.ui | 133 | ||||
-rw-r--r-- | video-ps3eye/lang/nl_NL.ts | 19 | ||||
-rw-r--r-- | video-ps3eye/lang/ru_RU.ts | 19 | ||||
-rw-r--r-- | video-ps3eye/lang/stub.ts | 19 | ||||
-rw-r--r-- | video-ps3eye/lang/zh_CN.ts | 19 | ||||
-rw-r--r-- | video-ps3eye/module.cpp | 58 | ||||
-rw-r--r-- | video-ps3eye/module.hpp | 34 |
7 files changed, 291 insertions, 10 deletions
diff --git a/video-ps3eye/dialog.ui b/video-ps3eye/dialog.ui new file mode 100644 index 00000000..1e94ce74 --- /dev/null +++ b/video-ps3eye/dialog.ui @@ -0,0 +1,133 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Dialog</class> + <widget class="QWidget" name="Dialog"> + <property name="windowModality"> + <enum>Qt::ApplicationModal</enum> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>439</width> + <height>211</height> + </rect> + </property> + <property name="minimumSize"> + <size> + <width>439</width> + <height>0</height> + </size> + </property> + <property name="windowTitle"> + <string>PS3 Eye</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Camera settings</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="2"> + <widget class="QSpinBox" name="exposure_label"> + <property name="readOnly"> + <bool>true</bool> + </property> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::NoButtons</enum> + </property> + <property name="maximum"> + <number>255</number> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QSpinBox" name="gain_label"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::NoButtons</enum> + </property> + <property name="maximum"> + <number>63</number> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QSlider" name="exposure_slider"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximum"> + <number>255</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Exposure</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QSlider" name="gain_slider"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximum"> + <number>63</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Gain</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/video-ps3eye/lang/nl_NL.ts b/video-ps3eye/lang/nl_NL.ts index 6401616d..c98370ec 100644 --- a/video-ps3eye/lang/nl_NL.ts +++ b/video-ps3eye/lang/nl_NL.ts @@ -1,4 +1,23 @@ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.1"> +<context> + <name>Dialog</name> + <message> + <source>PS3 Eye</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Camera settings</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Exposure</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Gain</source> + <translation type="unfinished"></translation> + </message> +</context> </TS> diff --git a/video-ps3eye/lang/ru_RU.ts b/video-ps3eye/lang/ru_RU.ts index 6401616d..c98370ec 100644 --- a/video-ps3eye/lang/ru_RU.ts +++ b/video-ps3eye/lang/ru_RU.ts @@ -1,4 +1,23 @@ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.1"> +<context> + <name>Dialog</name> + <message> + <source>PS3 Eye</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Camera settings</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Exposure</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Gain</source> + <translation type="unfinished"></translation> + </message> +</context> </TS> diff --git a/video-ps3eye/lang/stub.ts b/video-ps3eye/lang/stub.ts index 6401616d..c98370ec 100644 --- a/video-ps3eye/lang/stub.ts +++ b/video-ps3eye/lang/stub.ts @@ -1,4 +1,23 @@ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.1"> +<context> + <name>Dialog</name> + <message> + <source>PS3 Eye</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Camera settings</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Exposure</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Gain</source> + <translation type="unfinished"></translation> + </message> +</context> </TS> diff --git a/video-ps3eye/lang/zh_CN.ts b/video-ps3eye/lang/zh_CN.ts index 6401616d..c98370ec 100644 --- a/video-ps3eye/lang/zh_CN.ts +++ b/video-ps3eye/lang/zh_CN.ts @@ -1,4 +1,23 @@ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.1"> +<context> + <name>Dialog</name> + <message> + <source>PS3 Eye</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Camera settings</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Exposure</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Gain</source> + <translation type="unfinished"></translation> + </message> +</context> </TS> diff --git a/video-ps3eye/module.cpp b/video-ps3eye/module.cpp index 3ee43ec1..7dbdd8fb 100644 --- a/video-ps3eye/module.cpp +++ b/video-ps3eye/module.cpp @@ -4,12 +4,15 @@ #include "compat/run-in-thread.hpp" #include <cstddef> +#include <thread> #include <QCoreApplication> #include <QMessageBox> #include <libusb.h> +using namespace options; + #ifdef __GNUG__ # pragma clang diagnostic ignored "-Wcast-qual" #endif @@ -76,14 +79,21 @@ std::unique_ptr<camera> ps3eye_camera_::make_camera(const QString& name) else return {}; } + +static bool show_dialog_() +{ + (new dialog)->show(); + return true; +} + bool ps3eye_camera_::show_dialog(const QString&) { - // TODO - return false; + return show_dialog_(); } -bool ps3eye_camera_::can_show_dialog(const QString&) + +bool ps3eye_camera_::can_show_dialog(const QString& name) { - return false; + return name == camera_name && check_device_exists(); } ps3eye_camera::ps3eye_camera() @@ -210,7 +220,45 @@ ok: bool ps3eye_camera::show_dialog() { - return false; + return show_dialog_(); } OTR_REGISTER_CAMERA(ps3eye_camera_) + +dialog::dialog(QWidget* parent) : QWidget(parent) +{ + ui.setupUi(this); + 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(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); +} + +// XXX copypasta -sh 20200329 +void settings::set_gain() +{ + if (!shm.success()) + return; + + auto& ptr = *(ps3eye::shm volatile*)shm.ptr(); + ptr.in.gain = (unsigned char)*gain; + ++ptr.in.settings_updated; + std::atomic_thread_fence(std::memory_order_seq_cst); +} + +void settings::set_exposure() +{ + if (!shm.success()) + return; + + 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); +} diff --git a/video-ps3eye/module.hpp b/video-ps3eye/module.hpp index 957e221e..9f7aaec1 100644 --- a/video-ps3eye/module.hpp +++ b/video-ps3eye/module.hpp @@ -5,21 +5,45 @@ #include "compat/shm.h" #include "options/options.hpp" #include "compat/macros1.h" +#include "ui_dialog.h" -using namespace options; - +#include <QDialog> #include <QProcess> +using namespace options; + using video::impl::camera; using video::impl::camera_; using video::frame; -struct settings : opts +struct settings final { - settings() : opts{"video-ps3eye"} {} + bundle b = make_bundle("video-ps3eye"); + shm_wrapper shm { "ps3eye-driver-shm", nullptr, sizeof(ps3eye::shm) }; - value<slider_value> exposure{b, "exposure", {63, 0, 63}}; + value<slider_value> exposure{b, "exposure", {255, 0, 255}}; value<slider_value> gain{b, "gain", {30, 0, 63}}; + + void set_exposure(); + void set_gain(); +}; + +class dialog final : public QWidget +{ + Q_OBJECT + Ui_Dialog ui; + settings s; + + 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(); } + +protected: + void closeEvent(QCloseEvent*) override { do_cancel(); } + +public: + explicit dialog(QWidget* parent = nullptr); }; struct ps3eye_camera final : video::impl::camera |