X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/6658905f18a1eebc148836f26c731dea9c1377dc..3628c31882e371997087ecc0249710340bf170e6:/winsrc/gui.cpp diff --git a/winsrc/gui.cpp b/winsrc/gui.cpp index e4e530b3..3753a86e 100644 --- a/winsrc/gui.cpp +++ b/winsrc/gui.cpp @@ -33,8 +33,9 @@ void dbp(char *str, ...) int GraphBuffer[MAX_GRAPH_TRACE_LEN]; int GraphTraceLen; +int PlotGridX, PlotGridY; -HPEN GreyPen, GreenPen, WhitePen, YellowPen; +HPEN GreyPenLite, GreyPen, GreenPen, WhitePen, YellowPen; HBRUSH GreenBrush, YellowBrush; static int GraphStart = 0; @@ -61,9 +62,10 @@ static HFONT MyFixedFont; void ExecCmd(char *cmd) { - } + int CommandFinished; +int offset = 64; static void ResizeCommandWindow(void) { @@ -107,43 +109,63 @@ static LRESULT CALLBACK static void PaintGraph(HDC hdc) { + RECT r; HBRUSH brush; HPEN pen; + char str[250]; + int yMin = INT_MAX; + int yMax = INT_MIN; + int yMean = 0; + int startMax = 0; + int absYMax = 1; + int n = 0, i = 0; brush = GreenBrush; pen = GreenPen; - if(GraphStart < 0) { - GraphStart = 0; - } - - RECT r; GetClientRect(GraphWindow, &r); + int zeroHeight = (r.top + r.bottom) >> 1; + + // plot X and Y grid lines + if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) { + for(i = offset; 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); + } + } + + if ((PlotGridY > 0) && ((PlotGridY * GraphPixelsPerPoint) > 1)){ + for(i = 0; i < ((r.top + r.bottom)>>1); i += (int)(PlotGridY * GraphPixelsPerPoint)) { + SelectObject(hdc, GreyPenLite); + MoveToEx(hdc, r.left, zeroHeight + i, NULL); + LineTo(hdc, r.right, zeroHeight + i); + MoveToEx(hdc, r.left, zeroHeight - i, NULL); + LineTo(hdc, r.right, zeroHeight - i); + } + } + // print vertical separator white line on the left of the window SelectObject(hdc, WhitePen); + MoveToEx(hdc, r.left + offset, r.top, NULL); + LineTo(hdc, r.left + offset, r.bottom); - MoveToEx(hdc, r.left + 40, r.top, NULL); - LineTo(hdc, r.left + 40, r.bottom); - - int zeroHeight = r.top + (r.bottom - r.top) / 2; + // print horizontal grey zero axis line SelectObject(hdc, GreyPen); MoveToEx(hdc, r.left, zeroHeight, NULL); LineTo(hdc, r.right, zeroHeight); - int startMax = - (GraphTraceLen - (int)((r.right - r.left - 40) / GraphPixelsPerPoint)); - if(startMax < 0) { - startMax = 0; - } - if(GraphStart > startMax) { - GraphStart = startMax; - } + startMax = (GraphTraceLen - (int)((r.right - r.left - offset) / GraphPixelsPerPoint)); + // check boundaries + if(startMax < 0) startMax = 0; + if(GraphStart > startMax) GraphStart = startMax; + if(GraphStart < 0) GraphStart = 0; - int absYMax = 1; SelectObject(hdc, pen); - int i; + // go over the portion of the graph to be displayed and find the largest + // absolute value which will be used to auto scale the graph when displayed for(i = GraphStart; ; i++) { if(i >= GraphTraceLen) { break; @@ -151,7 +173,7 @@ static void PaintGraph(HDC hdc) if(fabs((double)GraphBuffer[i]) > absYMax) { absYMax = (int)fabs((double)GraphBuffer[i]); } - int x = 40 + (int)((i - GraphStart)*GraphPixelsPerPoint); + int x = offset + (int)((i - GraphStart)*GraphPixelsPerPoint); if(x > r.right) { break; } @@ -163,34 +185,29 @@ static void PaintGraph(HDC hdc) SetBkColor(hdc, RGB(0, 0, 0)); // number of points that will be plotted - int span = (int)((r.right - r.left) / GraphPixelsPerPoint); - // one label every 100 pixels, let us say - int labels = (r.right - r.left - 40) / 100; + double span = (int)((r.right - r.left) / GraphPixelsPerPoint); + + // one label every offset pixels, let us say + int labels = (r.right - r.left - offset) / offset; if(labels <= 0) labels = 1; - int pointsPerLabel = span / labels; + // round to nearest power of 2 + int pointsPerLabel = (int)(log(span / labels)/log(2.0)); if(pointsPerLabel <= 0) pointsPerLabel = 1; + pointsPerLabel = (int)pow(2.0,pointsPerLabel); - int yMin = INT_MAX; - int yMax = INT_MIN; - int yMean = 0; - int n = 0; - + // go over the graph and plot samples and labels for(i = GraphStart; ; i++) { if(i >= GraphTraceLen) { break; } - int x = 40 + (int)((i - GraphStart)*GraphPixelsPerPoint); + int x = offset + (int)((i - GraphStart)*GraphPixelsPerPoint); if(x > r.right + GraphPixelsPerPoint) { break; } int y = GraphBuffer[i]; - if(y < yMin) { - yMin = y; - } - if(y > yMax) { - yMax = y; - } + if(y < yMin) yMin = y; + if(y > yMax) yMax = y; yMean += y; n++; @@ -210,13 +227,13 @@ static void PaintGraph(HDC hdc) FillRect(hdc, &f, brush); } + // plot labels if(((i - GraphStart) % pointsPerLabel == 0) && i != GraphStart) { SelectObject(hdc, WhitePen); - MoveToEx(hdc, x, zeroHeight - 3, NULL); - LineTo(hdc, x, zeroHeight + 3); + MoveToEx(hdc, x, zeroHeight - 8, NULL); + LineTo(hdc, x, zeroHeight + 8); - char str[100]; - sprintf(str, "+%d", (i - GraphStart)); + sprintf(str, "+%d", i); SIZE size; GetTextExtentPoint32(hdc, str, strlen(str), &size); TextOut(hdc, x - size.cx, zeroHeight + 8, str, strlen(str)); @@ -225,6 +242,7 @@ static void PaintGraph(HDC hdc) MoveToEx(hdc, x, y, NULL); } + // plot measurement cursors if(i == CursorAPos || i == CursorBPos) { if(i == CursorAPos) { SelectObject(hdc, CursorAPen); @@ -243,10 +261,11 @@ static void PaintGraph(HDC hdc) yMean /= n; } - char str[100]; - sprintf(str, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f]", + // print misc information at bottom of graph window + sprintf(str, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f] zoom=%.3f CursorA=%d [%d] CursorB=%d [%d]", GraphStart, yMax, yMin, yMean, n, GraphTraceLen, - CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor); + CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor, GraphPixelsPerPoint, + CursorAPos, GraphBuffer[CursorAPos], CursorBPos, GraphBuffer[CursorBPos]); TextOut(hdc, 50, r.bottom - 20, str, strlen(str)); } @@ -277,28 +296,28 @@ static LRESULT CALLBACK case WM_KEYDOWN: switch(wParam) { case VK_DOWN: - if(GraphPixelsPerPoint <= 50) { + if(GraphPixelsPerPoint <= 8) { GraphPixelsPerPoint *= 2; } break; case VK_UP: - if(GraphPixelsPerPoint >= 0.02) { + if(GraphPixelsPerPoint >= 0.01) { GraphPixelsPerPoint /= 2; } break; case VK_RIGHT: - if(GraphPixelsPerPoint < 20) { - GraphStart += (int)(20 / GraphPixelsPerPoint); + if(GraphPixelsPerPoint < 16) { + GraphStart += (int)(16 / GraphPixelsPerPoint); } else { GraphStart++; } break; case VK_LEFT: - if(GraphPixelsPerPoint < 20) { - GraphStart -= (int)(20 / GraphPixelsPerPoint); + if(GraphPixelsPerPoint < 16) { + GraphStart -= (int)(16 / GraphPixelsPerPoint); } else { GraphStart--; } @@ -314,9 +333,10 @@ nopaint: case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: { int x = LOWORD(lParam); - x -= 40; + x -= offset; x = (int)(x / GraphPixelsPerPoint); x += GraphStart; + if(msg == WM_LBUTTONDOWN) { CursorAPos = x; } else { @@ -379,7 +399,7 @@ static void SetCommandEditTo(char *str) SendMessage(CommandEdit, EM_SETSEL, strlen(str), strlen(str)); } -void ShowGui(void) +void ShowGui() { WNDCLASSEX wc; memset(&wc, 0, sizeof(wc)); @@ -431,6 +451,7 @@ void ShowGui(void) PrintToScrollback(">> Started prox, built " __DATE__ " " __TIME__); PrintToScrollback(">> Connected to device"); + GreyPenLite = CreatePen(PS_SOLID, 1, RGB(50, 50, 50)); GreyPen = CreatePen(PS_SOLID, 1, RGB(100, 100, 100)); GreenPen = CreatePen(PS_SOLID, 1, RGB(100, 255, 100)); YellowPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 0)); @@ -500,9 +521,11 @@ void ShowGui(void) } } - UsbCommand c; - if(ReceiveCommandPoll(&c)) { - UsbCommandReceived(&c); + if (!offline) + { + UsbCommand c; + if(ReceiveCommandPoll(&c)) + UsbCommandReceived(&c); } Sleep(10);