- greyPath.moveTo(r.left(), zeroHeight);
- greyPath.lineTo(r.right(), zeroHeight);
- painter.setPen(QColor(100, 100, 100));
- painter.drawPath(greyPath);
-
- // plot X and Y grid lines
- int i;
- if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
- for(i = 40 + GridOffset; 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));
+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 GRAY = QColor(240,240,240);
+
+QColor Plot::getColor(int graphNum)
+{
+ switch (graphNum) {
+ case 0: return GREEN; //Green
+ case 1: return RED; //Red
+ case 2: return BLUE; //Blue
+ default: return GRAY; //Gray
+ }
+}
+
+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;
+ //clock_t begin = clock();
+ QPainterPath penPath;
+
+ int grid_delta_x = PlotGridX;
+ int first_delta_x = grid_delta_x; //(plotOffset > 0) ? PlotGridX : (PlotGridX +);
+ if (GraphStart > plotOffset) first_delta_x -= (GraphStart-plotOffset);
+ int DemodStart = GraphStart;
+ if (plotOffset > GraphStart) DemodStart = plotOffset;
+
+ int BitStart = 0;
+ // round down
+ if (DemodStart-plotOffset > 0) BitStart = (int)(((DemodStart-plotOffset)+(PlotGridX-1))/PlotGridX)-1;
+ first_delta_x += BitStart * PlotGridX;
+ if (BitStart > (int)len) return;
+ int delta_x = 0;
+ int v = 0;
+ //printf("first_delta_x %i, grid_delta_x %i, DemodStart %i, BitStart %i\n",first_delta_x,grid_delta_x,DemodStart, BitStart);
+
+ painter->setPen(getColor(graphNum));
+ char str[5];
+ int absVMax = (int)(100*1.05+1);
+ int x = xCoordOf(DemodStart, plotRect);
+ int y = yCoordOf((buffer[BitStart]*200-100)*-1,plotRect,absVMax);
+ penPath.moveTo(x, y);
+ delta_x = 0;
+ int clk = first_delta_x;
+ for(int i = BitStart; i < (int)len && xCoordOf(delta_x+DemodStart, plotRect) < plotRect.right(); i++) {
+ for (int ii = 0; ii < (clk) && i < (int)len && xCoordOf(DemodStart+delta_x+ii, plotRect) < plotRect.right() ; ii++ ) {
+ x = xCoordOf(DemodStart+delta_x+ii, plotRect);
+ v = buffer[i]*200-100;
+
+ y = yCoordOf( v, plotRect, absVMax);
+
+ penPath.lineTo(x, y);
+
+ if(GraphPixelsPerPoint > 10) {
+ QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
+ painter->fillRect(f, QColor(100, 255, 100));
+ }
+ if (ii == (int)clk/2) {
+ //print label
+ sprintf(str, "%u",buffer[i]);
+ painter->drawText(x-8, y + ((buffer[i] > 0) ? 18 : -6), str);
+ }
+ }
+ delta_x += clk;
+ clk = grid_delta_x;
+ }
+
+ //Graph annotations
+ painter->drawPath(penPath);
+}
+
+void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum)
+{
+ if (len == 0) return;
+ //clock_t begin = clock();
+ QPainterPath penPath;
+
+ startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint));