From 4f8ec1a2ab434c3896763685fb5dfba7194be143 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 16 Oct 2021 16:35:22 +0200 Subject: tracker/trackhat: buffer flush --- tracker-trackhat/camera.cpp | 41 ++++++++------- tracker-trackhat/dialog.cpp | 46 +++++++++++++---- tracker-trackhat/dialog.ui | 112 +++++++++++++++++++++++++++++++++++------ tracker-trackhat/lang/nl_NL.ts | 8 +++ tracker-trackhat/lang/ru_RU.ts | 8 +++ tracker-trackhat/lang/stub.ts | 8 +++ tracker-trackhat/lang/zh_CN.ts | 8 +++ tracker-trackhat/trackhat.hpp | 2 + 8 files changed, 193 insertions(+), 40 deletions(-) diff --git a/tracker-trackhat/camera.cpp b/tracker-trackhat/camera.cpp index 5338f11c..77175616 100644 --- a/tracker-trackhat/camera.cpp +++ b/tracker-trackhat/camera.cpp @@ -37,13 +37,12 @@ trackhat_camera::trackhat_camera() s.set_raii_dtor_state(false); t.set_raii_dtor_state(false); - QObject::connect(&t.exposure, options::value_::value_changed(), - &sig, &trackhat_impl::setting_receiver::settings_changed, - Qt::DirectConnection); - - QObject::connect(&t.threshold, options::value_::value_changed(), - &sig, &trackhat_impl::setting_receiver::settings_changed, - Qt::DirectConnection); + for (auto* slider : { &t.exposure, &t.gain, &t.threshold, &t.threshold_2 }) + { + QObject::connect(slider, options::value_::value_changed(), + &sig, &trackhat_impl::setting_receiver::settings_changed, + Qt::DirectConnection); + } } trackhat_camera::~trackhat_camera() @@ -99,20 +98,28 @@ error: int trackhat_camera::init_regs() { - auto exp = (uint8_t)t.exposure; - auto thres = (uint8_t)t.threshold; unsigned attempts = 0; constexpr unsigned max_attempts = 5; + auto exp = (uint8_t)t.exposure; + auto thres = (uint8_t)t.threshold; + auto thres2 = (uint8_t)std::clamp((int)*t.threshold_2, 0, std::max(0, (int)*t.threshold - 1)); + + auto gain = (uint8_t)*t.gain; + auto gain_c = (uint8_t)(gain < 0x0f ? 0 : (gain / 0x0f + 1) & 3); + gain %= 0x0f; + const uint8_t regs[][3] = { - { 0x0c, 0x0f, 0xf0 }, // exposure lo - { 0x0c, 0x10, exp }, // exposure hi - { 0x00, 0x0b, 0xff }, // blob area max size - { 0x00, 0x0c, 0x03 }, // blob area min size - { 0x0c, 0x47, thres }, // min brightness - { 0x00, 0x0f, (uint8_t)(thres/10) }, // brightness margin, formula is `thres >= px > thres - fuzz' - { 0x00, 0x01, 0x01 }, // bank0 sync - { 0x01, 0x01, 0x01 }, // bank1 sync + { 0x0c, 0x0f, 0xf0 }, // exposure lo + { 0x0c, 0x10, exp }, // exposure hi + { 0x00, 0x0b, 0xff }, // blob area max size + { 0x00, 0x0c, 0x03 }, // blob area min size + { 0x0c, 0x08, gain }, // gain + { 0x0c, 0x0c, gain_c }, // gain multiplier + { 0x0c, 0x47, thres }, // min brightness + { 0x00, 0x0f, thres2 }, // brightness margin, formula is `thres >= px > thres - fuzz' + { 0x00, 0x01, 0x01 }, // bank0 sync + { 0x01, 0x01, 0x01 }, // bank1 sync }; start: diff --git a/tracker-trackhat/dialog.cpp b/tracker-trackhat/dialog.cpp index 6a9ad56c..b51fbc3b 100644 --- a/tracker-trackhat/dialog.cpp +++ b/tracker-trackhat/dialog.cpp @@ -24,27 +24,55 @@ trackhat_dialog::trackhat_dialog() for (auto x : model_types) ui.model_type->addItem(QIcon{}, tr(x.name), (QVariant)(int)x.t); - ui.exposure_label->setValue((int)*t.exposure); - ui.threshold_label->setValue((int)*t.threshold); - ui.point_filter_label->setValue((int)*t.point_filter_coefficient); - + tie_setting(t.model, ui.model_type); tie_setting(t.min_pt_size, ui.min_point_size); tie_setting(t.max_pt_size, ui.max_point_size); + + ui.exposure_label->setValue((int)*t.exposure); + ui.gain_label->setValue((int)*t.gain); tie_setting(t.exposure, ui.exposure_slider); - tie_setting(t.model, ui.model_type); - tie_setting(t.threshold, ui.threshold_slider); + tie_setting(t.gain, ui.gain_slider); + + ui.point_filter_label->setValue((int)*t.point_filter_coefficient); 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.gain, value_::value_changed(), ui.gain_label, + [this] { ui.gain_label->setValue((int)*t.gain); }, 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(&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); + + connect(&t.threshold, value_::value_changed(), ui.threshold_label, [=] { + ui.threshold_label->setValue((int)*t.threshold); + }, Qt::QueuedConnection); + + connect(&t.threshold_2, value_::value_changed(), ui.threshold_2_label, [=] { + ui.threshold_2_label->setValue((int)*t.threshold_2); + }, Qt::QueuedConnection); + + ui.threshold_2_slider->setValue(std::min(ui.threshold_2_slider->value(), ui.threshold_slider->value()-1)); + + connect(ui.threshold_slider, &QSlider::valueChanged, this, [this] (int value) { + if (value <= ui.threshold_2_slider->value()) + ui.threshold_2_slider->setValue(value-1); + }, Qt::DirectConnection); + + connect(ui.threshold_2_slider, &QSlider::valueChanged, this, [this] (int value) { + if (value >= ui.threshold_slider->value()) + ui.threshold_slider->setValue(value+1); + }, Qt::DirectConnection); + + ui.threshold_label->setValue((int)*t.threshold); + ui.threshold_2_label->setValue((int)*t.threshold_2); + tie_setting(t.threshold, ui.threshold_slider); + tie_setting(t.threshold_2, ui.threshold_2_slider); } void trackhat_dialog::register_tracker(ITracker* tracker) diff --git a/tracker-trackhat/dialog.ui b/tracker-trackhat/dialog.ui index 5eb21956..a1199a19 100644 --- a/tracker-trackhat/dialog.ui +++ b/tracker-trackhat/dialog.ui @@ -7,7 +7,7 @@ 0 0 365 - 334 + 388 @@ -30,8 +30,8 @@ Camera - - + + 0 @@ -39,18 +39,15 @@ - 239 - - - 10 + 51 Qt::Horizontal - - + + 0 @@ -58,14 +55,17 @@ - 191 + 239 + + + 10 Qt::Horizontal - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -93,7 +93,49 @@ QAbstractSpinBox::NoButtons - 65535 + 999 + + + + + + + Threshold + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + 999 + + + + + + + + 0 + 0 + + + + 64 + + + 255 + + + Qt::Horizontal @@ -105,9 +147,51 @@ - + - Threshold + Gain + + + + + + + Fuzz + + + + + + + + 0 + 0 + + + + 1 + + + 254 + + + Qt::Horizontal + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + 999 diff --git a/tracker-trackhat/lang/nl_NL.ts b/tracker-trackhat/lang/nl_NL.ts index 1f46e7e3..d23b6528 100644 --- a/tracker-trackhat/lang/nl_NL.ts +++ b/tracker-trackhat/lang/nl_NL.ts @@ -59,6 +59,14 @@ Status + + Gain + + + + Fuzz + + trackhat_module diff --git a/tracker-trackhat/lang/ru_RU.ts b/tracker-trackhat/lang/ru_RU.ts index 1f46e7e3..d23b6528 100644 --- a/tracker-trackhat/lang/ru_RU.ts +++ b/tracker-trackhat/lang/ru_RU.ts @@ -59,6 +59,14 @@ Status + + Gain + + + + Fuzz + + trackhat_module diff --git a/tracker-trackhat/lang/stub.ts b/tracker-trackhat/lang/stub.ts index 1f46e7e3..d23b6528 100644 --- a/tracker-trackhat/lang/stub.ts +++ b/tracker-trackhat/lang/stub.ts @@ -59,6 +59,14 @@ Status + + Gain + + + + Fuzz + + trackhat_module diff --git a/tracker-trackhat/lang/zh_CN.ts b/tracker-trackhat/lang/zh_CN.ts index 1f46e7e3..d23b6528 100644 --- a/tracker-trackhat/lang/zh_CN.ts +++ b/tracker-trackhat/lang/zh_CN.ts @@ -59,6 +59,14 @@ Status + + Gain + + + + Fuzz + + trackhat_module diff --git a/tracker-trackhat/trackhat.hpp b/tracker-trackhat/trackhat.hpp index 9f87da66..ade162ef 100644 --- a/tracker-trackhat/trackhat.hpp +++ b/tracker-trackhat/trackhat.hpp @@ -27,7 +27,9 @@ struct trackhat_settings : opts { trackhat_settings(); value exposure{b, "exposure", {0x80, 0x10, 0xff}}; + value gain{b, "gain", {16, 0, 47}}; value threshold{b, "threshold", {0x97, 64, 0xff}}; + value threshold_2{b, "threshold-2", {0x03, 1, 0xfe}}; 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}; -- cgit v1.2.3