Driver Library for our displays

Dependents:   dm_bubbles dm_calc dm_paint dm_sdcard_with_adapter ... more

Revision:
9:bac5439e3c1c
Parent:
7:6cd8c36cbdb3
Child:
11:264e19992620
--- a/DmTouchCalibration.cpp	Mon Jul 07 10:38:09 2014 +0000
+++ b/DmTouchCalibration.cpp	Mon Jul 07 13:30:33 2014 +0000
@@ -92,16 +92,20 @@
 
 bool DmTouchCalibration::getRawTouch(uint16_t& x, uint16_t& y) const {
   bool touched = false;
-  bool hasAllSamples = false;
+  bool haveAllSamples = false;
 
   while(!touched) {
     if (_touch->isTouched()) {
       //Serial.println("is touched");
-      hasAllSamples = _touch->getMiddleXY(x, y);
-      touched = true;
+      haveAllSamples = _touch->getMiddleXY(x, y);
+        
+      // As many samples are take during calibration it is important to
+      // make sure that the screen is still touched. If the user has let
+      // go already then the gathered samples are not good enough.
+      touched = haveAllSamples && _touch->isTouched();
     }
   }
-  return hasAllSamples;
+  return haveAllSamples;
 }
 
 void DmTouchCalibration::drawCalibPoint(uint16_t x, uint16_t y) const {