diff --git a/client/src/graph.c b/client/src/graph.c index 8b97dcfad..c7a6fae8f 100644 --- a/client/src/graph.c +++ b/client/src/graph.c @@ -26,6 +26,7 @@ int g_GraphBuffer[MAX_GRAPH_TRACE_LEN]; +int g_OperationBuffer[MAX_GRAPH_TRACE_LEN]; size_t g_GraphTraceLen; /* write a manchester bit to the graph @@ -68,6 +69,7 @@ void AppendGraph(bool redraw, uint16_t clock, int bit) { size_t ClearGraph(bool redraw) { size_t gtl = g_GraphTraceLen; memset(g_GraphBuffer, 0x00, g_GraphTraceLen); + memset(g_OperationBuffer, 0x00, g_GraphTraceLen); g_GraphTraceLen = 0; g_GraphStart = 0; g_GraphStop = 0; @@ -78,6 +80,7 @@ size_t ClearGraph(bool redraw) { return gtl; } + // option '1' to save g_GraphBuffer any other to restore void save_restoreGB(uint8_t saveOpt) { static int SavedGB[MAX_GRAPH_TRACE_LEN]; diff --git a/client/src/graph.h b/client/src/graph.h index 3a05dd8eb..b5cbf99e0 100644 --- a/client/src/graph.h +++ b/client/src/graph.h @@ -48,6 +48,7 @@ bool fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, int *firstClockEdge); #define GRAPH_RESTORE 0 extern int g_GraphBuffer[MAX_GRAPH_TRACE_LEN]; +extern int g_OperationBuffer[MAX_GRAPH_TRACE_LEN]; extern size_t g_GraphTraceLen; #ifdef __cplusplus diff --git a/client/src/proxguiqt.cpp b/client/src/proxguiqt.cpp index cd465acde..26645b75c 100644 --- a/client/src/proxguiqt.cpp +++ b/client/src/proxguiqt.cpp @@ -778,6 +778,44 @@ void Plot::plotGridLines(QPainter *painter, QRect r) { } } +void Plot::plotOperations(int *buffer, size_t len, QPainter *painter, QRect plotRect) { + if(len == 0) { + return; + } + + QPainterPath penPath; + int32_t x = xCoordOf(g_GraphStart, plotRect), prevX = 0; + int32_t y = yCoordOf(buffer[g_GraphStart], plotRect, gs_absVMax), prevY = 0; + int32_t past = 0, current = 0; + + for (uint32_t pos = g_GraphStart; pos < len && xCoordOf(pos, plotRect) < plotRect.right(); pos++) { + if(pos == 0) continue; //Skip the first value of the buffer to prevent underflows + + //Store the previous x and y values to move the pen to if we need to draw a line + prevX = x; + prevY = y; + + x = xCoordOf(pos, plotRect); + current = buffer[pos]; + past = buffer[pos - 1]; //Get the previous value for checking + y = yCoordOf(current, plotRect, gs_absVMax); + + //We don't want to graph a line over the zero line, only operations stored in the buffer + if(current == 0 && past == 0) continue; + + penPath.moveTo(prevX, prevY); //Move the pen + penPath.lineTo(x, y); //Draw the line from the previous coords to the new ones + + if (g_GraphPixelsPerPoint > 10) { + QRect point(QPoint(x - 3, y - 3), QPoint(x + 3, y + 3)); + painter->fillRect(point, WHITE); + } + } + + painter->setPen(CITRON); + painter->drawPath(penPath); +} + #define HEIGHT_INFO 60 #define WIDTH_AXES 80 @@ -824,6 +862,12 @@ void Plot::paintEvent(QPaintEvent *event) { if (g_DemodBufferLen > 8) { PlotDemod(g_DemodBuffer, g_DemodBufferLen, plotRect, infoRect, &painter, 2, g_DemodStartIdx); } + + //Plot the Operation Overlay + //setMaxAndStart(g_OperationBuffer, g_GraphTraceLen, plotRect); + plotOperations(g_OperationBuffer, g_GraphTraceLen, &painter, plotRect); + + //Plot the Overlay if (gs_useOverlays) { //init graph variables setMaxAndStart(s_OverlayBuff, g_GraphTraceLen, plotRect); diff --git a/client/src/proxguiqt.h b/client/src/proxguiqt.h index 244d083e3..5fd739073 100644 --- a/client/src/proxguiqt.h +++ b/client/src/proxguiqt.h @@ -48,6 +48,7 @@ class Plot: public QWidget { void PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum); void PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, uint32_t plotOffset); void plotGridLines(QPainter *painter, QRect r); + void plotOperations(int *buffer, size_t len, QPainter *painter, QRect rect); int xCoordOf(int i, QRect r); int yCoordOf(int v, QRect r, int maxVal); int valueOf_yCoord(int y, QRect r, int maxVal);