]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - winsrc/gui.cpp
Create a stamp file for download completion so that it won't have to be redone later
[proxmark3-svn] / winsrc / gui.cpp
index 05f05e1aa78fb24287b2fd40e60f0c4889b1130e..3753a86e99a4a47aeb2f948ce2a65a10c1598de6 100644 (file)
@@ -33,8 +33,9 @@ void dbp(char *str, ...)
 \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
@@ -61,8 +62,8 @@ static HFONT MyFixedFont;
 \r
 void ExecCmd(char *cmd)\r
 {\r
-\r
 }\r
+\r
 int CommandFinished;\r
 int offset = 64;\r
 \r
@@ -108,43 +109,63 @@ static LRESULT CALLBACK
 \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
@@ -174,11 +195,7 @@ static void PaintGraph(HDC hdc)
        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
@@ -189,12 +206,8 @@ static void PaintGraph(HDC hdc)
                }\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
@@ -214,13 +227,13 @@ static void PaintGraph(HDC hdc)
                        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
@@ -229,6 +242,7 @@ static void PaintGraph(HDC hdc)
                        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
@@ -247,10 +261,11 @@ static void PaintGraph(HDC hdc)
                yMean /= n;\r
        }\r
 \r
-       char str[100];\r
-       sprintf(str, "@%d   max=%d min=%d mean=%d n=%d/%d    dt=%d [%.3f] zoom=%.3f",\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);\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
@@ -321,6 +336,7 @@ nopaint:
                        x -= offset;\r
                        x = (int)(x / GraphPixelsPerPoint);\r
                        x += GraphStart;\r
+\r
                        if(msg == WM_LBUTTONDOWN) {\r
                                CursorAPos = x;\r
                        } else {\r
@@ -383,7 +399,7 @@ static void SetCommandEditTo(char *str)
        SendMessage(CommandEdit, EM_SETSEL, strlen(str), strlen(str));\r
 }\r
 \r
-void ShowGui(void)\r
+void ShowGui()\r
 {\r
        WNDCLASSEX wc;\r
        memset(&wc, 0, sizeof(wc));\r
@@ -435,6 +451,7 @@ void ShowGui(void)
        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
@@ -504,9 +521,11 @@ void ShowGui(void)
                        }\r
                }\r
 \r
-               UsbCommand c;\r
-               if(ReceiveCommandPoll(&c)) {\r
-                       UsbCommandReceived(&c);\r
+               if (!offline)\r
+               {\r
+                       UsbCommand c;\r
+                       if(ReceiveCommandPoll(&c))\r
+                               UsbCommandReceived(&c);\r
                }\r
 \r
                Sleep(10);\r
Impressum, Datenschutz