Base library for various projects.

Dependents:   LEDFun NetTester

Base library for various projects.

Files at this revision

API Documentation at this revision

Comitter:
Searle95
Date:
Thu Aug 01 09:14:47 2013 +0000
Parent:
0:a2d01ba1a81b
Child:
2:a3deb705b78e
Commit message:
Modified for use in NetTester project.

Changed in this revision

Functions.cpp Show annotated file Show diff for this revision Revisions of this file
Functions.h Show annotated file Show diff for this revision Revisions of this file
variables.h Show annotated file Show diff for this revision Revisions of this file
--- a/Functions.cpp	Thu Aug 01 09:05:54 2013 +0000
+++ b/Functions.cpp	Thu Aug 01 09:14:47 2013 +0000
@@ -2,28 +2,16 @@
 #include "screens.h"
 #include "variables.h"
 
+Ethernet eth;
+EthernetInterface eth1;
 PwmOut led1(LED1);
 PwmOut led2(LED2);
 PwmOut led3(LED3);
 PwmOut led4(LED4);
+char buf[0x600];
+int packets;
 int loading_loop;
 int loading_line;
-    
-void Functions::Loading() {
-    lcd.cls();
-    lcd.writeString(10, 2, "Please wait", NORMAL);
-
-    while(loading_loop < 82) {
-        wait(0.05);
-        lcd.writeString(loading_line, 2, ".", NORMAL);
-        loading_line += 1;
-        if(loading_line == 82) {
-            lcd.cls();
-            lcd.writeString(25, 2, "Ready!", NORMAL);
-        }
-        loading_loop += 1;
-    }
-}
 
 void Functions::Intro() {
     lcd.init();
@@ -31,172 +19,141 @@
     lcd.writeString(19, 2, "Welcome!", NORMAL);
     wait(1);
     lcd.cls();
-    lcd.writeString(24, 1, "LEDFun", NORMAL);
+    lcd.writeString(16, 1, "NetTester", NORMAL);
     lcd.writeString(26, 2, "V1.00", NORMAL);
     lcd.writeString(13, 3, "Dan Searle", NORMAL);
     wait(5);
 }
-
-void Functions::Commands() {
+      
+void Functions::ContrastChange() {
+    lcd.cls();
+    lcd.printf("Contrast");
+    
     lcd.cls();
-    lcd.writeString(2, 2, "Continue = c", NORMAL);
-    lcd.writeString(2, 3, "Skip = x", NORMAL);
-    char c = pc.getc();
-    if(c == 'x') {
-        Loading();
-    }
-    else if(c == 'c') {
+    lcd.writeString(3, 1,"To change the", NORMAL);
+    lcd.writeString(2, 2,"contrast level", NORMAL);
+    lcd.writeString(3, 3,"use 'u' & 'd'", NORMAL);
+    wait(5);
+    
+    while(1) {
         lcd.cls();
-        lcd.printf(" All   = q    ");
-        lcd.printf(" LED 1 = w & a");
-        lcd.printf(" LED 2 = e & s");
-        lcd.printf(" LED 3 = r & d");
-        lcd.printf(" LED 4 = t & f");
-        lcd.printf(" All   = y    ");
-        wait(5);
-        Loading();
+        lcd.writeString(8, 2,"'c' to skip", NORMAL);
+        lcd.printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
+        lcd.writeString(7, 4,"Contrast:", NORMAL); 
+        lcd.printf("\n%X", contrast);
+        char c = pc.getc();
+        if(c == 'u') {
+            contrast += 1;
+            lcd.init();
+        }
+        if(c == 'd') {
+            contrast -= 1;
+            lcd.init();
+        }
+        if(c == 'c') {
+            break;
+        }
+        wait(0.5);
     }
 }
 
-void Functions::LEDAndRestart() {
-    double all_bright = 0.0;
+void Functions::Loading() {
+    lcd.cls();
+    lcd.writeString(10, 2, "Please wait", NORMAL);
+            
+    while(loading_loop < 82) {
+        wait(0.05);
+        lcd.writeString(loading_line, 2, ".", NORMAL);
+        loading_line += 1;
+        if(loading_line == 82) {
+            Packets();
+        }
+        loading_loop += 1;
+    }
+}
+
+void Functions::ReadLED() {
     double led1_bright = 0.0;
     double led2_bright = 0.0;
     double led3_bright = 0.0;
     double led4_bright = 0.0;
+
+    led1_bright += 1.0;
+    led1 = led1_bright;
+    wait(0.1);
+    led1_bright -= 1.0;
+    led1 = led1_bright;
+    led2_bright += 1.0;
+    led2 = led2_bright;
+    wait(0.1);
+    led2_bright -= 1.0;
+    led2 = led2_bright;
+    led3_bright += 1.0;
+    led3 = led3_bright;
+    wait(0.1);
+    led3_bright -= 1.0;
+    led3 = led3_bright;
+    led4_bright += 1.0;
+    led4 = led4_bright;
+    wait(0.1);
+    led4_bright -= 1.0;
+    led4 = led4_bright;
+}
+
+void Functions::FinishLED() {
+    double led1_bright = 0.0;
+    double led2_bright = 0.0;
+    double led3_bright = 0.0;
+    double led4_bright = 0.0;
+
+    led1_bright += 1.0;
+    led2_bright += 1.0;
+    led3_bright += 1.0;
+    led4_bright += 1.0;
+    led1 = led1_bright;
+    led2 = led2_bright;
+    led3 = led3_bright;
+    led4 = led4_bright;
+    wait(2);
+    led1_bright -= 1.0;
+    led2_bright -= 1.0;
+    led3_bright -= 1.0;
+    led4_bright -= 1.0;
+    led1 = led1_bright;
+    led2 = led2_bright;
+    led3 = led3_bright;
+    led4 = led4_bright;
+}
+
+void Functions::Packets() {
+    packets = 0;
     
-    while(1) {
-        char c = pc.getc();
-        if((c == 'q') && (all_bright < 0.9)) {
-            led1_bright += 1.0;
-            led2_bright += 1.0;
-            led3_bright += 1.0;
-            led4_bright += 1.0;
-            all_bright += 1.0;
-            led1 = led1_bright;
-            led2 = led2_bright;
-            led3 = led3_bright;
-            led4 = led4_bright;
-            lcd.cls();
-            lcd.writeString(5, 2, "All LED's On!", NORMAL);
-            lcd.writeString(13, 4, "Brightness", NORMAL);
-            lcd.printf("\n\n\n\n\n\n\n\n\n%g", all_bright);
-        }
-        
-        if((c == 'y') && (all_bright > 0.0)) {
-            led1_bright -= 1.0;
-            led2_bright -= 1.0;
-            led3_bright -= 1.0;
-            led4_bright -= 1.0;
-            all_bright -= 1.0;
-            led1 = led1_bright;
-            led2 = led2_bright;
-            led3 = led3_bright;
-            led4 = led4_bright;
-            if(all_bright < 0.01) {
-                all_bright = 0;
-            }
-            lcd.cls();
-            lcd.writeString(2, 2, "All LED's Off!", NORMAL);
-            lcd.writeString(13, 4, "Brightness", NORMAL);
-            lcd.printf("\n\n\n\n\n\n\n\n\n%g", all_bright);
-        } 
-         
-        if((c == 'w') && (led1_bright < 0.9)) {
-            led1_bright += 0.1;
-            led1 = led1_bright;
-            lcd.cls();
-            lcd.writeString(15, 2, "LED 1 Up!", NORMAL);
-            lcd.writeString(13, 4, "Brightness", NORMAL);
-            lcd.printf("\n\n\n\n\n\n\n\n\n%g", led1_bright);
-        }
-        
-        if((c == 'a') && (led1_bright > 0.0)) {
-            led1_bright -= 0.1;
-            led1 = led1_bright;
-            if(led1_bright < 0.01) {
-                led1_bright = 0;
-            }
-            lcd.cls();
-            lcd.writeString(10, 2, "LED 1 Down!", NORMAL);
-            lcd.writeString(13, 4, "Brightness", NORMAL);
-            lcd.printf("\n\n\n\n\n\n\n\n\n%g", led1_bright);
-        }
-        
-        if((c == 'e') && (led2_bright < 0.9)) {
-            led2_bright += 0.1;
-            led2 = led2_bright;
-            lcd.cls();
-            lcd.writeString(15, 2, "LED 2 Up!", NORMAL);
-            lcd.writeString(13, 4, "Brightness", NORMAL);
-            lcd.printf("\n\n\n\n\n\n\n\n\n%g", led2_bright);
+    while(packets < 25) {
+        lcd.cls();
+        lcd.writeString(21, 2, "Reading", NORMAL);
+        lcd.writeString(21, 3, "Packets", NORMAL);
+        int size = eth.receive();
+        if(size > 0) {
+            eth.read(buf, size);
+            ReadLED();
+            pc.printf("Destination:  %02X:%02X:%02X:%02X:%02X:%02X        ",
+                    buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
+            pc.printf("Source: %02X:%02X:%02X:%02X:%02X:%02X        ",
+                    buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
+            pc.printf("Buffer Remain: %d        ", (sizeof(buf) - size));       
+            pc.printf("Received Packet Size: %d\n\r", size);
+            
+            packets += 1;
         }
-        
-        if((c == 's') && (led2_bright > 0.0)) {
-            led2_bright -= 0.1;
-            led2 = led2_bright;
-            if(led2_bright < 0.01) {
-                led2_bright = 0;
-            }
-            lcd.cls();
-            lcd.writeString(10, 2, "LED 2 Down!", NORMAL);
-            lcd.writeString(13, 4, "Brightness", NORMAL);
-            lcd.printf("\n\n\n\n\n\n\n\n\n%g", led2_bright);
-        }  
-        
-        if((c == 'r') && (led3_bright < 0.9)) {
-            led3_bright += 0.1;
-            led3 = led3_bright;
-            lcd.cls();
-            lcd.writeString(15, 2, "LED 3 Up!", NORMAL);
-            lcd.writeString(13, 4, "Brightness", NORMAL);
-            lcd.printf("\n\n\n\n\n\n\n\n\n%g", led3_bright);
-        } 
-        
-        if((c == 'd') && (led3_bright > 0.0)) {
-            led3_bright -= 0.1;
-            led3 = led3_bright;
-            if(led3_bright < 0.01) {
-                led3_bright = 0;
-            }
-            lcd.cls();
-            lcd.writeString(10, 2, "LED 3 Down!", NORMAL);
-            lcd.writeString(13, 4, "Brightness", NORMAL);
-            lcd.printf("\n\n\n\n\n\n\n\n\n%g", led3_bright);
-        } 
-         
-        if((c == 't') && (led4_bright < 0.9)) {
-            led4_bright += 0.1;
-            led4 = led4_bright;
-            lcd.cls();
-            lcd.writeString(15, 2, "LED 4 Up!", NORMAL);
-            lcd.writeString(13, 4, "Brightness", NORMAL);
-            lcd.printf("\n\n\n\n\n\n\n\n\n%g", led4_bright);
-        }  
-        
-        if((c == 'f') && (led4_bright > 0.0)) {
-            led4_bright -= 0.1;
-            led4 = led4_bright;
-            if(led4_bright < 0.01) {
-                led4_bright = 0;
-            }
-            lcd.cls();
-            lcd.writeString(10, 2, "LED 4 Down!", NORMAL);
-            lcd.writeString(13, 4, "Brightness", NORMAL);
-            lcd.printf("\n\n\n\n\n\n\n\n\n%g", led4_bright);
-        } 
-        
-        if(c == 'z') {
-            lcd.cls();
-            lcd.writeString(24, 2, "System", NORMAL);
-            lcd.writeString(22, 3, "Restart", NORMAL);
-            all_bright = 1;
-            led1 = all_bright;
-            led2 = all_bright;
-            led3 = all_bright;
-            led4 = all_bright;
-            wait(2);
-            NVIC_SystemReset();
-        }
+        wait(1);
     }
+    FinishLED();
+}   
+
+void Functions::IPSettings() {
+    eth1.init();
+    eth1.connect();
+    lcd.cls();
+    lcd.printf("IP:\n\n\n\n\n\n\n\n\n\n\n");
+    lcd.printf("%s", eth1.getIPAddress());
 }
\ No newline at end of file
--- a/Functions.h	Thu Aug 01 09:05:54 2013 +0000
+++ b/Functions.h	Thu Aug 01 09:14:47 2013 +0000
@@ -4,17 +4,27 @@
 class Functions {
 
 public:
+
     /*Display revision details and initialise lcd screen*/
     void Intro();
+        
+    /*Take input from pc keyboard through serial and control lcd contrast using 'u' and 'd'*/
+    void ContrastChange();
     
-    /*Display brightness control commands*/
-    void Commands();
-
     /*Create and display a loading screen*/
     void Loading();
     
-    /*Take input from pc keyboard through serial and control led brightness using numerous keys*/
-    void LEDAndRestart();
+    /*Flash LED's to show the reading of packets*/
+    void ReadLED();
+    
+    /*Flash LED's to show the end of packet reading*/
+    void FinishLED();
+    
+    /*Read incoming broadcast packets and diplay source, desination, buffer and size on pc screen*/
+    void Packets();
+    
+    /*Retreive and display current IP address on lcd screen*/
+    void IPSettings();
 };
 
 #endif
\ No newline at end of file
--- a/variables.h	Thu Aug 01 09:05:54 2013 +0000
+++ b/variables.h	Thu Aug 01 09:14:47 2013 +0000
@@ -1,6 +1,14 @@
 #ifndef VARIABLES_H
 #define VARIABLES_H
 
+#include "EthernetInterface.h"
+#include "mbed.h"
+
+extern Ethernet eth;
+extern EthernetInterface eth1;
+extern int contrast;
+extern char buf[0x600];
+extern int packets;
 extern int loading_loop;
 extern int loading_line;