diff options
Diffstat (limited to 'demos/modules/ginput')
-rw-r--r-- | demos/modules/ginput/touch_driver_test/main.c | 118 |
1 files changed, 51 insertions, 67 deletions
diff --git a/demos/modules/ginput/touch_driver_test/main.c b/demos/modules/ginput/touch_driver_test/main.c index 1a1157b0..225a111c 100644 --- a/demos/modules/ginput/touch_driver_test/main.c +++ b/demos/modules/ginput/touch_driver_test/main.c @@ -28,7 +28,6 @@ */ #include "gfx.h" -#include "chprintf.h" static GConsoleObject gc; static GButtonObject gNext; @@ -39,15 +38,15 @@ static GListener gl; * GINPUT Touch Driver Calibrator. * *------------------------------------------------------------------------*/ int main(void) { - GSourceHandle gs, gsNext, gsPrev; + GSourceHandle gs; GEvent *pe; GEventMouse *pem; GEventGWinButton *peb; coord_t swidth, sheight; GHandle ghc, ghNext, ghPrev; - BaseSequentialStream *gp; GEventType deviceType; font_t font; + GWidgetInit wi; gfxInit(); // Initialize the display @@ -58,12 +57,13 @@ int main(void) { // Create our title font = gdispOpenFont("UI2"); + gwinSetDefaultFont(font); gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Red, White, justifyLeft); // Create our main display window - ghc = gwinCreateConsole(&gc, 0, 20, swidth, sheight-20, font); + wi.g.show = TRUE; wi.g.x = 0; wi.g.y = 20; wi.g.width = swidth; wi.g.height = sheight-20; + ghc = gwinConsoleCreate(&gc, &wi.g); gwinClear(ghc); - gp = gwinGetConsoleStream(ghc); // Initialize the mouse in our special no calibration mode. geventListenerInit(&gl); @@ -77,22 +77,22 @@ int main(void) { StepDeviceType: gwinClear(ghc); gwinSetColor(ghc, Yellow); - chprintf(gp, "\n1. DEVICE TYPE\n\n"); + gwinPrintf(ghc, "\n1. DEVICE TYPE\n\n"); pem = (GEventMouse *)&gl.event; ginputGetMouseStatus(0, pem); deviceType = pem->type; gwinSetColor(ghc, White); - chprintf(gp, "This is detected as a %s device\n\n", + gwinPrintf(ghc, "This is detected as a %s device\n\n", deviceType == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN")); if (ghNext) - chprintf(gp, "Press Next or Back to continue.\n"); + gwinPrintf(ghc, "Press Next or Back to continue.\n"); else if (deviceType == GEVENT_MOUSE) - chprintf(gp, "Click the mouse button to move on to the next test.\n"); + gwinPrintf(ghc, "Click the mouse button to move on to the next test.\n"); else - chprintf(gp, "Press and release your finger to move on to the next test.\n"); + gwinPrintf(ghc, "Press and release your finger to move on to the next test.\n"); while(1) { pe = geventEventWait(&gl, TIME_INFINITE); @@ -117,23 +117,23 @@ StepDeviceType: StepRawJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); - chprintf(gp, "\n2. GINPUT_MOUSE_READ_CYCLES\n\n"); + gwinPrintf(ghc, "\n2. GINPUT_MOUSE_READ_CYCLES\n\n"); gwinSetColor(ghc, White); if (deviceType == GEVENT_MOUSE) - chprintf(gp, "Press and hold the mouse button.\n\n"); + gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); else - chprintf(gp, "Press and hold on the surface.\n\n"); - chprintf(gp, "Numbers will display in this window.\n" + gwinPrintf(ghc, "Press and hold on the surface.\n\n"); + gwinPrintf(ghc, "Numbers will display in this window.\n" "Ensure that values don't jump around very much when your finger is stationary.\n\n" "Increasing GINPUT_MOUSE_READ_CYCLES helps reduce jitter but increases CPU usage.\n\n"); if (ghNext) - chprintf(gp, "Press Next or Back to continue.\n"); + gwinPrintf(ghc, "Press Next or Back to continue.\n"); else if (deviceType == GEVENT_MOUSE) - chprintf(gp, "Release the mouse button to move on to the next test.\n"); + gwinPrintf(ghc, "Release the mouse button to move on to the next test.\n"); else - chprintf(gp, "Release your finger to move on to the next test.\n"); + gwinPrintf(ghc, "Release your finger to move on to the next test.\n"); // For this test turn on ALL mouse movement events geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER); @@ -150,7 +150,7 @@ StepRawJitter: if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { pem = (GEventMouse *)pe; if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) - chprintf(gp, "%u:%u\n", pem->x, pem->y); + gwinPrintf(ghc, "%u:%u\n", pem->x, pem->y); if (!ghNext && (pem->meta & GMETA_MOUSE_UP)) break; } @@ -166,19 +166,19 @@ StepRawJitter: StepCalibrate: gwinClear(ghc); gwinSetColor(ghc, Yellow); - chprintf(gp, "\n3. GINPUT_MOUSE_CALIBRATION_ERROR\n\n"); + gwinPrintf(ghc, "\n3. GINPUT_MOUSE_CALIBRATION_ERROR\n\n"); gwinSetColor(ghc, Gray); - chprintf(gp, "Ensure GINPUT_MOUSE_NEED_CALIBRATION = TRUE and GINPUT_MOUSE_CALIBRATION_ERROR is >= 0\n\n"); + gwinPrintf(ghc, "Ensure GINPUT_MOUSE_NEED_CALIBRATION = TRUE and GINPUT_MOUSE_CALIBRATION_ERROR is >= 0\n\n"); gwinSetColor(ghc, White); - chprintf(gp, "You will be presented with a number of points to touch.\nPress them in turn.\n\n" + gwinPrintf(ghc, "You will be presented with a number of points to touch.\nPress them in turn.\n\n" "If the calibration repeatedly fails, increase GINPUT_MOUSE_CALIBRATION_ERROR and try again.\n\n"); if (ghNext) - chprintf(gp, "Press Next to start the calibration.\n"); + gwinPrintf(ghc, "Press Next to start the calibration.\n"); else if (deviceType == GEVENT_MOUSE) - chprintf(gp, "Click the mouse button to start the calibration.\n"); + gwinPrintf(ghc, "Click the mouse button to start the calibration.\n"); else - chprintf(gp, "Press and release your finger to start the calibration.\n"); + gwinPrintf(ghc, "Press and release your finger to start the calibration.\n"); while(1) { pe = geventEventWait(&gl, TIME_INFINITE); @@ -201,37 +201,21 @@ StepCalibrate: /* From now on we can use Next and Previous Buttons */ if (!ghNext) { + gwinAttachMouse(0); + gwinAttachListener(&gl); - ghNext = gwinCreateButton(&gNext, swidth-50, 0, 50, 20, font, GBTN_NORMAL); - gwinSetButtonText(ghNext, "Next", FALSE); - gsNext = gwinGetButtonSource(ghNext); - geventAttachSource(&gl, gsNext, 0); - gwinAttachButtonMouse(ghNext, 0); - - ghPrev = gwinCreateButton(&gPrev, swidth-100, 0, 50, 20, font, GBTN_NORMAL); - gwinSetButtonText(ghPrev, "Back", FALSE); - gsPrev = gwinGetButtonSource(ghPrev); - geventAttachSource(&gl, gsPrev, 0); - gwinAttachButtonMouse(ghPrev, 0); - -#if 0 - { - // Attach a couple of hardware toggle buttons to our Next and Back buttons as well. - // We can always use the mouse to trigger the buttons if you don't want to use hardware toggles. - // This code depends on your hardware. Turn it on only if you have - // defined a board definition for your toggle driver. Then change - // the next two lines to be correct for your hardware. The values - // below are correct for the Win32 toggle driver. - gwinAttachButtonToggle(ghNext, GINPUT_TOGGLE_MOMENTARY1); - gwinAttachButtonToggle(ghPrev, GINPUT_TOGGLE_MOMENTARY2); - } -#endif + wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0; + wi.g.show = TRUE; wi.g.x = swidth-50; wi.g.y = 0; wi.g.width = 50; wi.g.height = 20; + wi.text = "Next"; ghNext = gwinButtonCreate(&gNext, &wi); + + wi.g.show = TRUE; wi.g.x = swidth-100; + wi.text = "Back"; ghPrev = gwinButtonCreate(&gPrev, &wi); } // Calibration used the whole screen - re-establish our title gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Green, White, justifyLeft); - gwinButtonDraw(ghNext); - gwinButtonDraw(ghPrev); + gwinRedraw(ghNext); + gwinRedraw(ghPrev); /* * Test: Mouse movement jitter @@ -240,18 +224,18 @@ StepCalibrate: StepJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); - chprintf(gp, "\n4. GINPUT_MOUSE_MOVE_JITTER\n\n"); + gwinPrintf(ghc, "\n4. GINPUT_MOUSE_MOVE_JITTER\n\n"); gwinSetColor(ghc, White); if (deviceType == GEVENT_MOUSE) - chprintf(gp, "Press and hold the mouse button and move around as if to draw.\n\n"); + gwinPrintf(ghc, "Press and hold the mouse button and move around as if to draw.\n\n"); else - chprintf(gp, "Press firmly on the surface and move around as if to draw.\n\n"); + gwinPrintf(ghc, "Press firmly on the surface and move around as if to draw.\n\n"); - chprintf(gp, "Dots will display in this window. Ensure that when you stop moving your finger that " + gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your finger that " "new dots stop displaying.\nNew dots should only display when your finger is moving.\n\n" "Adjust GINPUT_MOUSE_MOVE_JITTER to the smallest value that this reliably works for.\n\n"); - chprintf(gp, "Press Next or Back to continue.\n\n"); + gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pe = geventEventWait(&gl, TIME_INFINITE); @@ -265,7 +249,7 @@ StepJitter: if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { pem = (GEventMouse *)pe; if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) - chprintf(gp, "."); + gwinPrintf(ghc, "."); } } @@ -276,16 +260,16 @@ StepJitter: StepPolling: gwinClear(ghc); gwinSetColor(ghc, Yellow); - chprintf(gp, "\n5. GINPUT_MOUSE_POLL_PERIOD\n\n"); + gwinPrintf(ghc, "\n5. GINPUT_MOUSE_POLL_PERIOD\n\n"); gwinSetColor(ghc, White); - chprintf(gp, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n"); - chprintf(gp, "A green line will follow your finger.\n" + gwinPrintf(ghc, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n"); + gwinPrintf(ghc, "A green line will follow your finger.\n" "Adjust GINPUT_MOUSE_POLL_PERIOD to the highest value that provides a line without " "gaps that are too big.\nDecreasing the value increases CPU usage.\n" "About 25 (millisecs) normally produces good results." "This test can be ignored for interrupt driven drivers.\n\n"); - chprintf(gp, "Press Next or Back to continue.\n\n"); + gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pe = geventEventWait(&gl, TIME_INFINITE); @@ -310,18 +294,18 @@ StepPolling: StepClickJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); - chprintf(gp, "\n6. GINPUT_MOUSE_MAX_CLICK_JITTER\n\n"); + gwinPrintf(ghc, "\n6. GINPUT_MOUSE_MAX_CLICK_JITTER\n\n"); gwinSetColor(ghc, White); - chprintf(gp, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n"); - chprintf(gp, "For a mouse click with the left and right buttons.\n\n"); - chprintf(gp, "Dots will display in this window. A yellow dash is a left (or short) click. " + gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n"); + gwinPrintf(ghc, "For a mouse click with the left and right buttons.\n\n"); + gwinPrintf(ghc, "Dots will display in this window. A yellow dash is a left (or short) click. " "A red x is a right (or long) click.\n\n" "Adjust GINPUT_MOUSE_CLICK_JITTER to the smallest value that this reliably works for.\n" "Adjust GINPUT_MOUSE_CLICK_TIME to adjust distinguishing short vs long presses.\n" "TIME_INFINITE means there are no long presses (although a right mouse button will still work).\n\n" "Note: moving your finger (mouse) during a click cancels it.\n\n"); - chprintf(gp, "This is the last test but you can press Next or Back to continue.\n\n"); + gwinPrintf(ghc, "This is the last test but you can press Next or Back to continue.\n\n"); while(1) { pe = geventEventWait(&gl, TIME_INFINITE); @@ -336,11 +320,11 @@ StepClickJitter: pem = (GEventMouse *)pe; if ((pem->meta & GMETA_MOUSE_CLICK)) { gwinSetColor(ghc, Yellow); - chprintf(gp, "-"); + gwinPrintf(ghc, "-"); } if ((pem->meta & GMETA_MOUSE_CXTCLICK)) { gwinSetColor(ghc, Red); - chprintf(gp, "x"); + gwinPrintf(ghc, "x"); } } } |