aboutsummaryrefslogtreecommitdiffstats
path: root/demos/modules/ginput_touch_driver_test/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'demos/modules/ginput_touch_driver_test/main.c')
-rw-r--r--demos/modules/ginput_touch_driver_test/main.c262
1 files changed, 191 insertions, 71 deletions
diff --git a/demos/modules/ginput_touch_driver_test/main.c b/demos/modules/ginput_touch_driver_test/main.c
index d93978cf..8a31ec74 100644
--- a/demos/modules/ginput_touch_driver_test/main.c
+++ b/demos/modules/ginput_touch_driver_test/main.c
@@ -26,18 +26,22 @@
#include "gwin.h"
static GConsoleObject gc;
+static GButtonObject gNext;
+static GButtonObject gPrev;
static GListener gl;
/*------------------------------------------------------------------------*
* GINPUT Touch Driver Calibrator. *
*------------------------------------------------------------------------*/
int main(void) {
- GSourceHandle gs;
+ GSourceHandle gs, gsNext, gsPrev;
+ GEvent *pe;
GEventMouse *pem;
+ GEventGWinButton *peb;
coord_t swidth, sheight;
- GHandle ghc;
+ GHandle ghc, ghNext, ghPrev;
BaseSequentialStream *gp;
- unsigned testnum;
+ GEventType deviceType;
halInit(); // Initialise the Hardware
chSysInit(); // Initialize the OS
@@ -46,7 +50,7 @@ int main(void) {
// Get the display dimensions
swidth = gdispGetWidth();
sheight = gdispGetHeight();
- testnum = 0;
+ ghNext = ghPrev = 0;
// Create our title
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", &fontUI2, Red, White, justifyCenter);
@@ -65,52 +69,87 @@ int main(void) {
* Test: Device Type
*/
+StepDeviceType:
gwinClear(ghc);
gwinSetColor(ghc, Yellow);
- chprintf(gp, "\n%u. DEVICE TYPE\n\n", ++testnum);
+ chprintf(gp, "\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",
- pem->type == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN"));
+ deviceType == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN"));
- chprintf(gp, "Press and release your finger (or mouse button) to move on to the next test.\n");
+ if (ghNext)
+ chprintf(gp, "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");
+ else
+ chprintf(gp, "Press and release your finger to move on to the next test.\n");
- do {
- pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
- if (pem->type != GEVENT_MOUSE && pem->type != GEVENT_TOUCH) // Safety Check
- continue;
-
- } while (!(pem->meta & GMETA_MOUSE_UP));
+ 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);
- chprintf(gp, "\n%u. GINPUT_MOUSE_READ_CYCLES\n\n", ++testnum);
+ chprintf(gp, "\n2. GINPUT_MOUSE_READ_CYCLES\n\n");
gwinSetColor(ghc, White);
- chprintf(gp, "Press on the surface (or press and hold the mouse button).\n\n");
+ if (deviceType == GEVENT_MOUSE)
+ chprintf(gp, "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"
"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"
- "Releasing your finger (or mouse button) will move on to the next test.\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");
+ else if (deviceType == GEVENT_MOUSE)
+ chprintf(gp, "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");
// For this test turn on ALL mouse movement events
geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);
- do {
- pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
- if (pem->type != GEVENT_MOUSE && pem->type != GEVENT_TOUCH) // Safety Check
- continue;
-
- if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
- chprintf(gp, "%u:%u\n", pem->x, pem->y);
- } while (!(pem->meta & GMETA_MOUSE_UP));
+ 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))
+ chprintf(gp, "%u:%u\n", pem->x, pem->y);
+ if (!ghNext && (pem->meta & GMETA_MOUSE_UP))
+ break;
+ }
+ }
// Reset to just changed movements.
geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);
@@ -119,60 +158,124 @@ int main(void) {
* Test: Calibration
*/
+StepCalibrate:
gwinClear(ghc);
gwinSetColor(ghc, Yellow);
- chprintf(gp, "\n%u. GINPUT_MOUSE_CALIBRATION_ERROR\n\n", ++testnum);
+ chprintf(gp, "\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");
gwinSetColor(ghc, White);
- chprintf(gp, "When you press and release the surface, calibration will start.\n");
chprintf(gp, "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");
+ "If the calibration repeatedly fails, increase GINPUT_MOUSE_CALIBRATION_ERROR and try again.\n\n");
- do {
- pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
- if (pem->type != GEVENT_MOUSE && pem->type != GEVENT_TOUCH) // Safety Check
- continue;
+ if (ghNext)
+ chprintf(gp, "Press Next to start the calibration.\n");
+ else if (deviceType == GEVENT_MOUSE)
+ chprintf(gp, "Click the mouse button to start the calibration.\n");
+ else
+ chprintf(gp, "Press and release your finger to start the calibration.\n");
- } while (!(pem->meta & GMETA_MOUSE_UP));
+ 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);
- // Calibration uses the whole screen - re-establish our title
+ /* From now on we can use Next and Previous Buttons */
+ if (!ghNext) {
+
+ ghNext = gwinCreateButton(&gNext, swidth-50, 0, 50, 20, &fontUI2, GBTN_NORMAL);
+ gwinSetButtonText(ghNext, "Next", FALSE);
+ gsNext = gwinGetButtonSource(ghNext);
+ geventAttachSource(&gl, gsNext, 0);
+ gwinAttachButtonSource(ghNext, gs, GEVENT_MOUSE);
+
+ ghPrev = gwinCreateButton(&gPrev, swidth-100, 0, 50, 20, &fontUI2, GBTN_NORMAL);
+ gwinSetButtonText(ghPrev, "Back", FALSE);
+ gsPrev = gwinGetButtonSource(ghPrev);
+ geventAttachSource(&gl, gsPrev, 0);
+ gwinAttachButtonSource(ghPrev, gs, GEVENT_MOUSE);
+
+#if 0
+ {
+ GSourceHandle gsButton1, gsButton2;
+
+ // 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.
+ gsButton1 = ginputGetToggle(GINPUT_TOGGLE_MOMENTARY1);
+ gsButton2 = ginputGetToggle(GINPUT_TOGGLE_MOMENTARY2);
+ gwinAttachButtonSource(ghNext, gsButton2, GEVENT_TOGGLE);
+ gwinAttachButtonSource(ghPrev, gsButton1, GEVENT_TOGGLE);
+ }
+#endif
+ }
+
+ // Calibration used the whole screen - re-establish our title
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", &fontUI2, Green, White, justifyCenter);
+ gwinButtonDraw(ghNext);
+ gwinButtonDraw(ghPrev);
/*
* Test: Mouse movement jitter
*/
+StepJitter:
gwinClear(ghc);
gwinSetColor(ghc, Yellow);
- chprintf(gp, "\n%u. GINPUT_MOUSE_MOVE_JITTER\n\n", ++testnum);
+ chprintf(gp, "\n4. GINPUT_MOUSE_MOVE_JITTER\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");
+ if (deviceType == GEVENT_MOUSE)
+ chprintf(gp, "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");
+
chprintf(gp, "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"
- "Releasing your finger (or mouse button) will move on to the next test.\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");
- do {
- pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
- if (pem->type != GEVENT_MOUSE && pem->type != GEVENT_TOUCH) // Safety Check
- continue;
-
- if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
- chprintf(gp, ".");
- } while (!(pem->meta & GMETA_MOUSE_UP));
+ 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))
+ chprintf(gp, ".");
+ }
+ }
/*
* Test: Polling frequency
*/
+StepPolling:
gwinClear(ghc);
gwinSetColor(ghc, Yellow);
- chprintf(gp, "\n%u. GINPUT_MOUSE_POLL_PERIOD\n\n", ++testnum);
+ chprintf(gp, "\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");
@@ -180,26 +283,33 @@ int main(void) {
"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"
- "Releasing your finger (or mouse button) will move on to the next test.\n");
-
- do {
- pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
- if (pem->type != GEVENT_MOUSE && pem->type != GEVENT_TOUCH) // Safety Check
- continue;
-
- if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
- gdispDrawPixel(pem->x, pem->y, Green);
- } while (!(pem->meta & GMETA_MOUSE_UP));
+ "This test can be ignored for interrupt driven drivers.\n\n");
+ chprintf(gp, "Press Next or Back to continue.\n\n");
+ 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);
- chprintf(gp, "\n%u. GINPUT_MOUSE_MAX_CLICK_JITTER\n\n", ++testnum);
+ chprintf(gp, "\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");
@@ -209,21 +319,31 @@ int main(void) {
"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."
- "This test does not end.\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");
while(1) {
- pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
- if (pem->type != GEVENT_MOUSE && pem->type != GEVENT_TOUCH) // Safety Check
- continue;
-
- if ((pem->meta & GMETA_MOUSE_CLICK)) {
- gwinSetColor(ghc, Yellow);
- chprintf(gp, "-");
+ 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 ((pem->meta & GMETA_MOUSE_CXTCLICK)) {
- gwinSetColor(ghc, Red);
- chprintf(gp, "x");
+ if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) {
+ pem = (GEventMouse *)pe;
+ if ((pem->meta & GMETA_MOUSE_CLICK)) {
+ gwinSetColor(ghc, Yellow);
+ chprintf(gp, "-");
+ }
+ if ((pem->meta & GMETA_MOUSE_CXTCLICK)) {
+ gwinSetColor(ghc, Red);
+ chprintf(gp, "x");
+ }
}
}
+
+ // Can't let this really exit
+ goto StepDeviceType;
}