Simple CAN test based on SKpang's work

Dependencies:   CANInterface mbed

Fork of ecu_reader by Nicholas Herriot

Revision:
6:c91e372617e3
Parent:
3:05bb8f0bd7a4
Child:
7:61b712aa2771
--- a/main.cpp	Tue Aug 28 13:16:46 2012 +0000
+++ b/main.cpp	Tue Jul 23 13:32:24 2013 +0000
@@ -38,11 +38,15 @@
 Serial pc(USBTX, USBRX);
 
 
+
 ecu_reader obdii(CANSPEED_500);     //Create object and set CAN speed
+void can_demo(void);
 void gps_demo(void);
 void sd_demo(void);
+void home(void);                    // Function to set the screen on a home position
 
-int main() {
+int main() 
+{
     pc.baud(115200);
     char buffer[20];
     
@@ -53,36 +57,35 @@
     left.mode(PullUp);
     up.mode(PullUp);
     
-    printf("ECU Reader \n"); 
+    // Display splash screen
+    printf("Vodafone UBI Prototype \n"); 
     lcd.locate(0,0);                // Set LCD cursor position
-    lcd.printf("CAN-Bus demo");
-    
+    lcd.printf("Voda UBI Prototype");    
     lcd.locate(0,1);
-    lcd.printf("www.skpang.co.uk");
-       
-    pc.printf("\n\rCAN-bus demo...");
-    
+    lcd.printf("www.vodafone.com");      
+    // Wait and clear screen
     wait(3);
     lcd.cls();
-    lcd.printf("Use joystick");
 
-    lcd.locate(0,1);
-    lcd.printf("U-CAN:D-GPS:L-SD");
-    
-    pc.printf("\nU-CAN:D-GPS:L-SD");
+    // Call up the home menu
+    home();
+}
+
 
-    while(1)    // Wait until option is selected by the joystick
-    {
-   
-        if(down == 0) gps_demo();
-        if(left == 0) sd_demo();
-               
-        if(up == 0) break;
-        
-    }
+void can_demo(void)
+{
+    char buffer[20];
     lcd.cls();
+    pc.printf("\nVodafone CAN selelected:");
+    
+    lcd.locate(0,0);                // Set LCD cursor position
+    lcd.printf("Voda Car Connect");
+    lcd.locate(0,1);
+    lcd.printf("CAN bus selected");  
 
-    while(1) {  // Main CAN loop
+    while(1) 
+    {  // Main CAN loop
+        if(click == 0) home();
         led2 = 1;
         wait(0.1);
         led2 = 0;
@@ -114,35 +117,69 @@
         }   
        
     }
+
 }
 
+
+
+void home(void)
+{
+    pc.printf("\nVodafone Home Menu");
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Home - use joystick");
+    lcd.locate(0,1);
+    lcd.printf("to select option...");
+    wait(2);
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Use joystick");
+    lcd.locate(0,1);
+    lcd.printf("U-CAN:D-GPS:L-SD:P-Ho");   
+    pc.printf("\nUse the joystick to select an option - hold down the joystick to get back to home");
+    pc.printf("\nUp = CAN buss demo:Down = GPS demo:Left = SD demo: Press = Home");
+ 
+    while(1)    // Wait until option is selected by the joystick
+    {
+        
+        if(down == 0) gps_demo();
+        if(left == 0) sd_demo();
+        if(up == 0) can_demo();       
+    }
+  
+}
+
+
 void gps_demo(void)
 {
+    
     lcd.cls();
     lcd.printf("GPS demo");
     lcd.locate(0,1);
     lcd.printf("Waiting for lock");
- 
-    wait(3);    
-    lcd.cls();
-   
+    pc.printf("\nVodafone Ublox GPS initiated");
+    pc.printf("\nGPS Sampling starting....\n");   
+
     while(1)
     {
-      if(gps.sample()) {
-         lcd.cls();
+      if(click == 0) home();  
+      if(gps.sample()) 
+      {
+        lcd.cls();
         lcd.printf("Long:%f", gps.longitude);
-           lcd.locate(0,1);
+        lcd.locate(0,1);
         lcd.printf("Lat:%f", gps.latitude);
-            pc.printf("I'm at %f, %f\n", gps.longitude, gps.latitude);
-        } else {
-            pc.printf("Oh Dear! No lock :(\n");
-            lcd.cls();
-            lcd.printf("Waiting for lock");
-   
-        }
+        pc.printf("I'm at Latitude: %f, Longitude: %f\n", gps.latitude, gps.longitude);
+      } 
+      else 
+      {
+        pc.printf("Oh Dear! No lock :(\n");
+        lcd.cls();
+        lcd.printf("Waiting for lock");
+      }
     }
- 
-}
+
+} 
 
 void sd_demo(void)
 {
@@ -166,6 +203,7 @@
         
     while(1)
     {
+        if(click == 0) home();
         led2 = 1;
         wait(0.1);
         led2 = 0;