]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - winsrc/gui.cpp
Junk Eclipse environment files. Not source code.
[proxmark3-svn] / winsrc / gui.cpp
index e4e530b334043c4af025d391a82bb9ad097b94fc..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,9 +62,10 @@ static HFONT MyFixedFont;
 \r
 void ExecCmd(char *cmd)\r
 {\r
-\r
 }\r
+\r
 int CommandFinished;\r
+int offset = 64;\r
 \r
 static void ResizeCommandWindow(void)\r
 {\r
@@ -107,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
+       MoveToEx(hdc, r.left + offset, r.top, NULL);\r
+       LineTo(hdc, r.left + offset, r.bottom);\r
 \r
-       MoveToEx(hdc, r.left + 40, r.top, NULL);\r
-       LineTo(hdc, r.left + 40, 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 - 40) / 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
@@ -151,7 +173,7 @@ static void PaintGraph(HDC hdc)
                if(fabs((double)GraphBuffer[i]) > absYMax) {\r
                        absYMax = (int)fabs((double)GraphBuffer[i]);\r
                }\r
-               int x = 40 + (int)((i - GraphStart)*GraphPixelsPerPoint);\r
+               int x = offset + (int)((i - GraphStart)*GraphPixelsPerPoint);\r
                if(x > r.right) {\r
                        break;\r
                }\r
@@ -163,34 +185,29 @@ static void PaintGraph(HDC hdc)
        SetBkColor(hdc, RGB(0, 0, 0));\r
 \r
        // number of points that will be plotted\r
-       int span = (int)((r.right - r.left) / GraphPixelsPerPoint);\r
-       // one label every 100 pixels, let us say\r
-       int labels = (r.right - r.left - 40) / 100;\r
+       double span = (int)((r.right - r.left) / GraphPixelsPerPoint);\r
+\r
+       // one label every offset pixels, let us say\r
+       int labels = (r.right - r.left - offset) / offset;\r
        if(labels <= 0) labels = 1;\r
-       int pointsPerLabel = span / labels;\r
+       // round to nearest power of 2\r
+       int pointsPerLabel = (int)(log(span / labels)/log(2.0));\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
-               int x = 40 + (int)((i - GraphStart)*GraphPixelsPerPoint);\r
+               int x = offset + (int)((i - GraphStart)*GraphPixelsPerPoint);\r
                if(x > r.right + GraphPixelsPerPoint) {\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
@@ -210,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 - 3, NULL);\r
-                       LineTo(hdc, x, zeroHeight + 3);\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
@@ -225,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
@@ -243,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]",\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);\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
@@ -277,28 +296,28 @@ static LRESULT CALLBACK
                case WM_KEYDOWN:\r
                        switch(wParam) {\r
                                case VK_DOWN:\r
-                                       if(GraphPixelsPerPoint <= 50) {\r
+                                       if(GraphPixelsPerPoint <= 8) {\r
                                                GraphPixelsPerPoint *= 2;\r
                                        }\r
                                        break;\r
 \r
                                case VK_UP:\r
-                                       if(GraphPixelsPerPoint >= 0.02) {\r
+                                       if(GraphPixelsPerPoint >= 0.01) {\r
                                                GraphPixelsPerPoint /= 2;\r
                                        }\r
                                        break;\r
 \r
                                case VK_RIGHT:\r
-                                       if(GraphPixelsPerPoint < 20) {\r
-                                               GraphStart += (int)(20 / GraphPixelsPerPoint);\r
+                                       if(GraphPixelsPerPoint < 16) {\r
+                                               GraphStart += (int)(16 / GraphPixelsPerPoint);\r
                                        } else {\r
                                                GraphStart++;\r
                                        }\r
                                        break;\r
 \r
                                case VK_LEFT:\r
-                                       if(GraphPixelsPerPoint < 20) {\r
-                                               GraphStart -= (int)(20 / GraphPixelsPerPoint);\r
+                                       if(GraphPixelsPerPoint < 16) {\r
+                                               GraphStart -= (int)(16 / GraphPixelsPerPoint);\r
                                        } else {\r
                                                GraphStart--;\r
                                        }\r
@@ -314,9 +333,10 @@ nopaint:
                case WM_LBUTTONDOWN:\r
                case WM_RBUTTONDOWN: {\r
                        int x = LOWORD(lParam);\r
-                       x -= 40;\r
+                       x -= offset;\r
                        x = (int)(x / GraphPixelsPerPoint);\r
                        x += GraphStart;\r
+\r
                        if(msg == WM_LBUTTONDOWN) {\r
                                CursorAPos = x;\r
                        } else {\r
@@ -379,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
@@ -431,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
@@ -500,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