From 20fc4b1b648ffc8e403c7b13e933ecd92b0458c7 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 16 Oct 2021 00:00:02 +0200 Subject: tracker/trackhat: buffer flush --- tracker-trackhat/camera.cpp | 22 ++++- tracker-trackhat/dialog.cpp | 82 ++++++++++++++++ tracker-trackhat/dialog.hpp | 29 ++++++ tracker-trackhat/dialog.ui | 200 ++++++++++++++++++++++++++++---------- tracker-trackhat/frame.cpp | 1 - tracker-trackhat/lang/nl_NL.ts | 28 ++++-- tracker-trackhat/lang/ru_RU.ts | 28 ++++-- tracker-trackhat/lang/stub.ts | 28 ++++-- tracker-trackhat/lang/zh_CN.ts | 28 ++++-- tracker-trackhat/metadata.cpp | 9 +- tracker-trackhat/metadata.hpp | 9 -- tracker-trackhat/settings.cpp | 66 +++++++++++++ tracker-trackhat/trackhat-res.qrc | 5 + tracker-trackhat/trackhat.hpp | 50 +++++++++- 14 files changed, 486 insertions(+), 99 deletions(-) create mode 100644 tracker-trackhat/settings.cpp create mode 100644 tracker-trackhat/trackhat-res.qrc (limited to 'tracker-trackhat') diff --git a/tracker-trackhat/camera.cpp b/tracker-trackhat/camera.cpp index c744a9f9..1c87229e 100644 --- a/tracker-trackhat/camera.cpp +++ b/tracker-trackhat/camera.cpp @@ -32,7 +32,15 @@ QString trackhat_camera::get_active_name() const void trackhat_camera::set_fov(pt_camera::f) {} void trackhat_camera::show_camera_settings() {} -trackhat_camera::trackhat_camera() = default; +trackhat_camera::trackhat_camera() +{ + s.set_raii_dtor_state(false); + t.set_raii_dtor_state(false); + + QObject::connect(t.b.get(), &options::bundle_::changed, + &sig, &trackhat_impl::setting_receiver::settings_changed, + Qt::DirectConnection); +} trackhat_camera::~trackhat_camera() { @@ -41,6 +49,13 @@ trackhat_camera::~trackhat_camera() pt_camera::result trackhat_camera::get_frame(pt_frame& frame_) { + if (sig.test_and_clear()) + { + set_pt_options(); + qDebug() << "tracker/trackhat: set regs"; + init_regs(); + } + auto& ret = *frame_.as(); trackhat_frame frame; trackHat_ExtendedPoints_t points = {}; @@ -81,6 +96,9 @@ int trackhat_camera::init_regs() constexpr uint8_t regs[][3] = { { 0x0c, 0x0f, 0xf0 }, // exposure lo { 0x0c, 0x10, 0x7f }, // exposure hi + { 0x00, 0x0b, 0xff }, // blob area max size + { 0x00, 0x0c, 0x03 }, // blob area min size + { 0x00, 0x01, 0x01 }, // bank0 sync { 0x01, 0x01, 0x01 }, // bank1 sync }; @@ -98,6 +116,8 @@ bool trackhat_camera::start(const pt_settings&) { int attempts = 0; + set_pt_options(); + if (status >= th_running) return true; diff --git a/tracker-trackhat/dialog.cpp b/tracker-trackhat/dialog.cpp index e69de29b..c51b0d59 100644 --- a/tracker-trackhat/dialog.cpp +++ b/tracker-trackhat/dialog.cpp @@ -0,0 +1,82 @@ +#include "dialog.hpp" + +using namespace options; + +trackhat_dialog::trackhat_dialog() +{ + ui.setupUi(this); + poll_tracker_info(); + poll_timer.setInterval(250); + + struct { + const char* name; + model_type t; + } model_types[] = { + { "Cap", model_cap }, + { "Clip (left)", model_clip_left }, + { "Clip (right)", model_clip_right }, + { "Mini Clip (left)", model_mini_clip_left }, + { "Mini Clip (right)", model_mini_clip_right }, + }; + + ui.model_type->clear(); + + for (auto x : model_types) + ui.model_type->addItem(QIcon{}, tr(x.name), (QVariant)(int)x.t); + + tie_setting(t.min_pt_size, ui.min_point_size); + tie_setting(t.max_pt_size, ui.max_point_size); + tie_setting(t.exposure, ui.exposure_slider); + tie_setting(t.model, ui.model_type); + tie_setting(t.threshold, ui.threshold_slider); + tie_setting(t.enable_point_filter, ui.enable_point_filter); + tie_setting(t.point_filter_coefficient, ui.point_filter_slider); + connect(&t.exposure, value_::value_changed(), ui.exposure_label, + [this] { ui.exposure_label->setValue((int)*t.exposure); }, Qt::QueuedConnection); + connect(&t.threshold, value_::value_changed(), ui.threshold_label, + [this] { ui.threshold_label->setValue((int)*t.threshold); }, Qt::QueuedConnection); + connect(&t.point_filter_coefficient, value_::value_changed(), ui.point_filter_label, + [this] { ui.point_filter_label->setValue((int)*t.point_filter_coefficient); }, Qt::QueuedConnection); + connect(&poll_timer, &QTimer::timeout, this, &trackhat_dialog::poll_tracker_info); + + connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &trackhat_dialog::doOK); + connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &trackhat_dialog::doCancel); +} + +void trackhat_dialog::register_tracker(ITracker* tracker) +{ + tracker = static_cast(tracker); + poll_timer.start(); +} + +void trackhat_dialog::unregister_tracker() +{ + tracker = nullptr; + poll_timer.stop(); +} + +void trackhat_dialog::doOK() +{ + s.b->save(); + t.b->save(); + close(); +} + +void trackhat_dialog::doCancel() +{ + close(); +} + +void trackhat_dialog::poll_tracker_info() +{ + if (!tracker) + { + poll_timer.stop(); + ui.status_label->setText(tr("Tracking stopped.")); + return; + } + + ui.status_label->setText(tr("Tracking. %1 points detected.").arg(tracker->get_n_points())); +} + +trackhat_dialog::~trackhat_dialog() = default; diff --git a/tracker-trackhat/dialog.hpp b/tracker-trackhat/dialog.hpp index e69de29b..0726a2c0 100644 --- a/tracker-trackhat/dialog.hpp +++ b/tracker-trackhat/dialog.hpp @@ -0,0 +1,29 @@ +#pragma once +#include "trackhat.hpp" +#include "ui_dialog.h" +#include "tracker-pt/ftnoir_tracker_pt.h" +#include "api/plugin-api.hpp" +#include + +class trackhat_dialog : public ITrackerDialog +{ + Q_OBJECT + + Ui_trackhat_dialog ui; + Tracker_PT* tracker = nullptr; + QTimer poll_timer{this}; + + pt_settings s{trackhat_metadata::module_name}; + trackhat_settings t; + +public: + trackhat_dialog(); + ~trackhat_dialog() override; + void register_tracker(ITracker *tracker) override; + void unregister_tracker() override; + +public slots: + void doOK(); + void doCancel(); + void poll_tracker_info(); +}; diff --git a/tracker-trackhat/dialog.ui b/tracker-trackhat/dialog.ui index db966ab2..ade5f6b2 100644 --- a/tracker-trackhat/dialog.ui +++ b/tracker-trackhat/dialog.ui @@ -1,17 +1,27 @@ - Form - + trackhat_dialog + 0 0 - 415 - 226 + 365 + 334 + + + 365 + 0 + + - TrackHat tracker + TrackHat + + + + :/images/trackhat-64x64.png:/images/trackhat-64x64.png @@ -20,26 +30,6 @@ Camera - - - - Threshold - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - @@ -49,29 +39,18 @@ - 200 + 65535 + + + 50 Qt::Horizontal - - - - Exposure - - - - - - - Gain - - - - + 0 @@ -79,40 +58,56 @@ - 200 + 191 Qt::Horizontal - - + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + true QAbstractSpinBox::NoButtons + + 999 + - - + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + true QAbstractSpinBox::NoButtons + + 65535 + - - - - true + + + + Exposure - - QAbstractSpinBox::NoButtons + + + + + + Threshold @@ -142,7 +137,7 @@ - 8 + 9 0 @@ -215,8 +210,105 @@ + + + + Tracking + + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Point filter + + + + + + + + 0 + 0 + + + + 300 + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + px + + + 300.000000000000000 + + + + + + + + + + + 0 + 0 + + + + Status + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + - + + + diff --git a/tracker-trackhat/frame.cpp b/tracker-trackhat/frame.cpp index 1ae3413f..c008ac87 100644 --- a/tracker-trackhat/frame.cpp +++ b/tracker-trackhat/frame.cpp @@ -102,7 +102,6 @@ void trackhat_frame::init_points(trackHat_ExtendedPoints_t points_, double min_s if (i < 3 && radius >= min_size && radius <= max_size) p.ok = true; - p.radius = radius; p.brightness = pt.m_averageBrightness; p.W = std::max(1, pt.m_boundryRigth - pt.m_boundryLeft); p.H = std::max(1, pt.m_boundryDown - pt.m_boundryUp); diff --git a/tracker-trackhat/lang/nl_NL.ts b/tracker-trackhat/lang/nl_NL.ts index e375a7a4..1f46e7e3 100644 --- a/tracker-trackhat/lang/nl_NL.ts +++ b/tracker-trackhat/lang/nl_NL.ts @@ -2,9 +2,9 @@ - Form + trackhat_dialog - TrackHat tracker + TrackHat @@ -19,10 +19,6 @@ Exposure - - Gain - - Model @@ -43,6 +39,26 @@ px + + Tracking + + + + Point filter + + + + Tracking stopped. + + + + Tracking. %1 points detected. + + + + Status + + trackhat_module diff --git a/tracker-trackhat/lang/ru_RU.ts b/tracker-trackhat/lang/ru_RU.ts index e375a7a4..1f46e7e3 100644 --- a/tracker-trackhat/lang/ru_RU.ts +++ b/tracker-trackhat/lang/ru_RU.ts @@ -2,9 +2,9 @@ - Form + trackhat_dialog - TrackHat tracker + TrackHat @@ -19,10 +19,6 @@ Exposure - - Gain - - Model @@ -43,6 +39,26 @@ px + + Tracking + + + + Point filter + + + + Tracking stopped. + + + + Tracking. %1 points detected. + + + + Status + + trackhat_module diff --git a/tracker-trackhat/lang/stub.ts b/tracker-trackhat/lang/stub.ts index e375a7a4..1f46e7e3 100644 --- a/tracker-trackhat/lang/stub.ts +++ b/tracker-trackhat/lang/stub.ts @@ -2,9 +2,9 @@ - Form + trackhat_dialog - TrackHat tracker + TrackHat @@ -19,10 +19,6 @@ Exposure - - Gain - - Model @@ -43,6 +39,26 @@ px + + Tracking + + + + Point filter + + + + Tracking stopped. + + + + Tracking. %1 points detected. + + + + Status + + trackhat_module diff --git a/tracker-trackhat/lang/zh_CN.ts b/tracker-trackhat/lang/zh_CN.ts index e375a7a4..1f46e7e3 100644 --- a/tracker-trackhat/lang/zh_CN.ts +++ b/tracker-trackhat/lang/zh_CN.ts @@ -2,9 +2,9 @@ - Form + trackhat_dialog - TrackHat tracker + TrackHat @@ -19,10 +19,6 @@ Exposure - - Gain - - Model @@ -43,6 +39,26 @@ px + + Tracking + + + + Point filter + + + + Tracking stopped. + + + + Tracking. %1 points detected. + + + + Status + + trackhat_module diff --git a/tracker-trackhat/metadata.cpp b/tracker-trackhat/metadata.cpp index a6dd12f8..8c6f4de0 100644 --- a/tracker-trackhat/metadata.cpp +++ b/tracker-trackhat/metadata.cpp @@ -1,9 +1,10 @@ #include "metadata.hpp" #include "api/plugin-api.hpp" #include "trackhat.hpp" +#include "dialog.hpp" // XXX TODO -const QString trackhat_metadata::module_name = QStringLiteral("tracker-pt"); +const QString trackhat_metadata::module_name = QStringLiteral("tracker-trackhat/pt"); pt_runtime_traits::pointer trackhat_metadata::make_camera() const { @@ -35,8 +36,4 @@ trackhat_pt::trackhat_pt() : { } -trackhat_pt_dialog::trackhat_pt_dialog() : TrackerDialog_PT(trackhat_metadata::module_name) -{ -} - -OPENTRACK_DECLARE_TRACKER(trackhat_pt, trackhat_pt_dialog, trackhat_module) +OPENTRACK_DECLARE_TRACKER(trackhat_pt, trackhat_dialog, trackhat_module) diff --git a/tracker-trackhat/metadata.hpp b/tracker-trackhat/metadata.hpp index d8d053b1..c0f7567c 100644 --- a/tracker-trackhat/metadata.hpp +++ b/tracker-trackhat/metadata.hpp @@ -1,7 +1,6 @@ #pragma once #include "trackhat.hpp" #include "../tracker-pt/ftnoir_tracker_pt.h" -#include "../tracker-pt/ftnoir_tracker_pt_dialog.h" class trackhat_pt final : public Tracker_PT { @@ -11,14 +10,6 @@ public: trackhat_pt(); }; -class trackhat_pt_dialog final : public TrackerDialog_PT -{ - Q_OBJECT - -public: - trackhat_pt_dialog(); -}; - class trackhat_module final : public Metadata { Q_OBJECT diff --git a/tracker-trackhat/settings.cpp b/tracker-trackhat/settings.cpp new file mode 100644 index 00000000..a2fd5c8c --- /dev/null +++ b/tracker-trackhat/settings.cpp @@ -0,0 +1,66 @@ +#include "trackhat.hpp" + +namespace trackhat_impl { + +trackhat_settings::trackhat_settings() : opts{"tracker-trackhat"} +{ +} + +void setting_receiver::settings_changed() +{ + changed = true; +} + +bool setting_receiver::test_and_clear() +{ + bool x = true; + return changed.compare_exchange_strong(x, false); +} + +} // ns trackhat_impl + +void trackhat_camera::set_pt_options() +{ + s.min_point_size = t.min_pt_size; + s.max_point_size = t.max_pt_size; + + switch (t.model) + { + default: + case model_cap: + s.t_MH_x = 0; s.t_MH_y = 0; s.t_MH_z = 0; + break; + case model_clip_left: + case model_mini_clip_left: + s.t_MH_x = -135; s.t_MH_y = 0; s.t_MH_z = 0; + break; + case model_clip_right: + case model_mini_clip_right: + s.t_MH_x = 135; s.t_MH_y = 0; s.t_MH_z = 0; + break; + } + + switch (t.model) + { + default: + eval_once(qDebug() << "tracker/trackhat: unknown model"); + [[fallthrough]]; + case model_clip_left: + case model_clip_right: + s.clip_tz = 27; s.clip_ty = 43; s.clip_by = 62; s.clip_bz = 74; + break; + case model_mini_clip_left: + case model_mini_clip_right: + s.clip_tz = 13; s.clip_ty = 42; s.clip_by = 60; s.clip_bz = 38; + break; + case model_cap: + s.cap_x = 60; s.cap_y = 90; s.cap_z = 95; + break; + } + + s.active_model_panel = t.model == model_cap ? 1 : 0; + s.enable_point_filter = t.enable_point_filter; + s.point_filter_coefficient = *t.point_filter_coefficient; + + s.b->save(); +} diff --git a/tracker-trackhat/trackhat-res.qrc b/tracker-trackhat/trackhat-res.qrc new file mode 100644 index 00000000..9aeb8879 --- /dev/null +++ b/tracker-trackhat/trackhat-res.qrc @@ -0,0 +1,5 @@ + + + images/trackhat-64x64.png + + diff --git a/tracker-trackhat/trackhat.hpp b/tracker-trackhat/trackhat.hpp index b0096cc3..2cdc083b 100644 --- a/tracker-trackhat/trackhat.hpp +++ b/tracker-trackhat/trackhat.hpp @@ -3,10 +3,53 @@ #include "../tracker-pt/pt-api.hpp" #include "track_hat_driver.h" #include "compat/macros.hpp" +#include "options/options.hpp" #include +#include #include +enum model_type : int +{ + model_cap = 1, + model_clip_left, + model_clip_right, + model_mini_clip_left, + model_mini_clip_right, +}; + +namespace trackhat_impl +{ +using namespace options; + +struct trackhat_settings : opts +{ + trackhat_settings(); + value exposure{b, "exposure", {0xfff0, 1, 0xfff0}}; + value threshold{b, "threshold", {0x97, 64, 0xff}}; + value model{b, "model", model_mini_clip_left}; + value min_pt_size{b, "min-point-size", 2}; + value max_pt_size{b, "max-point-size", 8}; + value enable_point_filter{b, "enable-point-filter", true }; + value point_filter_coefficient{b, "point-filter-coefficient", { 1, 0, 4 }}; +}; + +class setting_receiver : public QObject +{ + Q_OBJECT + +public: + bool test_and_clear(); +public slots: + void settings_changed(); +private: + std::atomic changed{false}; +}; + +} // ns trackhat_impl + +using typename trackhat_impl::trackhat_settings; + struct trackhat_metadata final : pt_runtime_traits { pt_runtime_traits::pointer make_camera() const override; @@ -25,7 +68,6 @@ struct trackhat_metadata final : pt_runtime_traits struct point { - double radius; int brightness = 0, x, y, W, H; bool ok = false; }; @@ -40,6 +82,7 @@ struct trackhat_camera final : pt_camera bool start(const pt_settings& s) override; void stop() override; [[nodiscard]] int init_regs(); + void set_pt_options(); pt_camera::result get_frame(pt_frame& frame) override; pt_camera::result get_info() const override; @@ -57,11 +100,13 @@ struct trackhat_camera final : pt_camera private: enum device_status { th_noinit, th_init, th_detect, th_connect, th_running, }; + trackhat_impl::setting_receiver sig; trackHat_Device_t device {}; device_status status = th_noinit; TH_ErrorCode error_code = TH_SUCCESS; pt_settings s{trackhat_metadata::module_name}; + trackhat_settings t; }; struct trackhat_frame final : pt_frame @@ -99,7 +144,4 @@ struct trackhat_extractor final : pt_point_extractor trackhat_extractor() = default; ~trackhat_extractor() override = default; - -private: - pt_settings s{trackhat_metadata::module_name}; }; -- cgit v1.2.3