modify

Dependencies:   Adafruit_GFX Adafruit_ST7735 GMMP_mbed NTPClient SDFileSystem WIZnet_Library mbed

Fork of ThingPlug_Ethernet_Example_temp_V2 by irina kim

Files at this revision

API Documentation at this revision

Comitter:
irinakim
Date:
Sat Aug 15 23:33:44 2015 +0000
Parent:
10:cf405a9d5c23
Commit message:
TFT_Ethernet

Changed in this revision

Adafruit_GFX.lib Show annotated file Show diff for this revision Revisions of this file
Adafruit_ST7735.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.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
diff -r cf405a9d5c23 -r f15177f282a6 Adafruit_GFX.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_GFX.lib	Sat Aug 15 23:33:44 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/irinakim/code/Adafruit_GFX/#d533c761006e
diff -r cf405a9d5c23 -r f15177f282a6 Adafruit_ST7735.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_ST7735.lib	Sat Aug 15 23:33:44 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/irinakim/code/Adafruit_ST7735/#5ca1a1692044
diff -r cf405a9d5c23 -r f15177f282a6 SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Sat Aug 15 23:33:44 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/azsymaivan/code/SDFileSystem/#f242d7bdef28
diff -r cf405a9d5c23 -r f15177f282a6 main.cpp
--- a/main.cpp	Fri Aug 14 09:12:20 2015 +0000
+++ b/main.cpp	Sat Aug 15 23:33:44 2015 +0000
@@ -1,7 +1,30 @@
 #include "mbed.h"
+#include "Adafruit_ST7735.h"
+#include "SDFileSystem.h"
+#include "mbed_debug.h"
+
+#define BUTTON_NONE 0
+#define BUTTON_DOWN 1
+#define BUTTON_RIGHT 2
+#define BUTTON_SELECT 3
+#define BUTTON_UP 4
+#define BUTTON_LEFT 5
 
-//DigitalOut myled(LED1); //conflict with SPI1_PA5 for W5500 Ethernet Shield
-Serial pc(USBTX, USBRX);
+#define BUFFPIXEL 20
+#define MAX_SIZE 100 
+
+SDFileSystem sd(D11, D12, D13, D4, "sd"); // the pinout on the mbed
+Adafruit_ST7735 tft(D11, D12, D13, D10, D8, D9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST
+AnalogIn joystick(A3);
+Serial pc(D1,D0);
+Serial device(D8,D2);
+LocateDef locate;
+LocateDef org;
+uint8_t readButton(void);
+void bmpDraw(char *filename, uint8_t x, uint8_t y);
+char str[MAX_SIZE];
+char str_l[MAX_SIZE];
+
 
 #include "config.h"
 
@@ -300,6 +323,119 @@
         isSensing = 1;
 }
 
+void tft_operation(void)
+{
+	 char temp1[40];
+    char temp2[10];
+    char buf[40];
+    char data[30];
+    uint8_t b; 
+    uint8_t i=0;
+    int cnt = 0;
+    char ret;
+    buf[0] = 0xec;
+    buf[1] = 0xec;
+    buf[2] = 0xd6;
+    buf[3] = 0xf6;
+    buf[4] = 0x56;
+    buf[5] = 0x36;
+    buf[6] = 0xf6;
+    buf[7] = 0x36;
+    buf[8] = 0xf6;
+    buf[9] = 0xb6;
+    buf[10] = 0x16;
+    buf[11] = 0xf6;
+    buf[12] = 0x56;
+    buf[13] = 0x76;
+    
+	 tft.fillScreen(ST7735_BLACK);
+	 sprintf(data,"Name  Date   Etc\n"); 
+	 tft.printf("%s",data);
+	/* FILE *fp = fopen("/sd/fr_list.txt", "w"); 
+        if(fp == NULL) {
+            error("Could not open file for write\n");
+        }
+    */
+
+    
+    FILE *db = fopen("/sd/db.txt", "r");
+    fscanf(db,"%s%s",&temp1, &temp2);
+    
+    printf("test\r\n");
+    printf("d : %x, %x\r\n", temp1[0], temp1[1]);
+    printf("s : %s\r\n", temp2);
+    
+    while(1) {
+  
+        if(device.readable()) {
+            buf[cnt] = device.getc();
+            if(buf[cnt] == 0)
+            {
+                for(int i=0; i<cnt; i++)
+                    printf("%x ", buf[i]);
+                printf("\r\n");
+                cnt = 0;
+                
+            }    
+            else 
+                cnt ++;
+        }
+    }
+     FILE *fp = fopen("/sd/fr_list.txt", "w");
+	 if(fp == NULL) {
+            error("Could not open file for write\n");
+        }    
+        /////////////ADD/////////////  
+	       
+	    fp = fopen("/sd/fr_list.txt", "r");
+	    while(fgets(str,MAX_SIZE,fp)!=NULL)
+	    {
+	       sprintf(str_l, "%s", str);
+	       tft.printf("%s",str_l);
+	    } fclose(fp);
+ 
+    tft.setCursor(0,0);
+    tft.getCursor(&org);
+    int8_t count=0;
+    while(1)
+    {
+         b = readButton();
+         tft.getCursor(&locate);
+        if(b == BUTTON_DOWN)
+        {
+         	tft.setCursor(120,locate.y_data-8);
+         	count--;
+         	if(count <=0)
+         	{
+         		count =0;
+         		tft.printf("%s",count);
+         	}
+         	tft.printf("%s",count);            
+         
+         }
+         else if(b == BUTTON_UP)
+         {
+         
+         	tft.setCursor(120,locate.y_data-8);
+         	count++;
+         	if(count >=255)
+         	{
+         		count =0;
+         		tft.printf("%s",count);
+         	}
+         	tft.printf("%s",count);       
+        }
+        else if(b == BUTTON_SELECT)
+        {
+             tft.getCursor(&org);
+             tft.setCursor(org.x_data,org.y_data+8);
+            // printf("x =%d, y=%d\r\n",org.x_data,org.y_data);
+        
+        }
+       
+    }
+}
+
 #define BUF_SIZE 10
 GMMPHeader header;
 void *pBody = NULL;
@@ -314,7 +450,9 @@
     g_t.start();
 
   infoln("Start setup()");
-
+  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
+    tft.fillScreen(ST7735_BLACK);
+    mkdir("/sd/fridge_care", 0777);
 	#ifdef USE_SNIC_WIFI
 	wifi.init();
 
@@ -427,6 +565,21 @@
     wait(delay_time);
 }
 
+uint8_t readButton(void) {
+    float a = joystick.read();
+      
+    a *= 5.0;
+          
+//    printf("Button read analog = %f\r\n",a);
+    if (a < 0.2) return BUTTON_DOWN;//BUTTON_LEFT;
+    if (a < 1.0) return BUTTON_RIGHT;//BUTTON_DOWN;  
+    if (a < 1.7) return BUTTON_SELECT;
+    if (a < 2.6) return BUTTON_UP;//BUTTON_RIGHT;
+    if (a < 4.6) return BUTTON_LEFT;//BUTTON_UP;
+   
+    else return BUTTON_NONE;
+}
+
 void loop(void)
 {
   int ret = GetReadData(&header, &pBody);
@@ -523,9 +676,20 @@
 
 int main() {
 
+time_t ctTime;
+    char buffer[50];
+     char data[30];
+    uint8_t b; 
+    uint8_t i=0;
     if( setup() < 0 ) return 0;
 
     while(1) {
+        ctTime = time(NULL)+(3600*9);  //TIME with offset for eastern time KR
+        //FORMAT TIME FOR DISPLAY AND STORE FORMATTED RESULT IN BUFFER
+        strftime(buffer,80,"%a %b %d\r\n%T %p %z\r\n %Z\r\n",localtime(&ctTime));
+        
         loop();
+	   tft_operation();
+    
     }
 }