Update the touch driver test program for newmouse.

This commit is contained in:
inmarket 2014-10-09 12:30:41 +10:00
parent 38b4af7e20
commit 4766b060a8

View File

@ -38,6 +38,48 @@
static GConsoleObject gc; static GConsoleObject gc;
static GListener gl; static GListener gl;
static font_t font; static font_t font;
static coord_t bWidth, bWidth2, bHeight;
static GHandle ghc;
static coord_t swidth, sheight;
static void DrawHeader(const char *title, bool_t btnNext, bool_t btnPrev, bool_t btnPlusMinus) {
#if GDISP_NEED_CLIP
gdispSetClip(0, 0, swidth, sheight);
#endif
gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Red, White, justifyLeft);
if (btnNext)
gdispFillStringBox(swidth-1*bWidth, 0, bWidth , bHeight, "Next", font, Black, Gray, justifyCenter);
if (btnPrev)
gdispFillStringBox(swidth-2*bWidth, 0, bWidth-1, bHeight, "Prev", font, Black, Gray, justifyCenter);
if (btnPlusMinus) {
gdispFillStringBox(swidth-2*bWidth-1*bWidth2, 0, bWidth2-1, bHeight, "+", font, Black, Gray, justifyCenter);
gdispFillStringBox(swidth-2*bWidth-2*bWidth2, 0, bWidth2-1, bHeight, "-", font, Black, Gray, justifyCenter);
}
gwinClear(ghc);
gwinSetColor(ghc, Yellow);
gwinPrintf(ghc, "\n%s\n\n", title);
gwinSetColor(ghc, White);
}
#define BTN_NONE 0
#define BTN_NEXT 1
#define BTN_PREV 2
#define BTN_PLUS 3
#define BTN_MINUS 4
static int CheckButtons(GEventMouse *pem) {
if (pem->y < bHeight && (pem->buttons & GMETA_MOUSE_UP)) {
if (pem->x >= swidth-1*bWidth)
return BTN_NEXT;
if (pem->x >= swidth-2*bWidth)
return BTN_PREV;
if (pem->x >= swidth-2*bWidth-1*bWidth2)
return BTN_PLUS;
if (pem->x >= swidth-2*bWidth-2*bWidth2)
return BTN_MINUS;
}
return BTN_NONE;
}
/*------------------------------------------------------------------------* /*------------------------------------------------------------------------*
* GINPUT Touch Driver Calibrator. * * GINPUT Touch Driver Calibrator. *
@ -45,17 +87,16 @@ static font_t font;
int main(void) { int main(void) {
GSourceHandle gs; GSourceHandle gs;
GEventMouse *pem; GEventMouse *pem;
coord_t swidth, sheight;
GHandle ghc;
bool_t isFirstTime; bool_t isFirstTime;
bool_t isCalibrated; bool_t isCalibrated;
bool_t isTouch; bool_t isTouch;
bool_t isFinger; bool_t isFinger;
const char * isFingerText; const char * isFingerText;
const char * deviceText; const char * deviceText;
coord_t bWidth, bHeight;
GMouse * m; GMouse * m;
GMouseVMT * vmt; GMouseVMT * vmt;
GMouseJitter * pjit;
uint32_t calerr;
gfxInit(); // Initialize the display gfxInit(); // Initialize the display
@ -70,8 +111,11 @@ int main(void) {
bHeight = gdispGetStringWidth("Prev", font); bHeight = gdispGetStringWidth("Prev", font);
if (bHeight > bWidth) bWidth = bHeight; if (bHeight > bWidth) bWidth = bHeight;
bWidth += 4; bWidth += 4;
bHeight = gdispGetFontMetric(font, fontHeight)+2; bWidth2 = gdispGetStringWidth("+", font)*2;
gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Red, White, justifyLeft); bHeight = gdispGetStringWidth("-", font)*2;
if (bHeight > bWidth2) bWidth2 = bHeight;
bWidth2 += 4;
bHeight = gdispGetFontMetric(font, fontHeight)*2+2;
// Create our main display window // Create our main display window
{ {
@ -81,7 +125,6 @@ int main(void) {
wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight; wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight;
ghc = gwinConsoleCreate(&gc, &wi); ghc = gwinConsoleCreate(&gc, &wi);
} }
gwinClear(ghc);
// Initialize the listener // Initialize the listener
geventListenerInit(&gl); geventListenerInit(&gl);
@ -100,50 +143,60 @@ int main(void) {
gs = ginputGetMouse(0); gs = ginputGetMouse(0);
geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);
// Is the mouse good enough initially for buttons? // Get initial display settings for buttons
isFirstTime = TRUE; isFirstTime = TRUE;
isCalibrated = (vmt->d.flags & GMOUSE_VFLG_CALIBRATE) ? FALSE : TRUE; isCalibrated = (vmt->d.flags & GMOUSE_VFLG_CALIBRATE) ? FALSE : TRUE;
if (isCalibrated) calerr = 0;
gdispFillStringBox(swidth-1*bWidth, 0, bWidth , bHeight, "Next", font, Black, Gray, justifyCenter);
/* /*
* Test: Device Type * Test: Device Type
*/ */
StepDeviceType: StepDeviceType:
gwinClear(ghc); DrawHeader("1. Device Type", isCalibrated, isCalibrated && !isFirstTime, isCalibrated);
gwinSetColor(ghc, Yellow);
gwinPrintf(ghc, "\n1. Device Type\n\n");
// Get the type of device and the current mode // Get the type of device and the current mode
isTouch = (vmt->d.flags & GMOUSE_VFLG_TOUCH) ? TRUE : FALSE; isTouch = (vmt->d.flags & GMOUSE_VFLG_TOUCH) ? TRUE : FALSE;
isFinger = (m->flags & GMOUSE_FLG_FINGERMODE) ? TRUE : FALSE; isFinger = (m->flags & GMOUSE_FLG_FINGERMODE) ? TRUE : FALSE;
pjit = isFinger ? &vmt->finger_jitter : &vmt->pen_jitter;
isFingerText = isFinger ? "finger" : "pen"; isFingerText = isFinger ? "finger" : "pen";
deviceText = isTouch ? isFingerText : "mouse"; deviceText = isTouch ? isFingerText : "mouse";
gwinSetColor(ghc, White);
gwinPrintf(ghc, "This is detected as a %s device\n\n", isTouch ? "TOUCH" : "MOUSE"); gwinPrintf(ghc, "This is detected as a %s device\n\n", isTouch ? "TOUCH" : "MOUSE");
gwinPrintf(ghc, "It is currently in %s mode\n\n", isFinger ? "FINGER" : "PEN"); gwinPrintf(ghc, "It is currently in %s mode\n\n", isFinger ? "FINGER" : "PEN");
if (!isCalibrated) if (!isCalibrated)
gwinPrintf(ghc, "Press and release your %s to move on to the next test.\n", deviceText); gwinPrintf(ghc, "Press and release your %s to move on to the next test.\n", deviceText);
else if (isFirstTime) else {
gwinPrintf(ghc, "Press + for pen or - for finger.\n");
if (isFirstTime)
gwinPrintf(ghc, "Press Next to continue.\n"); gwinPrintf(ghc, "Press Next to continue.\n");
else else
gwinPrintf(ghc, "Press Next or Back to continue.\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n");
}
while(1) { while(1) {
pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
if (isCalibrated) { if (isCalibrated) {
if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { switch (CheckButtons(pem)) {
if ((pem->buttons & GMETA_MOUSE_UP)) { case BTN_NEXT:
if (pem->x >= swidth-bWidth)
break; break;
case BTN_PREV:
if (!isFirstTime) if (!isFirstTime)
goto StepDrawing; goto StepDrawing;
continue;
case BTN_PLUS:
m->flags &= ~GMOUSE_FLG_FINGERMODE;
goto StepDeviceType;
case BTN_MINUS:
m->flags |= GMOUSE_FLG_FINGERMODE;
goto StepDeviceType;
default:
continue;
} }
break;
} }
} else if ((pem->buttons & GMETA_MOUSE_UP)) if ((pem->buttons & GMETA_MOUSE_UP))
break; break;
} }
@ -152,22 +205,19 @@ StepDeviceType:
*/ */
StepRawReading: StepRawReading:
gwinClear(ghc); DrawHeader("2. Raw Mouse Output", FALSE, FALSE, FALSE);
gwinSetColor(ghc, Yellow);
gwinPrintf(ghc, "\n2. Raw Mouse Output\n\n");
// Make sure we are in uncalibrated mode
m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP);
gwinSetColor(ghc, White);
if (isTouch) if (isTouch)
gwinPrintf(ghc, "Press and hold on the surface.\n\n"); gwinPrintf(ghc, "Press and hold on the surface.\n\n");
else else
gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
gwinPrintf(ghc, "The raw values coming from your mouse driver will display.\n\n"); gwinPrintf(ghc, "The raw values coming from your mouse driver will display.\n\n");
gwinPrintf(ghc, "Make sure the x and y values change as you move.\n\n");
gwinPrintf(ghc, "Release your %s to move on to the next test.\n", deviceText); gwinPrintf(ghc, "Release your %s to move on to the next test.\n", deviceText);
// Make sure we are in uncalibrated mode
m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP);
// For this test turn on ALL mouse movement events // For this test turn on ALL mouse movement events
geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER); geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);
@ -176,12 +226,12 @@ StepRawReading:
// mind missing events for this test. // mind missing events for this test.
gfxSleepMilliseconds(100); gfxSleepMilliseconds(100);
pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT);
if ((pem->buttons & GMETA_MOUSE_UP)) if ((pem->buttons & GMETA_MOUSE_UP))
break; break;
gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT);
} }
// Reset to calibrated // Reset to calibrated condition
if (isCalibrated) { if (isCalibrated) {
m->flags |= GMOUSE_FLG_CLIP; m->flags |= GMOUSE_FLG_CLIP;
if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE))
@ -196,45 +246,53 @@ StepRawReading:
*/ */
StepCalibrate: StepCalibrate:
gwinClear(ghc); DrawHeader("3. Calibration Jitter", isCalibrated, isCalibrated, isCalibrated);
gwinSetColor(ghc, Yellow);
gwinPrintf(ghc, "\n3. Calibration Jitter\n\n");
gwinSetColor(ghc, White);
if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) { if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) {
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 the jitter for %s calibration and try again.\n\n", isFingerText); "If the calibration repeatedly fails, increase the jitter for %s calibration and try again.\n\n", isFingerText);
gwinPrintf(ghc, "Press and release your %s to start the calibration.\n", deviceText); gwinPrintf(ghc, "Pressing the surface for longer gives more accurate results.\n\n");
if (calerr)
gwinPrintf(ghc, "Last calibration error ^ 2 = %u\n", calerr);
gwinPrintf(ghc, "Calibration jitter (%s) = %u\n", isFingerText, pjit->calibrate);
if (isCalibrated)
gwinPrintf(ghc, "Press + or - to adjust.\n");
} else { } else {
gwinPrintf(ghc, "This device does not need calibration.\n\n"); gwinPrintf(ghc, "This device does not need calibration.\n\n");
} }
if (isCalibrated) if (isCalibrated)
gwinPrintf(ghc, "Press Next or Back to continue.\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n");
else else
gwinPrintf(ghc, "Press and release your %s to move on to the next test.\n", deviceText); gwinPrintf(ghc, "Press and release your %s to move on to start calibration.\n", deviceText);
while(1) { while(1) {
pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
if (isCalibrated) { if (isCalibrated) {
if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { switch (CheckButtons(pem)) {
if ((pem->buttons & GMETA_MOUSE_UP)) { case BTN_NEXT:
if (pem->x >= swidth-bWidth)
break; break;
case BTN_PREV:
goto StepRawReading; goto StepRawReading;
case BTN_PLUS:
gwinPrintf(ghc, "Calibration jitter (%s) = %u", isFingerText, ++pjit->calibrate);
continue;
case BTN_MINUS:
gwinPrintf(ghc, "Calibration jitter (%s) = %u", isFingerText, --pjit->calibrate);
continue;
default:
continue;
} }
break;
} }
} else if ((pem->buttons & GMETA_MOUSE_UP)) if ((pem->buttons & GMETA_MOUSE_UP))
break; break;
} }
// Calibrate // Calibrate
if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) { if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) {
ginputCalibrateMouse(0); calerr = ginputCalibrateMouse(0);
if (calerr)
goto StepCalibrate;
isCalibrated = TRUE; isCalibrated = TRUE;
// Calibration used the whole screen - re-establish our title and Next and Previous Buttons
gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Green, White, justifyLeft);
gdispFillStringBox(swidth-2*bWidth, 0, bWidth-1, bHeight, "Prev", font, Black, Gray, justifyCenter);
gdispFillStringBox(swidth-1*bWidth, 0, bWidth , bHeight, "Next", font, Black, Gray, justifyCenter);
} }
/* /*
@ -242,18 +300,14 @@ StepCalibrate:
*/ */
StepMouseCoords: StepMouseCoords:
gwinClear(ghc); DrawHeader("4. Show Mouse Coordinates", TRUE, TRUE, TRUE);
gwinSetColor(ghc, Yellow);
gwinPrintf(ghc, "\n4. Show Mouse Coordinates\n\n");
gwinSetColor(ghc, White);
if (isTouch) if (isTouch)
gwinPrintf(ghc, "Press and hold on the surface.\n\n"); gwinPrintf(ghc, "Press and hold on the surface.\n\n");
else else
gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
gwinPrintf(ghc, "Numbers will display in this window.\n" gwinPrintf(ghc, "Check the coordinates against where it should be on the screen.\n\n");
"Check the coordinates against where it should be on the screen.\n\n"); gwinPrintf(ghc, "X should be 0 to %u\nY should be 0 to %u\n\n", swidth-1, sheight-1);
gwinPrintf(ghc, "Press + to retry using extremes or - for normal calibration.\n");
gwinPrintf(ghc, "Press Next or Back to continue.\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n");
// For this test normal mouse movement events // For this test normal mouse movement events
@ -264,14 +318,23 @@ StepMouseCoords:
// mind missing events for this test. // mind missing events for this test.
gfxSleepMilliseconds(100); gfxSleepMilliseconds(100);
pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
if ((pem->buttons & GMETA_MOUSE_UP)) { switch (CheckButtons(pem)) {
if (pem->x >= swidth-bWidth) case BTN_NEXT:
break; break;
case BTN_PREV:
goto StepCalibrate; goto StepCalibrate;
} case BTN_PLUS:
} vmt->d.flags |= GMOUSE_VFLG_CAL_EXTREMES;
goto StepCalibrate;
case BTN_MINUS:
vmt->d.flags &= ~GMOUSE_VFLG_CAL_EXTREMES;
goto StepCalibrate;
default:
gwinPrintf(ghc, "%u, %u\n", pem->x, pem->y); gwinPrintf(ghc, "%u, %u\n", pem->x, pem->y);
continue;
}
break;
} }
// Reset to just changed movements. // Reset to just changed movements.
@ -282,11 +345,7 @@ StepMouseCoords:
*/ */
StepMovementJitter: StepMovementJitter:
gwinClear(ghc); DrawHeader("5. Movement Jitter", TRUE, TRUE, TRUE);
gwinSetColor(ghc, Yellow);
gwinPrintf(ghc, "\n5. Movement Jitter\n\n");
gwinSetColor(ghc, White);
if (isTouch) if (isTouch)
gwinPrintf(ghc, "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");
else else
@ -295,19 +354,29 @@ StepMovementJitter:
gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your %s that " gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your %s that "
"new dots stop displaying.\nNew dots should only display when your %s is moving.\n\n" "new dots stop displaying.\nNew dots should only display when your %s is moving.\n\n"
"Adjust %s movement jitter to the smallest value that this reliably works for.\n\n", deviceText, deviceText, isFingerText); "Adjust %s movement jitter to the smallest value that this reliably works for.\n\n", deviceText, deviceText, isFingerText);
gwinPrintf(ghc, "Movement jitter (%s) = %u\n", isFingerText, pjit->move);
gwinPrintf(ghc, "Press + or - to adjust.\n");
gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n\n");
while(1) { while(1) {
pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { switch (CheckButtons(pem)) {
if ((pem->buttons & GMETA_MOUSE_UP)) { case BTN_NEXT:
if (pem->x >= swidth-bWidth)
break; break;
case BTN_PREV:
goto StepMouseCoords; goto StepMouseCoords;
} case BTN_PLUS:
} gwinPrintf(ghc, "Movement jitter (%s) = %u", isFingerText, ++pjit->move);
continue;
case BTN_MINUS:
gwinPrintf(ghc, "Movement jitter (%s) = %u", isFingerText, --pjit->move);
continue;
default:
if ((pem->buttons & GINPUT_MOUSE_BTN_LEFT)) if ((pem->buttons & GINPUT_MOUSE_BTN_LEFT))
gwinPrintf(ghc, "."); gwinPrintf(ghc, ".");
continue;
}
break;
} }
/* /*
@ -324,21 +393,28 @@ StepClickJitter:
gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n"); gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n");
else else
gwinPrintf(ghc, "Click the mouse with the left and right buttons.\n\n"); gwinPrintf(ghc, "Click the mouse 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. " gwinPrintf(ghc, "A yellow dash is a left (or short) click.\n"
"A red x is a right (or long) click.\n\n" "A red x is a right (or long) click.\n\n"
"Adjust %s click jitter to the smallest value that this reliably works for.\n" "Adjust %s click jitter to the smallest value that this reliably works for.\n"
"Note: moving your %s during a click cancels it.\n\n", isFingerText, deviceText); "Note: moving your %s during a click cancels it.\n\n", isFingerText, deviceText);
gwinPrintf(ghc, "Click jitter (%s) = %u\n", isFingerText, pjit->click);
gwinPrintf(ghc, "Press + or - to adjust.\n");
gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n\n");
while(1) { while(1) {
pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { switch (CheckButtons(pem)) {
if ((pem->buttons & GMETA_MOUSE_UP)) { case BTN_NEXT:
if (pem->x >= swidth-bWidth)
break; break;
case BTN_PREV:
goto StepMovementJitter; goto StepMovementJitter;
} case BTN_PLUS:
} gwinPrintf(ghc, "Click jitter (%s) = %u", isFingerText, ++pjit->click);
continue;
case BTN_MINUS:
gwinPrintf(ghc, "Click jitter (%s) = %u", isFingerText, --pjit->click);
continue;
default:
if ((pem->buttons & GMETA_MOUSE_CLICK)) { if ((pem->buttons & GMETA_MOUSE_CLICK)) {
gwinSetColor(ghc, Yellow); gwinSetColor(ghc, Yellow);
gwinPrintf(ghc, "-"); gwinPrintf(ghc, "-");
@ -347,6 +423,9 @@ StepClickJitter:
gwinSetColor(ghc, Red); gwinSetColor(ghc, Red);
gwinPrintf(ghc, "x"); gwinPrintf(ghc, "x");
} }
continue;
}
break;
} }
/* /*
@ -361,7 +440,8 @@ StepDrawing:
gwinSetColor(ghc, White); gwinSetColor(ghc, White);
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, "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 %s.\n\n", deviceText); gwinPrintf(ghc, "A green line will follow your %s.\n\n", deviceText);
gwinPrintf(ghc, "This is the last test but you can press Next or Back to continue.\n\n"); gwinPrintf(ghc, "Pressing Next will start the tests again but with the option of changing pen/finger mode.\n\n");
gwinPrintf(ghc, "Press Next or Back to continue.\n\n");
while(1) { while(1) {
pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);