This device can operate at areas where mobile network is not available. It has friendly user interface and shortcuts dedicated for emergency use.

Dependencies:   4DGL-uLCD-SE max32630fthr USBDevice

Files at this revision

API Documentation at this revision

Comitter:
Phyu
Date:
Tue Sep 03 07:49:26 2019 +0000
Parent:
0:7f19ba74283d
Commit message:
Final Product of the SatChat

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7f19ba74283d -r 4e64402a9bcf main.cpp
--- a/main.cpp	Mon Oct 09 15:21:33 2017 +0000
+++ b/main.cpp	Tue Sep 03 07:49:26 2019 +0000
@@ -8,7 +8,7 @@
 #include "max32630fthr.h"
 #include <stdbool.h>
 #include <string>
-//#include <Keypad.h>
+
 /*  BLACK CODE INCLUDE END */
 
 /*  BLACK CODE DEFINE START */
@@ -19,7 +19,7 @@
 /*  BLACK CODE DEFINE END */
 
 /*  BLACK CODE GLOBAL VAR START */
-//const int GPS_TIMEOUT=180;            //Wait three minutes maximum for GPS.
+const int GPS_TIMEOUT=180;            //Wait three minutes maximum for GPS.
 char gpsfix_last_utc_time[11] = {0};
 char gpsfix_last_utc_date[7] = {0};
 char gpsfix_longtitude[12] = {0};
@@ -56,207 +56,37 @@
 Serial gps(P5_3, P5_4, 9600);
 I2C i2c(P5_7,P6_0); // SDA, SCL
 /*  BLACK CODE PERIPHERAL INIT END */
-
+int one; 
+int two;
+int three;
+int four;
+int five;
+int six;
+int seven;
+int eight;
+int nine;  
 void home(); 
 void CompareKey();
 void Getmessage();
 void TrackingService();
 void Sos();
-char ChartoAlpha(char num);
+char ChartoAlpha();
 void shortcut();
+void gps_final();
 void ReadMessage();
 void PrintChar(char key);
 void tracking_power(bool state); 
-
-
-/*char getkey(void)
-{
-    keypadLine3 = 0;
-    keypadLine1 = 1;
-    keypadLine5 = 1;
-    if (!keypadLine2) {
-        
-      wait(.5);
-        return '1';
-    }
-    if (!keypadLine7) {
-        wait(.5);
-        return '4';
-    }
-    if (!keypadLine6) {
-        wait(.5);
-        return '7';
-    }
-    if (!keypadLine4) {
-        wait(.5);
-        return '*';
-    }
-    keypadLine3 = 1;
-    keypadLine1 = 0;
-    if (!keypadLine2) {
-        wait(.5);
-        return '2';
-      
-    }
-    if (!keypadLine7) {
-        wait(.5);
-        return '5';
-    }
-    if (!keypadLine6) {
-        wait(.5);
-        return '8';
-    }
-    if (!keypadLine4) {
-        wait(.5);
-        return '0';
-    }
-    keypadLine1 = 1;
-    keypadLine5 = 0;
-    if (!keypadLine2) {
-        wait(.5);
-        return '3';
-    }
-    if (!keypadLine7) {
-        wait(.5);
-        return '6';
-    }
-    if (!keypadLine6) {
-        
-      wait(.5);
-        return '9';
-   
-    }
-    if (!keypadLine4) {
-        wait(.5);
-        return '#';
-    }
-    return NULL;
-}
-   */
-
-/*int i, k, pwcount=0;
-char password[] = "999", entry[10];
+int gps_update(void);
+void Icon(); 
+void DeleteMessage();
+void interval();
 
-char  getkey()
-{
-    
-    keypadLine3 = 0;
-    keypadLine1 = 1;
-    keypadLine5 = 1;
-    if (!keypadLine2) {
-    entry[pwcount] = '1';
-  //  pwcount++;
-   wait(.5);
-       
-         return '1' ; 
-    }
-    if (!keypadLine7) {
-         entry[pwcount] = '4';
- //   pwcount++;
-    wait(.5);
-    
-        return '4' ; 
-    }
-    if (!keypadLine6) {
-         entry[pwcount] = '7';
-   // pwcount++;
-    wait(.5);
-        return '7';
-    }
-    if (!keypadLine4) {
-         entry[pwcount] = '*';
-  //  pwcount++;
-    wait(.5);
-       return '*';
-    }
-    keypadLine3 = 1;
-    keypadLine1 = 0;
-    if (!keypadLine2) {
-         entry[pwcount] = '2';
-  //  pwcount++;
-  wait(.5);
-      
-         return '2' ; 
-    }
-    if (!keypadLine7) {
-         entry[pwcount] = '5';
-  //  pwcount++;
-   wait(.5);
-        return '5';
-    }
-    if (!keypadLine6) {
-         entry[pwcount] = '8';
-  //  pwcount++;
-  wait(.5);
-      return '8';
-    }
-    if (!keypadLine4) {
-         entry[pwcount] = '0';
-   // pwcount++;
-   wait(.5);
-      return '0';
-    }
-    keypadLine1 = 1;
-    keypadLine5 = 0;
-    if (!keypadLine2) {
-         entry[pwcount] = '3';
- //   pwcount++;
-    wait(.5);
-    
-      return '3' ; 
-    }
-    if (!keypadLine7) {
-         entry[pwcount] = '6';
- //   pwcount++;
-  wait(.5);
-        return '6';
-    }
-    if (!keypadLine6) {
-        entry[pwcount] = '9';
-    pwcount++;
-   uLCD.printf("%d",pwcount);
-  wait(.5);
-       return '9';
-    }
-    if (!keypadLine4) {
-         entry[pwcount] = '#';
-    pwcount++;
-   wait(.5);
-     return '#';
-   }
-    if (blackButton == 0)
- {
-     wait(.5); 
-     pwcount=0;     
-for(k=0; k<=3; k++){
-   if(password[k] != entry[k]){
-    k=0;
-    uLCD.cls();
-     uLCD.text_string("Wrong Number", 1, 4, FONT_7X8, GREEN);
-      uLCD.printf("%d",k);
-     wait(3);
-     uLCD.cls();
-     Sos();
-     break; 
-   }
-   if(k==2){
-    uLCD.cls();
-    uLCD.text_string("Calling has\nreached!", 1, 4, FONT_7X8, GREEN);
-    uLCD.printf("%d",k);
-    wait(3);
-    uLCD.cls();
-    home();
-     break;
-   }
- }
-  for(k=0; k<10; k++)
-  entry[k]=0;
-} 
-   return NULL; 
-}
-*/
+char amessage[] = "1.This is first\n\n2.This is second\n3.This is third\n" ; 
+char sendMessage[10]; 
 
-int i, k, pw2 , j,pwcount=0;
+void gps_power(bool state);
+
+int i, k, pw2 , j,pwcount=0; int check ; int countcheck ; 
 char sos[] = "999", entry[10];
 char track2[] = "111", entry2[10]; bool track ;
 char  getkey()
@@ -306,6 +136,7 @@
    if ( track == ONN)
    {
     uLCD.text_string("Tracking has\nswitched On!", 1, 4, FONT_7X8, GREEN);
+      
      }
     if ( track == OFFF )
     {
@@ -316,7 +147,7 @@
      for(j=0; j<10; j++)
    entry2[j]=0;
     home();
-   break;
+   break; 
    }
    
   }
@@ -401,6 +232,12 @@
     uLCD.text_string("SOS calling has\nreached!", 1, 4, FONT_7X8, GREEN);
     wait(3);
     uLCD.cls();
+     uLCD.text_string("Requesting for\nyour GPS\ncoordinates.....", 1, 4, FONT_7X8, GREEN);
+     wait(3);
+    uLCD.cls();
+     gps_power(ONN);
+     wait(3);
+    uLCD.cls();
      for(k=0; k<10; k++)
    entry[k]=0;
     home();
@@ -415,13 +252,12 @@
    return NULL; 
 }
 
-
+  /* 
 void ReadMessage()
 {
-    
-    uLCD.printf("\n1.Hey I have been busy..... ");
-    uLCD.printf("\n2.Hi Sir,we would like..... ");
-    uLCD.printf("\n3.Darling,Be safe.C you..... ");
+      uLCD.printf("\n1.Hey I have been busy..... ");
+     uLCD.printf("\n2.Hi Sir,we would like..... ");
+     uLCD.printf("\n3.Darling,Be safe.C you..... ");
      while ( true)
          {   char cut = getkey();
              switch ( cut )
@@ -453,6 +289,7 @@
                            break; 
                            
                            
+                           
                 case '0' :
                            uLCD.cls();
                         Getmessage(); 
@@ -462,79 +299,367 @@
                 } 
             }
 }
+void Deletemessage(char num)
+{
+    
+      uLCD.printf("Please select the no of the message you would like to delete"); 
+      wait(3);
+      uLCD.cls();
+       uLCD.printf("\n1.Hey I have been busy..... ");
+     uLCD.printf("\n2.Hi Sir,we would like..... ");
+     uLCD.printf("\n3.Darling,Be safe.C you..... ");
+   
+     
+    while( true)
+    { num = getkey();
+      
+    switch (num)
+    { 
+      case '1' : uLCD.cls();
+                  uLCD.printf("\n1.Message has been sucessfully deleted");
+                  uLCD.printf("\n1.Hi Sir,we would like..... ");
+                  uLCD.printf("\n2.Darling,Be safe.C you..... ");
+                  wait(5);
+                  uLCD.cls();
+                  Getmessage();
+                  break; 
+      case '2' : uLCD.cls();
+                  uLCD.printf("\n1.Message has been sucessfully deleted");
+                    uLCD.printf("\n1.Hey I have been busy..... ");
+                   uLCD.printf("\n2.Darling,Be safe.C you..... ");
+                   wait(5);
+                  uLCD.cls();
+                  Getmessage();
+                  break;
+      case '3' : uLCD.cls();
+                  uLCD.printf("\n1.Message has been sucessfully deleted");
+                   uLCD.printf("\n1.Hey I have been busy..... ");
+                      uLCD.printf("\n2.Hi Sir,we would like..... ");
+                      wait(5);
+                  uLCD.cls();
+                  Getmessage();
+                 break;
+      case '#'  : uLCD.cls();
+                 home(); 
+    }
+    
+    }
+} 
+*/
 
+void ReadMessage()
+{
+for ( int i = 0 ; i < sizeof(amessage) ; i++)
+{
+uLCD.putc(amessage[i]); 
+}
+}
 
 
-char ChartoAlpha(char num)
+void DeleteMessage()
+{
+
+uLCD.printf("\n\nEnter the id of the message to delete:\n\n");
+ReadMessage();
+while(true)
+{
+char key = getkey(); 
+
+if ( key)
+{
+switch ( key) 
 {
-   
-    if ( num == '2')
-    { 
+    case '1' : for ( int j = 0 ; j < 16 ; j++)
+              {   amessage[j] = ' ' ;  }
+              uLCD.cls();
+               uLCD.text_string("Message has been\nsuccessfully\ndeleted!.....", 1, 4, FONT_7X8, GREEN);
+               wait(3);
+              uLCD.cls();
+              ReadMessage();
+              wait(3);
+              uLCD.cls();
+              Getmessage();
+              break; 
+    case '2' : for ( int j = 16 ; j < 33 ; j++)
+              {   amessage[j] = ' ' ;  }
+               uLCD.cls();
+                uLCD.text_string("Message has been\nsuccessfully\ndeleted!.....", 1, 4, FONT_7X8, GREEN);
+               wait(3);
+              uLCD.cls();
+               
+              ReadMessage();
+               wait(3);
+               uLCD.cls();
+              Getmessage();
+              break;
+    case '3' :  for ( int j = 33 ; j < 53  ; j++)
+              {   amessage[j] = ' ' ;  }
+               uLCD.cls();
+                uLCD.text_string("Message has been\nsuccessfully\ndeleted!.....", 1, 4, FONT_7X8, GREEN);
+               wait(3);
+              uLCD.cls();
+                 ReadMessage();
+                  wait(3);
+                  uLCD.cls();
+              Getmessage();
+              break;
+    case '#' : uLCD.cls();
+               home(); 
+    case '0' : uLCD.cls();
+               Getmessage();
+
+}
+}
+}
+
+}
+
+ 
+  char getkey2(void)
+{
+    keypadLine3 = 0;
+    keypadLine1 = 1;
+    keypadLine5 = 1;
+    if (!keypadLine2) {
+      one++;
+      wait(.5);
+        
+        return '1';
+        
+    }
+    if (!keypadLine7) {
+        four++; 
+        wait(.5);
+        return '4';
+    }
+    if (!keypadLine6) {
+        seven++; 
+        wait(.5);
+        return '7';
+    }
+    if (!keypadLine4) {
+        
+        wait(.5);
+        return '*';
+    }
+    keypadLine3 = 1;
+    keypadLine1 = 0;
+    if (!keypadLine2) {
+        
+        two++; 
+        wait(.5);
+        
+        return '2';
+        
        
-       uLCD.putc('A');
-      
-    } 
-    if ( num == '2' && num == '2' )
-    {   
        
-         uLCD.putc('B'); 
-         
-    } 
-    if ( num == '2' && num == '2' && num == '2' )
-    {   
-       wait(.5);
-         uLCD.putc('C'); 
+        
+    }
+    if (!keypadLine7) {
+        five++;
+        wait(.5);
+        return '5';
+    }
+    if (!keypadLine6) {
+        eight++;
+        wait(.5);
+        return '8';
+    }
+    if (!keypadLine4) {
+        wait(.5);
+          
+        return '0';
+    }
+    keypadLine1 = 1;
+    keypadLine5 = 0;
+    if (!keypadLine2) {
+        three++;
+        wait(.5);
+        return '3';
+    }
+    if (!keypadLine7) {
+        six++; 
+        wait(.5);
+        return '6';
+    }
+    if (!keypadLine6) {
+        nine++;
+        wait(.5);
+        return '9';
+    }
+    if (!keypadLine4) {
+        
+        wait(.5);
+        return '#';
+    }
+     
+  
          
-    } 
-    if ( num == '0' )
-    {  wait(.2);
-       uLCD.putc(' ');
-    } 
-    if ( num == '3' )
-    {  wait(.2);
-       uLCD.putc('D');
-    } 
-   
-    if ( num == '4' )
-    {  wait(.2);
-       uLCD.putc('G');
-    } 
-    if ( num == '5' )
-    {  wait(.2);
-       uLCD.putc('J');
-    } 
-    if ( num == '6' )
-    {  wait(.2);
-       uLCD.putc('M');
-    } 
-    if ( num == '7' )
-    {  wait(.2);
-       uLCD.putc('P');
-    } 
-    if ( num == '8' )
-    { wait(.2);
-       uLCD.putc('T');
-    } 
-    if ( num == '9' )
-    { wait(.2);
-       uLCD.putc('W');
-    } 
-     if (blackButton == 0)
+    return NULL;
+}
+
+
+char ChartoAlpha()
+{
+     char num2 ; 
+      if ( one == 1 )
+     { 
+       while ( true)
+       { 
+          num2 = getkey2();
+          switch(num2)
+        {  case '*' : 
+           one = 0 ; 
+           return 'S'; 
+           
+          case '0' : 
+           one = 0 ; 
+           return ' ';    
+          case '#' : 
+          one = 0 ; 
+          return 'Z';    
+         
+        }
+       }
+      
+    }
+    
+     if ( two == 1 )
+     { 
+       while ( true)
+       { 
+          num2 = getkey2();
+          switch(num2)
+        {  case '*' : 
+           two = 0 ; 
+           return 'A'; 
+           
+          case '0' : 
+           two = 0 ; 
+           return 'B';    
+          case '#' : 
+          two = 0 ; 
+          return 'C';    
+         
+        }
+       }
+      
+    }
+    if ( three == 1 )
+     { 
+       while ( true)
+       { 
+          num2 = getkey2();
+          switch(num2)
+        {  case '*' : 
+           three = 0 ; 
+           return 'D';
+          case '0' :
+          three = 0 ; 
+           return 'E';
+          case '#' : 
+          three = 0 ; 
+          return 'F';
+           
+        }
+       }
+    }
+    if ( four == 1 )
      { 
-       uLCD.cls();
-       uLCD.text_string("Your message\nhas been\nsucessfully sent!", 1, 4, FONT_7X8, GREEN);
-       wait(2);
-       uLCD.cls();
-       home();
+       while ( true)
+       { 
+          num2 = getkey2();
+          switch(num2)
+        {  case '*' :
+         four = 0 ; 
+         return 'G';
+          case '0' :
+           four = 0 ; 
+           return 'H';
+          case '#' :
+          four = 0 ; 
+           return 'I';
+            
+        }
+       }
+    }
+    if ( five == 1 )
+     { 
+       while ( true)
+       { 
+          num2 = getkey2();
+          switch(num2)
+        {  case '*' : 
+        five = 0 ; 
+        return 'J';
+          case '0' :
+           five = 0 ; 
+           return 'K';
+          case '#' :
+          five = 0 ;  
+          return 'L';
+            
+        }
        }
-    if ( num == '#')
+    }
+    if ( six == 1 )
+     { 
+       while ( true)
+       { 
+          num2 = getkey2();
+          switch(num2)
+        {  case '*' : six = 0 ; return 'M';
+          case '0' : six = 0 ;  return 'N';
+          case '#' :six = 0 ;  return 'O';
+            
+        }
+       }
+    }
+    if ( seven == 1 )
+     { 
+       while ( true)
+       { 
+          num2 = getkey2();
+          switch(num2)
+        {  case '*' : seven = 0 ; return 'P';
+          case '0' : seven = 0 ; return 'Q';
+          case '#' : seven = 0 ; return 'R';
+        
+            
+        }
+       }
+    }
+    if ( eight == 1 )
      { 
-        uLCD.cls();
-        home();
-    } 
+       while ( true)
+       { 
+          num2 = getkey2();
+          switch(num2)
+        {  case '*' : eight = 0 ;  return 'T';
+          case '0' : eight = 0 ;return 'U';
+          case '#' :eight = 0 ; return 'V';
+            
+        }
+       }
+    }
+    if ( nine == 1 )
+     { 
+       while ( true)
+       { 
+          num2 = getkey2();
+          switch(num2)
+        {  case '*' : nine = 0 ; return 'W';
+          case '0' : nine = 0 ;  return 'X';
+          case '#' : nine = 0 ; return 'Y';
+            
+        }
+       }
+    }
     
-} 
-
+    return NULL; 
+}
+         
+    
  void shortcut()
 {
            uLCD.printf("\n Press 1 to call help!");
@@ -546,19 +671,20 @@
              switch ( cut )
              { 
                 case '1' : uLCD.cls(); 
-                           uLCD.text_string("Calling Help\nIt will\narrive in 30-45mins!", 1, 4, FONT_7X8, GREEN);
+                           uLCD.text_string("Calling Help\nIt will\narrive in\n30-45mins!", 1, 4, FONT_7X8, GREEN);
                            wait (5); 
                            uLCD.cls();
                             shortcut();
                            break; 
                 
                 case '2' : uLCD.cls(); 
-                           uLCD.text_string("Thank you.\nIf you need\nany help,\nPress *999 for \nSOS!", 1, 4, FONT_7X8, GREEN);
+                           uLCD.text_string("Thank you.\nIf you need\nany help,\nPress 999 for \nSOS!", 1, 4, FONT_7X8, GREEN);
                             wait (5); 
                            uLCD.cls();
                             shortcut();
                            break; 
-                
+                case '3'  :  uLCD.cls(); 
+                             TrackingService();
                            
                 case '#' :
                            uLCD.cls();
@@ -601,11 +727,53 @@
           if ( keyy  == '1' )
      {    
           uLCD.cls(); 
-          uLCD.printf("\n Type your message and Press Black button to send.\n");
+          uLCD.printf("\n Type your message and joystick to send.\n");
           while (true)
-          { char num = getkey();
-             
-             char alpah =  ChartoAlpha(num);
+          { 
+              bool press; 
+               char keypressed = getkey2();
+               if (keypressed)
+                {  press = ONN ;}  
+             char alpha =  ChartoAlpha();
+              uLCD.putc(alpha); 
+           
+             if ( joyButton == 0  )
+        { 
+        
+           
+        uLCD.cls(); 
+         uLCD.text_string("Sending\nMessage.......", 1, 4, FONT_7X8, GREEN);
+        uLCD.text_width(4); //4X size text
+       uLCD.text_height(4);
+       uLCD.color(RED);
+       for (int i=10; i>=0; --i) {
+        uLCD.locate(1,2);
+        uLCD.printf("%2D",i);
+        wait(.5);
+          }
+       uLCD.cls();
+       
+        if (press == ONN )   
+     {   
+       uLCD.text_string("Your message\nhas been\nsucessfully sent!", 1, 4, FONT_7X8, GREEN);
+       wait(2);
+       uLCD.cls();
+       home();
+       } 
+       
+       else 
+           {
+              uLCD.text_string("You haven't\ntyped anything!", 1, 4, FONT_7X8, GREEN);
+              wait(2);
+              uLCD.cls();
+             uLCD.text_string("Your message\nhas failed\nto send!", 1, 4, FONT_7X8, GREEN);
+             wait(2);
+           uLCD.cls();
+             Getmessage(); 
+            }
+     
+       }
+            
             
            } 
        }
@@ -620,7 +788,8 @@
      }
      if ( keyy  == '4' )
      {   uLCD.cls(); 
-         uLCD.printf("\n Select to delete message: ");
+        
+         DeleteMessage();
      }
       
            
@@ -628,19 +797,36 @@
 
 }
 
-     
+
 
 
 void TrackingService()
 {
+    
     if ( track == ONN )
     {
-    uLCD.printf("Tracking Service is On!Press 111 and * to turn off!");
-    uLCD.printf("\n\n Press # to go back to home page");
+    
+     Icon(); 
+    uLCD.printf("\n\n\nTracking Service is On!");
+    wait(3);
+    uLCD.cls();
+     uLCD.text_string("Requesting for\nyour GPS\ncoordinates.....", 1, 4, FONT_7X8, GREEN);
+     wait(3);
+    uLCD.cls();
+     gps_power(ONN);
+     wait(3);
+    uLCD.cls();
+      uLCD.printf("\n\n\nGPS fix will be checking at every %d interval!", check);
+    uLCD.printf("\n\n Press 111 and * to turn off Tracking Service! \n\n Press # to go back to home page");
+   
+    
+           
     }
     if ( track == OFFF )
     {
-         uLCD.printf("Tracking Service is Off!Press 111 and * to turn on!");
+         
+     gps_power(OFFF); 
+         uLCD.printf("\n\n\nTracking Service is Off!Press 111 and * to turn on!");
     uLCD.printf("\n\n Press # to go back to home page");
     }
          
@@ -678,6 +864,7 @@
 
 void GPS()
 {
+     gps_power(ONN);
      uLCD.printf("\nYour co-ordinates now is X=%i Y=%i ", int(joyX.read_u16()), int(joyY.read_u16()));
    
   
@@ -717,22 +904,34 @@
     } 
 }
 
+void Icon()
+{
+   uLCD.filled_circle(115 , 10 , 5 , 0xFF00FF);
+}
 
 void home()
 {
+    countcheck++;
     
+  
        uLCD.printf("\nHello\nWelcome to SatChat.\n"); //Default Green on black text
      uLCD.printf("\n1.Message");
-     uLCD.printf("\n2.Call for help(#999)");
+     uLCD.printf("\n2.Call for help(999)");
       uLCD.printf("\n3.Tracking Service");
       uLCD.printf("\n4.Request GPS co-ordinates");
       uLCD.printf("\n5.Power on/off");
-      
-
+ if ( track == ONN ) 
+    {
+    
+     Icon(); 
+    }
+ 
+  
+   int Y=  int(joyY.read_u16());
+// uLCD.printf("%d",X); 
       while(true)
- {
-        
-         gps_led= !gps_led ; 
+ {     
+           gps_led= !gps_led ; 
         //uLCD.printf("\nJoystick: X=%i Y=%i ", int(joyX.read_u16()), int(joyY.read_u16()));
         if (joyButton==0){
             uLCD.printf("Joystick Button pressed");
@@ -770,7 +969,7 @@
          if (redButton == 0)
        {   uLCD.cls(); 
          uLCD.text_string("Shutting\nDown.......", 1, 4, FONT_7X8, GREEN);
-          wait(3 );
+          wait (3);
           uLCD.reset();
           
         } 
@@ -779,28 +978,53 @@
                uLCD.cls();
              
         }
-    }
+        
+        
+        
+        int X = int(joyX.read_u16()) ; 
+ 
+    /*   if ( X != 26585 )
+       {
+           uLCD.cls(); 
+           uLCD.text_string("Your location\nhas changed.....", 1, 4, FONT_7X8, GREEN);
+          wait(3);
+          uLCD.cls();
+          uLCD.text_string("Tracking\nyour location", 1, 4, FONT_7X8, GREEN);
+          wait(3);
+          uLCD.cls();
+          uLCD.text_string("Tracking is\nsuccessful", 1, 4, FONT_7X8, GREEN);
+            wait(3);
+          uLCD.cls();
+          home();
+        
+         }*/
+  
+      
+     }
+     
+     
+   
 }
-/*
-void tracking_power(bool state)
+
+void gps_power(bool state)
 /*  BLACK CODE
     MAX32630FTHR routine to control the output of the 3v3 line.
     This is achieved by issuing commands to the MAX14690 controller.
     In this case when the GPS is shutdown we clear any serial
     data to avoid issues with mbeds buggy serial code  */
-/*{
-/*    char    data[2];
-    data[0] = 0x16;     //MAX14690 LDO3cfg register
-    uLCD.printf("Tracing Service is:");
+{
+    //char    data[2];
+  //  data[0] = 0x16;     //MAX14690 LDO3cfg register
+    uLCD.printf("GPS Power:");
     if (state == ONN) {
-        data[1] = 0xE2; //Enable LDO3
-        i2c.write( 0x50, data, 2 );
-        gps_led= ONN;
+   //   data[0] = 0xE2; //Enable LDO3
+    //  i2c.write( 0x50, data, 2 );
+    //  gps_led=ONN;
         uLCD.printf("ON\n\r");
     } else {
-        data[1] = 0xE0; //Disable LDO3
-        i2c.write( 0x50, data, 2 );
-        gps_led=OFFF;
+    //data[0] = 0xE0; //Disable LDO3
+  //  i2c.write( 0x50, data, 2 );
+     // gps_led=OFFF;
         while (gps.readable()) {
                 char dummy = gps.getc();    //Empty serial buffer because overflows reveal MBED bugs :-(
         }
@@ -813,7 +1037,7 @@
     Given appropriate global char arrays of time and date information,
     return a unix time epoch.
 */
-/*{
+{
     struct tm t;
     time_t epoch;
     char two_char_str[3] = {0};
@@ -835,7 +1059,7 @@
     //BLACK CODE
 }
 
-/*int gps_update(void)
+int gps_update(void)
 /*  BLACK CODE
     gps_update
     Reads NMEA data from a serial interface defined as "gps".
@@ -860,7 +1084,7 @@
     The serial port is continuously read while waiting for a fix. Once a fix is obtained or a timeout occurs
     the GPS is powered down and remaining data read out of the buffer.
 */
-/*{
+{
     gps_power(ONN);
     time_t gps_on_time = time(NULL);    //Start time for GPS timeout calculation.
     bool wait_for_fix = true;           //Set this to false once a fix is obtained.
@@ -896,11 +1120,11 @@
             char *token;
             token = strtok(nmea_sentence, ",");
             if (strcmp(token,gprmc) == 0) {     //GPRMC
-pc.printf( " %s\n\r", token );  //Get the time
+uLCD.printf( " %s\n\r", token );  //Get the time
                 if (token != NULL) {
                     token = strtok(NULL, ",");
                     if (*token != 32) {         //If there is a time present (anything but a space), record it.
-                        //pc.printf("Time: %s\n\r",token);
+                        //uLCD.printf("Time: %s\n\r",token);
                         gps_led =! gps_led;   //Flash blue LED
                         memcpy(gpsfix_last_utc_time, token, sizeof gpsfix_last_utc_time - 1);
                     }
@@ -908,53 +1132,53 @@
                 if (token != NULL) {
                     token = strtok(NULL, ",");
 if (*token == 'V') {
-       pc.printf("VOID");
+       uLCD.printf("VOID");
 } 
                 } 
                 if (*token == 'A') {                //Is this an 'A'ctive (valid) fix?
-                    pc.printf("Got a fix\n\r");
-                    gps_power(OFF);                 //Yes - No need for GPS now
+                    uLCD.printf("Got a fix\n\r");
+                    gps_power(OFFF);                 //Yes - No need for GPS now
                     wait_for_fix = false;           //Stop looping now we have a fix.
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-pc.printf("Latitude: %s\n\r",token);
+uLCD.printf("Latitude: %s\n\r",token);
                         memcpy(gpsfix_latitude, token, sizeof gpsfix_latitude - 1);
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-pc.printf("North/South: %s\n\r",token);
+uLCD.printf("North/South: %s\n\r",token);
                         gpsfix_ns = *token;
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-pc.printf("Longitude: %s\n\r",token);
+uLCD.printf("Longitude: %s\n\r",token);
                         memcpy(gpsfix_longtitude, token, sizeof gpsfix_longtitude - 1);
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-pc.printf("East/West: %s\n\r",token);
+uLCD.printf("East/West: %s\n\r",token);
                         gpsfix_ew = *token;
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-                        //pc.printf("Speed in knots: %s\n\r",token);
+                        //uLCD.printf("Speed in knots: %s\n\r",token);
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-                        //pc.printf("True course: %s\n\r",token);
+                        //uLCD.printf("True course: %s\n\r",token);
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-pc.printf("Date: %s\n\r",token);
+uLCD.printf("Date: %s\n\r",token);
                         memcpy(gpsfix_last_utc_date, token, sizeof gpsfix_last_utc_date - 1);
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-                        //pc.printf("Variation: %s\n\r",token);
+                        //uLCD.printf("Variation: %s\n\r",token);
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-                        //pc.printf("Variation East/West: %s\n\r",token);
+                        //uLCD.printf("Variation East/West: %s\n\r",token);
                     }
                 }
             }
@@ -962,7 +1186,100 @@
     }
     return EXIT_SUCCESS;
     //BLACK CODE
-}*/
+}
+
+void gps_final()
+{   /*Set the power button behaviour.
+      char    data[2];
+      data[0] = 0x1A;     //MAX14690 BootCfg register
+      data[1] = 0x30;     //Always-On Mode, off state via PWR_OFF_CMD
+      i2c.write( 0x50, data, 2 );
+    */
+    
+    //Set the voltage to 3v3 for the GPS.
+    char data[2];
+    data[0] = 0x17;     //MAX14690 LDO3Vset register
+    data[1] = 0x19;     //3.3V
+    i2c.write( 0x50, data, 2 );
+    gps_power(OFFF);
+
+    while (1) {
+        if (gps_update()==EXIT_SUCCESS) {
+            
+            gps_data_present = true;
+            int gps_epoch = get_epoch_from_last_gps_time();
+            set_time(gps_epoch);
+            uLCD.printf("Got a GPS fix and time.\n\r");
+        } else {
+            uLCD.printf("GPS timed out and we have no existing fix.\n\r");
+            uLCD.printf("We can send an Iridium packet but coordinates are rough.\n\r");
+        }
+        time_t seconds = time(NULL);
+        //uLCD.printf("Time as a basic string = %s", ctime(&seconds));
+        wait(60);
+        seconds = time(NULL);
+
+        wait(33);
+        seconds = time(NULL);
+        uLCD.printf("Time as a basic string = %s", ctime(&seconds));
+        wait(60);
+    } 
+}
+
+
+void Trace()
+
+{ 
+    uLCD.printf("\nTracking Service is On!");
+     uLCD.printf("\n\nThis Unit require your GPS fix at every interval");
+     wait (3);
+     uLCD.cls(); 
+     uLCD.printf("\n\nPlesae enter your desirable interval for us to check on you");
+     
+  
+  while ( true)
+  {   char mins = getkey(); 
+      int min = mins  ; 
+      check = min - 48 ; 
+     if ( mins)
+    {    uLCD.printf("\n\nYou have entered %d mins for the interval",check);
+        wait (3);
+        uLCD.cls(); 
+        home();
+    }
+
+     if (redButton == 0)
+       {   uLCD.cls(); 
+         uLCD.text_string("Shutting\nDown.......", 1, 4, FONT_7X8, GREEN);
+          wait(3 );
+          uLCD.reset();
+          
+        } 
+        
+      
+    
+ } 
+ }
+
+
+
+void interval()
+{
+    
+     check = 0 ; 
+   
+       uLCD.cls();
+    uLCD.text_string("Requesting for\nyour GPS\ncoordinates.....", 1, 4, FONT_7X8, GREEN);
+     wait(3);
+    uLCD.cls();
+     gps_power(ONN);
+     wait(3);
+    uLCD.cls();
+     home();
+}
+
+
+
 
 main()
 {   /*Set the power button behaviour.
@@ -979,84 +1296,37 @@
      //tracking_power(OFFF);
             
             
-     uLCD.printf("\nTracking Service is On!");
-     uLCD.printf("\n\nThis Unit require your GPS fix at every interval");
-     uLCD.printf("\n\nPlesae enter your desirable interval for us to check on you");
-     
-     wait(3);
-     
-  while ( true)
-  {   char mins = getkey(); 
-     int min = mins; 
-     if ( mins )
-     {  uLCD.cls(); 
-        uLCD.printf("\n You have entered %c mins for the interval",mins);
-    } 
-     if (redButton == 0)
+    Trace(); 
+   
+    
+    
+    while ( true)
+    
+    {
+        if ( joyX > 0.3f || joyY > 0.3f )
+       { 
+          uLCD.cls();
+         uLCD.text_string("Your location\nhas changed.....", 1, 4, FONT_7X8, GREEN);
+          wait(3);
+          uLCD.cls();
+          uLCD.text_string("Tracking\nyour location", 1, 4, FONT_7X8, GREEN);
+          wait(3);
+          uLCD.cls();
+          uLCD.text_string("Tracking is\nsuccessful", 1, 4, FONT_7X8, GREEN);
+            wait(3);
+          uLCD.cls();
+          home();
+        }
+      
+        if (redButton == 0)
        {   uLCD.cls(); 
          uLCD.text_string("Shutting\nDown.......", 1, 4, FONT_7X8, GREEN);
           wait(3 );
           uLCD.reset();
           
         } 
-     uLCD.cls(); 
-     home(); 
- } 
-     
-     
+    } 
      
      
    
-  //wait(5); 
-  //uLCD.cls(); 
-  
-  //uLCD.printf("Tracking Service is On!Press 111 to turn off!");
-     
-     // gps_led= !gps_led ; 
-    
-    
- 
-        
-    
-     
-     
-      
-    
-    //Set the voltage to 3v3 for the GPS.
-   /* char data[2];
-    data[0] = 0x17;     //MAX14690 LDO3Vset register
-    data[1] = 0x19;     //3.3V
-    i2c.write( 0x50, data, 2 );
-    gps_power(OFF);*/
-
-  /*  while (1) {
-        
-        if (gps_update()==EXIT_SUCCESS) {
-            gps_data_present = true;
-            int gps_epoch = get_epoch_from_last_gps_time();
-            set_time(gps_epoch);
-            pc.printf("Got a GPS fix and time.\n\r");
-        } else {
-            pc.printf("GPS timed out and we have no existing fix.\n\r");
-            pc.printf("We can send an Iridium packet but coordinates are rough.\n\r");
-        }
-        time_t seconds = time(NULL);
-        //printf("Time as a basic string = %s", ctime(&seconds));
-        wait(60);
-        seconds = time(NULL);
-
-        wait(33);
-        seconds = time(NULL);
-        printf("Time as a basic string = %s", ctime(&seconds));
-        wait(60);
-    } */
-}
-
-
-
-
-
-
-
-
-
+}  
\ No newline at end of file