fix y grid +

and move em4x50 saveGB to allow graph restore after lf search
clean up plotgraph unused code.
should be done for a bit...
This commit is contained in:
marshmellow42 2017-04-16 00:26:26 -04:00
parent 537f80f2c8
commit 999d57c201
3 changed files with 74 additions and 56 deletions

View file

@ -474,9 +474,6 @@ int EM4x50Read(const char *Cmd, bool verbose)
// get user entry if any // get user entry if any
sscanf(Cmd, "%i %i", &clk, &invert); sscanf(Cmd, "%i %i", &clk, &invert);
// save GraphBuffer - to restore it later
save_restoreGB(1);
// first get high and low values // first get high and low values
for (i = 0; i < GraphTraceLen; i++) { for (i = 0; i < GraphTraceLen; i++) {
if (GraphBuffer[i] > high) if (GraphBuffer[i] > high)
@ -573,6 +570,8 @@ int EM4x50Read(const char *Cmd, bool verbose)
} else if (start < 0) return 0; } else if (start < 0) return 0;
start = skip; start = skip;
snprintf(tmp2, sizeof(tmp2),"%d %d 1000 %d", clk, invert, clk*47); snprintf(tmp2, sizeof(tmp2),"%d %d 1000 %d", clk, invert, clk*47);
// save GraphBuffer - to restore it later
save_restoreGB(1);
// get rid of leading crap // get rid of leading crap
snprintf(tmp, sizeof(tmp), "%i", skip); snprintf(tmp, sizeof(tmp), "%i", skip);
CmdLtrim(tmp); CmdLtrim(tmp);

View file

@ -9,6 +9,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "proxguiqt.h" #include "proxguiqt.h"
#include <stdbool.h>
#include <iostream> #include <iostream>
#include <QPainterPath> #include <QPainterPath>
#include <QBrush> #include <QBrush>
@ -27,10 +28,12 @@
#include <QtGui> #include <QtGui>
//#include <ctime> //#include <ctime>
bool g_useOverlays = false;
int g_absVMax = 0;
int startMax; int startMax;
int PageWidth; int PageWidth;
void ProxGuiQT::ShowGraphWindow(void) void ProxGuiQT::ShowGraphWindow(void)
{ {
emit ShowGraphWindowSignal(); emit ShowGraphWindowSignal();
@ -130,6 +133,7 @@ void ProxWidget::vchange_autocorr(int v)
int ans; int ans;
ans = AutoCorrelate(GraphBuffer, s_Buff, GraphTraceLen, v, true, false); ans = AutoCorrelate(GraphBuffer, s_Buff, GraphTraceLen, v, true, false);
if (g_debugMode) printf("vchange_autocorr(w:%d): %d\n", v, ans); if (g_debugMode) printf("vchange_autocorr(w:%d): %d\n", v, ans);
g_useOverlays = true;
RepaintGraphWindow(); RepaintGraphWindow();
} }
void ProxWidget::vchange_askedge(int v) void ProxWidget::vchange_askedge(int v)
@ -138,6 +142,7 @@ void ProxWidget::vchange_askedge(int v)
//extern int AskEdgeDetect(const int *in, int *out, int len, int threshold); //extern int AskEdgeDetect(const int *in, int *out, int len, int threshold);
ans = AskEdgeDetect(GraphBuffer, s_Buff, GraphTraceLen, v); ans = AskEdgeDetect(GraphBuffer, s_Buff, GraphTraceLen, v);
if (g_debugMode) printf("vchange_askedge(w:%d)%d\n", v, ans); if (g_debugMode) printf("vchange_askedge(w:%d)%d\n", v, ans);
g_useOverlays = true;
RepaintGraphWindow(); RepaintGraphWindow();
} }
void ProxWidget::vchange_dthr_up(int v) void ProxWidget::vchange_dthr_up(int v)
@ -145,16 +150,16 @@ void ProxWidget::vchange_dthr_up(int v)
int down = opsController->horizontalSlider_dirthr_down->value(); int down = opsController->horizontalSlider_dirthr_down->value();
directionalThreshold(GraphBuffer, s_Buff, GraphTraceLen, v, down); directionalThreshold(GraphBuffer, s_Buff, GraphTraceLen, v, down);
//printf("vchange_dthr_up(%d)", v); //printf("vchange_dthr_up(%d)", v);
g_useOverlays = true;
RepaintGraphWindow(); RepaintGraphWindow();
} }
void ProxWidget::vchange_dthr_down(int v) void ProxWidget::vchange_dthr_down(int v)
{ {
//printf("vchange_dthr_down(%d)", v); //printf("vchange_dthr_down(%d)", v);
int up = opsController->horizontalSlider_dirthr_up->value(); int up = opsController->horizontalSlider_dirthr_up->value();
directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, up); directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, up);
g_useOverlays = true;
RepaintGraphWindow(); RepaintGraphWindow();
} }
ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent)
{ {
@ -170,6 +175,11 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent)
opsController->horizontalSlider_dirthr_down->setMinimum(-128); opsController->horizontalSlider_dirthr_down->setMinimum(-128);
opsController->horizontalSlider_dirthr_down->setMaximum(0); opsController->horizontalSlider_dirthr_down->setMaximum(0);
opsController->horizontalSlider_dirthr_down->setValue(-20); opsController->horizontalSlider_dirthr_down->setValue(-20);
opsController->horizontalSlider_dirthr_up->setMinimum(-40);
opsController->horizontalSlider_dirthr_up->setMaximum(128);
opsController->horizontalSlider_dirthr_up->setValue(20);
opsController->horizontalSlider_askedge->setValue(25);
opsController->horizontalSlider_window->setValue(4000);
QObject::connect(opsController->pushButton_apply, SIGNAL(clicked()), this, SLOT(applyOperation())); QObject::connect(opsController->pushButton_apply, SIGNAL(clicked()), this, SLOT(applyOperation()));
@ -223,6 +233,7 @@ void ProxWidget::closeEvent(QCloseEvent *event)
{ {
event->ignore(); event->ignore();
this->hide(); this->hide();
g_useOverlays = false;
} }
void ProxWidget::hideEvent(QHideEvent *event) { void ProxWidget::hideEvent(QHideEvent *event) {
controlWidget->hide(); controlWidget->hide();
@ -266,6 +277,32 @@ QColor Plot::getColor(int graphNum)
} }
} }
void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect)
{
if (len == 0) return;
startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint));
if(startMax < 0) {
startMax = 0;
}
if(GraphStart > startMax) {
GraphStart = startMax;
}
if (GraphStart > len) return;
int vMin = INT_MAX, vMax = INT_MIN, v = 0;
int sample_index = GraphStart ;
for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) {
v = buffer[sample_index];
if(v < vMin) vMin = v;
if(v > vMax) vMax = v;
}
g_absVMax = 0;
if(fabs( (double) vMin) > g_absVMax) g_absVMax = (int)fabs( (double) vMin);
if(fabs( (double) vMax) > g_absVMax) g_absVMax = (int)fabs( (double) vMax);
g_absVMax = (int)(g_absVMax*1.25 + 1);
}
void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset) void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset)
{ {
if (len == 0 || PlotGridX <= 0) return; if (len == 0 || PlotGridX <= 0) return;
@ -327,47 +364,16 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
if (len == 0) return; if (len == 0) return;
//clock_t begin = clock(); //clock_t begin = clock();
QPainterPath penPath; QPainterPath penPath;
int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, i = 0;
startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint));
if(startMax < 0) {
startMax = 0;
}
if(GraphStart > startMax) {
GraphStart = startMax;
}
if (GraphStart > len) return;
int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, absVMax = 0;
int sample_index = GraphStart ;
for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) {
v = buffer[sample_index];
if(v < vMin) vMin = v;
if(v > vMax) vMax = v;
vMean += v;
}
vMean /= (sample_index - GraphStart);
if(fabs( (double) vMin) > absVMax) absVMax = (int)fabs( (double) vMin);
if(fabs( (double) vMax) > absVMax) absVMax = (int)fabs( (double) vMax);
absVMax = (int)(absVMax*1.25 + 1);
// number of points that will be plotted
int span = (int)((plotRect.right() - plotRect.left()) / GraphPixelsPerPoint);
// one label every 100 pixels, let us say
int labels = (plotRect.right() - plotRect.left() - 40) / 100;
if(labels <= 0) labels = 1;
int pointsPerLabel = span / labels;
if(pointsPerLabel <= 0) pointsPerLabel = 1;
int x = xCoordOf(GraphStart, plotRect); int x = xCoordOf(GraphStart, plotRect);
int y = yCoordOf(buffer[GraphStart],plotRect,absVMax); int y = yCoordOf(buffer[GraphStart],plotRect,g_absVMax);
penPath.moveTo(x, y); penPath.moveTo(x, y);
for(int i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) { for(i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) {
x = xCoordOf(i, plotRect); x = xCoordOf(i, plotRect);
v = buffer[i]; v = buffer[i];
y = yCoordOf( v, plotRect, absVMax);//(y * (r.top() - r.bottom()) / (2*absYMax)) + zeroHeight; y = yCoordOf( v, plotRect, g_absVMax);
penPath.lineTo(x, y); penPath.lineTo(x, y);
@ -375,7 +381,12 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3)); QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
painter->fillRect(f, QColor(100, 255, 100)); painter->fillRect(f, QColor(100, 255, 100));
} }
//catch stats
if(v < vMin) vMin = v;
if(v > vMax) vMax = v;
vMean += v;
} }
vMean /= (i - GraphStart);
painter->setPen(getColor(graphNum)); painter->setPen(getColor(graphNum));
@ -383,7 +394,7 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
int xo = 5+(graphNum*40); int xo = 5+(graphNum*40);
painter->drawLine(xo, plotRect.top(),xo, plotRect.bottom()); painter->drawLine(xo, plotRect.top(),xo, plotRect.bottom());
int vMarkers = (absVMax - (absVMax % 10)) / 5; int vMarkers = (g_absVMax - (g_absVMax % 10)) / 5;
int minYDist = 40; //Minimum pixel-distance between markers int minYDist = 40; //Minimum pixel-distance between markers
char yLbl[20]; char yLbl[20];
@ -391,10 +402,10 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
int n = 0; int n = 0;
int lasty0 = 65535; int lasty0 = 65535;
for(int v = vMarkers; yCoordOf(v,plotRect,absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++) for(v = vMarkers; yCoordOf(v,plotRect,g_absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++)
{ {
int y0 = yCoordOf(v,plotRect,absVMax); int y0 = yCoordOf(v,plotRect,g_absVMax);
int y1 = yCoordOf(-v,plotRect,absVMax); int y1 = yCoordOf(-v,plotRect,g_absVMax);
if(lasty0 - y0 < minYDist) continue; if(lasty0 - y0 < minYDist) continue;
@ -413,7 +424,7 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
painter->drawPath(penPath); painter->drawPath(penPath);
char str[200]; char str[200];
sprintf(str, "max=%d min=%d mean=%d n=%d/%d CursorAVal=[%d] CursorBVal=[%d]", sprintf(str, "max=%d min=%d mean=%d n=%d/%d CursorAVal=[%d] CursorBVal=[%d]",
vMax, vMin, vMean, sample_index, len, buffer[CursorAPos], buffer[CursorBPos]); vMax, vMin, vMean, i, len, buffer[CursorAPos], buffer[CursorBPos]);
painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str); painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str);
//clock_t end = clock(); //clock_t end = clock();
@ -423,20 +434,18 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
void Plot::plotGridLines(QPainter* painter,QRect r) void Plot::plotGridLines(QPainter* painter,QRect r)
{ {
int zeroHeight = r.top() + (r.bottom() - r.top()) / 2;
int i; int i;
int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint); int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint);
int grid_delta_y = (int) (PlotGridY * GraphPixelsPerPoint); int grid_delta_y = PlotGridY;
if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) { if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
for(i = (GridOffset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) { for(i = (GridOffset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) {
painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom()); painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom());
} }
} }
if ((PlotGridY > 0) && ((PlotGridY * GraphPixelsPerPoint) > 1)){ if (PlotGridY > 0) {
for(i = 0; i < ((r.top() + r.bottom())>>1); i += grid_delta_y) { for(i = 0; yCoordOf(i,r,g_absVMax) > r.top(); i += grid_delta_y) {
painter->drawLine(r.left(),zeroHeight + i,r.right(),zeroHeight + i); painter->drawLine( r.left(), yCoordOf(i,r,g_absVMax), r.right(), yCoordOf(i,r,g_absVMax) );
painter->drawLine(r.left(),zeroHeight - i,r.right(),zeroHeight - i); painter->drawLine( r.left(), yCoordOf(i*-1,r,g_absVMax), r.right(), yCoordOf(i*-1,r,g_absVMax) );
} }
} }
} }
@ -446,6 +455,7 @@ void Plot::plotGridLines(QPainter* painter,QRect r)
void Plot::paintEvent(QPaintEvent *event) void Plot::paintEvent(QPaintEvent *event)
{ {
QPainter painter(this); QPainter painter(this);
QBrush brush(QColor(100, 255, 100)); QBrush brush(QColor(100, 255, 100));
QPen pen(QColor(100, 255, 100)); QPen pen(QColor(100, 255, 100));
@ -473,6 +483,9 @@ void Plot::paintEvent(QPaintEvent *event)
//Black foreground //Black foreground
painter.fillRect(plotRect, QColor(0, 0, 0)); painter.fillRect(plotRect, QColor(0, 0, 0));
//init graph variables
setMaxAndStart(GraphBuffer,GraphTraceLen,plotRect);
// center line // center line
int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2; int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2;
painter.setPen(QColor(100, 100, 100)); painter.setPen(QColor(100, 100, 100));
@ -481,11 +494,15 @@ void Plot::paintEvent(QPaintEvent *event)
plotGridLines(&painter, plotRect); plotGridLines(&painter, plotRect);
//Start painting graph //Start painting graph
PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0);
if (showDemod && DemodBufferLen > 8) { if (showDemod && DemodBufferLen > 8) {
PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx); PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx);
} }
PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1); if (g_useOverlays) {
PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0); //init graph variables
setMaxAndStart(s_Buff,GraphTraceLen,plotRect);
PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1);
}
// End graph drawing // End graph drawing
//Draw the cursors //Draw the cursors
@ -542,6 +559,7 @@ void Plot::closeEvent(QCloseEvent *event)
{ {
event->ignore(); event->ignore();
this->hide(); this->hide();
g_useOverlays = false;
} }
void Plot::mouseMoveEvent(QMouseEvent *event) void Plot::mouseMoveEvent(QMouseEvent *event)

View file

@ -35,6 +35,7 @@ private:
int xCoordOf(int i, QRect r ); int xCoordOf(int i, QRect r );
int yCoordOf(int v, QRect r, int maxVal); int yCoordOf(int v, QRect r, int maxVal);
int valueOf_yCoord(int y, QRect r, int maxVal); int valueOf_yCoord(int y, QRect r, int maxVal);
void setMaxAndStart(int *buffer, int len, QRect plotRect);
QColor getColor(int graphNum); QColor getColor(int graphNum);
public: public:
Plot(QWidget *parent = 0); Plot(QWidget *parent = 0);