Base library for various projects.
Base library for various projects.
Functions.cpp@1:a5f21c409f51, 2013-08-01 (annotated)
- Committer:
- Searle95
- Date:
- Thu Aug 01 09:14:47 2013 +0000
- Revision:
- 1:a5f21c409f51
- Parent:
- 0:a2d01ba1a81b
- Child:
- 2:a3deb705b78e
Modified for use in NetTester project.
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:a2d01ba1a81b | 4 | |
Searle95 | 1:a5f21c409f51 | 5 | Ethernet eth; |
Searle95 | 1:a5f21c409f51 | 6 | EthernetInterface eth1; |
Searle95 | 0:a2d01ba1a81b | 7 | PwmOut led1(LED1); |
Searle95 | 0:a2d01ba1a81b | 8 | PwmOut led2(LED2); |
Searle95 | 0:a2d01ba1a81b | 9 | PwmOut led3(LED3); |
Searle95 | 0:a2d01ba1a81b | 10 | PwmOut led4(LED4); |
Searle95 | 1:a5f21c409f51 | 11 | char buf[0x600]; |
Searle95 | 1:a5f21c409f51 | 12 | int packets; |
Searle95 | 0:a2d01ba1a81b | 13 | int loading_loop; |
Searle95 | 0:a2d01ba1a81b | 14 | int loading_line; |
Searle95 | 0:a2d01ba1a81b | 15 | |
Searle95 | 0:a2d01ba1a81b | 16 | void Functions::Intro() { |
Searle95 | 0:a2d01ba1a81b | 17 | lcd.init(); |
Searle95 | 0:a2d01ba1a81b | 18 | lcd.cls(); |
Searle95 | 0:a2d01ba1a81b | 19 | lcd.writeString(19, 2, "Welcome!", NORMAL); |
Searle95 | 0:a2d01ba1a81b | 20 | wait(1); |
Searle95 | 0:a2d01ba1a81b | 21 | lcd.cls(); |
Searle95 | 1:a5f21c409f51 | 22 | lcd.writeString(16, 1, "NetTester", NORMAL); |
Searle95 | 0:a2d01ba1a81b | 23 | lcd.writeString(26, 2, "V1.00", NORMAL); |
Searle95 | 0:a2d01ba1a81b | 24 | lcd.writeString(13, 3, "Dan Searle", NORMAL); |
Searle95 | 0:a2d01ba1a81b | 25 | wait(5); |
Searle95 | 0:a2d01ba1a81b | 26 | } |
Searle95 | 1:a5f21c409f51 | 27 | |
Searle95 | 1:a5f21c409f51 | 28 | void Functions::ContrastChange() { |
Searle95 | 1:a5f21c409f51 | 29 | lcd.cls(); |
Searle95 | 1:a5f21c409f51 | 30 | lcd.printf("Contrast"); |
Searle95 | 1:a5f21c409f51 | 31 | |
Searle95 | 0:a2d01ba1a81b | 32 | lcd.cls(); |
Searle95 | 1:a5f21c409f51 | 33 | lcd.writeString(3, 1,"To change the", NORMAL); |
Searle95 | 1:a5f21c409f51 | 34 | lcd.writeString(2, 2,"contrast level", NORMAL); |
Searle95 | 1:a5f21c409f51 | 35 | lcd.writeString(3, 3,"use 'u' & 'd'", NORMAL); |
Searle95 | 1:a5f21c409f51 | 36 | wait(5); |
Searle95 | 1:a5f21c409f51 | 37 | |
Searle95 | 1:a5f21c409f51 | 38 | while(1) { |
Searle95 | 0:a2d01ba1a81b | 39 | lcd.cls(); |
Searle95 | 1:a5f21c409f51 | 40 | lcd.writeString(8, 2,"'c' to skip", NORMAL); |
Searle95 | 1:a5f21c409f51 | 41 | lcd.printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); |
Searle95 | 1:a5f21c409f51 | 42 | lcd.writeString(7, 4,"Contrast:", NORMAL); |
Searle95 | 1:a5f21c409f51 | 43 | lcd.printf("\n%X", contrast); |
Searle95 | 1:a5f21c409f51 | 44 | char c = pc.getc(); |
Searle95 | 1:a5f21c409f51 | 45 | if(c == 'u') { |
Searle95 | 1:a5f21c409f51 | 46 | contrast += 1; |
Searle95 | 1:a5f21c409f51 | 47 | lcd.init(); |
Searle95 | 1:a5f21c409f51 | 48 | } |
Searle95 | 1:a5f21c409f51 | 49 | if(c == 'd') { |
Searle95 | 1:a5f21c409f51 | 50 | contrast -= 1; |
Searle95 | 1:a5f21c409f51 | 51 | lcd.init(); |
Searle95 | 1:a5f21c409f51 | 52 | } |
Searle95 | 1:a5f21c409f51 | 53 | if(c == 'c') { |
Searle95 | 1:a5f21c409f51 | 54 | break; |
Searle95 | 1:a5f21c409f51 | 55 | } |
Searle95 | 1:a5f21c409f51 | 56 | wait(0.5); |
Searle95 | 0:a2d01ba1a81b | 57 | } |
Searle95 | 0:a2d01ba1a81b | 58 | } |
Searle95 | 0:a2d01ba1a81b | 59 | |
Searle95 | 1:a5f21c409f51 | 60 | void Functions::Loading() { |
Searle95 | 1:a5f21c409f51 | 61 | lcd.cls(); |
Searle95 | 1:a5f21c409f51 | 62 | lcd.writeString(10, 2, "Please wait", NORMAL); |
Searle95 | 1:a5f21c409f51 | 63 | |
Searle95 | 1:a5f21c409f51 | 64 | while(loading_loop < 82) { |
Searle95 | 1:a5f21c409f51 | 65 | wait(0.05); |
Searle95 | 1:a5f21c409f51 | 66 | lcd.writeString(loading_line, 2, ".", NORMAL); |
Searle95 | 1:a5f21c409f51 | 67 | loading_line += 1; |
Searle95 | 1:a5f21c409f51 | 68 | if(loading_line == 82) { |
Searle95 | 1:a5f21c409f51 | 69 | Packets(); |
Searle95 | 1:a5f21c409f51 | 70 | } |
Searle95 | 1:a5f21c409f51 | 71 | loading_loop += 1; |
Searle95 | 1:a5f21c409f51 | 72 | } |
Searle95 | 1:a5f21c409f51 | 73 | } |
Searle95 | 1:a5f21c409f51 | 74 | |
Searle95 | 1:a5f21c409f51 | 75 | void Functions::ReadLED() { |
Searle95 | 0:a2d01ba1a81b | 76 | double led1_bright = 0.0; |
Searle95 | 0:a2d01ba1a81b | 77 | double led2_bright = 0.0; |
Searle95 | 0:a2d01ba1a81b | 78 | double led3_bright = 0.0; |
Searle95 | 0:a2d01ba1a81b | 79 | double led4_bright = 0.0; |
Searle95 | 1:a5f21c409f51 | 80 | |
Searle95 | 1:a5f21c409f51 | 81 | led1_bright += 1.0; |
Searle95 | 1:a5f21c409f51 | 82 | led1 = led1_bright; |
Searle95 | 1:a5f21c409f51 | 83 | wait(0.1); |
Searle95 | 1:a5f21c409f51 | 84 | led1_bright -= 1.0; |
Searle95 | 1:a5f21c409f51 | 85 | led1 = led1_bright; |
Searle95 | 1:a5f21c409f51 | 86 | led2_bright += 1.0; |
Searle95 | 1:a5f21c409f51 | 87 | led2 = led2_bright; |
Searle95 | 1:a5f21c409f51 | 88 | wait(0.1); |
Searle95 | 1:a5f21c409f51 | 89 | led2_bright -= 1.0; |
Searle95 | 1:a5f21c409f51 | 90 | led2 = led2_bright; |
Searle95 | 1:a5f21c409f51 | 91 | led3_bright += 1.0; |
Searle95 | 1:a5f21c409f51 | 92 | led3 = led3_bright; |
Searle95 | 1:a5f21c409f51 | 93 | wait(0.1); |
Searle95 | 1:a5f21c409f51 | 94 | led3_bright -= 1.0; |
Searle95 | 1:a5f21c409f51 | 95 | led3 = led3_bright; |
Searle95 | 1:a5f21c409f51 | 96 | led4_bright += 1.0; |
Searle95 | 1:a5f21c409f51 | 97 | led4 = led4_bright; |
Searle95 | 1:a5f21c409f51 | 98 | wait(0.1); |
Searle95 | 1:a5f21c409f51 | 99 | led4_bright -= 1.0; |
Searle95 | 1:a5f21c409f51 | 100 | led4 = led4_bright; |
Searle95 | 1:a5f21c409f51 | 101 | } |
Searle95 | 1:a5f21c409f51 | 102 | |
Searle95 | 1:a5f21c409f51 | 103 | void Functions::FinishLED() { |
Searle95 | 1:a5f21c409f51 | 104 | double led1_bright = 0.0; |
Searle95 | 1:a5f21c409f51 | 105 | double led2_bright = 0.0; |
Searle95 | 1:a5f21c409f51 | 106 | double led3_bright = 0.0; |
Searle95 | 1:a5f21c409f51 | 107 | double led4_bright = 0.0; |
Searle95 | 1:a5f21c409f51 | 108 | |
Searle95 | 1:a5f21c409f51 | 109 | led1_bright += 1.0; |
Searle95 | 1:a5f21c409f51 | 110 | led2_bright += 1.0; |
Searle95 | 1:a5f21c409f51 | 111 | led3_bright += 1.0; |
Searle95 | 1:a5f21c409f51 | 112 | led4_bright += 1.0; |
Searle95 | 1:a5f21c409f51 | 113 | led1 = led1_bright; |
Searle95 | 1:a5f21c409f51 | 114 | led2 = led2_bright; |
Searle95 | 1:a5f21c409f51 | 115 | led3 = led3_bright; |
Searle95 | 1:a5f21c409f51 | 116 | led4 = led4_bright; |
Searle95 | 1:a5f21c409f51 | 117 | wait(2); |
Searle95 | 1:a5f21c409f51 | 118 | led1_bright -= 1.0; |
Searle95 | 1:a5f21c409f51 | 119 | led2_bright -= 1.0; |
Searle95 | 1:a5f21c409f51 | 120 | led3_bright -= 1.0; |
Searle95 | 1:a5f21c409f51 | 121 | led4_bright -= 1.0; |
Searle95 | 1:a5f21c409f51 | 122 | led1 = led1_bright; |
Searle95 | 1:a5f21c409f51 | 123 | led2 = led2_bright; |
Searle95 | 1:a5f21c409f51 | 124 | led3 = led3_bright; |
Searle95 | 1:a5f21c409f51 | 125 | led4 = led4_bright; |
Searle95 | 1:a5f21c409f51 | 126 | } |
Searle95 | 1:a5f21c409f51 | 127 | |
Searle95 | 1:a5f21c409f51 | 128 | void Functions::Packets() { |
Searle95 | 1:a5f21c409f51 | 129 | packets = 0; |
Searle95 | 0:a2d01ba1a81b | 130 | |
Searle95 | 1:a5f21c409f51 | 131 | while(packets < 25) { |
Searle95 | 1:a5f21c409f51 | 132 | lcd.cls(); |
Searle95 | 1:a5f21c409f51 | 133 | lcd.writeString(21, 2, "Reading", NORMAL); |
Searle95 | 1:a5f21c409f51 | 134 | lcd.writeString(21, 3, "Packets", NORMAL); |
Searle95 | 1:a5f21c409f51 | 135 | int size = eth.receive(); |
Searle95 | 1:a5f21c409f51 | 136 | if(size > 0) { |
Searle95 | 1:a5f21c409f51 | 137 | eth.read(buf, size); |
Searle95 | 1:a5f21c409f51 | 138 | ReadLED(); |
Searle95 | 1:a5f21c409f51 | 139 | pc.printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X ", |
Searle95 | 1:a5f21c409f51 | 140 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); |
Searle95 | 1:a5f21c409f51 | 141 | pc.printf("Source: %02X:%02X:%02X:%02X:%02X:%02X ", |
Searle95 | 1:a5f21c409f51 | 142 | buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); |
Searle95 | 1:a5f21c409f51 | 143 | pc.printf("Buffer Remain: %d ", (sizeof(buf) - size)); |
Searle95 | 1:a5f21c409f51 | 144 | pc.printf("Received Packet Size: %d\n\r", size); |
Searle95 | 1:a5f21c409f51 | 145 | |
Searle95 | 1:a5f21c409f51 | 146 | packets += 1; |
Searle95 | 0:a2d01ba1a81b | 147 | } |
Searle95 | 1:a5f21c409f51 | 148 | wait(1); |
Searle95 | 0:a2d01ba1a81b | 149 | } |
Searle95 | 1:a5f21c409f51 | 150 | FinishLED(); |
Searle95 | 1:a5f21c409f51 | 151 | } |
Searle95 | 1:a5f21c409f51 | 152 | |
Searle95 | 1:a5f21c409f51 | 153 | void Functions::IPSettings() { |
Searle95 | 1:a5f21c409f51 | 154 | eth1.init(); |
Searle95 | 1:a5f21c409f51 | 155 | eth1.connect(); |
Searle95 | 1:a5f21c409f51 | 156 | lcd.cls(); |
Searle95 | 1:a5f21c409f51 | 157 | lcd.printf("IP:\n\n\n\n\n\n\n\n\n\n\n"); |
Searle95 | 1:a5f21c409f51 | 158 | lcd.printf("%s", eth1.getIPAddress()); |
Searle95 | 0:a2d01ba1a81b | 159 | } |