diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2021-10-16 17:24:31 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-03-29 00:04:47 +0200 |
commit | 1ebb642f192f93144b4383f3e756da4675114cb0 (patch) | |
tree | a3a6b4c0525c2f0f1ca80aece592113a98de3bcc | |
parent | 4f8ec1a2ab434c3896763685fb5dfba7194be143 (diff) |
tracker/trackhat: buffer flush
-rw-r--r-- | tracker-trackhat/camera.cpp | 14 | ||||
-rw-r--r-- | tracker-trackhat/dialog.cpp | 59 | ||||
-rw-r--r-- | tracker-trackhat/dialog.ui | 3 | ||||
-rw-r--r-- | tracker-trackhat/trackhat.hpp | 2 |
4 files changed, 46 insertions, 32 deletions
diff --git a/tracker-trackhat/camera.cpp b/tracker-trackhat/camera.cpp index 77175616..1ec3bbe7 100644 --- a/tracker-trackhat/camera.cpp +++ b/tracker-trackhat/camera.cpp @@ -100,13 +100,14 @@ int trackhat_camera::init_regs() { unsigned attempts = 0; constexpr unsigned max_attempts = 5; + TH_ErrorCode error; 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 thres2 = (uint8_t)std::clamp((int)*t.threshold_2, 0, std::max(64, thres-1)); auto gain = (uint8_t)*t.gain; - auto gain_c = (uint8_t)(gain < 0x0f ? 0 : (gain / 0x0f + 1) & 3); + auto gain_c = (uint8_t)((gain/0x0f + !!(gain/0x0f)) & 3); gain %= 0x0f; const uint8_t regs[][3] = { @@ -117,21 +118,22 @@ int trackhat_camera::init_regs() { 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, 0x0f, thres2 }, // brightness margin, formula is `thres >= px > thres - fuzz' { 0x00, 0x01, 0x01 }, // bank0 sync { 0x01, 0x01, 0x01 }, // bank1 sync }; start: - for (const auto& reg : regs) { trackHat_SetRegister_t r{reg[0], reg[1], reg[2]}; - if (TH_ErrorCode error = trackHat_SetRegisterValue(&device, &r); error != TH_SUCCESS) + error = trackHat_SetRegisterValue(&device, &r); + if (error != TH_SUCCESS) goto error; } return TH_SUCCESS; + error: if (attempts++ < max_attempts) { @@ -139,7 +141,7 @@ error: goto start; } - return error_code; + return error; } bool trackhat_camera::start(const pt_settings&) diff --git a/tracker-trackhat/dialog.cpp b/tracker-trackhat/dialog.cpp index b51fbc3b..7e38bf52 100644 --- a/tracker-trackhat/dialog.cpp +++ b/tracker-trackhat/dialog.cpp @@ -24,30 +24,41 @@ trackhat_dialog::trackhat_dialog() for (auto x : model_types) ui.model_type->addItem(QIcon{}, tr(x.name), (QVariant)(int)x.t); + // model + 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); + // exposure + tie_setting(t.exposure, ui.exposure_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); + ui.exposure_label->setValue((int)*t.exposure); + ui.gain_label->setValue((int)*t.gain); connect(&t.exposure, value_::value_changed<slider_value>(), ui.exposure_label, - [this] { ui.exposure_label->setValue((int)*t.exposure); }, Qt::QueuedConnection); + [this] { ui.exposure_label->setValue((int)*t.exposure); }, Qt::QueuedConnection); connect(&t.gain, value_::value_changed<slider_value>(), ui.gain_label, [this] { ui.gain_label->setValue((int)*t.gain); }, Qt::QueuedConnection); - connect(&t.point_filter_coefficient, value_::value_changed<slider_value>(), ui.point_filter_label, - [this] { ui.point_filter_label->setValue((int)*t.point_filter_coefficient); }, Qt::QueuedConnection); + // threshold - 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(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); + + tie_setting(t.threshold, ui.threshold_slider); + tie_setting(t.threshold_2, ui.threshold_2_slider); + + ui.threshold_label->setValue((int)*t.threshold); + ui.threshold_2_label->setValue((int)*t.threshold_2); connect(&t.threshold, value_::value_changed<slider_value>(), ui.threshold_label, [=] { ui.threshold_label->setValue((int)*t.threshold); @@ -57,22 +68,20 @@ trackhat_dialog::trackhat_dialog() 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)); + // point filter - 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); + tie_setting(t.enable_point_filter, ui.enable_point_filter); + tie_setting(t.point_filter_coefficient, ui.point_filter_slider); + ui.point_filter_label->setValue((int)*t.point_filter_coefficient); - 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); + connect(&t.point_filter_coefficient, value_::value_changed<slider_value>(), ui.point_filter_label, + [this] { ui.point_filter_label->setValue(*t.point_filter_coefficient); }, Qt::QueuedConnection); - 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); + // stuff + + 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) diff --git a/tracker-trackhat/dialog.ui b/tracker-trackhat/dialog.ui index a1199a19..379f5347 100644 --- a/tracker-trackhat/dialog.ui +++ b/tracker-trackhat/dialog.ui @@ -361,6 +361,9 @@ <property name="maximum"> <double>300.000000000000000</double> </property> + <property name="singleStep"> + <double>0.100000000000000</double> + </property> </widget> </item> </layout> diff --git a/tracker-trackhat/trackhat.hpp b/tracker-trackhat/trackhat.hpp index ade162ef..8d14ad24 100644 --- a/tracker-trackhat/trackhat.hpp +++ b/tracker-trackhat/trackhat.hpp @@ -34,7 +34,7 @@ struct trackhat_settings : opts value<double> min_pt_size{b, "min-point-size", 2}; value<double> max_pt_size{b, "max-point-size", 8}; value<bool> enable_point_filter{b, "enable-point-filter", true }; - value<slider_value> point_filter_coefficient{b, "point-filter-coefficient", { 1, 0, 4 }}; + value<slider_value> point_filter_coefficient{b, "point-filter-coefficient", { 1.5, 1, 4 }}; }; class setting_receiver : public QObject |