diff --git a/V203/usb/scope/software/displaywidget.cpp b/V203/usb/scope/software/displaywidget.cpp index 37bb0ad..3462e84 100644 --- a/V203/usb/scope/software/displaywidget.cpp +++ b/V203/usb/scope/software/displaywidget.cpp @@ -20,6 +20,7 @@ static const double ChannelsSteps [] = { }; static constexpr double REF_Y = 3.3; // maximum napětí převodníku static constexpr double MAX_Y = double (1 << 12); // 12. bit rozlišení - 4096 steps +static constexpr double HALF_Y = 0.5 * MAX_Y; static constexpr double STEP_Y = REF_Y / MAX_Y; // jeden krok ve Voltech static constexpr unsigned T_SIZE = 1u << 10; static constexpr unsigned T_MASK = T_SIZE - 1u; @@ -29,13 +30,14 @@ DisplayWidget::DisplayWidget(QWidget * p) : QWidget(p), pcol(), ACopy(), BCopy() x_lenght = T_SIZE; m_time.a = 200.0; m_time.b = 300.0; - m_volt.a = 1.0 / STEP_Y; - m_volt.b = 2.0 / STEP_Y; + m_volt.a = -1.0 / STEP_Y; + m_volt.b = +1.0 / STEP_Y; m_channels.a = ChannelsSteps[3]; m_channels.b = ChannelsSteps[3]; - m_offset.a = 0.0; - m_offset.b = 0.0; + m_offset.a = 0; + m_offset.b = 0; marker_type = MARKER_TIME; + m_TrgSource = 0; int n = 0; for (QPointF & e : ChA) { const QPointF p (n++, 0); e = p; } n = 0; @@ -43,6 +45,12 @@ DisplayWidget::DisplayWidget(QWidget * p) : QWidget(p), pcol(), ACopy(), BCopy() } DisplayWidget::~DisplayWidget() { } +void DisplayWidget::SendTrigerChan(int n) { + m_TrgSource = n; + drawBackground(); + update(); +} + void DisplayWidget::MarkerChanged (int n, bool b) { if (!b) return; // qDebug ("Marker : %d -> %s", n, b ? "true" : "false"); // OK @@ -90,6 +98,10 @@ void DisplayWidget::wheelEvent(QWheelEvent * event) { m_inverse = m_forward.inverted(); } } break; + case OFSET_A: { + } break; + case OFSET_B: { + } break; default : { qDebug ("wheelEvent : %d", int (m_items)); } break; @@ -101,10 +113,12 @@ void DisplayWidget::wheelEvent(QWheelEvent * event) { void DisplayWidget::mousePressEvent(QMouseEvent * event) { if (m_ts == nullptr) return; const QPointF dp = m_inverse.map (event->pos ()); - // qDebug ("dp:[%g, %g]", dp.x(), dp.y()); + const double ofs = m_TrgSource ? m_offset.b : m_offset.a; + // qDebug ("dp:[%g, %g] %g", dp.x(), dp.y(), ofs); switch (m_items) { case MOVE_VALUE: { - m_ts->value = dp.y(); + m_ts->value = dp.y() - ofs + HALF_Y; + // qDebug("Set Triger : %d", m_ts->value); emit SettingsChanged (m_items); } break; case MOVE_OFSET: { @@ -119,6 +133,12 @@ void DisplayWidget::mousePressEvent(QMouseEvent * event) { if (marker_type == MARKER_TIME) m_time.b = dp.x(); else m_volt.b = dp.y(); } break; + case OFSET_A: { + m_offset.a = dp.y(); + } break; + case OFSET_B: { + m_offset.b = dp.y(); + } break; case TIME_ZOOM: QWidget::mousePressEvent(event); return; default : { qDebug ("mousePressEvent : %d", int (m_items)); @@ -143,9 +163,13 @@ void DisplayWidget::paintEvent(QPaintEvent * event) { QPen pa (pcol.colA, 2); QPen pb (pcol.colB, 2); p.setPen(pb); - p.drawPolyline (m_forward.map(ChB)); + QMatrix mb (m_forward); + mb.translate(0, m_offset.b - HALF_Y); + p.drawPolyline (mb.map(ChB)); p.setPen(pa); - p.drawPolyline (m_forward.map(ChA)); + QMatrix ma (m_forward); + ma.translate(0, m_offset.a - HALF_Y); + p.drawPolyline (ma.map(ChA)); } void DisplayWidget::setTrigger(TrigerSettings * ts) { m_ts = ts; @@ -189,7 +213,7 @@ void DisplayWidget::reloadMatrix(const QSize & sz) { const double ym = sz.height(); const double xz = xm / (x_lenght); // převod zpět ma pixely const double yz = ym / (MAX_Y); - const QMatrix tm (xz,0,0,-yz, 0, ym); + const QMatrix tm (xz,0,0,-yz, 0, 0.5 * ym); m_forward = tm; m_inverse = m_forward.inverted(); } @@ -213,36 +237,43 @@ void DisplayWidget::drawBackground() { QRect r = background.rect(); p.fillRect (r, QBrush(Qt::black, Qt::SolidPattern)); if (!m_ts) return; - const double yb = 0.0, ye = MAX_Y; + const double yb = 0.0, ye = HALF_Y; const double xb = 0.0, xe = x_lenght; // rastr QPen pg (QColor(64,64,64), 1); p.setPen(pg); const double dx = 100.0; for (double x=xb; xoffset, m_ts->value); + const double ofs = (m_TrgSource ? m_offset.b : m_offset.a) - HALF_Y; + QPointF trg (m_ts->offset, m_ts->value + ofs); QPen pc (QColor(0,0,255), 1); p.setPen(pc); - const QLineF hline (xb, trg.y(), xe, trg.y()); - const QLineF vline (trg.x(), yb, trg.x(), ye); + const QLineF hline (xb, trg.y(), xe, trg.y()); + const QLineF vline (trg.x(), -ye, trg.x(), ye); p.drawLine (m_forward.map(hline)); p.drawLine (m_forward.map(vline)); // markers QPen pm (QColor(255,255,0,196), 2); p.setPen(pm); if (marker_type == MARKER_TIME) { - const QLineF ma (m_time.a, yb, m_time.a, ye); - const QLineF mb (m_time.b, yb, m_time.b, ye); + const QLineF ma (m_time.a, -ye, m_time.a, ye); + const QLineF mb (m_time.b, -ye, m_time.b, ye); p.drawLine (m_forward.map(ma)); p.drawLine (m_forward.map(mb)); } else { @@ -251,6 +282,18 @@ void DisplayWidget::drawBackground() { p.drawLine (m_forward.map(ma)); p.drawLine (m_forward.map(mb)); } + // offsets + QPen ofpen(pcol.colA); + QVectordashes; + dashes << 5 << 5 << 1 << 5; + ofpen.setDashPattern(dashes); + p.setPen (ofpen); + const QLineF oa (xb, m_offset.a, xe, m_offset.a); + p.drawLine (m_forward.map(oa)); + ofpen.setColor(pcol.colB); + p.setPen (ofpen); + const QLineF ob (xb, m_offset.b, xe, m_offset.b); + p.drawLine (m_forward.map(ob)); // text p.setPen (QPen (pcol.colT)); QFont font = p.font(); @@ -268,13 +311,14 @@ void DisplayWidget::drawBackground() { desc.sprintf("Marker A: %ss, Marker B: %ss, Δ=%ss, f=%sHz", ing_fmt(xz * m_time.a).c_str(), ing_fmt(xz * m_time.b).c_str(), ing_fmt(delta).c_str(), ing_fmt(freq).c_str()); } else { - double scl = 0.0; + const double ofs = 0;// HALF_Y + (marker_type == MARKER_VOLT_A ? m_offset.a : m_offset.b); + double scl = 0.0; // TODO - ofset to text if (marker_type == MARKER_VOLT_A) { p.setPen (QPen (pcol.colA)); scl = m_channels.a; } else { p.setPen (QPen (pcol.colB)); scl = m_channels.b; } - // qDebug("scl = %g", scl); + //qDebug("scl = %g, a=%g, b=%g, oa=%g, ob=%g", scl, m_volt.a, m_volt.b, m_offset.a, m_offset.b); const double yz = STEP_Y * scl; - const double delta = yz * (m_volt.b - m_volt.a); - desc.sprintf("Marker A: %sV, Marker B: %sV, Δ=%sV", ing_fmt(yz * m_volt.a).c_str(), ing_fmt(yz * m_volt.b).c_str(), + const double delta = yz * (m_volt.b - m_volt.a), va = m_volt.a + ofs, vb = m_volt.b + ofs; + desc.sprintf("Marker A: %sV, Marker B: %sV, Δ=%sV", ing_fmt(yz * va).c_str(), ing_fmt(yz * vb).c_str(), ing_fmt(delta).c_str()); } p.drawText(10,my, desc); diff --git a/V203/usb/scope/software/displaywidget.h b/V203/usb/scope/software/displaywidget.h index 9b496a9..97177b5 100644 --- a/V203/usb/scope/software/displaywidget.h +++ b/V203/usb/scope/software/displaywidget.h @@ -28,6 +28,7 @@ class DisplayWidget : public QWidget { MOVE_ITEMS m_items; int m_timeBase; int m_ChBase; + int m_TrgSource; double x_lenght; struct MarkSetting { double a,b; @@ -55,6 +56,7 @@ class DisplayWidget : public QWidget { void reloadChRange (int a, int b); void saveSettings (QSettings & setting); void restSettings (QSettings & setting); + void SendTrigerChan(int n); void resizeEvent (QResizeEvent * event) override; void paintEvent (QPaintEvent * event) override; diff --git a/V203/usb/scope/software/mainwindow.cpp b/V203/usb/scope/software/mainwindow.cpp index c9cba93..ea52b4e 100644 --- a/V203/usb/scope/software/mainwindow.cpp +++ b/V203/usb/scope/software/mainwindow.cpp @@ -89,8 +89,9 @@ void MainWindow::SetSelections(AllSettings as) { ui->comboTimeRange->setCurrentIndex(as.part.tim); ui->comboVA ->setCurrentIndex(as.part.asc); ui->comboVB ->setCurrentIndex(as.part.bsc); - ui->Display->TimeBaseRange(as.part.tim); - ui->Display->reloadChRange(as.part.asc, as.part.bsc); + ui->Display->TimeBaseRange (as.part.tim); + ui->Display->reloadChRange (as.part.asc, as.part.bsc); + ui->Display->SendTrigerChan(as.part.trg.channel); } MainWindow::~MainWindow () { @@ -133,7 +134,8 @@ void MainWindow::SendTrigerEdge (int n) { firmware.SendTrigerEdge(n); } void MainWindow::SendTrigerChan (int n) { - firmware.SendTrigerChan(n); + firmware.SendTrigerChan (n); + ui->Display->SendTrigerChan(n); } void MainWindow::TimeBaseRange (int n) { firmware.SendBaseRange(n);