Move touch driver test to tools.

Also replace gwin buttons as they comptete with the test for touch events
ugfx_release_2.6
inmarket 2013-11-23 12:57:49 +10:00
parent 1dfbc0ab82
commit 51dedb56d1
2 changed files with 130 additions and 108 deletions

View File

@ -53,7 +53,6 @@
#define GDISP_INCLUDE_FONT_UI2 TRUE #define GDISP_INCLUDE_FONT_UI2 TRUE
/* Features for the GWIN sub-system. */ /* Features for the GWIN sub-system. */
#define GWIN_NEED_BUTTON TRUE
#define GWIN_NEED_CONSOLE TRUE #define GWIN_NEED_CONSOLE TRUE
/* Features for the GINPUT sub-system. */ /* Features for the GINPUT sub-system. */

View File

@ -30,39 +30,45 @@
#include "gfx.h" #include "gfx.h"
static GConsoleObject gc; static GConsoleObject gc;
static GButtonObject gNext;
static GButtonObject gPrev;
static GListener gl; static GListener gl;
static font_t font;
/*------------------------------------------------------------------------* /*------------------------------------------------------------------------*
* GINPUT Touch Driver Calibrator. * * GINPUT Touch Driver Calibrator. *
*------------------------------------------------------------------------*/ *------------------------------------------------------------------------*/
int main(void) { int main(void) {
GSourceHandle gs; GSourceHandle gs;
GEvent *pe;
GEventMouse *pem; GEventMouse *pem;
GEventGWinButton *peb;
coord_t swidth, sheight; coord_t swidth, sheight;
GHandle ghc, ghNext, ghPrev; GHandle ghc;
GEventType deviceType; GEventType deviceType;
font_t font; bool_t calibrated;
GWidgetInit wi; coord_t bWidth, bHeight;
gfxInit(); // Initialize the display gfxInit(); // Initialize the display
// Get the display dimensions // Get the display dimensions
swidth = gdispGetWidth(); swidth = gdispGetWidth();
sheight = gdispGetHeight(); sheight = gdispGetHeight();
ghNext = ghPrev = 0; calibrated = FALSE;
// Create our title // Create our title
font = gdispOpenFont("UI2"); font = gdispOpenFont("UI2");
gwinSetDefaultFont(font); gwinSetDefaultFont(font);
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Red, White, justifyLeft); bWidth = gdispGetStringWidth("Next", font);
bHeight = gdispGetStringWidth("Prev", font);
if (bHeight > bWidth) bWidth = bHeight;
bWidth += 4;
bHeight = gdispGetFontMetric(font, fontHeight)+2;
gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Red, White, justifyLeft);
// Create our main display window // Create our main display window
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); GWindowInit wi;
wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight;
ghc = gwinConsoleCreate(&gc, &wi);
}
gwinClear(ghc); gwinClear(ghc);
// Initialize the mouse in our special no calibration mode. // Initialize the mouse in our special no calibration mode.
@ -87,7 +93,7 @@ StepDeviceType:
gwinPrintf(ghc, "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")); deviceType == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN"));
if (ghNext) if (calibrated)
gwinPrintf(ghc, "Press Next or Back to continue.\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n");
else if (deviceType == GEVENT_MOUSE) else if (deviceType == GEVENT_MOUSE)
gwinPrintf(ghc, "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");
@ -95,19 +101,17 @@ StepDeviceType:
gwinPrintf(ghc, "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) { while(1) {
pe = geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
if (pe->type == GEVENT_GWIN_BUTTON) { if (calibrated) {
peb = (GEventGWinButton *)pe; if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
if (peb->button == ghPrev) if ((pem->meta & GMETA_MOUSE_UP)) {
goto StepClickJitter; if (pem->x >= swidth-bWidth)
if (peb->button == ghNext) break;
break; goto StepClickJitter;
} }
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { }
pem = (GEventMouse *)pe; } else if ((pem->meta & GMETA_MOUSE_UP))
if (!ghNext && (pem->meta & GMETA_MOUSE_UP)) break;
break;
}
} }
/* /*
@ -128,7 +132,7 @@ StepRawJitter:
"Ensure that values don't jump around very much when your finger is stationary.\n\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"); "Increasing GINPUT_MOUSE_READ_CYCLES helps reduce jitter but increases CPU usage.\n\n");
if (ghNext) if (calibrated)
gwinPrintf(ghc, "Press Next or Back to continue.\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n");
else if (deviceType == GEVENT_MOUSE) else if (deviceType == GEVENT_MOUSE)
gwinPrintf(ghc, "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");
@ -139,21 +143,22 @@ StepRawJitter:
geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER); geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);
while(1) { while(1) {
pe = geventEventWait(&gl, TIME_INFINITE); // Always sleep a bit first to enable other events. We actually don't
if (pe->type == GEVENT_GWIN_BUTTON) { // mind missing events for this test.
peb = (GEventGWinButton *)pe; gfxSleepMilliseconds(100);
if (peb->button == ghPrev) pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
goto StepDeviceType; if (calibrated) {
if (peb->button == ghNext) if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
break; if ((pem->meta & GMETA_MOUSE_UP)) {
} if (pem->x >= swidth-bWidth)
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { break;
pem = (GEventMouse *)pe; goto StepDeviceType;
if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) }
gwinPrintf(ghc, "%u:%u\n", pem->x, pem->y); }
if (!ghNext && (pem->meta & GMETA_MOUSE_UP)) } else if ((pem->meta & GMETA_MOUSE_UP))
break; break;
} if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
gwinPrintf(ghc, "%u:%u\n", pem->x, pem->y);
} }
// Reset to just changed movements. // Reset to just changed movements.
@ -173,7 +178,7 @@ StepCalibrate:
gwinPrintf(ghc, "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 the calibration repeatedly fails, increase GINPUT_MOUSE_CALIBRATION_ERROR and try again.\n\n");
if (ghNext) if (calibrated)
gwinPrintf(ghc, "Press Next to start the calibration.\n"); gwinPrintf(ghc, "Press Next to start the calibration.\n");
else if (deviceType == GEVENT_MOUSE) else if (deviceType == GEVENT_MOUSE)
gwinPrintf(ghc, "Click the mouse button to start the calibration.\n"); gwinPrintf(ghc, "Click the mouse button to start the calibration.\n");
@ -181,41 +186,68 @@ StepCalibrate:
gwinPrintf(ghc, "Press and release your finger to start the calibration.\n"); gwinPrintf(ghc, "Press and release your finger to start the calibration.\n");
while(1) { while(1) {
pe = geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
if (pe->type == GEVENT_GWIN_BUTTON) { if (calibrated) {
peb = (GEventGWinButton *)pe; if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
if (peb->button == ghPrev) if ((pem->meta & GMETA_MOUSE_UP)) {
goto StepRawJitter; if (pem->x >= swidth-bWidth)
if (peb->button == ghNext) break;
break; goto StepRawJitter;
} }
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { }
pem = (GEventMouse *)pe; } else if ((pem->meta & GMETA_MOUSE_UP))
if (!ghNext && (pem->meta & GMETA_MOUSE_UP)) break;
break;
}
} }
// Calibrate // Calibrate
ginputCalibrateMouse(0); ginputCalibrateMouse(0);
calibrated = TRUE;
/* From now on we can use Next and Previous Buttons */ // Calibration used the whole screen - re-establish our title and Next and Previous Buttons
if (!ghNext) { gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Green, White, justifyLeft);
gwinAttachMouse(0); gdispFillStringBox(swidth-2*bWidth, 0, bWidth-1, bHeight, "Prev", font, Black, Gray, justifyCenter);
gwinAttachListener(&gl); gdispFillStringBox(swidth-1*bWidth, 0, bWidth , bHeight, "Next", font, Black, Gray, justifyCenter);
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; * Test: Mouse coords
wi.text = "Next"; ghNext = gwinButtonCreate(&gNext, &wi); */
wi.g.show = TRUE; wi.g.x = swidth-100; StepMouseCoords:
wi.text = "Back"; ghPrev = gwinButtonCreate(&gPrev, &wi); gwinClear(ghc);
gwinSetColor(ghc, Yellow);
gwinPrintf(ghc, "\n4. Show Mouse Coordinates\n\n");
gwinSetColor(ghc, White);
if (deviceType == GEVENT_MOUSE)
gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
else
gwinPrintf(ghc, "Press and hold on the surface.\n\n");
gwinPrintf(ghc, "Numbers will display in this window.\n"
"Check the coordinates against where it should be on the screen.\n\n");
gwinPrintf(ghc, "Press Next or Back to continue.\n");
// For this test normal mouse movement events
geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);
while(1) {
// Always sleep a bit first to enable other events. We actually don't
// mind missing events for this test.
gfxSleepMilliseconds(100);
pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
if ((pem->meta & GMETA_MOUSE_UP)) {
if (pem->x >= swidth-bWidth)
break;
goto StepCalibrate;
}
}
if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
gwinPrintf(ghc, "%u:%u\n", pem->x, pem->y);
} }
// Calibration used the whole screen - re-establish our title // Reset to just changed movements.
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Green, White, justifyLeft); geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);
gwinRedraw(ghNext);
gwinRedraw(ghPrev);
/* /*
* Test: Mouse movement jitter * Test: Mouse movement jitter
@ -238,19 +270,16 @@ StepJitter:
gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n\n");
while(1) { while(1) {
pe = geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
if (pe->type == GEVENT_GWIN_BUTTON) { if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
peb = (GEventGWinButton *)pe; if ((pem->meta & GMETA_MOUSE_UP)) {
if (peb->button == ghPrev) if (pem->x >= swidth-bWidth)
goto StepCalibrate; break;
if (peb->button == ghNext) goto StepMouseCoords;
break; }
}
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) {
pem = (GEventMouse *)pe;
if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
gwinPrintf(ghc, ".");
} }
if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
gwinPrintf(ghc, ".");
} }
/* /*
@ -272,19 +301,16 @@ StepPolling:
gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n\n");
while(1) { while(1) {
pe = geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
if (pe->type == GEVENT_GWIN_BUTTON) { if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
peb = (GEventGWinButton *)pe; if ((pem->meta & GMETA_MOUSE_UP)) {
if (peb->button == ghPrev) if (pem->x >= swidth-bWidth)
break;
goto StepJitter; goto StepJitter;
if (peb->button == ghNext) }
break;
}
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) {
pem = (GEventMouse *)pe;
if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
gdispDrawPixel(pem->x, pem->y, Green);
} }
if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
gdispDrawPixel(pem->x, pem->y, Green);
} }
/* /*
@ -308,24 +334,21 @@ StepClickJitter:
gwinPrintf(ghc, "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) { while(1) {
pe = geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
if (pe->type == GEVENT_GWIN_BUTTON) { if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
peb = (GEventGWinButton *)pe; if ((pem->meta & GMETA_MOUSE_UP)) {
if (peb->button == ghPrev) if (pem->x >= swidth-bWidth)
break;
goto StepPolling; goto StepPolling;
if (peb->button == ghNext) }
break;
} }
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { if ((pem->meta & GMETA_MOUSE_CLICK)) {
pem = (GEventMouse *)pe; gwinSetColor(ghc, Yellow);
if ((pem->meta & GMETA_MOUSE_CLICK)) { gwinPrintf(ghc, "-");
gwinSetColor(ghc, Yellow); }
gwinPrintf(ghc, "-"); if ((pem->meta & GMETA_MOUSE_CXTCLICK)) {
} gwinSetColor(ghc, Red);
if ((pem->meta & GMETA_MOUSE_CXTCLICK)) { gwinPrintf(ghc, "x");
gwinSetColor(ghc, Red);
gwinPrintf(ghc, "x");
}
} }
} }