code

Dependencies:   BME280 BMP280 TextLCD mbed

Revision:
0:7023c3f98f36
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/putty.h	Sat Jan 06 17:28:05 2018 +0000
@@ -0,0 +1,270 @@
+#include "mbed.h"
+#include "data.h"
+Serial pc(USBTX, USBRX); 
+char user_command[40] = {0};
+char user_command2[40] = {0};
+int n, datan = 0, datac = 0, counterd = 0, dates, times, interrupt = 0;
+float t;
+
+
+void readall()
+{
+    datan = counterw;
+    pc.printf("readall selected\n\r");
+    if (full == 1)
+        {
+            datac = 120;
+        }
+    else
+        {
+            datac = counterw;
+        }
+    pc.printf("printting %i datas\n\r", datac);
+    while (counterd < datac)  
+        { 
+            pc.printf("light: %2.4f, temp: %3.4f, press: %3.4f\n\r", data_light[datan], data_temp [datan], data_press[datan]);  
+            if (datan == 0)
+                {
+                    datan = 121;
+                }
+            datan--;
+            counterd++;     
+        }
+    counterd = 0;
+}
+
+void readn()
+{
+    
+    counterd = 0; 
+    n = atoi(user_command2);
+    pc.printf("read %i datas\n\r",n);
+    if (n > counterw)
+        {
+            pc.printf("we only have %i datas \n\r", counterw);
+        }
+    else
+        {
+            while (counterd < n)  
+                { 
+                    pc.printf("light: %2.4f, temp: %3.4f, press: %3.4f\n\r",data_light[datan], data_temp [datan], data_press[datan]);  
+                    if (datan == 0)
+                        {
+                            datan = 121;
+                        }
+                    datan--;
+                    counterd++;     
+                }  
+         }   
+}
+
+void deleteall()
+{
+    pc.printf("deleted %i datas \n\r", counterw);
+    counterw = 0;
+    int counter = 0;
+    while (counter < 121)
+        {
+            data_light[counter] = 0;
+            data_temp [counter] = 0; 
+            data_press[counter] = 0; 
+            counter ++;
+            full = 0;
+        }  
+}
+
+void deleten()
+{
+    datan = counterw;
+    counterd = 0;
+    n = atoi(user_command2);
+    if (n > counterw && full == 0)
+    {
+        pc.printf("we only have %i datas \n\r", counterw);
+    }
+    else if(full == 1 && n> 120)
+    {
+        pc.printf("we only have 120 datas \n\r");
+    }
+    else if(full == 0 && n < counterw)
+        {
+            pc.printf("deleted %i datas \n\r", n);
+            counterw = counterw-n;
+            while (counterd < n)
+                {
+                    data_light[datan] = 0;
+                    data_temp [datan] = 0; 
+                    data_press[datan] = 0; 
+                    counterd ++;
+                    datan--;
+                }
+        }
+   else if(full == 1 && n < 120)
+        {
+            pc.printf("deleted %i datas \n\r", n);
+            counterw = counterw-n;
+            while (counterd < 120)
+                {
+                    data_light[datan] = 0;
+                    data_temp [datan] = 0; 
+                    data_press[datan] = 0; 
+                    counterd ++;
+                    datan--;
+                }
+        } 
+}
+//void fill(char c[20], char c2[20])
+//{
+//    int counterino = 0;
+//    while (counterino <21)
+//    {
+//    user_command[counterino] = c[counterino];
+//    user_command2[counterino] = c2[counterino];
+//    counterino++;
+//    }
+      
+//}
+void clear()
+{
+    int counter = 0;
+    while (counter < 40)
+   {
+        user_command[counter] = 0;
+        counter ++;
+    }
+}
+
+
+void clear2()
+{
+    int counter = 0;
+    while (counter < 40)
+    {
+        user_command2[counter] = 0;
+        counter ++;
+    }
+}
+
+void selection()
+{
+    counterd = 0;
+    datan = counterw-1;
+    if (user_command[0] == 'R'&& user_command[1] == 'E'&& user_command[2] == 'A'&& user_command[3] == 'D')
+    {
+        if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L')
+        {
+            readall();
+          }
+        
+        else
+        {
+            readn();
+        }
+    }   
+    
+    else if (user_command[0] == 'D'&& user_command[1] == 'E'&& user_command[2] == 'L'&& user_command[3] == 'E' && user_command[4] == 'T' && user_command[5] == 'E')
+    {
+        if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L')
+        {
+            pc.printf("deleteall selected\n\r");
+            deleteall();
+        }
+    
+         else
+        {
+            n = atoi(user_command2);
+            pc.printf("delete %i\n\r",n);
+            deleten();
+         }
+    }
+    
+    else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'D' && user_command[4] == 'A' && user_command[5] == 'T' && user_command[6] == 'E')
+    {
+          dates = atoi(user_command2); 
+          yyyy =  dates%10;
+          dates /= 10;
+          yyy = dates%10;
+          dates /= 10; 
+          yy = dates%10;
+          dates /= 10;
+          y = dates%10;
+          dates /= 10;
+          mm = dates%10;
+          dates /= 10;
+          m = dates%10;
+          dates /= 10;
+          dd = dates%10;
+          dates /= 10;
+          d = dates%10;
+          pc.printf("you set the date to %i%i/%i%i/%i%i%i%i\n\r", d,dd,m,mm,y,yy,yyy,yyyy);
+    }
+    else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'T' && user_command[4] == 'I' && user_command[5] == 'M' && user_command[6] == 'E')
+    {
+          times = atoi(user_command2); 
+          ss =  times%10;
+          times /= 10;
+          s = times%10;
+          times /= 10; 
+          mmi = times%10;
+          times /= 10;
+          mi = times%10;
+          times /= 10;
+          hh = times%10;
+          times /= 10;
+          h = times%10;
+          pc.printf("you set the time to %i%i:%i%i:%i%i\n\r", h,hh,mi,mmi,s,ss);
+    }
+    else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'T')
+    {
+        t = atof(user_command2);
+        pc.printf("you set the period to %2.2f", t);
+        interrupt = 1;
+    }
+}
+//int main()
+//{
+//    pc.printf("putty ready\n\r");
+//    while(1)
+//        {
+//            clear();
+//            clear2();
+//            while (user_command[0] == 0)
+//                {
+//                     pc.scanf("%s",user_command);
+//                     pc.scanf("%s",user_command2);
+//                     pc.printf("you typed: %s %s\n\r",user_command,user_command2);
+//                }
+//                
+//                selection();
+//         }
+//}
+
+
+void putty_write ()
+{
+    int count = 0;
+            int wcount = 0;
+            while (user_command[wcount]!= ' ')
+            {
+                user_command[count] = pc.getc();
+                pc.putc(user_command[count]);
+                count++;
+                wcount = count -1;
+            }
+            int count2 = 0;
+            int wcount2 = 0;
+            while(user_command2[wcount2]!= '\r')
+            {
+                user_command2[count2] = pc.getc();
+                pc.putc(user_command2[count2]);
+                count2++;
+                wcount2 = count2 -1;
+            }
+            
+            
+            pc.printf("you typed: %s %s\n\r",user_command,user_command2);
+            selection();
+            clear();
+            clear2();  
+            
+}
\ No newline at end of file