Basic calculator example to show the LPC4088 Experiment Base Board with a touch LCD from DisplayModule

Dependencies:   DmTftLibrary mbed

Fork of dm_calc by Display Module

Revision:
5:d2802a0c5af2
Parent:
4:71588a1e3618
--- a/main.cpp	Wed Sep 10 12:48:14 2014 +0000
+++ b/main.cpp	Thu Sep 11 14:28:56 2014 +0000
@@ -43,6 +43,8 @@
 
 #define NUM_BUTTONS  (sizeof(captions)/sizeof(captions[0]))
 
+#define NUM_CHARS_IN_DISPLAY  20
+
 #if 0
   /* Displays without adapter (DM_TFT28_105 & DM_TFT35_107) */
   #define DM_PIN_CS_TOUCH   D4
@@ -111,7 +113,7 @@
   
 Button* buttons[NUM_BUTTONS];
 
-static char buff[25] = {0};
+static char buff[NUM_CHARS_IN_DISPLAY + 1] = {0};
 static bool redrawResult = true;
 static bool clearResult = true;
 
@@ -132,6 +134,13 @@
   static calc_mode_t mode = MODE_WANT_ARG1;
   static int strpos = 0;
   
+  if (strpos == NUM_CHARS_IN_DISPLAY) {
+    // only accept 'clr' and '=' to prevent overflow
+    if ((arg != 'c') && (arg != '=')) {
+      return;
+    }
+  }
+    
   switch (arg)
   {
     case '0':
@@ -256,18 +265,6 @@
   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);