\r
int GraphBuffer[MAX_GRAPH_TRACE_LEN];\r
int GraphTraceLen;\r
+int PlotGridX, PlotGridY;\r
\r
-HPEN GreyPen, GreenPen, WhitePen, YellowPen;\r
+HPEN GreyPenLite, GreyPen, GreenPen, WhitePen, YellowPen;\r
HBRUSH GreenBrush, YellowBrush;\r
\r
static int GraphStart = 0;\r
\r
void ExecCmd(char *cmd)\r
{\r
-\r
}\r
+\r
int CommandFinished;\r
int offset = 64;\r
\r
\r
static void PaintGraph(HDC hdc)\r
{\r
+ RECT r;\r
HBRUSH brush;\r
HPEN pen;\r
+ char str[250];\r
+ int yMin = INT_MAX;\r
+ int yMax = INT_MIN;\r
+ int yMean = 0;\r
+ int startMax = 0;\r
+ int absYMax = 1;\r
+ int n = 0, i = 0;\r
\r
brush = GreenBrush;\r
pen = GreenPen;\r
\r
- if(GraphStart < 0) {\r
- GraphStart = 0;\r
- }\r
-\r
- RECT r;\r
GetClientRect(GraphWindow, &r);\r
+ int zeroHeight = (r.top + r.bottom) >> 1;\r
+\r
+ // plot X and Y grid lines\r
+ if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {\r
+ for(i = offset; i < r.right; i += (int)(PlotGridX * GraphPixelsPerPoint)) {\r
+ SelectObject(hdc, GreyPenLite);\r
+ MoveToEx(hdc, r.left + i, r.top, NULL);\r
+ LineTo(hdc, r.left + i, r.bottom);\r
+ }\r
+ }\r
+\r
+ if ((PlotGridY > 0) && ((PlotGridY * GraphPixelsPerPoint) > 1)){\r
+ for(i = 0; i < ((r.top + r.bottom)>>1); i += (int)(PlotGridY * GraphPixelsPerPoint)) {\r
+ SelectObject(hdc, GreyPenLite);\r
+ MoveToEx(hdc, r.left, zeroHeight + i, NULL);\r
+ LineTo(hdc, r.right, zeroHeight + i);\r
+ MoveToEx(hdc, r.left, zeroHeight - i, NULL);\r
+ LineTo(hdc, r.right, zeroHeight - i);\r
+ }\r
+ }\r
\r
+ // print vertical separator white line on the left of the window\r
SelectObject(hdc, WhitePen);\r
-\r
MoveToEx(hdc, r.left + offset, r.top, NULL);\r
LineTo(hdc, r.left + offset, r.bottom);\r
\r
- int zeroHeight = r.top + (r.bottom - r.top) / 2;\r
+ // print horizontal grey zero axis line\r
SelectObject(hdc, GreyPen);\r
MoveToEx(hdc, r.left, zeroHeight, NULL);\r
LineTo(hdc, r.right, zeroHeight);\r
\r
- int startMax =\r
- (GraphTraceLen - (int)((r.right - r.left - offset) / GraphPixelsPerPoint));\r
- if(startMax < 0) {\r
- startMax = 0;\r
- }\r
- if(GraphStart > startMax) {\r
- GraphStart = startMax;\r
- }\r
+ startMax = (GraphTraceLen - (int)((r.right - r.left - offset) / GraphPixelsPerPoint));\r
+ // check boundaries\r
+ if(startMax < 0) startMax = 0;\r
+ if(GraphStart > startMax) GraphStart = startMax;\r
+ if(GraphStart < 0) GraphStart = 0;\r
\r
- int absYMax = 1;\r
\r
SelectObject(hdc, pen);\r
\r
- int i;\r
+ // go over the portion of the graph to be displayed and find the largest\r
+ // absolute value which will be used to auto scale the graph when displayed\r
for(i = GraphStart; ; i++) {\r
if(i >= GraphTraceLen) {\r
break;\r
if(pointsPerLabel <= 0) pointsPerLabel = 1;\r
pointsPerLabel = (int)pow(2.0,pointsPerLabel);\r
\r
- int yMin = INT_MAX;\r
- int yMax = INT_MIN;\r
- int yMean = 0;\r
- int n = 0;\r
-\r
+ // go over the graph and plot samples and labels\r
for(i = GraphStart; ; i++) {\r
if(i >= GraphTraceLen) {\r
break;\r
}\r
\r
int y = GraphBuffer[i];\r
- if(y < yMin) {\r
- yMin = y;\r
- }\r
- if(y > yMax) {\r
- yMax = y;\r
- }\r
+ if(y < yMin) yMin = y;\r
+ if(y > yMax) yMax = y;\r
yMean += y;\r
n++;\r
\r
FillRect(hdc, &f, brush);\r
}\r
\r
+ // plot labels\r
if(((i - GraphStart) % pointsPerLabel == 0) && i != GraphStart) {\r
SelectObject(hdc, WhitePen);\r
MoveToEx(hdc, x, zeroHeight - 8, NULL);\r
LineTo(hdc, x, zeroHeight + 8);\r
\r
- char str[100];\r
- sprintf(str, "+%d", (i - GraphStart));\r
+ sprintf(str, "+%d", i);\r
SIZE size;\r
GetTextExtentPoint32(hdc, str, strlen(str), &size);\r
TextOut(hdc, x - size.cx, zeroHeight + 8, str, strlen(str));\r
MoveToEx(hdc, x, y, NULL);\r
}\r
\r
+ // plot measurement cursors\r
if(i == CursorAPos || i == CursorBPos) {\r
if(i == CursorAPos) {\r
SelectObject(hdc, CursorAPen);\r
yMean /= n;\r
}\r
\r
- char str[100];\r
+ // print misc information at bottom of graph window\r
sprintf(str, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f] zoom=%.3f CursorA=%d [%d] CursorB=%d [%d]",\r
GraphStart, yMax, yMin, yMean, n, GraphTraceLen,\r
- CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor, GraphPixelsPerPoint, CursorAPos, GraphBuffer[CursorAPos], CursorBPos, GraphBuffer[CursorBPos]);\r
+ CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor, GraphPixelsPerPoint,\r
+ CursorAPos, GraphBuffer[CursorAPos], CursorBPos, GraphBuffer[CursorBPos]);\r
TextOut(hdc, 50, r.bottom - 20, str, strlen(str));\r
}\r
\r
x -= offset;\r
x = (int)(x / GraphPixelsPerPoint);\r
x += GraphStart;\r
+\r
if(msg == WM_LBUTTONDOWN) {\r
CursorAPos = x;\r
} else {\r
PrintToScrollback(">> Started prox, built " __DATE__ " " __TIME__);\r
PrintToScrollback(">> Connected to device");\r
\r
+ GreyPenLite = CreatePen(PS_SOLID, 1, RGB(50, 50, 50));\r
GreyPen = CreatePen(PS_SOLID, 1, RGB(100, 100, 100));\r
GreenPen = CreatePen(PS_SOLID, 1, RGB(100, 255, 100));\r
YellowPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 0));\r