GINPUT Touch Calibration
Improvements to error detection and displaying that to the user during a calibration. Also introduced a hack to allow initialisation of a touch device without an automatic calibration for when the user application wants to do something with the raw readings first.
This commit is contained in:
parent
e741d6045b
commit
64ceade60c
1 changed files with 39 additions and 7 deletions
|
@ -40,7 +40,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GINPUT_MOUSE_CALIBRATION_FONT &fontUI2Double
|
#define GINPUT_MOUSE_CALIBRATION_FONT &fontUI2Double
|
||||||
|
#define GINPUT_MOUSE_CALIBRATION_FONT2 &fontUI2Narrow
|
||||||
#define GINPUT_MOUSE_CALIBRATION_TEXT "Calibration"
|
#define GINPUT_MOUSE_CALIBRATION_TEXT "Calibration"
|
||||||
|
#define GINPUT_MOUSE_CALIBRATION_ERROR_TEXT "Failed - Please try again!"
|
||||||
|
#define GINPUT_MOUSE_CALIBRATION_SAME_TEXT "Error: Same Reading - Check Driver!"
|
||||||
|
|
||||||
#if GINPUT_MOUSE_MAX_CALIBRATION_ERROR < 0
|
#if GINPUT_MOUSE_MAX_CALIBRATION_ERROR < 0
|
||||||
#define GINPUT_MOUSE_CALIBRATION_POINTS 3
|
#define GINPUT_MOUSE_CALIBRATION_POINTS 3
|
||||||
|
@ -327,7 +330,9 @@ GSourceHandle ginputGetMouse(uint16_t instance) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// We only support a single mouse instance currently
|
// We only support a single mouse instance currently
|
||||||
if (instance)
|
// Instance 9999 is the same as instance 0 except that it installs
|
||||||
|
// a special "raw" calibration if there isn't one we can load.
|
||||||
|
if (instance && instance != 9999)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Do we need to initialise the mouse subsystem?
|
// Do we need to initialise the mouse subsystem?
|
||||||
|
@ -348,6 +353,14 @@ GSourceHandle ginputGetMouse(uint16_t instance) {
|
||||||
MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED);
|
MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED);
|
||||||
if ((MouseConfig.flags & FLG_CAL_FREE))
|
if ((MouseConfig.flags & FLG_CAL_FREE))
|
||||||
chHeapFree((void *)pc);
|
chHeapFree((void *)pc);
|
||||||
|
} else if (instance == 9999) {
|
||||||
|
MouseConfig.caldata.ax = 1;
|
||||||
|
MouseConfig.caldata.bx = 0;
|
||||||
|
MouseConfig.caldata.cx = 0;
|
||||||
|
MouseConfig.caldata.ay = 0;
|
||||||
|
MouseConfig.caldata.by = 1;
|
||||||
|
MouseConfig.caldata.cy = 0;
|
||||||
|
MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED);
|
||||||
} else
|
} else
|
||||||
ginputCalibrateMouse(instance);
|
ginputCalibrateMouse(instance);
|
||||||
#endif
|
#endif
|
||||||
|
@ -410,6 +423,9 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
|
||||||
MousePoint *pt;
|
MousePoint *pt;
|
||||||
int32_t px, py;
|
int32_t px, py;
|
||||||
unsigned i, j;
|
unsigned i, j;
|
||||||
|
#if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0
|
||||||
|
unsigned err;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (instance || (MouseConfig.flags & FLG_IN_CAL))
|
if (instance || (MouseConfig.flags & FLG_IN_CAL))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -422,13 +438,17 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
|
||||||
gdispSetOrientation(GDISP_ROTATE_0);
|
gdispSetOrientation(GDISP_ROTATE_0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if GDISP_NEED_CLIP
|
||||||
|
gdispSetClip(0, 0, width, height);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0
|
||||||
|
while(1) {
|
||||||
|
#endif
|
||||||
gdispClear(Blue);
|
gdispClear(Blue);
|
||||||
|
|
||||||
gdispFillStringBox(0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, GINPUT_MOUSE_CALIBRATION_FONT, White, Blue, justifyCenter);
|
gdispFillStringBox(0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, GINPUT_MOUSE_CALIBRATION_FONT, White, Blue, justifyCenter);
|
||||||
|
|
||||||
#if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0
|
|
||||||
do {
|
|
||||||
#endif
|
|
||||||
for(i = 0, pt = points, pc = cross; i < GINPUT_MOUSE_CALIBRATION_POINTS; i++, pt++, pc++) {
|
for(i = 0, pt = points, pc = cross; i < GINPUT_MOUSE_CALIBRATION_POINTS; i++, pt++, pc++) {
|
||||||
_tsDrawCross(pc);
|
_tsDrawCross(pc);
|
||||||
|
|
||||||
|
@ -454,6 +474,13 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
|
||||||
pt->y = py / j;
|
pt->y = py / j;
|
||||||
|
|
||||||
_tsClearCross(pc);
|
_tsClearCross(pc);
|
||||||
|
|
||||||
|
if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) {
|
||||||
|
gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, GINPUT_MOUSE_CALIBRATION_FONT2, Red, Yellow, justifyCenter);
|
||||||
|
chThdSleepMilliseconds(5000);
|
||||||
|
gdispFillArea(0, 35, width, 40, Blue);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply 3 point calibration algorithm */
|
/* Apply 3 point calibration algorithm */
|
||||||
|
@ -471,10 +498,15 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
|
||||||
_tsTransform(&MouseConfig.t, &MouseConfig.caldata);
|
_tsTransform(&MouseConfig.t, &MouseConfig.caldata);
|
||||||
|
|
||||||
/* Calculate the delta */
|
/* Calculate the delta */
|
||||||
px = (MouseConfig.t.x - cross[3].x) * (MouseConfig.t.x - cross[3].x) +
|
err = (MouseConfig.t.x - cross[3].x) * (MouseConfig.t.x - cross[3].x) +
|
||||||
(MouseConfig.t.y - cross[3].y) * (MouseConfig.t.y - cross[3].y);
|
(MouseConfig.t.y - cross[3].y) * (MouseConfig.t.y - cross[3].y);
|
||||||
|
|
||||||
} while (px > GINPUT_MOUSE_MAX_CALIBRATION_ERROR * GINPUT_MOUSE_MAX_CALIBRATION_ERROR);
|
if (err <= GINPUT_MOUSE_MAX_CALIBRATION_ERROR * GINPUT_MOUSE_MAX_CALIBRATION_ERROR)
|
||||||
|
break;
|
||||||
|
|
||||||
|
gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, GINPUT_MOUSE_CALIBRATION_FONT2, Red, Yellow, justifyCenter);
|
||||||
|
chThdSleepMilliseconds(5000);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Restart everything
|
// Restart everything
|
||||||
|
|
Loading…
Add table
Reference in a new issue