Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Functions.cpp
00001 #include "Functions.h" 00002 #include "screens.h" 00003 #include "variables.h" 00004 #include "rtos.h" 00005 00006 Ethernet eth; 00007 EthernetInterface eth1; 00008 PwmOut led1(LED1); 00009 PwmOut led2(LED2); 00010 PwmOut led3(LED3); 00011 PwmOut led4(LED4); 00012 char buf[0x600]; 00013 int packets; 00014 int loading_loop; 00015 int loading_line; 00016 00017 double version = 1.05; 00018 00019 void Functions::Intro() { 00020 lcd.init(); 00021 lcd.cls(); 00022 lcd.writeString(19, 2, "Welcome!", NORMAL); 00023 wait(1); 00024 lcd.cls(); 00025 lcd.writeString(16, 1, "NetTester", NORMAL); 00026 lcd.writeString(26, 2, "V", NORMAL); 00027 lcd.printf("%g", version); 00028 lcd.writeString(13, 3, "Dan Searle", NORMAL); 00029 wait(5); 00030 } 00031 00032 void Functions::ContrastChange() { 00033 lcd.cls(); 00034 lcd.printf("Contrast"); 00035 00036 lcd.cls(); 00037 lcd.writeString(3, 1,"To change the", NORMAL); 00038 lcd.writeString(2, 2,"contrast level", NORMAL); 00039 lcd.writeString(1, 3,"use the up and", NORMAL); 00040 lcd.writeString(8, 4,"down arrows", NORMAL); 00041 wait(5); 00042 00043 while(1) { 00044 lcd.cls(); 00045 lcd.writeString(8, 2,"'c' to skip", NORMAL); 00046 lcd.printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); 00047 lcd.writeString(7, 4,"Contrast:", NORMAL); 00048 lcd.printf("\n%X", contrast); 00049 char c = pc.getc(); 00050 if(c == 0x41) { 00051 contrast += 1; 00052 lcd.init(); 00053 } 00054 if(c == 0x42) { 00055 contrast -= 1; 00056 lcd.init(); 00057 } 00058 if(c == 'c') { 00059 break; 00060 } 00061 wait(0.1); 00062 } 00063 } 00064 00065 void Functions::Loading() { 00066 lcd.cls(); 00067 lcd.writeString(10, 2, "Please wait", NORMAL); 00068 00069 while(loading_loop < 82) { 00070 wait(0.05); 00071 lcd.writeString(loading_line, 2, ".", NORMAL); 00072 loading_line += 1; 00073 if(loading_line == 82) { 00074 Packets(); 00075 } 00076 loading_loop += 1; 00077 } 00078 } 00079 00080 void Functions::ReadLED() { 00081 double led1_bright = 0.0; 00082 double led2_bright = 0.0; 00083 double led3_bright = 0.0; 00084 double led4_bright = 0.0; 00085 00086 led1_bright += 1.0; 00087 led1 = led1_bright; 00088 wait(0.1); 00089 led1_bright -= 1.0; 00090 led1 = led1_bright; 00091 led2_bright += 1.0; 00092 led2 = led2_bright; 00093 wait(0.1); 00094 led2_bright -= 1.0; 00095 led2 = led2_bright; 00096 led3_bright += 1.0; 00097 led3 = led3_bright; 00098 wait(0.1); 00099 led3_bright -= 1.0; 00100 led3 = led3_bright; 00101 led4_bright += 1.0; 00102 led4 = led4_bright; 00103 wait(0.1); 00104 led4_bright -= 1.0; 00105 led4 = led4_bright; 00106 } 00107 00108 void Functions::FinishLED() { 00109 double led1_bright = 0.0; 00110 double led2_bright = 0.0; 00111 double led3_bright = 0.0; 00112 double led4_bright = 0.0; 00113 00114 led1_bright += 1.0; 00115 led2_bright += 1.0; 00116 led3_bright += 1.0; 00117 led4_bright += 1.0; 00118 led1 = led1_bright; 00119 led2 = led2_bright; 00120 led3 = led3_bright; 00121 led4 = led4_bright; 00122 wait(2); 00123 led1_bright -= 1.0; 00124 led2_bright -= 1.0; 00125 led3_bright -= 1.0; 00126 led4_bright -= 1.0; 00127 led1 = led1_bright; 00128 led2 = led2_bright; 00129 led3 = led3_bright; 00130 led4 = led4_bright; 00131 } 00132 00133 void Functions::Packets() { 00134 packets = 0; 00135 00136 while(packets < 25) { 00137 lcd.cls(); 00138 lcd.writeString(21, 2, "Reading", NORMAL); 00139 lcd.writeString(21, 3, "Packets", NORMAL); 00140 int size = eth.receive(); 00141 if(size > 0) { 00142 eth.read(buf, size); 00143 ReadLED(); 00144 pc.printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X ", 00145 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); 00146 pc.printf("Source: %02X:%02X:%02X:%02X:%02X:%02X ", 00147 buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); 00148 pc.printf("Buffer Remain: %d ", (sizeof(buf) - size)); 00149 pc.printf("Received Packet Size: %d\n\r", size); 00150 00151 packets += 1; 00152 } 00153 wait(1); 00154 } 00155 FinishLED(); 00156 } 00157 00158 void Functions::IPSettings() { 00159 eth1.init(); 00160 eth1.connect(); 00161 lcd.cls(); 00162 lcd.printf("IP:\n\n\n\n\n\n\n\n\n\n\n"); 00163 lcd.printf("%s", eth1.getIPAddress()); 00164 } 00165 00166 void Functions::SystemRestart() { 00167 double led1_bright = 0.0; 00168 double led2_bright = 0.0; 00169 double led3_bright = 0.0; 00170 double led4_bright = 0.0; 00171 00172 lcd.writeString(1, 4,"'z' to restart", NORMAL); 00173 00174 while(1) { 00175 char c = pc.getc(); 00176 if(c == 'z') { 00177 lcd.cls(); 00178 lcd.writeString(24, 2, "System", NORMAL); 00179 lcd.writeString(22, 3, "Restart", NORMAL); 00180 led1_bright += 1.0; 00181 led2_bright += 1.0; 00182 led3_bright += 1.0; 00183 led4_bright += 1.0; 00184 led1 = led1_bright; 00185 led2 = led2_bright; 00186 led3 = led3_bright; 00187 led4 = led4_bright; 00188 wait(2); 00189 NVIC_SystemReset(); 00190 } 00191 } 00192 }
Generated on Sun Jul 24 2022 08:49:38 by
1.7.2