Base library for various projects.

Dependents:   LEDFun NetTester

Base library for various projects.

Committer:
Searle95
Date:
Thu Aug 01 12:14:19 2013 +0000
Revision:
2:a3deb705b78e
Parent:
1:a5f21c409f51
Added in a system restart at the end of cycle, version variable added for ease and minor timing changes. Version updated to 1.05.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Searle95 0:a2d01ba1a81b 1 #include "Functions.h"
Searle95 0:a2d01ba1a81b 2 #include "screens.h"
Searle95 0:a2d01ba1a81b 3 #include "variables.h"
Searle95 2:a3deb705b78e 4 #include "rtos.h"
Searle95 0:a2d01ba1a81b 5
Searle95 1:a5f21c409f51 6 Ethernet eth;
Searle95 1:a5f21c409f51 7 EthernetInterface eth1;
Searle95 0:a2d01ba1a81b 8 PwmOut led1(LED1);
Searle95 0:a2d01ba1a81b 9 PwmOut led2(LED2);
Searle95 0:a2d01ba1a81b 10 PwmOut led3(LED3);
Searle95 0:a2d01ba1a81b 11 PwmOut led4(LED4);
Searle95 1:a5f21c409f51 12 char buf[0x600];
Searle95 1:a5f21c409f51 13 int packets;
Searle95 0:a2d01ba1a81b 14 int loading_loop;
Searle95 0:a2d01ba1a81b 15 int loading_line;
Searle95 0:a2d01ba1a81b 16
Searle95 2:a3deb705b78e 17 double version = 1.05;
Searle95 2:a3deb705b78e 18
Searle95 0:a2d01ba1a81b 19 void Functions::Intro() {
Searle95 0:a2d01ba1a81b 20 lcd.init();
Searle95 0:a2d01ba1a81b 21 lcd.cls();
Searle95 0:a2d01ba1a81b 22 lcd.writeString(19, 2, "Welcome!", NORMAL);
Searle95 0:a2d01ba1a81b 23 wait(1);
Searle95 0:a2d01ba1a81b 24 lcd.cls();
Searle95 1:a5f21c409f51 25 lcd.writeString(16, 1, "NetTester", NORMAL);
Searle95 2:a3deb705b78e 26 lcd.writeString(26, 2, "V", NORMAL);
Searle95 2:a3deb705b78e 27 lcd.printf("%g", version);
Searle95 0:a2d01ba1a81b 28 lcd.writeString(13, 3, "Dan Searle", NORMAL);
Searle95 0:a2d01ba1a81b 29 wait(5);
Searle95 0:a2d01ba1a81b 30 }
Searle95 1:a5f21c409f51 31
Searle95 1:a5f21c409f51 32 void Functions::ContrastChange() {
Searle95 1:a5f21c409f51 33 lcd.cls();
Searle95 1:a5f21c409f51 34 lcd.printf("Contrast");
Searle95 1:a5f21c409f51 35
Searle95 0:a2d01ba1a81b 36 lcd.cls();
Searle95 1:a5f21c409f51 37 lcd.writeString(3, 1,"To change the", NORMAL);
Searle95 1:a5f21c409f51 38 lcd.writeString(2, 2,"contrast level", NORMAL);
Searle95 2:a3deb705b78e 39 lcd.writeString(1, 3,"use the up and", NORMAL);
Searle95 2:a3deb705b78e 40 lcd.writeString(8, 4,"down arrows", NORMAL);
Searle95 1:a5f21c409f51 41 wait(5);
Searle95 1:a5f21c409f51 42
Searle95 1:a5f21c409f51 43 while(1) {
Searle95 0:a2d01ba1a81b 44 lcd.cls();
Searle95 1:a5f21c409f51 45 lcd.writeString(8, 2,"'c' to skip", NORMAL);
Searle95 1:a5f21c409f51 46 lcd.printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
Searle95 1:a5f21c409f51 47 lcd.writeString(7, 4,"Contrast:", NORMAL);
Searle95 1:a5f21c409f51 48 lcd.printf("\n%X", contrast);
Searle95 1:a5f21c409f51 49 char c = pc.getc();
Searle95 2:a3deb705b78e 50 if(c == 0x41) {
Searle95 1:a5f21c409f51 51 contrast += 1;
Searle95 1:a5f21c409f51 52 lcd.init();
Searle95 1:a5f21c409f51 53 }
Searle95 2:a3deb705b78e 54 if(c == 0x42) {
Searle95 1:a5f21c409f51 55 contrast -= 1;
Searle95 1:a5f21c409f51 56 lcd.init();
Searle95 1:a5f21c409f51 57 }
Searle95 1:a5f21c409f51 58 if(c == 'c') {
Searle95 1:a5f21c409f51 59 break;
Searle95 1:a5f21c409f51 60 }
Searle95 2:a3deb705b78e 61 wait(0.1);
Searle95 0:a2d01ba1a81b 62 }
Searle95 0:a2d01ba1a81b 63 }
Searle95 0:a2d01ba1a81b 64
Searle95 1:a5f21c409f51 65 void Functions::Loading() {
Searle95 1:a5f21c409f51 66 lcd.cls();
Searle95 1:a5f21c409f51 67 lcd.writeString(10, 2, "Please wait", NORMAL);
Searle95 1:a5f21c409f51 68
Searle95 1:a5f21c409f51 69 while(loading_loop < 82) {
Searle95 1:a5f21c409f51 70 wait(0.05);
Searle95 1:a5f21c409f51 71 lcd.writeString(loading_line, 2, ".", NORMAL);
Searle95 1:a5f21c409f51 72 loading_line += 1;
Searle95 1:a5f21c409f51 73 if(loading_line == 82) {
Searle95 1:a5f21c409f51 74 Packets();
Searle95 1:a5f21c409f51 75 }
Searle95 1:a5f21c409f51 76 loading_loop += 1;
Searle95 1:a5f21c409f51 77 }
Searle95 1:a5f21c409f51 78 }
Searle95 1:a5f21c409f51 79
Searle95 1:a5f21c409f51 80 void Functions::ReadLED() {
Searle95 0:a2d01ba1a81b 81 double led1_bright = 0.0;
Searle95 0:a2d01ba1a81b 82 double led2_bright = 0.0;
Searle95 0:a2d01ba1a81b 83 double led3_bright = 0.0;
Searle95 0:a2d01ba1a81b 84 double led4_bright = 0.0;
Searle95 1:a5f21c409f51 85
Searle95 1:a5f21c409f51 86 led1_bright += 1.0;
Searle95 1:a5f21c409f51 87 led1 = led1_bright;
Searle95 1:a5f21c409f51 88 wait(0.1);
Searle95 1:a5f21c409f51 89 led1_bright -= 1.0;
Searle95 1:a5f21c409f51 90 led1 = led1_bright;
Searle95 1:a5f21c409f51 91 led2_bright += 1.0;
Searle95 1:a5f21c409f51 92 led2 = led2_bright;
Searle95 1:a5f21c409f51 93 wait(0.1);
Searle95 1:a5f21c409f51 94 led2_bright -= 1.0;
Searle95 1:a5f21c409f51 95 led2 = led2_bright;
Searle95 1:a5f21c409f51 96 led3_bright += 1.0;
Searle95 1:a5f21c409f51 97 led3 = led3_bright;
Searle95 1:a5f21c409f51 98 wait(0.1);
Searle95 1:a5f21c409f51 99 led3_bright -= 1.0;
Searle95 1:a5f21c409f51 100 led3 = led3_bright;
Searle95 1:a5f21c409f51 101 led4_bright += 1.0;
Searle95 1:a5f21c409f51 102 led4 = led4_bright;
Searle95 1:a5f21c409f51 103 wait(0.1);
Searle95 1:a5f21c409f51 104 led4_bright -= 1.0;
Searle95 1:a5f21c409f51 105 led4 = led4_bright;
Searle95 1:a5f21c409f51 106 }
Searle95 1:a5f21c409f51 107
Searle95 1:a5f21c409f51 108 void Functions::FinishLED() {
Searle95 1:a5f21c409f51 109 double led1_bright = 0.0;
Searle95 1:a5f21c409f51 110 double led2_bright = 0.0;
Searle95 1:a5f21c409f51 111 double led3_bright = 0.0;
Searle95 1:a5f21c409f51 112 double led4_bright = 0.0;
Searle95 1:a5f21c409f51 113
Searle95 1:a5f21c409f51 114 led1_bright += 1.0;
Searle95 1:a5f21c409f51 115 led2_bright += 1.0;
Searle95 1:a5f21c409f51 116 led3_bright += 1.0;
Searle95 1:a5f21c409f51 117 led4_bright += 1.0;
Searle95 1:a5f21c409f51 118 led1 = led1_bright;
Searle95 1:a5f21c409f51 119 led2 = led2_bright;
Searle95 1:a5f21c409f51 120 led3 = led3_bright;
Searle95 1:a5f21c409f51 121 led4 = led4_bright;
Searle95 1:a5f21c409f51 122 wait(2);
Searle95 1:a5f21c409f51 123 led1_bright -= 1.0;
Searle95 1:a5f21c409f51 124 led2_bright -= 1.0;
Searle95 1:a5f21c409f51 125 led3_bright -= 1.0;
Searle95 1:a5f21c409f51 126 led4_bright -= 1.0;
Searle95 1:a5f21c409f51 127 led1 = led1_bright;
Searle95 1:a5f21c409f51 128 led2 = led2_bright;
Searle95 1:a5f21c409f51 129 led3 = led3_bright;
Searle95 1:a5f21c409f51 130 led4 = led4_bright;
Searle95 1:a5f21c409f51 131 }
Searle95 1:a5f21c409f51 132
Searle95 1:a5f21c409f51 133 void Functions::Packets() {
Searle95 1:a5f21c409f51 134 packets = 0;
Searle95 0:a2d01ba1a81b 135
Searle95 1:a5f21c409f51 136 while(packets < 25) {
Searle95 1:a5f21c409f51 137 lcd.cls();
Searle95 1:a5f21c409f51 138 lcd.writeString(21, 2, "Reading", NORMAL);
Searle95 1:a5f21c409f51 139 lcd.writeString(21, 3, "Packets", NORMAL);
Searle95 1:a5f21c409f51 140 int size = eth.receive();
Searle95 1:a5f21c409f51 141 if(size > 0) {
Searle95 1:a5f21c409f51 142 eth.read(buf, size);
Searle95 1:a5f21c409f51 143 ReadLED();
Searle95 1:a5f21c409f51 144 pc.printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X ",
Searle95 1:a5f21c409f51 145 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
Searle95 1:a5f21c409f51 146 pc.printf("Source: %02X:%02X:%02X:%02X:%02X:%02X ",
Searle95 1:a5f21c409f51 147 buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
Searle95 1:a5f21c409f51 148 pc.printf("Buffer Remain: %d ", (sizeof(buf) - size));
Searle95 1:a5f21c409f51 149 pc.printf("Received Packet Size: %d\n\r", size);
Searle95 1:a5f21c409f51 150
Searle95 1:a5f21c409f51 151 packets += 1;
Searle95 0:a2d01ba1a81b 152 }
Searle95 1:a5f21c409f51 153 wait(1);
Searle95 0:a2d01ba1a81b 154 }
Searle95 1:a5f21c409f51 155 FinishLED();
Searle95 1:a5f21c409f51 156 }
Searle95 1:a5f21c409f51 157
Searle95 1:a5f21c409f51 158 void Functions::IPSettings() {
Searle95 1:a5f21c409f51 159 eth1.init();
Searle95 1:a5f21c409f51 160 eth1.connect();
Searle95 1:a5f21c409f51 161 lcd.cls();
Searle95 1:a5f21c409f51 162 lcd.printf("IP:\n\n\n\n\n\n\n\n\n\n\n");
Searle95 1:a5f21c409f51 163 lcd.printf("%s", eth1.getIPAddress());
Searle95 2:a3deb705b78e 164 }
Searle95 2:a3deb705b78e 165
Searle95 2:a3deb705b78e 166 void Functions::SystemRestart() {
Searle95 2:a3deb705b78e 167 double led1_bright = 0.0;
Searle95 2:a3deb705b78e 168 double led2_bright = 0.0;
Searle95 2:a3deb705b78e 169 double led3_bright = 0.0;
Searle95 2:a3deb705b78e 170 double led4_bright = 0.0;
Searle95 2:a3deb705b78e 171
Searle95 2:a3deb705b78e 172 lcd.writeString(1, 4,"'z' to restart", NORMAL);
Searle95 2:a3deb705b78e 173
Searle95 2:a3deb705b78e 174 while(1) {
Searle95 2:a3deb705b78e 175 char c = pc.getc();
Searle95 2:a3deb705b78e 176 if(c == 'z') {
Searle95 2:a3deb705b78e 177 lcd.cls();
Searle95 2:a3deb705b78e 178 lcd.writeString(24, 2, "System", NORMAL);
Searle95 2:a3deb705b78e 179 lcd.writeString(22, 3, "Restart", NORMAL);
Searle95 2:a3deb705b78e 180 led1_bright += 1.0;
Searle95 2:a3deb705b78e 181 led2_bright += 1.0;
Searle95 2:a3deb705b78e 182 led3_bright += 1.0;
Searle95 2:a3deb705b78e 183 led4_bright += 1.0;
Searle95 2:a3deb705b78e 184 led1 = led1_bright;
Searle95 2:a3deb705b78e 185 led2 = led2_bright;
Searle95 2:a3deb705b78e 186 led3 = led3_bright;
Searle95 2:a3deb705b78e 187 led4 = led4_bright;
Searle95 2:a3deb705b78e 188 wait(2);
Searle95 2:a3deb705b78e 189 NVIC_SystemReset();
Searle95 2:a3deb705b78e 190 }
Searle95 2:a3deb705b78e 191 }
Searle95 0:a2d01ba1a81b 192 }