Shows how to use a display and the touch controller. A very basic calculator. Note that for some displays the LANDSCAPE define must be set for the layout to be correct.

Dependencies:   DmTftLibrary mbed

Files at this revision

API Documentation at this revision

Comitter:
displaymodule
Date:
Wed Jul 09 08:34:25 2014 +0000
Parent:
1:9a3ae682a75e
Child:
3:45df69ebc420
Commit message:
Added fix for online compiler. Fixed issue with Button class.

Changed in this revision

Button.cpp Show annotated file Show diff for this revision Revisions of this file
DmTftLibrary.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Button.cpp	Fri Jul 04 10:33:40 2014 +0000
+++ b/Button.cpp	Wed Jul 09 08:34:25 2014 +0000
@@ -21,19 +21,20 @@
 {
   bool needsRepaint = false;
   if (_enabled) {
-    if ((x >= _x0) && (y >= _y0) && (x <= _x1) && (y <= _y1)) {
+    if (!pressed && _pressed) {
+      // user released => click
+      needsRepaint = true;
+      _pressed = false;
+      if (_func != NULL) {
+        _func(_funcArg);
+      }       
+    }
+    else if ((x >= _x0) && (y >= _y0) && (x <= _x1) && (y <= _y1)) {
       if (pressed && !_pressed) {
         // user pressing inside area
         needsRepaint = true;
         _pressed = true;
-      } else if (!pressed && _pressed) {
-        // user released inside area => click
-        needsRepaint = true;
-        _pressed = false;
-        if (_func != NULL) {
-          _func(_funcArg);
-        }       
-      }
+      } 
     }
   }
   return needsRepaint;
@@ -53,4 +54,3 @@
     tft->drawStringCentered(_x0, _y0, _x1-_x0, _y1-_y0, _caption);
   }
 }
-
--- a/DmTftLibrary.lib	Fri Jul 04 10:33:40 2014 +0000
+++ b/DmTftLibrary.lib	Wed Jul 09 08:34:25 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/displaymodule/code/DmTftLibrary/#6cd8c36cbdb3
+http://mbed.org/users/displaymodule/code/DmTftLibrary/#d263094e666d
--- a/main.cpp	Fri Jul 04 10:33:40 2014 +0000
+++ b/main.cpp	Wed Jul 09 08:34:25 2014 +0000
@@ -68,8 +68,6 @@
  * Local variables
  *****************************************************************************/
 
-//DmTftHX8353C tft;  /* DM_TFT18_101 */
-//DmTftS6D0164 tft;  /* DM_TFT22_102 */
 //DmTftIli9325 tft;  /* DM_TFT28_103 and DM_TFT24_104 */
 DmTftIli9341 tft;  /* DM_TFT28_105 */
 //DmTftSsd2119 tft;   /* DM_TFT35_107 */
@@ -124,12 +122,6 @@
 static bool redrawResult = true;
 static bool clearResult = true;
 
-#ifdef DEBUG
-  static char debug[25] = {0};
-  static char debug2[25] = {0};
-  static int debug_pos = 0;
-#endif
-
 /******************************************************************************
  * Global variables
  *****************************************************************************/
@@ -147,13 +139,6 @@
   static calc_mode_t mode = MODE_WANT_ARG1;
   static int strpos = 0;
   
-#ifdef DEBUG
-  debug2[debug_pos] = '0'+mode;
-  debug[debug_pos] = arg;
-  debug_pos++;
-  debug[debug_pos] = '\0';
-  debug_pos = debug_pos%25;
-#endif  
   switch (arg)
   {
     case '0':
@@ -258,6 +243,18 @@
   while(true) {
     touch.readTouchData(x, y, down);
     
+    /* The following printouts are for some unexplainable reason needed
+       on the LPC4088 QuickStart Board in combination with the MBED online compiler.
+       The printouts are not needed when using an external compiler, e.g. Keil uVision
+       or LPCXpresso IDE. */
+#if defined(__LPC407x_8x_177x_8x_H__)
+    if (down) {
+      printf("DOWN %4d, %4d\n", x, y);
+    } else {
+      printf("UP   %4d, %4d\n", x, y);
+    }
+#endif
+    
     for (int i = 0; i < NUM_BUTTONS; i++) {
       if (buttons[i]->handle(x, y, down)) {
         buttons[i]->draw(&tft);
@@ -270,13 +267,6 @@
     if (redrawResult) {
       redrawResult = false;
       tft.drawStringCentered(RESULT_MARGIN_X, RESULT_MARGIN_Y, w-RESULT_MARGIN_X, yoff-RESULT_MARGIN_Y, &buff[0]);
-#ifdef DEBUG      
-      tft.drawString(5, 5, &debug[0]);
-      tft.drawString(5, 25, &debug2[0]);
-      tft.drawNumber(5, 45, val1, 6);
-      tft.drawNumber(5, 65, val2, 6);
-      tft.drawString(5, 25, &debug2[0]);
-#endif      
     }
     wait(0.02);
   }