From 0d704c7f5e1ddcf2a4e18f9f5759e6779a30119a Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 9 Feb 2015 15:26:29 +0100 Subject: [PATCH] First stab at new graphing; dual buffers, immediate results --- client/Makefile | 1 + client/cmddata.c | 59 +----- client/data_operations.c | 58 ++++++ client/data_operations.h | 17 ++ client/graph.c | 3 + client/graph.h | 5 +- client/proxgui.h | 10 +- client/proxguiqt.cpp | 402 ++++++++++++++++++++++++++------------- client/proxguiqt.h | 87 +++++++-- client/ui/overlays.ui | 272 ++++++++++++++++++++++++++ client/ui/ui_overlays.h | 224 ++++++++++++++++++++++ 11 files changed, 936 insertions(+), 202 deletions(-) create mode 100644 client/data_operations.c create mode 100644 client/data_operations.h create mode 100644 client/ui/overlays.ui create mode 100644 client/ui/ui_overlays.h diff --git a/client/Makefile b/client/Makefile index e63581ba..621b5779 100644 --- a/client/Makefile +++ b/client/Makefile @@ -60,6 +60,7 @@ CMDSRCS = nonce2key/crapto1.c\ loclass/ikeys.c \ loclass/elite_crack.c\ loclass/fileutils.c\ + data_operations.c\ mifarehost.c\ crc16.c \ iso14443crc.c \ diff --git a/client/cmddata.c b/client/cmddata.c index 430afb17..53a6584c 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -22,7 +22,7 @@ #include "cmddata.h" #include "lfdemod.h" #include "usb_cmd.h" - +#include "data_operations.h" uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; uint8_t g_debugMode; int DemodBufferLen; @@ -439,38 +439,16 @@ int Cmdaskrawdemod(const char *Cmd) return 1; } + int CmdAutoCorr(const char *Cmd) { - static int CorrelBuffer[MAX_GRAPH_TRACE_LEN]; - int window = atoi(Cmd); - - if (window == 0) { - PrintAndLog("needs a window"); - return 0; - } - if (window >= GraphTraceLen) { - PrintAndLog("window must be smaller than trace (%d samples)", - GraphTraceLen); - return 0; - } - - PrintAndLog("performing %d correlations", GraphTraceLen - window); - - for (int i = 0; i < GraphTraceLen - window; ++i) { - int sum = 0; - for (int j = 0; j < window; ++j) { - sum += (GraphBuffer[j]*GraphBuffer[i + j]) / 256; - } - CorrelBuffer[i] = sum; - } - GraphTraceLen = GraphTraceLen - window; - memcpy(GraphBuffer, CorrelBuffer, GraphTraceLen * sizeof (int)); - + autoCorr(GraphBuffer, GraphBuffer,GraphTraceLen,window); RepaintGraphWindow(); return 0; } + int CmdBitsamples(const char *Cmd) { int cnt = 0; @@ -1670,8 +1648,8 @@ int CmdLoad(const char *Cmd) FILE *f = fopen(filename, "r"); if (!f) { - PrintAndLog("couldn't open '%s'", filename); - return 0; + PrintAndLog("couldn't open '%s'", filename); + return 0; } GraphTraceLen = 0; @@ -2033,30 +2011,7 @@ int CmdDirectionalThreshold(const char *Cmd) printf("Applying Up Threshold: %d, Down Threshold: %d\n", upThres, downThres); - int lastValue = GraphBuffer[0]; - GraphBuffer[0] = 0; // Will be changed at the end, but init 0 as we adjust to last samples value if no threshold kicks in. - - for (int i = 1; i < GraphTraceLen; ++i) { - // Apply first threshold to samples heading up - if (GraphBuffer[i] >= upThres && GraphBuffer[i] > lastValue) - { - lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. - GraphBuffer[i] = 1; - } - // Apply second threshold to samples heading down - else if (GraphBuffer[i] <= downThres && GraphBuffer[i] < lastValue) - { - lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. - GraphBuffer[i] = -1; - } - else - { - lastValue = GraphBuffer[i]; // Buffer last value as we overwrite it. - GraphBuffer[i] = GraphBuffer[i-1]; - - } - } - GraphBuffer[0] = GraphBuffer[1]; // Aline with first edited sample. + directionalThreshold(GraphBuffer, GraphBuffer,GraphTraceLen, upThres, downThres); RepaintGraphWindow(); return 0; } diff --git a/client/data_operations.c b/client/data_operations.c new file mode 100644 index 00000000..f694600c --- /dev/null +++ b/client/data_operations.c @@ -0,0 +1,58 @@ +#include + +extern void PrintAndLog(char *fmt, ...); + +int autoCorr(const int* in, int *out, size_t len, int window) +{ + static int CorrelBuffer[MAX_GRAPH_TRACE_LEN]; + + if (window == 0) { + PrintAndLog("needs a window"); + return 0; + } + if (window >= len) { + PrintAndLog("window must be smaller than trace (%d samples)", + len); + return 0; + } + + PrintAndLog("performing %d correlations", len - window); + + for (int i = 0; i < len - window; ++i) { + int sum = 0; + for (int j = 0; j < window; ++j) { + sum += (in[j]*in[i + j]) / 256; + } + CorrelBuffer[i] = sum; + } + //GraphTraceLen = GraphTraceLen - window; + memcpy(out, CorrelBuffer, len * sizeof (int)); + return 0; +} +int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down) +{ + int lastValue = in[0]; + out[0] = 0; // Will be changed at the end, but init 0 as we adjust to last samples value if no threshold kicks in. + + for (int i = 1; i < len; ++i) { + // Apply first threshold to samples heading up + if (in[i] >= up && in[i] > lastValue) + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = 1; + } + // Apply second threshold to samples heading down + else if (in[i] <= down && in[i] < lastValue) + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = -1; + } + else + { + lastValue = out[i]; // Buffer last value as we overwrite it. + out[i] = out[i-1]; + } + } + out[0] = out[1]; // Align with first edited sample. + return 0; +} diff --git a/client/data_operations.h b/client/data_operations.h new file mode 100644 index 00000000..88da1bd7 --- /dev/null +++ b/client/data_operations.h @@ -0,0 +1,17 @@ +#ifndef DATA_OPERATIONS_H +#define DATA_OPERATIONS_H + +#include +#include + +// Max graph trace len: 40000 (bigbuf) * 8 (at 1 bit per sample) +#define MAX_GRAPH_TRACE_LEN (40000 * 8 ) + +extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; +extern int GraphTraceLen; +extern int s_Buff[MAX_GRAPH_TRACE_LEN]; + + +int autoCorr(const int* in, int *out, size_t len, int window); +int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down); +#endif // DATA_OPERATIONS_H diff --git a/client/graph.c b/client/graph.c index 95050f55..94c65569 100644 --- a/client/graph.c +++ b/client/graph.c @@ -18,6 +18,9 @@ int GraphBuffer[MAX_GRAPH_TRACE_LEN]; int GraphTraceLen; +int s_Buff[MAX_GRAPH_TRACE_LEN]; + + /* write a bit to the graph */ void AppendGraph(int redraw, int clock, int bit) { diff --git a/client/graph.h b/client/graph.h index 9817d776..dc9ed9a0 100644 --- a/client/graph.h +++ b/client/graph.h @@ -11,6 +11,7 @@ #ifndef GRAPH_H__ #define GRAPH_H__ #include +#include "data_operations.h" void AppendGraph(int redraw, int clock, int bit); int ClearGraph(int redraw); @@ -23,9 +24,5 @@ void setGraphBuf(uint8_t *buff, size_t size); bool HasGraphData(); void DetectHighLowInGraph(int *high, int *low, bool addFuzz); -// Max graph trace len: 40000 (bigbuf) * 8 (at 1 bit per sample) -#define MAX_GRAPH_TRACE_LEN (40000 * 8 ) -extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; -extern int GraphTraceLen; #endif diff --git a/client/proxgui.h b/client/proxgui.h index 6fcf4d0a..0d50a4f6 100644 --- a/client/proxgui.h +++ b/client/proxgui.h @@ -7,6 +7,7 @@ //----------------------------------------------------------------------------- // GUI functions //----------------------------------------------------------------------------- +#include #ifdef __cplusplus extern "C" { @@ -19,14 +20,21 @@ void MainGraphics(void); void InitGraphics(int argc, char **argv); void ExitGraphics(void); -#define MAX_GRAPH_TRACE_LEN (1024*128) +#define MAX_GRAPH_TRACE_LEN (40000 * 8 ) extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; extern int GraphTraceLen; +extern int s_Buff[MAX_GRAPH_TRACE_LEN]; + extern double CursorScaleFactor; extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault; extern int CommandFinished; extern int offline; +//Operations defined in data_operations +extern int autoCorr(const int* in, int *out, size_t len, int window); +extern int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down); + + #ifdef __cplusplus } #endif diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index 3e9bdfd5..ec8c1c26 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -19,8 +19,14 @@ #include #include #include +#include +#include +#include #include "proxguiqt.h" #include "proxgui.h" +#include +//#include "data_operations.h" +#include int GridOffset= 0; bool GridLocked= 0; @@ -83,6 +89,7 @@ void ProxGuiQT::MainLoop() ProxGuiQT::ProxGuiQT(int argc, char **argv) : plotapp(NULL), plotwidget(NULL), argc(argc), argv(argv) { + } ProxGuiQT::~ProxGuiQT(void) @@ -99,65 +106,121 @@ ProxGuiQT::~ProxGuiQT(void) } } -void ProxWidget::paintEvent(QPaintEvent *event) +//-------------------- + +void ProxWidget::applyOperation() { - QPainter painter(this); - QPainterPath penPath, whitePath, greyPath, lightgreyPath, cursorAPath, cursorBPath; - QRect r; - QBrush brush(QColor(100, 255, 100)); - QPen pen(QColor(100, 255, 100)); + printf("ApplyOperation()"); + memcpy(GraphBuffer,s_Buff, GraphTraceLen); + RepaintGraphWindow(); - painter.setFont(QFont("Arial", 10)); +} +void ProxWidget::stickOperation() +{ + printf("stickOperation()"); +} +void ProxWidget::vchange_autocorr(int v) +{ + autoCorr(GraphBuffer,s_Buff, GraphTraceLen, v); + printf("vchange_autocorr(%d)\n", v); + RepaintGraphWindow(); +} +void ProxWidget::vchange_dthr_up(int v) +{ + int down = opsController->horizontalSlider_dirthr_down->value(); + directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, down); + printf("vchange_dthr_up(%d)", v); + RepaintGraphWindow(); - if(GraphStart < 0) { - GraphStart = 0; - } +} +void ProxWidget::vchange_dthr_down(int v) +{ + printf("vchange_dthr_down(%d)", v); + int up = opsController->horizontalSlider_dirthr_up->value(); + directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, up); + RepaintGraphWindow(); - if (CursorAPos > GraphTraceLen) - CursorAPos= 0; - if(CursorBPos > GraphTraceLen) - CursorBPos= 0; +} +ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) +{ + this->master = master; + resize(800,500); + + /** Setup the controller widget **/ + + QWidget* controlWidget = new QWidget(); + opsController = new Ui::Form(); + opsController->setupUi(controlWidget); + //Due to quirks in QT Designer, we need to fiddle a bit + opsController->horizontalSlider_dirthr_down->setMinimum(-128); + opsController->horizontalSlider_dirthr_down->setMaximum(0); + opsController->horizontalSlider_dirthr_down->setValue(-20); + + + QObject::connect(opsController->pushButton_apply, SIGNAL(clicked()), this, SLOT(applyOperation())); + QObject::connect(opsController->pushButton_sticky, SIGNAL(clicked()), this, SLOT(stickOperation())); + QObject::connect(opsController->horizontalSlider_window, SIGNAL(valueChanged(int)), this, SLOT(vchange_autocorr(int))); + QObject::connect(opsController->horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_up(int))); + QObject::connect(opsController->horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_down(int))); + + controlWidget->show(); + + // Set up the plot widget, which does the actual plotting + + plot = new Plot(this); + /* + QSlider* slider = new QSlider(Qt::Horizontal); + slider->setFocusPolicy(Qt::StrongFocus); + slider->setTickPosition(QSlider::TicksBothSides); + slider->setTickInterval(10); + slider->setSingleStep(1); + */ + QVBoxLayout *layout = new QVBoxLayout; + //layout->addWidget(slider); + layout->addWidget(plot); + setLayout(layout); + printf("Proxwidget Constructor just set layout\r\n"); +} - r = rect(); +//----------- Plotting - painter.fillRect(r, QColor(0, 0, 0)); +int Plot::xCoordOf(int i ) +{ + return 40 + (int)((i - GraphStart)*GraphPixelsPerPoint); +} - whitePath.moveTo(r.left() + 40, r.top()); - whitePath.lineTo(r.left() + 40, r.bottom()); +int Plot::yCoordOf(int v, QRect r, int maxVal) +{ + int z = (r.bottom() - r.top())/2; + return -(z * v) / maxVal + z; +} - int zeroHeight = r.top() + (r.bottom() - r.top()) / 2; +int Plot::valueOf_yCoord(int y, QRect r, int maxVal) +{ + int z = (r.bottom() - r.top())/2; + return (y-z) * maxVal / z; +} +static const QColor GREEN = QColor(100, 255, 100); +static const QColor RED = QColor(255, 100, 100); +static const QColor BLUE = QColor(100,100,255); +static const QColor GREY = QColor(240,240,240); - greyPath.moveTo(r.left(), zeroHeight); - greyPath.lineTo(r.right(), zeroHeight); - painter.setPen(QColor(100, 100, 100)); - painter.drawPath(greyPath); +QColor Plot::getColor(int graphNum) +{ + switch (graphNum){ + case 0: return GREEN;//Green + case 1: return RED;//Red + case 2: return BLUE;//Blue + default: return GREY; + } +} - PageWidth= (int)((r.right() - r.left() - 40) / GraphPixelsPerPoint); - - // plot X and Y grid lines - int i; - if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) { - for(i = 40 + (GridOffset * GraphPixelsPerPoint); i < r.right(); i += (int)(PlotGridX * GraphPixelsPerPoint)) { - //SelectObject(hdc, GreyPenLite); - //MoveToEx(hdc, r.left + i, r.top, NULL); - //LineTo(hdc, r.left + i, r.bottom); - lightgreyPath.moveTo(r.left()+i,r.top()); - lightgreyPath.lineTo(r.left()+i,r.bottom()); - painter.drawPath(lightgreyPath); - } - } - if ((PlotGridY > 0) && ((PlotGridY * GraphPixelsPerPoint) > 1)){ - for(i = 0; i < ((r.top() + r.bottom())>>1); i += (int)(PlotGridY * GraphPixelsPerPoint)) { - lightgreyPath.moveTo(r.left() + 40,zeroHeight + i); - lightgreyPath.lineTo(r.right(),zeroHeight + i); - painter.drawPath(lightgreyPath); - lightgreyPath.moveTo(r.left() + 40,zeroHeight - i); - lightgreyPath.lineTo(r.right(),zeroHeight - i); - painter.drawPath(lightgreyPath); - } - } - - startMax = (GraphTraceLen - (int)((r.right() - r.left() - 40) / GraphPixelsPerPoint)); +void Plot::PlotGraph(int *buffer, int len, QRect r,QPainter *painter, int graphNum) +{ + clock_t begin = clock(); + QPainterPath penPath; + + startMax = (len - (int)((r.right() - r.left() - 40) / GraphPixelsPerPoint)); if(startMax < 0) { startMax = 0; } @@ -165,23 +228,22 @@ void ProxWidget::paintEvent(QPaintEvent *event) GraphStart = startMax; } - int absYMax = 1; + int vMin = INT_MAX, vMax = INT_MIN,vMean = 0, v = 0,absVMax = 0; + int sample_index =GraphStart ; + for( ; sample_index < len && xCoordOf(sample_index) < r.right() ; sample_index++) { - for(i = GraphStart; ; i++) { - if(i >= GraphTraceLen) { - break; - } - if(fabs((double)GraphBuffer[i]) > absYMax) { - absYMax = (int)fabs((double)GraphBuffer[i]); - } - int x = 40 + (int)((i - GraphStart)*GraphPixelsPerPoint); - if(x > r.right()) { - break; - } + v = buffer[sample_index]; + if(v < vMin) vMin = v; + if(v > vMax) vMax = v; + vMean += v; } - absYMax = (int)(absYMax*1.2 + 1); - + 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.2 + 1); + // number of points that will be plotted int span = (int)((r.right() - r.left()) / GraphPixelsPerPoint); // one label every 100 pixels, let us say @@ -190,96 +252,173 @@ void ProxWidget::paintEvent(QPaintEvent *event) int pointsPerLabel = span / labels; if(pointsPerLabel <= 0) pointsPerLabel = 1; - int yMin = INT_MAX; - int yMax = INT_MIN; - int yMean = 0; - int n = 0; + int x = xCoordOf(0)+40; + int y = yCoordOf(buffer[0],r,absVMax); + penPath.moveTo(x, y); - for(i = GraphStart; ; i++) { - if(i >= GraphTraceLen) { - break; - } - int x = 40 + (int)((i - GraphStart)*GraphPixelsPerPoint); - if(x > r.right() + GraphPixelsPerPoint) { - break; - } + int zeroY = yCoordOf( 0 , r , absVMax); + for(int i = GraphStart; i < len && xCoordOf(i) < r.right(); i++) { - int y = GraphBuffer[i]; - if(y < yMin) { - yMin = y; - } - if(y > yMax) { - yMax = y; - } - yMean += y; - n++; - - y = (y * (r.top() - r.bottom()) / (2*absYMax)) + zeroHeight; - if(i == GraphStart) { - penPath.moveTo(x, y); - } else { - penPath.lineTo(x, y); - } + x = xCoordOf(i); + v = buffer[i]; + + y = yCoordOf( v, r, absVMax);//(y * (r.top() - r.bottom()) / (2*absYMax)) + zeroHeight; + + penPath.lineTo(x, y); if(GraphPixelsPerPoint > 10) { QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3)); - painter.fillRect(f, brush); + painter->fillRect(f, QColor(100, 255, 100)); } if(((i - GraphStart) % pointsPerLabel == 0) && i != GraphStart) { - whitePath.moveTo(x, zeroHeight - 3); - whitePath.lineTo(x, zeroHeight + 3); - char str[100]; sprintf(str, "+%d", (i - GraphStart)); - painter.setPen(QColor(255, 255, 255)); + painter->setPen(QColor(255, 255, 255)); QRect size; - QFontMetrics metrics(painter.font()); + QFontMetrics metrics(painter->font()); size = metrics.boundingRect(str); - painter.drawText(x - (size.right() - size.left()), zeroHeight + 9, str); - - penPath.moveTo(x,y); + painter->drawText(x - (size.right() - size.left()), zeroY + 9, str); } - if(i == CursorAPos || i == CursorBPos) { - QPainterPath *cursorPath; + } + painter->setPen(getColor(graphNum)); + painter->drawPath(penPath); + char str[200]; + sprintf(str, "max=%5d min=%5d mean=%5d n=%5d/%5d CursorA=[%5d] CursorB=[%5d]", + vMax, vMin, vMean, sample_index, len, buffer[CursorAPos], buffer[CursorBPos]); + + painter->drawText(120, r.bottom() - 25 - 15 * graphNum, str); + + //Draw y-axis + + int xo = r.left()+40+(graphNum*40); + painter->drawLine(xo, r.top(),xo, r.bottom()); + + int vMarkers = (absVMax - (absVMax % 10)) / 10; + int minYDist = 20; //Minimum pixel-distance between markers + + char yLbl[20]; + + int n = 0; + int lasty0 = 65535; + + for(int v = vMarkers; yCoordOf(v,r,absVMax) > r.top() && n < 20; v+= vMarkers ,n++) + { + int y0 = yCoordOf(v,r,absVMax); + int y1 = yCoordOf(-v,r,absVMax); + + if(lasty0 - y0 < minYDist) continue; + + painter->drawLine(xo-5,y0, xo+5, y0); + + sprintf(yLbl, "%d", v); + painter->drawText(xo+5,y0-2,yLbl); + + painter->drawLine(xo-5, y1, xo+5, y1); + sprintf(yLbl, "%d",-v); + painter->drawText(xo+5, y1-2 , yLbl); + lasty0 = y0; + } + + + clock_t end = clock(); + double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC; + printf("Plot time %f\n", elapsed_secs); +} +void Plot::plotGridLines(QPainter* painter,QRect r) +{ + int zeroHeight = r.top() + (r.bottom() - r.top()) / 2; + + int i; + int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint); + int grid_delta_y = (int) (PlotGridY * GraphPixelsPerPoint); + + if (PlotGridX > 0 && grid_delta_x > 1) { + for(i = 40 + (GridOffset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) + painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom()); + } + if (PlotGridY > 0 && grid_delta_y > 1){ + for(i = 0; i < ((r.top() + r.bottom())>>1); i += grid_delta_y) { + painter->drawLine(r.left() + 40,zeroHeight + i,r.right(),zeroHeight + i); + painter->drawLine(r.left() + 40,zeroHeight - i,r.right(),zeroHeight - i); - if(i == CursorAPos) { - cursorPath = &cursorAPath; - } else { - cursorPath = &cursorBPath; - } - cursorPath->moveTo(x, r.top()); - cursorPath->lineTo(x, r.bottom()); - penPath.moveTo(x, y); } } - if(n != 0) { - yMean /= n; +} + +void Plot::paintEvent(QPaintEvent *event) +{ + + QPainter painter(this); + QRect r; + QBrush brush(QColor(100, 255, 100)); + QPen pen(QColor(100, 255, 100)); + + painter.setFont(QFont("Courier New", 10)); + + if(GraphStart < 0) { + GraphStart = 0; + } + + if (CursorAPos > GraphTraceLen) + CursorAPos= 0; + if(CursorBPos > GraphTraceLen) + CursorBPos= 0; + + r = rect(); + + //Black foreground + painter.fillRect(r, QColor(0, 0, 0)); + + //Draw y-axis + //painter.setPen(QColor(255, 255, 255)); + //painter.drawLine(r.left()+40, r.top(),r.left() + 40, r.bottom()); + + int zeroHeight = r.top() + (r.bottom() - r.top()) / 2; + // Draw 0-line + painter.setPen(QColor(100, 100, 100)); + painter.drawLine(r.left(), zeroHeight, r.right(), zeroHeight); + + PageWidth= (int)((r.right() - r.left() - 40) / GraphPixelsPerPoint); + + // plot X and Y grid lines + plotGridLines(&painter, r); + + //Start painting graph + PlotGraph(s_Buff, GraphTraceLen,r,&painter,1); + PlotGraph(GraphBuffer, GraphTraceLen,r,&painter,0); + // End graph drawing + + //Draw the two cursors + if(CursorAPos > GraphStart && xCoordOf(CursorAPos) < r.right()) + { + painter.setPen(QColor(255, 255, 0)); + painter.drawLine(xCoordOf(CursorAPos),r.top(),xCoordOf(CursorAPos),r.bottom()); + } + if(CursorBPos > GraphStart && xCoordOf(CursorBPos) < r.right()) + { + painter.setPen(QColor(255, 0, 255)); + painter.drawLine(xCoordOf(CursorBPos),r.top(),xCoordOf(CursorBPos),r.bottom()); } - painter.setPen(QColor(255, 255, 255)); - painter.drawPath(whitePath); - painter.setPen(pen); - painter.drawPath(penPath); - painter.setPen(QColor(255, 255, 0)); - painter.drawPath(cursorAPath); - painter.setPen(QColor(255, 0, 255)); - painter.drawPath(cursorBPath); char str[200]; - sprintf(str, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f] zoom=%.3f CursorA=%d [%d] CursorB=%d [%d] GridX=%d GridY=%d (%s)", - GraphStart, yMax, yMin, yMean, n, GraphTraceLen, - CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor,GraphPixelsPerPoint,CursorAPos,GraphBuffer[CursorAPos],CursorBPos,GraphBuffer[CursorBPos],PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked"); - + sprintf(str, "@%5d dt=%5d [%2.2f] zoom=%2.2f CursorA= %5d CursorB= %5d GridX=%5d GridY=%5d (%s)", + GraphStart, CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor, + GraphPixelsPerPoint,CursorAPos,CursorBPos,PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked"); painter.setPen(QColor(255, 255, 255)); - painter.drawText(50, r.bottom() - 20, str); + painter.drawText(120, r.bottom() - 10, str); + } -ProxWidget::ProxWidget(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1) + +Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1) { + //Need to set this, otherwise we don't receive keypress events + setFocusPolicy( Qt::StrongFocus); resize(600, 300); QPalette palette(QColor(0,0,0,0)); @@ -290,15 +429,19 @@ ProxWidget::ProxWidget(QWidget *parent) : QWidget(parent), GraphStart(0), GraphP setAutoFillBackground(true); CursorAPos = 0; CursorBPos = 0; + + setWindowTitle(tr("Sliders")); + + } -void ProxWidget::closeEvent(QCloseEvent *event) +void Plot::closeEvent(QCloseEvent *event) { event->ignore(); this->hide(); } -void ProxWidget::mouseMoveEvent(QMouseEvent *event) +void Plot::mouseMoveEvent(QMouseEvent *event) { int x = event->x(); x -= 40; @@ -314,13 +457,12 @@ void ProxWidget::mouseMoveEvent(QMouseEvent *event) this->update(); } -void ProxWidget::keyPressEvent(QKeyEvent *event) +void Plot::keyPressEvent(QKeyEvent *event) { int offset; int gridchanged; gridchanged= 0; - if(event->modifiers() & Qt::ShiftModifier) { if (PlotGridX) offset= PageWidth - (PageWidth % PlotGridX); diff --git a/client/proxguiqt.h b/client/proxguiqt.h index 303a37d0..7901178c 100644 --- a/client/proxguiqt.h +++ b/client/proxguiqt.h @@ -13,28 +13,84 @@ #include #include #include +#include +#include "ui/ui_overlays.h" +/** + * @brief The actual plot, black area were we paint the graph + */ +class Plot: public QWidget +{ +private: + int GraphStart; + double GraphPixelsPerPoint; + int CursorAPos; + int CursorBPos; + void PlotGraph(int *buffer, int len, QRect r,QPainter* painter, int graphNum); + void plotGridLines(QPainter* painter,QRect r); + int xCoordOf(int i ); + int yCoordOf(int v, QRect r, int maxVal); + int valueOf_yCoord(int y, QRect r, int maxVal); + QColor getColor(int graphNum); +public: + Plot(QWidget *parent = 0); + +protected: + void paintEvent(QPaintEvent *event); + void closeEvent(QCloseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); } + void keyPressEvent(QKeyEvent *event); + +}; +class ProxGuiQT; + +/** + * The window with plot and controls + */ class ProxWidget : public QWidget { Q_OBJECT; +private: + Plot *plot; + Ui::Form *opsController; + ProxGuiQT *master; +public: + ProxWidget(QWidget *parent = 0, ProxGuiQT *master = NULL); - private: - int GraphStart; - double GraphPixelsPerPoint; - int CursorAPos; - int CursorBPos; - - public: - ProxWidget(QWidget *parent = 0); +//signals: +// void mySignal(); - protected: - void paintEvent(QPaintEvent *event); - void closeEvent(QCloseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); } - void keyPressEvent(QKeyEvent *event); +public slots: + void applyOperation(); + void stickOperation(); + void vchange_autocorr(int v); + void vchange_dthr_up(int v); + void vchange_dthr_down(int v); + //void tabChange(int currentTab); }; +/* +class ProxGuiOverlayController: public UI_form +{ + Q_OBJECT; +public: + void setupOverlayUi(QWidget *Form) + { + //Let auto-generated class setup the UI + Ui_Form::setupUi(Form); + //Then connect the signals + + QObject::connect(UI_form::pushButton_apply, SIGNAL(clicked()), label_4, SLOT(clear())); + QObject::connect(pushButton_sticky, SIGNAL(clicked()), label_4, SLOT(clear())); + QObject::connect(horizontalSlider_window, SIGNAL(valueChanged(int)), label_4, SLOT(setNum(int))); + QObject::connect(horizontalSlider_window, SIGNAL(valueChanged(int)), label_5, SLOT(setNum(int))); + QObject::connect(horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), label_6, SLOT(setNum(int))); + QObject::connect(horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), label_7, SLOT(setNum(int))); + QMetaObject::connectSlotsByName(Form); + } +}; +*/ class ProxGuiQT : public QObject { Q_OBJECT; @@ -42,10 +98,11 @@ class ProxGuiQT : public QObject private: QApplication *plotapp; ProxWidget *plotwidget; + //ProxGuiOverlayController *overlayController; int argc; char **argv; void (*main_func)(void); - + public: ProxGuiQT(int argc, char **argv); ~ProxGuiQT(void); diff --git a/client/ui/overlays.ui b/client/ui/overlays.ui new file mode 100644 index 00000000..8b7f85e5 --- /dev/null +++ b/client/ui/overlays.ui @@ -0,0 +1,272 @@ + + + Form + + + + 0 + 0 + 614 + 286 + + + + Overlays + + + + + + 0 + + + + Qt::StrongFocus + + + Autocorrelate + + + + + + + + Window size + + + + + + + + + + + + + + + + 10 + + + 10000 + + + 2000 + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Askdemod + + + + + Dirthreshold + + + + + + + + Up + + + + + + + + + + + + + + + + 128 + + + 20 + + + Qt::Horizontal + + + + + + + + + Down + + + + + + + + + + + + + + + + 127 + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + Apply + + + + + + + Sticky + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + TextLabel + + + + + + + + + + + horizontalSlider_window + valueChanged(int) + label_4 + setNum(int) + + + 29 + 90 + + + 597 + 257 + + + + + horizontalSlider_window + valueChanged(int) + label_5 + setNum(int) + + + 153 + 84 + + + 161 + 69 + + + + + horizontalSlider_dirthr_up + valueChanged(int) + label_6 + setNum(int) + + + 53 + 92 + + + 68 + 67 + + + + + horizontalSlider_dirthr_down + valueChanged(int) + label_7 + setNum(int) + + + 184 + 161 + + + 149 + 135 + + + + + diff --git a/client/ui/ui_overlays.h b/client/ui/ui_overlays.h new file mode 100644 index 00000000..6e652c12 --- /dev/null +++ b/client/ui/ui_overlays.h @@ -0,0 +1,224 @@ +/******************************************************************************** +** Form generated from reading UI file 'overlaystQ7020.ui' +** +** Created by: Qt User Interface Compiler version 4.8.6 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef OVERLAYSTQ7020_H +#define OVERLAYSTQ7020_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Ui_Form +{ +public: + QVBoxLayout *verticalLayout_3; + QTabWidget *tabWidget_overlays; + QWidget *tab; + QVBoxLayout *verticalLayout_2; + QFormLayout *formLayout; + QLabel *label; + QLabel *label_5; + QSlider *horizontalSlider_window; + QSpacerItem *verticalSpacer; + QWidget *tab_3; + QWidget *tab_2; + QVBoxLayout *verticalLayout; + QFormLayout *formLayout_2; + QLabel *label_2; + QLabel *label_6; + QSlider *horizontalSlider_dirthr_up; + QFormLayout *formLayout_3; + QLabel *label_3; + QLabel *label_7; + QSlider *horizontalSlider_dirthr_down; + QSpacerItem *verticalSpacer_2; + QHBoxLayout *horizontalLayout; + QPushButton *pushButton_apply; + QPushButton *pushButton_sticky; + QSpacerItem *horizontalSpacer; + QLabel *label_4; + + void setupUi(QWidget *Form) + { + if (Form->objectName().isEmpty()) + Form->setObjectName(QString::fromUtf8("Form")); + Form->resize(614, 286); + verticalLayout_3 = new QVBoxLayout(Form); + verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3")); + tabWidget_overlays = new QTabWidget(Form); + tabWidget_overlays->setObjectName(QString::fromUtf8("tabWidget_overlays")); + tab = new QWidget(); + tab->setObjectName(QString::fromUtf8("tab")); + tab->setFocusPolicy(Qt::StrongFocus); + verticalLayout_2 = new QVBoxLayout(tab); + verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2")); + formLayout = new QFormLayout(); + formLayout->setObjectName(QString::fromUtf8("formLayout")); + label = new QLabel(tab); + label->setObjectName(QString::fromUtf8("label")); + + formLayout->setWidget(0, QFormLayout::LabelRole, label); + + label_5 = new QLabel(tab); + label_5->setObjectName(QString::fromUtf8("label_5")); + + formLayout->setWidget(0, QFormLayout::FieldRole, label_5); + + + verticalLayout_2->addLayout(formLayout); + + horizontalSlider_window = new QSlider(tab); + horizontalSlider_window->setObjectName(QString::fromUtf8("horizontalSlider_window")); + horizontalSlider_window->setMinimum(10); + horizontalSlider_window->setMaximum(10000); + horizontalSlider_window->setValue(2000); + horizontalSlider_window->setOrientation(Qt::Horizontal); + + verticalLayout_2->addWidget(horizontalSlider_window); + + verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); + + verticalLayout_2->addItem(verticalSpacer); + + tabWidget_overlays->addTab(tab, QString()); + tab_3 = new QWidget(); + tab_3->setObjectName(QString::fromUtf8("tab_3")); + tabWidget_overlays->addTab(tab_3, QString()); + tab_2 = new QWidget(); + tab_2->setObjectName(QString::fromUtf8("tab_2")); + verticalLayout = new QVBoxLayout(tab_2); + verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); + formLayout_2 = new QFormLayout(); + formLayout_2->setObjectName(QString::fromUtf8("formLayout_2")); + label_2 = new QLabel(tab_2); + label_2->setObjectName(QString::fromUtf8("label_2")); + + formLayout_2->setWidget(0, QFormLayout::LabelRole, label_2); + + label_6 = new QLabel(tab_2); + label_6->setObjectName(QString::fromUtf8("label_6")); + + formLayout_2->setWidget(0, QFormLayout::FieldRole, label_6); + + + verticalLayout->addLayout(formLayout_2); + + horizontalSlider_dirthr_up = new QSlider(tab_2); + horizontalSlider_dirthr_up->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_up")); + horizontalSlider_dirthr_up->setMaximum(128); + horizontalSlider_dirthr_up->setValue(20); + horizontalSlider_dirthr_up->setOrientation(Qt::Horizontal); + + verticalLayout->addWidget(horizontalSlider_dirthr_up); + + formLayout_3 = new QFormLayout(); + formLayout_3->setObjectName(QString::fromUtf8("formLayout_3")); + label_3 = new QLabel(tab_2); + label_3->setObjectName(QString::fromUtf8("label_3")); + + formLayout_3->setWidget(0, QFormLayout::LabelRole, label_3); + + label_7 = new QLabel(tab_2); + label_7->setObjectName(QString::fromUtf8("label_7")); + + formLayout_3->setWidget(0, QFormLayout::FieldRole, label_7); + + + verticalLayout->addLayout(formLayout_3); + + horizontalSlider_dirthr_down = new QSlider(tab_2); + horizontalSlider_dirthr_down->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_down")); + horizontalSlider_dirthr_down->setMaximum(127); + horizontalSlider_dirthr_down->setOrientation(Qt::Horizontal); + + verticalLayout->addWidget(horizontalSlider_dirthr_down); + + verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); + + verticalLayout->addItem(verticalSpacer_2); + + tabWidget_overlays->addTab(tab_2, QString()); + + verticalLayout_3->addWidget(tabWidget_overlays); + + horizontalLayout = new QHBoxLayout(); + horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); + pushButton_apply = new QPushButton(Form); + pushButton_apply->setObjectName(QString::fromUtf8("pushButton_apply")); + + horizontalLayout->addWidget(pushButton_apply); + + pushButton_sticky = new QPushButton(Form); + pushButton_sticky->setObjectName(QString::fromUtf8("pushButton_sticky")); + + horizontalLayout->addWidget(pushButton_sticky); + + horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + + horizontalLayout->addItem(horizontalSpacer); + + label_4 = new QLabel(Form); + label_4->setObjectName(QString::fromUtf8("label_4")); + + horizontalLayout->addWidget(label_4); + + + verticalLayout_3->addLayout(horizontalLayout); + + + retranslateUi(Form); + QObject::connect(horizontalSlider_window, SIGNAL(valueChanged(int)), label_4, SLOT(setNum(int))); + QObject::connect(horizontalSlider_window, SIGNAL(valueChanged(int)), label_5, SLOT(setNum(int))); + QObject::connect(horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), label_6, SLOT(setNum(int))); + QObject::connect(horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), label_7, SLOT(setNum(int))); + + tabWidget_overlays->setCurrentIndex(0); + + + QMetaObject::connectSlotsByName(Form); + } // setupUi + + void retranslateUi(QWidget *Form) + { + Form->setWindowTitle(QApplication::translate("Form", "Overlays", 0, QApplication::UnicodeUTF8)); + label->setText(QApplication::translate("Form", "Window size", 0, QApplication::UnicodeUTF8)); + label_5->setText(QString()); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab), QApplication::translate("Form", "Autocorrelate", 0, QApplication::UnicodeUTF8)); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "Askdemod", 0, QApplication::UnicodeUTF8)); + label_2->setText(QApplication::translate("Form", "Up", 0, QApplication::UnicodeUTF8)); + label_6->setText(QString()); + label_3->setText(QApplication::translate("Form", "Down", 0, QApplication::UnicodeUTF8)); + label_7->setText(QString()); + tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_2), QApplication::translate("Form", "Dirthreshold", 0, QApplication::UnicodeUTF8)); + pushButton_apply->setText(QApplication::translate("Form", "Apply", 0, QApplication::UnicodeUTF8)); + pushButton_sticky->setText(QApplication::translate("Form", "Sticky", 0, QApplication::UnicodeUTF8)); + label_4->setText(QApplication::translate("Form", "TextLabel", 0, QApplication::UnicodeUTF8)); + } // retranslateUi + +}; + +namespace Ui { + class Form: public Ui_Form {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // OVERLAYSTQ7020_H -- 2.39.5