Compare commits

..

No commits in common. "e0e6b368785e13b1baf5947ddfe7b4c054b06e28" and "2359fe5aca510dea5d32951509281713e62e28b9" have entirely different histories.

3 changed files with 25 additions and 73 deletions

View file

@ -20,7 +20,6 @@ static const double ChannelsSteps [] = {
}; };
static constexpr double REF_Y = 3.3; // maximum napětí převodníku 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 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 double STEP_Y = REF_Y / MAX_Y; // jeden krok ve Voltech
static constexpr unsigned T_SIZE = 1u << 10; static constexpr unsigned T_SIZE = 1u << 10;
static constexpr unsigned T_MASK = T_SIZE - 1u; static constexpr unsigned T_MASK = T_SIZE - 1u;
@ -30,14 +29,13 @@ DisplayWidget::DisplayWidget(QWidget * p) : QWidget(p), pcol(), ACopy(), BCopy()
x_lenght = T_SIZE; x_lenght = T_SIZE;
m_time.a = 200.0; m_time.a = 200.0;
m_time.b = 300.0; m_time.b = 300.0;
m_volt.a = -1.0 / STEP_Y; m_volt.a = 1.0 / STEP_Y;
m_volt.b = +1.0 / STEP_Y; m_volt.b = 2.0 / STEP_Y;
m_channels.a = ChannelsSteps[3]; m_channels.a = ChannelsSteps[3];
m_channels.b = ChannelsSteps[3]; m_channels.b = ChannelsSteps[3];
m_offset.a = 0; m_offset.a = 0.0;
m_offset.b = 0; m_offset.b = 0.0;
marker_type = MARKER_TIME; marker_type = MARKER_TIME;
m_TrgSource = 0;
int n = 0; int n = 0;
for (QPointF & e : ChA) { const QPointF p (n++, 0); e = p; } for (QPointF & e : ChA) { const QPointF p (n++, 0); e = p; }
n = 0; n = 0;
@ -45,12 +43,6 @@ DisplayWidget::DisplayWidget(QWidget * p) : QWidget(p), pcol(), ACopy(), BCopy()
} }
DisplayWidget::~DisplayWidget() { DisplayWidget::~DisplayWidget() {
} }
void DisplayWidget::SendTrigerChan(int n) {
m_TrgSource = n;
drawBackground();
update();
}
void DisplayWidget::MarkerChanged (int n, bool b) { void DisplayWidget::MarkerChanged (int n, bool b) {
if (!b) return; if (!b) return;
// qDebug ("Marker : %d -> %s", n, b ? "true" : "false"); // OK // qDebug ("Marker : %d -> %s", n, b ? "true" : "false"); // OK
@ -98,10 +90,6 @@ void DisplayWidget::wheelEvent(QWheelEvent * event) {
m_inverse = m_forward.inverted(); m_inverse = m_forward.inverted();
} }
} break; } break;
case OFSET_A: {
} break;
case OFSET_B: {
} break;
default : { default : {
qDebug ("wheelEvent : %d", int (m_items)); qDebug ("wheelEvent : %d", int (m_items));
} break; } break;
@ -113,12 +101,10 @@ void DisplayWidget::wheelEvent(QWheelEvent * event) {
void DisplayWidget::mousePressEvent(QMouseEvent * event) { void DisplayWidget::mousePressEvent(QMouseEvent * event) {
if (m_ts == nullptr) return; if (m_ts == nullptr) return;
const QPointF dp = m_inverse.map (event->pos ()); const QPointF dp = m_inverse.map (event->pos ());
const double ofs = m_TrgSource ? m_offset.b : m_offset.a; // qDebug ("dp:[%g, %g]", dp.x(), dp.y());
// qDebug ("dp:[%g, %g] %g", dp.x(), dp.y(), ofs);
switch (m_items) { switch (m_items) {
case MOVE_VALUE: { case MOVE_VALUE: {
m_ts->value = dp.y() - ofs + HALF_Y; m_ts->value = dp.y();
// qDebug("Set Triger : %d", m_ts->value);
emit SettingsChanged (m_items); emit SettingsChanged (m_items);
} break; } break;
case MOVE_OFSET: { case MOVE_OFSET: {
@ -133,12 +119,6 @@ void DisplayWidget::mousePressEvent(QMouseEvent * event) {
if (marker_type == MARKER_TIME) m_time.b = dp.x(); if (marker_type == MARKER_TIME) m_time.b = dp.x();
else m_volt.b = dp.y(); else m_volt.b = dp.y();
} break; } 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; case TIME_ZOOM: QWidget::mousePressEvent(event); return;
default : { default : {
qDebug ("mousePressEvent : %d", int (m_items)); qDebug ("mousePressEvent : %d", int (m_items));
@ -163,13 +143,9 @@ void DisplayWidget::paintEvent(QPaintEvent * event) {
QPen pa (pcol.colA, 2); QPen pa (pcol.colA, 2);
QPen pb (pcol.colB, 2); QPen pb (pcol.colB, 2);
p.setPen(pb); p.setPen(pb);
QMatrix mb (m_forward); p.drawPolyline (m_forward.map(ChB));
mb.translate(0, m_offset.b - HALF_Y);
p.drawPolyline (mb.map(ChB));
p.setPen(pa); p.setPen(pa);
QMatrix ma (m_forward); p.drawPolyline (m_forward.map(ChA));
ma.translate(0, m_offset.a - HALF_Y);
p.drawPolyline (ma.map(ChA));
} }
void DisplayWidget::setTrigger(TrigerSettings * ts) { void DisplayWidget::setTrigger(TrigerSettings * ts) {
m_ts = ts; m_ts = ts;
@ -213,7 +189,7 @@ void DisplayWidget::reloadMatrix(const QSize & sz) {
const double ym = sz.height(); const double ym = sz.height();
const double xz = xm / (x_lenght); // převod zpět ma pixely const double xz = xm / (x_lenght); // převod zpět ma pixely
const double yz = ym / (MAX_Y); const double yz = ym / (MAX_Y);
const QMatrix tm (xz,0,0,-yz, 0, 0.5 * ym); const QMatrix tm (xz,0,0,-yz, 0, ym);
m_forward = tm; m_forward = tm;
m_inverse = m_forward.inverted(); m_inverse = m_forward.inverted();
} }
@ -237,43 +213,36 @@ void DisplayWidget::drawBackground() {
QRect r = background.rect(); QRect r = background.rect();
p.fillRect (r, QBrush(Qt::black, Qt::SolidPattern)); p.fillRect (r, QBrush(Qt::black, Qt::SolidPattern));
if (!m_ts) return; if (!m_ts) return;
const double yb = 0.0, ye = HALF_Y; const double yb = 0.0, ye = MAX_Y;
const double xb = 0.0, xe = x_lenght; const double xb = 0.0, xe = x_lenght;
// rastr // rastr
QPen pg (QColor(64,64,64), 1); QPen pg (QColor(64,64,64), 1);
p.setPen(pg); p.setPen(pg);
const double dx = 100.0; const double dx = 100.0;
for (double x=xb; x<xe; x+=dx) { for (double x=xb; x<xe; x+=dx) {
const QLineF yline (x, -ye, x, +ye); const QLineF yline (x, yb, x, ye);
p.drawLine (m_forward.map(yline)); p.drawLine (m_forward.map(yline));
} }
const double dv = 0.5; const double dv = 0.5;
const double dy = dv / STEP_Y; const double dy = dv / STEP_Y;
for (double y=yb; y<ye; y+=dy) { for (double y=yb; y<ye; y+=dy) {
const QLineF xlinep (xb, +y, xe, +y); const QLineF xline (xb, y, xe, y);
p.drawLine (m_forward.map(xlinep)); p.drawLine (m_forward.map(xline));
const QLineF xlinem (xb, -y, xe, -y);
p.drawLine (m_forward.map(xlinem));
} }
QPen pg0 (QColor(128,128,128), 2);
p.setPen(pg0);
const QLineF hline0 (xb, 0, xe, 0);
p.drawLine (m_forward.map(hline0));
// triger // triger
const double ofs = (m_TrgSource ? m_offset.b : m_offset.a) - HALF_Y; QPointF trg (m_ts->offset, m_ts->value);
QPointF trg (m_ts->offset, m_ts->value + ofs);
QPen pc (QColor(0,0,255), 1); QPen pc (QColor(0,0,255), 1);
p.setPen(pc); p.setPen(pc);
const QLineF hline (xb, trg.y(), xe, trg.y()); const QLineF hline (xb, trg.y(), xe, trg.y());
const QLineF vline (trg.x(), -ye, trg.x(), ye); const QLineF vline (trg.x(), yb, trg.x(), ye);
p.drawLine (m_forward.map(hline)); p.drawLine (m_forward.map(hline));
p.drawLine (m_forward.map(vline)); p.drawLine (m_forward.map(vline));
// markers // markers
QPen pm (QColor(255,255,0,196), 1); QPen pm (QColor(255,255,0,196), 2);
p.setPen(pm); p.setPen(pm);
if (marker_type == MARKER_TIME) { if (marker_type == MARKER_TIME) {
const QLineF ma (m_time.a, -ye, m_time.a, ye); const QLineF ma (m_time.a, yb, m_time.a, ye);
const QLineF mb (m_time.b, -ye, m_time.b, ye); const QLineF mb (m_time.b, yb, m_time.b, ye);
p.drawLine (m_forward.map(ma)); p.drawLine (m_forward.map(ma));
p.drawLine (m_forward.map(mb)); p.drawLine (m_forward.map(mb));
} else { } else {
@ -282,18 +251,6 @@ void DisplayWidget::drawBackground() {
p.drawLine (m_forward.map(ma)); p.drawLine (m_forward.map(ma));
p.drawLine (m_forward.map(mb)); p.drawLine (m_forward.map(mb));
} }
// offsets
QPen ofpen(pcol.colA);
QVector<qreal>dashes;
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 // text
p.setPen (QPen (pcol.colT)); p.setPen (QPen (pcol.colT));
QFont font = p.font(); QFont font = p.font();
@ -311,14 +268,13 @@ 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(), 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()); ing_fmt(delta).c_str(), ing_fmt(freq).c_str());
} else { } else {
const double ofs = - (marker_type == MARKER_VOLT_A ? m_offset.a : m_offset.b);
double scl = 0.0; double scl = 0.0;
if (marker_type == MARKER_VOLT_A) { p.setPen (QPen (pcol.colA)); scl = m_channels.a; } 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; } else { p.setPen (QPen (pcol.colB)); scl = m_channels.b; }
//qDebug("scl = %g, a=%g, b=%g, oa=%g, ob=%g", scl, m_volt.a, m_volt.b, m_offset.a, m_offset.b); // qDebug("scl = %g", scl);
const double yz = STEP_Y * scl; const double yz = STEP_Y * scl;
const double delta = yz * (m_volt.b - m_volt.a), va = m_volt.a + ofs, vb = m_volt.b + ofs; const double delta = yz * (m_volt.b - m_volt.a);
desc.sprintf("Marker A: %sV, Marker B: %sV, Δ=%sV", ing_fmt(yz * va).c_str(), ing_fmt(yz * vb).c_str(), 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(),
ing_fmt(delta).c_str()); ing_fmt(delta).c_str());
} }
p.drawText(10,my, desc); p.drawText(10,my, desc);

View file

@ -28,7 +28,6 @@ class DisplayWidget : public QWidget {
MOVE_ITEMS m_items; MOVE_ITEMS m_items;
int m_timeBase; int m_timeBase;
int m_ChBase; int m_ChBase;
int m_TrgSource;
double x_lenght; double x_lenght;
struct MarkSetting { struct MarkSetting {
double a,b; double a,b;
@ -56,7 +55,6 @@ class DisplayWidget : public QWidget {
void reloadChRange (int a, int b); void reloadChRange (int a, int b);
void saveSettings (QSettings & setting); void saveSettings (QSettings & setting);
void restSettings (QSettings & setting); void restSettings (QSettings & setting);
void SendTrigerChan(int n);
void resizeEvent (QResizeEvent * event) override; void resizeEvent (QResizeEvent * event) override;
void paintEvent (QPaintEvent * event) override; void paintEvent (QPaintEvent * event) override;

View file

@ -89,9 +89,8 @@ void MainWindow::SetSelections(AllSettings as) {
ui->comboTimeRange->setCurrentIndex(as.part.tim); ui->comboTimeRange->setCurrentIndex(as.part.tim);
ui->comboVA ->setCurrentIndex(as.part.asc); ui->comboVA ->setCurrentIndex(as.part.asc);
ui->comboVB ->setCurrentIndex(as.part.bsc); ui->comboVB ->setCurrentIndex(as.part.bsc);
ui->Display->TimeBaseRange (as.part.tim); ui->Display->TimeBaseRange(as.part.tim);
ui->Display->reloadChRange (as.part.asc, as.part.bsc); ui->Display->reloadChRange(as.part.asc, as.part.bsc);
ui->Display->SendTrigerChan(as.part.trg.channel);
} }
MainWindow::~MainWindow () { MainWindow::~MainWindow () {
@ -134,8 +133,7 @@ void MainWindow::SendTrigerEdge (int n) {
firmware.SendTrigerEdge(n); firmware.SendTrigerEdge(n);
} }
void MainWindow::SendTrigerChan (int n) { void MainWindow::SendTrigerChan (int n) {
firmware.SendTrigerChan (n); firmware.SendTrigerChan(n);
ui->Display->SendTrigerChan(n);
} }
void MainWindow::TimeBaseRange (int n) { void MainWindow::TimeBaseRange (int n) {
firmware.SendBaseRange(n); firmware.SendBaseRange(n);