V.062 11/3

Dependencies:   FT6206 SDFileSystem ILI9341_t3

Fork of ATT_AWS_IoT_demo_v06 by attiot

Revision:
28:54d9a550adf1
Parent:
24:224c07ec3bd0
Child:
29:f71a0be59b99
--- a/main.cpp	Tue Feb 07 16:18:57 2017 +0000
+++ b/main.cpp	Mon Oct 09 21:13:49 2017 +0000
@@ -3,6 +3,11 @@
  */
 #include "mbed.h"
 
+//TFT
+#include "SPI_TFT_ILI9341.h"
+#include "FT6206.h"
+#include "Arial12x12.h"
+
 // SD File System
 #include "SDFileSystem.h"
 
@@ -28,6 +33,8 @@
 #include "mbedtls/debug.h"
 #endif
 
+
+
 //=====================================================================================================================
 //
 // Defines
@@ -73,6 +80,41 @@
 // Sensor defines
 #define CTOF(x)  ((x)*1.8+32) // Temperature
 
+//TFT
+
+//#define PIN_XP          A3
+//#define PIN_XM          A1
+//#define PIN_YP          A2
+//#define PIN_YM          A0
+#define PIN_SCLK        D13
+#define PIN_MISO        D12
+#define PIN_MOSI        D11
+#define PIN_CS_TFT      D10  // chip select pin
+#define PIN_DC_TFT      D9   // data/command select pin.
+
+#define PIN_RESET_TFT   D8
+//#define PIN_BL_TFT      D7
+//#define PIN_CS_SD       D4
+
+
+#define PORTRAIT        0
+#define LANDSCAPE       1
+#define LANDSCAPE_R     3
+
+//#if 0
+/*
+#define PIN_SCL_FT6206  PTE24
+#define PIN_SDA_FT6206  PTE25
+#define PIN_INT_FT6206  PTC6
+*/
+//#else
+#define PIN_SCL_FT6206  D15
+#define PIN_SDA_FT6206  D14
+#define PIN_INT_FT6206  PTC3
+//#endif
+
+SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "TFT"); // mosi, miso, sclk, cs, reset, dc 
+
 //=====================================================================================================================
 //
 // Globals
@@ -100,6 +142,8 @@
 float temperature = 0.0;
 int   humidity    = 0;
 
+char iccid[] = "89011702278124165220";
+
 // Temp/humidity object
 HTS221 hts221; 
 
@@ -414,6 +458,58 @@
     return rc;
 }
 
+void TFTStuff()
+{
+    INFO("DBG> main\r\n");
+    
+    FT6206 ft6206(PIN_SDA_FT6206, PIN_SCL_FT6206, PIN_INT_FT6206); // sda, scl, int
+
+    //Configure the display driver
+    TFT.claim(stdout);
+    //TFT.background(Black);
+    //TFT.foreground(White);
+    
+    TFT.background(White);
+    TFT.foreground(Black);
+
+    
+    TFT.set_orientation(LANDSCAPE_R);
+    TFT.cls();
+
+    //Print a welcome message
+    TFT.set_font((unsigned char*) Arial12x12);
+    TFT.locate(0,0);
+    TFT.printf("Hello mbed!\n");
+    TFT.printf("Touch Screen to Continue!\n");
+    INFO("Hello mbed!\r\n");
+    INFO("Touch Screen to Continue!!\r\n");
+    
+    while(1) {
+        int X1, Y1, X2, Y2;
+        TS_Point p;
+        if(ft6206.touched()){
+            INFO("Touched\r\n");
+            p = ft6206.getPoint();
+            ft6206.clearPoint();
+            return;
+        }
+
+        if (ft6206.getTouchPoint(p)) {
+            X1 = X2;
+            Y1 = Y2;
+            X2 = TFT.width()-p.x;
+            Y2 = TFT.height()-p.y;
+            TFT.locate(0,12);
+            INFO("Touch %3d %3d\n", p.x, p.y);
+            return;
+            if ((X1 > 0) && (Y1 > 0) && (X2 > 0) && (Y2 > 0)) {
+                TFT.line(X1, Y1, X2, Y2, RGB(255,128,255));
+            }
+        }
+    }
+    
+}
+
 //=====================================================================================================================
 //
 // Main
@@ -423,7 +519,7 @@
     
     // Set baud rate for PC Serial
     pc.baud(115200);
-    INFO("Hello World from AT&T IoT Start Kit demo!");
+    INFO("AT&T AWS IoT Demo V.01!");
               
     int i;          
     IoT_Error_t rc = NONE_ERROR;  
@@ -450,6 +546,13 @@
     humidityHandler.pData = &humidity;
     humidityHandler.type = SHADOW_JSON_INT16;
     
+    jsonStruct_t iccidHandler;
+    iccidHandler.cb = NULL;
+    iccidHandler.pKey = "iccid";
+    iccidHandler.pData = iccidName;
+    iccidHandler.type = SHADOW_JSON_STRING;
+    
+    
     INFO("AWS IoT SDK Version(dev) %d.%d.%d-%s", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG);
 
 #ifdef USING_SD_CARD
@@ -460,7 +563,7 @@
     DEBUG("- clientCRT path: %s", AWS_IOT_CERTIFICATE_FILENAME);
     DEBUG("- clientKey path: %s", AWS_IOT_PRIVATE_KEY_FILENAME);
 #else
-    INFO("Using #defines in aws_iot_config.h and certs from certs.cpp for AWS config.");      
+    //INFO("Using #defines in aws_iot_config.h and certs from certs.cpp for AWS config.");      
 #endif
     
     // Startup signal - blinks through RGBW then turns off
@@ -474,6 +577,9 @@
     wait(.5);
     SetLedColor(COLOR_OFF);
     
+    //TFT Stuff
+    TFTStuff();
+    
     // Initialize sensors
     INFO("Init sensors...");
     void hts221_init(void);
@@ -485,6 +591,9 @@
     // Setup SW3 button to falling edge interrupt
     INFO("Init interrupts...");
     Interrupt.fall(&sw3ButtonHandler);
+    
+   
+    
       
     // Boot the Avnet Shield before any other operations
     INFO("Net Boot...");
@@ -585,9 +694,9 @@
             }
                   
             // Updates the 'reported' color/temp/humidity
-            rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer, 3, &ledController,
+            rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer, 4, &ledController,
                                                                                               &temperatureHandler,
-                                                                                              &humidityHandler);
+                                                                                              &humidityHandler, &iccidHandler);
                  
             if (rc == NONE_ERROR) {               
                 rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);