Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of RA8875 by
Revision 88:bfddef6ec836, committed 2015-01-19
- Comitter:
- WiredHome
- Date:
- Mon Jan 19 15:44:41 2015 +0000
- Parent:
- 87:ee2240581aa7
- Child:
- 89:04575562c961
- Commit message:
- Added a timeout to the touch calibration process, so that it will return if there is no touchscreen, user not present, or a stuck touchscreen.
Changed in this revision
--- a/DisplayDefs.h Mon Jan 19 13:32:56 2015 +0000
+++ b/DisplayDefs.h Mon Jan 19 15:44:41 2015 +0000
@@ -18,6 +18,7 @@
not_supported_format, ///< file format is not yet supported
image_too_big, ///< image is too large for the screen
not_enough_ram, ///< could not allocate ram for scanline
+ touch_cal_timeout, ///< timeout while trying to calibrate touchscreen, perhaps it is not installed.
LastErrCode, // Private marker.
} RetCode_t;
--- a/RA8875.h Mon Jan 19 13:32:56 2015 +0000
+++ b/RA8875.h Mon Jan 19 15:44:41 2015 +0000
@@ -638,9 +638,12 @@
/// @param[out] matrix is an optional parameter to hold the calibration matrix
/// as a result of the calibration. This can be saved in
/// non-volatile memory to recover the calibration after a power fail.
+ /// @param[in] maxwait_s is the maximum number of seconds to wait for a touch
+ /// calibration. If no touch panel installed, it then reports
+ /// touch_cal_timeout.
/// @returns success/failure code. @see RetCode_t.
///
- RetCode_t TouchPanelCalibrate(const char * msg, tpMatrix_t * matrix = NULL);
+ RetCode_t TouchPanelCalibrate(const char * msg, tpMatrix_t * matrix = NULL, int maxwait_s = 15);
/// Set the calibration matrix for the touch panel.
///
--- a/RA8875_Touch.cpp Mon Jan 19 13:32:56 2015 +0000
+++ b/RA8875_Touch.cpp Mon Jan 19 15:44:41 2015 +0000
@@ -74,13 +74,15 @@
}
-RetCode_t RA8875::TouchPanelCalibrate(const char * msg, tpMatrix_t * matrix)
+RetCode_t RA8875::TouchPanelCalibrate(const char * msg, tpMatrix_t * matrix, int maxwait_s)
{
point_t pTest[3];
point_t pSample[3];
int x,y;
+ Timer timeout; // timeout guards for not-installed, stuck, user not present...
- while (TouchPanelA2DFiltered(&x, &y))
+ timeout.start();
+ while (TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s)
wait_ms(20);
cls();
if (msg)
@@ -89,12 +91,13 @@
pTest[0].x = 50; pTest[0].y = 50;
pTest[1].x = width() - 50; pTest[1].y = height()/2;
pTest[2].x = width()/2; pTest[2].y = height() - 50;
+
for (int i=0; i<3; i++) {
foreground(Blue);
printf(" (%3d,%3d) => ", pTest[i].x, pTest[i].y);
line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, White);
line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, White);
- while (!TouchPanelA2DFiltered(&x, &y))
+ while (!TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s)
wait_ms(20);
pSample[i].x = x;
pSample[i].y = y;
@@ -102,11 +105,14 @@
line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, Black);
foreground(Blue);
printf(" (%4d,%4d)\r\n", x,y);
- while (TouchPanelA2DFiltered(&x, &y))
+ while (TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s)
wait_ms(20);
wait(2);
}
- return TouchPanelComputeCalibration(pTest, pSample, matrix);
+ if (timeout.read() >= maxwait_s)
+ return touch_cal_timeout;
+ else
+ return TouchPanelComputeCalibration(pTest, pSample, matrix);
}
