From 1028a01cd81b044b896c2b44e71d20fd0110bfca Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Sun, 7 Apr 2024 20:33:49 +0800 Subject: [PATCH] fix: the math trace got an error factor --- DSView/pv/data/mathstack.cpp | 43 +++++++++++++++++++++++++++++++++--- DSView/pv/data/mathstack.h | 2 ++ DSView/pv/view/dsldial.cpp | 2 +- DSView/pv/view/dsosignal.cpp | 3 +++ DSView/pv/view/mathtrace.cpp | 1 + DSView/pv/view/view.cpp | 8 +++++++ DSView/pv/view/view.h | 3 +++ 7 files changed, 58 insertions(+), 4 deletions(-) diff --git a/DSView/pv/data/mathstack.cpp b/DSView/pv/data/mathstack.cpp index 7b803dbf..1d85bdfd 100644 --- a/DSView/pv/data/mathstack.cpp +++ b/DSView/pv/data/mathstack.cpp @@ -164,13 +164,16 @@ uint64_t MathStack::default_vDialValue() uint64_t value = 0; view::dslDial *dial1 = _dsoSig1->get_vDial(); view::dslDial *dial2 = _dsoSig2->get_vDial(); - const uint64_t dial1_value = dial1->get_value() * dial1->get_factor(); - const uint64_t dial2_value = dial2->get_value() * dial2->get_factor(); + const uint64_t dial1_value = dial1->get_value(); + const uint64_t dial2_value = dial2->get_value(); + + const uint64_t v1 = dial1_value * dial1->get_factor(); + const uint64_t v2 = dial2_value * dial2->get_factor(); switch(_type) { case MATH_ADD: case MATH_SUB: - value = max(dial1_value, dial2_value); + value = v1 > v2 ? dial1_value : dial2_value; break; case MATH_MUL: value = dial1_value * dial2_value / 1000.0; @@ -180,13 +183,47 @@ uint64_t MathStack::default_vDialValue() break; } + bool bFind = false; + for (int i = 0; i < vDialValueCount; i++) { if (vDialValue[i] >= value) { value = vDialValue[i]; + bFind = true; break; } } + if (!bFind){ + value = vDialValue[vDialValueCount-1]; + } + + return value; +} + +uint64_t MathStack::default_factor() +{ + uint64_t value = 0; + view::dslDial *dial1 = _dsoSig1->get_vDial(); + view::dslDial *dial2 = _dsoSig2->get_vDial(); + uint64_t factor1 = dial1->get_factor(); + uint64_t factor2 = dial1->get_factor(); + + const uint64_t dial1_value = dial1->get_value() * factor1; + const uint64_t dial2_value = dial2->get_value() * factor2; + + switch(_type) { + case MATH_ADD: + case MATH_SUB: + value = dial1_value > dial2_value ? factor1 : factor2; + break; + case MATH_MUL: + value = factor1 * factor2; + break; + case MATH_DIV: + value = factor1 / factor2; + break; + } + return value; } diff --git a/DSView/pv/data/mathstack.h b/DSView/pv/data/mathstack.h index 3b175f1c..27a3a545 100644 --- a/DSView/pv/data/mathstack.h +++ b/DSView/pv/data/mathstack.h @@ -116,6 +116,8 @@ public: void enable_envelope(bool enable); uint64_t default_vDialValue(); + uint64_t default_factor(); + view::dslDial *get_vDial(); QString get_unit(int level); double get_math_scale(); diff --git a/DSView/pv/view/dsldial.cpp b/DSView/pv/view/dsldial.cpp index 3ac842f1..a586310a 100644 --- a/DSView/pv/view/dsldial.cpp +++ b/DSView/pv/view/dsldial.cpp @@ -80,7 +80,7 @@ void dslDial::paint(QPainter &p, QRectF dialRect, QColor dialColor, const QPoint } p.restore(); // draw value - uint64_t displayValue = _value[_sel]*_factor; + uint64_t displayValue = _value[_sel]; uint64_t displayIndex = 0; while(displayValue / _step >= 1) { displayValue = displayValue / _step; diff --git a/DSView/pv/view/dsosignal.cpp b/DSView/pv/view/dsosignal.cpp index 3b0d112c..71a98b48 100644 --- a/DSView/pv/view/dsosignal.cpp +++ b/DSView/pv/view/dsosignal.cpp @@ -1178,12 +1178,15 @@ bool DsoSignal::mouse_press(int right, const QPoint pt) } else if (x1_rect.contains(pt)) { set_factor(1); + _view->dso_factor_updated(); } else if (x10_rect.contains(pt)) { set_factor(10); + _view->dso_factor_updated(); } else if (x100_rect.contains(pt)) { set_factor(100); + _view->dso_factor_updated(); } else { return false; diff --git a/DSView/pv/view/mathtrace.cpp b/DSView/pv/view/mathtrace.cpp index 5c394ec6..915fb547 100644 --- a/DSView/pv/view/mathtrace.cpp +++ b/DSView/pv/view/mathtrace.cpp @@ -99,6 +99,7 @@ int MathTrace::get_name_width() void MathTrace::update_vDial() { _vDial->set_value(_math_stack->default_vDialValue()); + _vDial->set_factor(_math_stack->default_factor()); } void MathTrace::go_vDialPre() diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index c4d0406f..1a10311e 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -1183,6 +1183,14 @@ void View::vDial_updated() } } +void View::dso_factor_updated() +{ + auto math_trace = _session->get_math_trace(); + if (math_trace && math_trace->enabled()) { + math_trace->update_vDial(); + } +} + // -- lissajous figure void View::show_lissajous(bool show) { diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index d80a9ba5..f3c23fbd 100644 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -386,6 +386,9 @@ public slots: void timebase_changed(); // -- void vDial_updated(); + + void dso_factor_updated(); + // -- void update_hori_res();