2013-04-06 11:53:40 +00:00
|
|
|
/*
|
2013-04-08 19:55:13 +00:00
|
|
|
* Copyright (c) 2012, 2013, Joel Bodenmann aka Tectu <joel@unormal.org>
|
2013-06-15 11:37:22 +00:00
|
|
|
* Copyright (c) 2012, 2013, Andrew Hannam aka inmarket
|
|
|
|
*
|
2013-04-08 19:55:13 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of the <organization> nor the
|
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
#include "gfx.h"
|
|
|
|
|
|
|
|
static GConsoleObject gc;
|
|
|
|
static GButtonObject gNext;
|
|
|
|
static GButtonObject gPrev;
|
|
|
|
static GListener gl;
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* GINPUT Touch Driver Calibrator. *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
int main(void) {
|
2013-07-07 09:43:34 +00:00
|
|
|
GSourceHandle gs;
|
2013-04-06 11:53:40 +00:00
|
|
|
GEvent *pe;
|
|
|
|
GEventMouse *pem;
|
|
|
|
GEventGWinButton *peb;
|
|
|
|
coord_t swidth, sheight;
|
|
|
|
GHandle ghc, ghNext, ghPrev;
|
|
|
|
GEventType deviceType;
|
|
|
|
font_t font;
|
2013-07-07 09:43:34 +00:00
|
|
|
GWidgetInit wi;
|
2013-04-06 11:53:40 +00:00
|
|
|
|
2013-05-24 15:26:52 +00:00
|
|
|
gfxInit(); // Initialize the display
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
// Get the display dimensions
|
|
|
|
swidth = gdispGetWidth();
|
|
|
|
sheight = gdispGetHeight();
|
|
|
|
ghNext = ghPrev = 0;
|
|
|
|
|
|
|
|
// Create our title
|
|
|
|
font = gdispOpenFont("UI2");
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinSetDefaultFont(font);
|
2013-04-06 11:53:40 +00:00
|
|
|
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Red, White, justifyLeft);
|
|
|
|
|
|
|
|
// Create our main display window
|
2013-07-07 09:43:34 +00:00
|
|
|
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);
|
2013-04-06 11:53:40 +00:00
|
|
|
gwinClear(ghc);
|
|
|
|
|
|
|
|
// Initialize the mouse in our special no calibration mode.
|
|
|
|
geventListenerInit(&gl);
|
|
|
|
gs = ginputGetMouse(9999);
|
|
|
|
geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test: Device Type
|
|
|
|
*/
|
|
|
|
|
|
|
|
StepDeviceType:
|
|
|
|
gwinClear(ghc);
|
|
|
|
gwinSetColor(ghc, Yellow);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "\n1. DEVICE TYPE\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
pem = (GEventMouse *)&gl.event;
|
|
|
|
ginputGetMouseStatus(0, pem);
|
|
|
|
deviceType = pem->type;
|
|
|
|
|
|
|
|
gwinSetColor(ghc, White);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "This is detected as a %s device\n\n",
|
2013-04-06 11:53:40 +00:00
|
|
|
deviceType == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN"));
|
|
|
|
|
|
|
|
if (ghNext)
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Press Next or Back to continue.\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
else if (deviceType == GEVENT_MOUSE)
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Click the mouse button to move on to the next test.\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
else
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Press and release your finger to move on to the next test.\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
pe = geventEventWait(&gl, TIME_INFINITE);
|
|
|
|
if (pe->type == GEVENT_GWIN_BUTTON) {
|
|
|
|
peb = (GEventGWinButton *)pe;
|
|
|
|
if (peb->button == ghPrev)
|
|
|
|
goto StepClickJitter;
|
|
|
|
if (peb->button == ghNext)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) {
|
|
|
|
pem = (GEventMouse *)pe;
|
|
|
|
if (!ghNext && (pem->meta & GMETA_MOUSE_UP))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test: Mouse raw reading jitter
|
|
|
|
*/
|
|
|
|
|
|
|
|
StepRawJitter:
|
|
|
|
gwinClear(ghc);
|
|
|
|
gwinSetColor(ghc, Yellow);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "\n2. GINPUT_MOUSE_READ_CYCLES\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
gwinSetColor(ghc, White);
|
|
|
|
if (deviceType == GEVENT_MOUSE)
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
else
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Press and hold on the surface.\n\n");
|
|
|
|
gwinPrintf(ghc, "Numbers will display in this window.\n"
|
2013-04-06 11:53:40 +00:00
|
|
|
"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)
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Press Next or Back to continue.\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
else if (deviceType == GEVENT_MOUSE)
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Release the mouse button to move on to the next test.\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
else
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Release your finger to move on to the next test.\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
// For this test turn on ALL mouse movement events
|
|
|
|
geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
pe = geventEventWait(&gl, TIME_INFINITE);
|
|
|
|
if (pe->type == GEVENT_GWIN_BUTTON) {
|
|
|
|
peb = (GEventGWinButton *)pe;
|
|
|
|
if (peb->button == ghPrev)
|
|
|
|
goto StepDeviceType;
|
|
|
|
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))
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "%u:%u\n", pem->x, pem->y);
|
2013-04-06 11:53:40 +00:00
|
|
|
if (!ghNext && (pem->meta & GMETA_MOUSE_UP))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset to just changed movements.
|
|
|
|
geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test: Calibration
|
|
|
|
*/
|
|
|
|
|
|
|
|
StepCalibrate:
|
|
|
|
gwinClear(ghc);
|
|
|
|
gwinSetColor(ghc, Yellow);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "\n3. GINPUT_MOUSE_CALIBRATION_ERROR\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
gwinSetColor(ghc, Gray);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Ensure GINPUT_MOUSE_NEED_CALIBRATION = TRUE and GINPUT_MOUSE_CALIBRATION_ERROR is >= 0\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
gwinSetColor(ghc, White);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "You will be presented with a number of points to touch.\nPress them in turn.\n\n"
|
2013-04-06 11:53:40 +00:00
|
|
|
"If the calibration repeatedly fails, increase GINPUT_MOUSE_CALIBRATION_ERROR and try again.\n\n");
|
|
|
|
|
|
|
|
if (ghNext)
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Press Next to start the calibration.\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
else if (deviceType == GEVENT_MOUSE)
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Click the mouse button to start the calibration.\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
else
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Press and release your finger to start the calibration.\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
pe = geventEventWait(&gl, TIME_INFINITE);
|
|
|
|
if (pe->type == GEVENT_GWIN_BUTTON) {
|
|
|
|
peb = (GEventGWinButton *)pe;
|
|
|
|
if (peb->button == ghPrev)
|
|
|
|
goto StepRawJitter;
|
|
|
|
if (peb->button == ghNext)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) {
|
|
|
|
pem = (GEventMouse *)pe;
|
|
|
|
if (!ghNext && (pem->meta & GMETA_MOUSE_UP))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calibrate
|
|
|
|
ginputCalibrateMouse(0);
|
|
|
|
|
|
|
|
/* From now on we can use Next and Previous Buttons */
|
|
|
|
if (!ghNext) {
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinAttachMouse(0);
|
|
|
|
gwinAttachListener(&gl);
|
2013-04-06 11:53:40 +00:00
|
|
|
|
2013-07-07 09:43:34 +00:00
|
|
|
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);
|
2013-04-06 11:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calibration used the whole screen - re-establish our title
|
|
|
|
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Green, White, justifyLeft);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinRedraw(ghNext);
|
|
|
|
gwinRedraw(ghPrev);
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test: Mouse movement jitter
|
|
|
|
*/
|
|
|
|
|
|
|
|
StepJitter:
|
|
|
|
gwinClear(ghc);
|
|
|
|
gwinSetColor(ghc, Yellow);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "\n4. GINPUT_MOUSE_MOVE_JITTER\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
gwinSetColor(ghc, White);
|
|
|
|
if (deviceType == GEVENT_MOUSE)
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Press and hold the mouse button and move around as if to draw.\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
else
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Press firmly on the surface and move around as if to draw.\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your finger that "
|
2013-04-06 11:53:40 +00:00
|
|
|
"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");
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Press Next or Back to continue.\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
pe = geventEventWait(&gl, TIME_INFINITE);
|
|
|
|
if (pe->type == GEVENT_GWIN_BUTTON) {
|
|
|
|
peb = (GEventGWinButton *)pe;
|
|
|
|
if (peb->button == ghPrev)
|
|
|
|
goto StepCalibrate;
|
|
|
|
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))
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, ".");
|
2013-04-06 11:53:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test: Polling frequency
|
|
|
|
*/
|
|
|
|
|
|
|
|
StepPolling:
|
|
|
|
gwinClear(ghc);
|
|
|
|
gwinSetColor(ghc, Yellow);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "\n5. GINPUT_MOUSE_POLL_PERIOD\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
gwinSetColor(ghc, White);
|
2013-07-07 09:43:34 +00:00
|
|
|
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"
|
2013-04-06 11:53:40 +00:00
|
|
|
"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");
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "Press Next or Back to continue.\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
pe = geventEventWait(&gl, TIME_INFINITE);
|
|
|
|
if (pe->type == GEVENT_GWIN_BUTTON) {
|
|
|
|
peb = (GEventGWinButton *)pe;
|
|
|
|
if (peb->button == ghPrev)
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test: Click Jitter
|
|
|
|
*/
|
|
|
|
|
|
|
|
StepClickJitter:
|
|
|
|
gwinClear(ghc);
|
|
|
|
gwinSetColor(ghc, Yellow);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "\n6. GINPUT_MOUSE_MAX_CLICK_JITTER\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
gwinSetColor(ghc, White);
|
2013-07-07 09:43:34 +00:00
|
|
|
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. "
|
2013-04-06 11:53:40 +00:00
|
|
|
"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");
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "This is the last test but you can press Next or Back to continue.\n\n");
|
2013-04-06 11:53:40 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
pe = geventEventWait(&gl, TIME_INFINITE);
|
|
|
|
if (pe->type == GEVENT_GWIN_BUTTON) {
|
|
|
|
peb = (GEventGWinButton *)pe;
|
|
|
|
if (peb->button == ghPrev)
|
|
|
|
goto StepPolling;
|
|
|
|
if (peb->button == ghNext)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) {
|
|
|
|
pem = (GEventMouse *)pe;
|
|
|
|
if ((pem->meta & GMETA_MOUSE_CLICK)) {
|
|
|
|
gwinSetColor(ghc, Yellow);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "-");
|
2013-04-06 11:53:40 +00:00
|
|
|
}
|
|
|
|
if ((pem->meta & GMETA_MOUSE_CXTCLICK)) {
|
|
|
|
gwinSetColor(ghc, Red);
|
2013-07-07 09:43:34 +00:00
|
|
|
gwinPrintf(ghc, "x");
|
2013-04-06 11:53:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can't let this really exit
|
|
|
|
goto StepDeviceType;
|
|
|
|
}
|