![](/media/cache/profiles/f720ec3e5486f090fd382b68e230b435.50x50_q85.jpg)
The London Hackspace bandwidth meter
Dependencies: LPD8806 MODSERIAL mbed picojson
See:
- https://github.com/londonhackspace/net-o-meter
- http://wiki.london.hackspace.org.uk/view/Projects/BandwidthMeter
main.cpp@4:7087ea3d13c1, 2012-08-27 (annotated)
- Committer:
- Jasper
- Date:
- Mon Aug 27 01:32:52 2012 +0000
- Revision:
- 4:7087ea3d13c1
- Parent:
- 3:7fca72f96711
- Child:
- 5:24172484b8c5
much fiddlign later, better cmd processor on the serial interface, give up on netcode for the moment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jasper | 0:0a6f193d5344 | 1 | #include "mbed.h" |
Jasper | 3:7fca72f96711 | 2 | #include "ctype.h" |
Jasper | 0:0a6f193d5344 | 3 | |
Jasper | 0:0a6f193d5344 | 4 | #include "LPD8806.h" |
Jasper | 3:7fca72f96711 | 5 | #include "vfd.h" |
Jasper | 0:0a6f193d5344 | 6 | |
Jasper | 4:7087ea3d13c1 | 7 | /* |
Jasper | 4:7087ea3d13c1 | 8 | #include "EthernetNetIf.h" |
Jasper | 4:7087ea3d13c1 | 9 | #include "HTTPServer.h" |
Jasper | 4:7087ea3d13c1 | 10 | |
Jasper | 4:7087ea3d13c1 | 11 | EthernetNetIf eth; |
Jasper | 4:7087ea3d13c1 | 12 | HTTPServer svr; |
Jasper | 4:7087ea3d13c1 | 13 | */ |
Jasper | 4:7087ea3d13c1 | 14 | |
Jasper | 0:0a6f193d5344 | 15 | DigitalOut led1(LED1); |
Jasper | 0:0a6f193d5344 | 16 | DigitalOut led2(LED2); |
Jasper | 0:0a6f193d5344 | 17 | DigitalOut led3(LED3); |
Jasper | 0:0a6f193d5344 | 18 | DigitalOut led4(LED4); |
Jasper | 0:0a6f193d5344 | 19 | |
Jasper | 1:e384e7146746 | 20 | /* talk to the world */ |
Jasper | 1:e384e7146746 | 21 | Serial pc(USBTX, USBRX); |
Jasper | 0:0a6f193d5344 | 22 | |
Jasper | 1:e384e7146746 | 23 | LPD8806 strip = LPD8806(32); |
Jasper | 0:0a6f193d5344 | 24 | |
Jasper | 0:0a6f193d5344 | 25 | void setPixelsTop(int start, int end, int colour) { |
Jasper | 0:0a6f193d5344 | 26 | int i; |
Jasper | 0:0a6f193d5344 | 27 | |
Jasper | 0:0a6f193d5344 | 28 | for (i = start; i < end + 1 ; i++) { |
Jasper | 0:0a6f193d5344 | 29 | strip.setPixelColor(i, colour); |
Jasper | 0:0a6f193d5344 | 30 | } |
Jasper | 0:0a6f193d5344 | 31 | } |
Jasper | 0:0a6f193d5344 | 32 | |
Jasper | 0:0a6f193d5344 | 33 | void setPixelsBottom(int start, int end, int colour) { |
Jasper | 0:0a6f193d5344 | 34 | int i; |
Jasper | 0:0a6f193d5344 | 35 | |
Jasper | 0:0a6f193d5344 | 36 | for (i = start; i < end + 1 ; i++) { |
Jasper | 0:0a6f193d5344 | 37 | strip.setPixelColor(16 + i, colour); |
Jasper | 0:0a6f193d5344 | 38 | } |
Jasper | 0:0a6f193d5344 | 39 | } |
Jasper | 0:0a6f193d5344 | 40 | |
Jasper | 1:e384e7146746 | 41 | /* 0 - 16 */ |
Jasper | 1:e384e7146746 | 42 | void top_strip(int quantity){ |
Jasper | 1:e384e7146746 | 43 | if (quantity < 16) { |
Jasper | 1:e384e7146746 | 44 | // blank unused bits. |
Jasper | 4:7087ea3d13c1 | 45 | setPixelsTop(quantity, 15, 0); |
Jasper | 1:e384e7146746 | 46 | } |
Jasper | 1:e384e7146746 | 47 | |
Jasper | 1:e384e7146746 | 48 | if (quantity == 0) return; |
Jasper | 1:e384e7146746 | 49 | |
Jasper | 1:e384e7146746 | 50 | quantity --; |
Jasper | 1:e384e7146746 | 51 | |
Jasper | 1:e384e7146746 | 52 | setPixelsTop(0, quantity < 12 ? quantity : 11, strip.Color(0, 127, 0)); |
Jasper | 1:e384e7146746 | 53 | |
Jasper | 1:e384e7146746 | 54 | if (quantity > 11) |
Jasper | 1:e384e7146746 | 55 | setPixelsTop(12, quantity < 14 ? quantity : 14, strip.Color(127, 127, 0)); |
Jasper | 1:e384e7146746 | 56 | |
Jasper | 1:e384e7146746 | 57 | if (quantity > 13) |
Jasper | 1:e384e7146746 | 58 | setPixelsTop(14, quantity < 16 ? quantity : 16, strip.Color(127, 0, 0)); |
Jasper | 1:e384e7146746 | 59 | } |
Jasper | 1:e384e7146746 | 60 | |
Jasper | 1:e384e7146746 | 61 | void bottom_strip(int quantity){ |
Jasper | 1:e384e7146746 | 62 | if (quantity < 16) { |
Jasper | 1:e384e7146746 | 63 | // blank unused bits. |
Jasper | 4:7087ea3d13c1 | 64 | setPixelsBottom(quantity, 15, 0); |
Jasper | 1:e384e7146746 | 65 | } |
Jasper | 1:e384e7146746 | 66 | |
Jasper | 1:e384e7146746 | 67 | if (quantity == 0) return; |
Jasper | 1:e384e7146746 | 68 | quantity --; |
Jasper | 1:e384e7146746 | 69 | |
Jasper | 1:e384e7146746 | 70 | setPixelsBottom(0, quantity < 12 ? quantity : 11, strip.Color(0, 127, 0)); |
Jasper | 1:e384e7146746 | 71 | |
Jasper | 1:e384e7146746 | 72 | if (quantity > 11) |
Jasper | 1:e384e7146746 | 73 | setPixelsBottom(12, quantity < 14 ? quantity : 14, strip.Color(127, 127, 0)); |
Jasper | 1:e384e7146746 | 74 | |
Jasper | 1:e384e7146746 | 75 | if (quantity > 13) |
Jasper | 1:e384e7146746 | 76 | setPixelsBottom(14, quantity < 16 ? quantity : 16, strip.Color(127, 0, 0)); |
Jasper | 1:e384e7146746 | 77 | } |
Jasper | 1:e384e7146746 | 78 | |
Jasper | 3:7fca72f96711 | 79 | void emf_blue() { |
Jasper | 3:7fca72f96711 | 80 | setPixelsBottom(0, 15, strip.Color(0, 161, 228)); |
Jasper | 3:7fca72f96711 | 81 | setPixelsTop(0, 15, strip.Color(0, 161, 228)); |
Jasper | 3:7fca72f96711 | 82 | } |
Jasper | 3:7fca72f96711 | 83 | |
Jasper | 4:7087ea3d13c1 | 84 | void strip_clear() { |
Jasper | 4:7087ea3d13c1 | 85 | int i; |
Jasper | 4:7087ea3d13c1 | 86 | |
Jasper | 4:7087ea3d13c1 | 87 | for (i = 0 ; i < strip.numPixels() ; i++) { |
Jasper | 4:7087ea3d13c1 | 88 | // clear the strip |
Jasper | 4:7087ea3d13c1 | 89 | strip.setPixelColor(i, 0); |
Jasper | 4:7087ea3d13c1 | 90 | } |
Jasper | 4:7087ea3d13c1 | 91 | } |
Jasper | 4:7087ea3d13c1 | 92 | |
Jasper | 1:e384e7146746 | 93 | #define s_looking 1 |
Jasper | 1:e384e7146746 | 94 | #define s_top 2 |
Jasper | 1:e384e7146746 | 95 | #define s_bottom 3 |
Jasper | 1:e384e7146746 | 96 | |
Jasper | 4:7087ea3d13c1 | 97 | void send_text(const char *s) { |
Jasper | 4:7087ea3d13c1 | 98 | int i; char c; |
Jasper | 4:7087ea3d13c1 | 99 | |
Jasper | 4:7087ea3d13c1 | 100 | for (i = 0, c=s[i]; c != 0; i++, c=s[i]) |
Jasper | 4:7087ea3d13c1 | 101 | vfd_data(c); |
Jasper | 4:7087ea3d13c1 | 102 | } |
Jasper | 4:7087ea3d13c1 | 103 | |
Jasper | 4:7087ea3d13c1 | 104 | void text_centered(const char *s, int hpos) { |
Jasper | 4:7087ea3d13c1 | 105 | |
Jasper | 4:7087ea3d13c1 | 106 | vfd_pos((20 / 2) - (strlen(s)) / 2, hpos); |
Jasper | 4:7087ea3d13c1 | 107 | send_text(s); |
Jasper | 4:7087ea3d13c1 | 108 | } |
Jasper | 4:7087ea3d13c1 | 109 | |
Jasper | 4:7087ea3d13c1 | 110 | void emf_logo(void) { |
Jasper | 4:7087ea3d13c1 | 111 | const char line0[] = "Welcome to"; |
Jasper | 4:7087ea3d13c1 | 112 | const char line2[] = "EMFCamp!"; |
Jasper | 4:7087ea3d13c1 | 113 | |
Jasper | 4:7087ea3d13c1 | 114 | text_centered(line0, 0); |
Jasper | 4:7087ea3d13c1 | 115 | text_centered(line2, 2); |
Jasper | 4:7087ea3d13c1 | 116 | } |
Jasper | 4:7087ea3d13c1 | 117 | |
Jasper | 0:0a6f193d5344 | 118 | int main() { |
Jasper | 4:7087ea3d13c1 | 119 | |
Jasper | 4:7087ea3d13c1 | 120 | setbuf(stdout, NULL); |
Jasper | 3:7fca72f96711 | 121 | |
Jasper | 3:7fca72f96711 | 122 | pc.printf("Hello!\r\n"); |
Jasper | 3:7fca72f96711 | 123 | |
Jasper | 4:7087ea3d13c1 | 124 | wait_ms(10); |
Jasper | 4:7087ea3d13c1 | 125 | vfd_reset(); |
Jasper | 4:7087ea3d13c1 | 126 | wait_ms(10); |
Jasper | 3:7fca72f96711 | 127 | vfd_init(); |
Jasper | 4:7087ea3d13c1 | 128 | wait_ms(10); |
Jasper | 4:7087ea3d13c1 | 129 | emf_logo(); |
Jasper | 4:7087ea3d13c1 | 130 | wait_ms(10); |
Jasper | 0:0a6f193d5344 | 131 | |
Jasper | 0:0a6f193d5344 | 132 | strip.begin(); |
Jasper | 4:7087ea3d13c1 | 133 | pc.printf("post strip.begin\r\n"); |
Jasper | 4:7087ea3d13c1 | 134 | strip_clear(); |
Jasper | 4:7087ea3d13c1 | 135 | strip.show(); |
Jasper | 4:7087ea3d13c1 | 136 | pc.printf("post strip.show\r\n"); |
Jasper | 4:7087ea3d13c1 | 137 | |
Jasper | 4:7087ea3d13c1 | 138 | wait_ms(500); |
Jasper | 4:7087ea3d13c1 | 139 | emf_blue(); |
Jasper | 4:7087ea3d13c1 | 140 | strip.show(); |
Jasper | 4:7087ea3d13c1 | 141 | |
Jasper | 4:7087ea3d13c1 | 142 | wait_ms(500); |
Jasper | 4:7087ea3d13c1 | 143 | strip_clear(); |
Jasper | 4:7087ea3d13c1 | 144 | strip.show(); |
Jasper | 4:7087ea3d13c1 | 145 | |
Jasper | 4:7087ea3d13c1 | 146 | wait_ms(500); |
Jasper | 4:7087ea3d13c1 | 147 | emf_blue(); |
Jasper | 4:7087ea3d13c1 | 148 | strip.show(); |
Jasper | 4:7087ea3d13c1 | 149 | |
Jasper | 4:7087ea3d13c1 | 150 | wait_ms(500); |
Jasper | 4:7087ea3d13c1 | 151 | strip_clear(); |
Jasper | 4:7087ea3d13c1 | 152 | strip.show(); |
Jasper | 4:7087ea3d13c1 | 153 | |
Jasper | 4:7087ea3d13c1 | 154 | vfd_init(); |
Jasper | 4:7087ea3d13c1 | 155 | |
Jasper | 4:7087ea3d13c1 | 156 | /* print our mac address & ip (when/if we get it). */ |
Jasper | 4:7087ea3d13c1 | 157 | |
Jasper | 4:7087ea3d13c1 | 158 | /* |
Jasper | 4:7087ea3d13c1 | 159 | EthernetErr ethErr = eth.setup(); |
Jasper | 4:7087ea3d13c1 | 160 | |
Jasper | 4:7087ea3d13c1 | 161 | if(ethErr) |
Jasper | 4:7087ea3d13c1 | 162 | { |
Jasper | 4:7087ea3d13c1 | 163 | printf("Error %d in setup.\n", ethErr); |
Jasper | 4:7087ea3d13c1 | 164 | return -1; |
Jasper | 4:7087ea3d13c1 | 165 | } |
Jasper | 4:7087ea3d13c1 | 166 | printf("Setup OK\n"); |
Jasper | 4:7087ea3d13c1 | 167 | // printf("link: %d\r\n", eth.link()); |
Jasper | 4:7087ea3d13c1 | 168 | // if (eth.link()) { |
Jasper | 4:7087ea3d13c1 | 169 | // eth.address(mad); |
Jasper | 4:7087ea3d13c1 | 170 | // printf("mymac: %02X:%02X:%02X:%02X:%02X:%02X\r\n", |
Jasper | 4:7087ea3d13c1 | 171 | // mad[0], mad[1], mad[2], mad[3], mad[4], mad[5]); |
Jasper | 4:7087ea3d13c1 | 172 | // } |
Jasper | 4:7087ea3d13c1 | 173 | |
Jasper | 4:7087ea3d13c1 | 174 | svr.addHandler<SimpleHandler>("/"); //Default handler |
Jasper | 4:7087ea3d13c1 | 175 | svr.addHandler<SimpleHandler>("/hello"); |
Jasper | 4:7087ea3d13c1 | 176 | svr.bind(80); |
Jasper | 4:7087ea3d13c1 | 177 | |
Jasper | 4:7087ea3d13c1 | 178 | printf("Listening...\n"); |
Jasper | 0:0a6f193d5344 | 179 | |
Jasper | 4:7087ea3d13c1 | 180 | Timer tm; |
Jasper | 4:7087ea3d13c1 | 181 | tm.start(); |
Jasper | 4:7087ea3d13c1 | 182 | //Listen indefinitely |
Jasper | 4:7087ea3d13c1 | 183 | while(true) |
Jasper | 4:7087ea3d13c1 | 184 | { |
Jasper | 4:7087ea3d13c1 | 185 | Net::poll(); |
Jasper | 4:7087ea3d13c1 | 186 | if(tm.read() > .5) |
Jasper | 4:7087ea3d13c1 | 187 | { |
Jasper | 4:7087ea3d13c1 | 188 | // vfd_data('.'); |
Jasper | 4:7087ea3d13c1 | 189 | tm.start(); |
Jasper | 0:0a6f193d5344 | 190 | } |
Jasper | 4:7087ea3d13c1 | 191 | } |
Jasper | 4:7087ea3d13c1 | 192 | */ |
Jasper | 4:7087ea3d13c1 | 193 | |
Jasper | 4:7087ea3d13c1 | 194 | /* if (ret != 0) { |
Jasper | 4:7087ea3d13c1 | 195 | sprintf(buf, "unable to get ip address!"); |
Jasper | 4:7087ea3d13c1 | 196 | printf("%s\r\n", buf); |
Jasper | 4:7087ea3d13c1 | 197 | send_text(buf); |
Jasper | 4:7087ea3d13c1 | 198 | } else { |
Jasper | 4:7087ea3d13c1 | 199 | ret = sprintf(buf, "IP Address is %s", eth.getIPAddress()); |
Jasper | 4:7087ea3d13c1 | 200 | printf("%s : %d\r\n", buf, ret); |
Jasper | 4:7087ea3d13c1 | 201 | send_text(buf); |
Jasper | 4:7087ea3d13c1 | 202 | }*/ |
Jasper | 4:7087ea3d13c1 | 203 | // eth.disconnect(); |
Jasper | 0:0a6f193d5344 | 204 | |
Jasper | 4:7087ea3d13c1 | 205 | int tmp = 0; |
Jasper | 4:7087ea3d13c1 | 206 | bool changed = false; |
Jasper | 4:7087ea3d13c1 | 207 | char got; |
Jasper | 4:7087ea3d13c1 | 208 | char buf[128]; |
Jasper | 4:7087ea3d13c1 | 209 | int bufpos = 0; |
Jasper | 4:7087ea3d13c1 | 210 | |
Jasper | 4:7087ea3d13c1 | 211 | enum state {Looking, Number, String, Cmd}; |
Jasper | 4:7087ea3d13c1 | 212 | enum cmd {None, Top, Bottom, VfdWrite, VfdPos, Emf, VfdReset, VfdClear}; |
Jasper | 4:7087ea3d13c1 | 213 | state state; |
Jasper | 4:7087ea3d13c1 | 214 | cmd cmd; |
Jasper | 4:7087ea3d13c1 | 215 | state = Looking; |
Jasper | 4:7087ea3d13c1 | 216 | cmd = None; |
Jasper | 4:7087ea3d13c1 | 217 | int num = 0; |
Jasper | 0:0a6f193d5344 | 218 | |
Jasper | 0:0a6f193d5344 | 219 | while(1) { |
Jasper | 0:0a6f193d5344 | 220 | |
Jasper | 1:e384e7146746 | 221 | if (pc.readable()) { |
Jasper | 1:e384e7146746 | 222 | got = pc.getc(); |
Jasper | 3:7fca72f96711 | 223 | if (isprint(got)) |
Jasper | 3:7fca72f96711 | 224 | pc.putc(got); // remote echo |
Jasper | 4:7087ea3d13c1 | 225 | // vfd_data(got); |
Jasper | 1:e384e7146746 | 226 | changed = false; |
Jasper | 4:7087ea3d13c1 | 227 | |
Jasper | 4:7087ea3d13c1 | 228 | if (state == Looking) { |
Jasper | 4:7087ea3d13c1 | 229 | switch (got) { |
Jasper | 4:7087ea3d13c1 | 230 | case 't': |
Jasper | 4:7087ea3d13c1 | 231 | state = Number; |
Jasper | 4:7087ea3d13c1 | 232 | num = 0; |
Jasper | 4:7087ea3d13c1 | 233 | cmd = Top; |
Jasper | 4:7087ea3d13c1 | 234 | break; |
Jasper | 4:7087ea3d13c1 | 235 | case 'b': |
Jasper | 4:7087ea3d13c1 | 236 | state = Number; |
Jasper | 4:7087ea3d13c1 | 237 | num = 0; |
Jasper | 4:7087ea3d13c1 | 238 | cmd = Bottom; |
Jasper | 4:7087ea3d13c1 | 239 | break; |
Jasper | 4:7087ea3d13c1 | 240 | case 'e': |
Jasper | 4:7087ea3d13c1 | 241 | cmd = Emf; |
Jasper | 4:7087ea3d13c1 | 242 | state = Cmd; |
Jasper | 4:7087ea3d13c1 | 243 | break; |
Jasper | 4:7087ea3d13c1 | 244 | case 'r': |
Jasper | 4:7087ea3d13c1 | 245 | cmd = VfdReset; |
Jasper | 4:7087ea3d13c1 | 246 | state = Cmd; |
Jasper | 4:7087ea3d13c1 | 247 | break; |
Jasper | 4:7087ea3d13c1 | 248 | case 'w': |
Jasper | 4:7087ea3d13c1 | 249 | cmd = VfdWrite; |
Jasper | 4:7087ea3d13c1 | 250 | state = String; |
Jasper | 4:7087ea3d13c1 | 251 | bufpos = 0; |
Jasper | 4:7087ea3d13c1 | 252 | break; |
Jasper | 4:7087ea3d13c1 | 253 | case 'p': |
Jasper | 4:7087ea3d13c1 | 254 | cmd = VfdPos; |
Jasper | 4:7087ea3d13c1 | 255 | state = String; |
Jasper | 4:7087ea3d13c1 | 256 | bufpos = 0; |
Jasper | 4:7087ea3d13c1 | 257 | break; |
Jasper | 4:7087ea3d13c1 | 258 | case 'c': |
Jasper | 4:7087ea3d13c1 | 259 | cmd = VfdClear; |
Jasper | 4:7087ea3d13c1 | 260 | state = Cmd; |
Jasper | 4:7087ea3d13c1 | 261 | break; |
Jasper | 3:7fca72f96711 | 262 | } |
Jasper | 4:7087ea3d13c1 | 263 | } else { // not looking for a command |
Jasper | 4:7087ea3d13c1 | 264 | // cr or lf terminates a command. |
Jasper | 4:7087ea3d13c1 | 265 | if (got == '\n' || got == '\r') { |
Jasper | 4:7087ea3d13c1 | 266 | switch (cmd) { |
Jasper | 4:7087ea3d13c1 | 267 | case Top: |
Jasper | 4:7087ea3d13c1 | 268 | if (num > 16) |
Jasper | 4:7087ea3d13c1 | 269 | num = 16; |
Jasper | 4:7087ea3d13c1 | 270 | top_strip(num); |
Jasper | 4:7087ea3d13c1 | 271 | changed = true; |
Jasper | 4:7087ea3d13c1 | 272 | break; |
Jasper | 4:7087ea3d13c1 | 273 | case Bottom: |
Jasper | 4:7087ea3d13c1 | 274 | if (num > 16) |
Jasper | 4:7087ea3d13c1 | 275 | num = 16; |
Jasper | 4:7087ea3d13c1 | 276 | bottom_strip(num); |
Jasper | 4:7087ea3d13c1 | 277 | changed = true; |
Jasper | 4:7087ea3d13c1 | 278 | break; |
Jasper | 4:7087ea3d13c1 | 279 | case Emf: |
Jasper | 4:7087ea3d13c1 | 280 | emf_blue(); |
Jasper | 4:7087ea3d13c1 | 281 | changed = true; |
Jasper | 4:7087ea3d13c1 | 282 | printf("emf_blue\r\n"); |
Jasper | 4:7087ea3d13c1 | 283 | break; |
Jasper | 4:7087ea3d13c1 | 284 | case VfdReset: |
Jasper | 4:7087ea3d13c1 | 285 | vfd_reset(); |
Jasper | 4:7087ea3d13c1 | 286 | break; |
Jasper | 4:7087ea3d13c1 | 287 | case VfdWrite: |
Jasper | 4:7087ea3d13c1 | 288 | send_text(buf); |
Jasper | 4:7087ea3d13c1 | 289 | bufpos = 0; |
Jasper | 4:7087ea3d13c1 | 290 | break; |
Jasper | 4:7087ea3d13c1 | 291 | case VfdPos: |
Jasper | 4:7087ea3d13c1 | 292 | int v,h; |
Jasper | 4:7087ea3d13c1 | 293 | sscanf(buf, "%d,%d", &h,&v); |
Jasper | 4:7087ea3d13c1 | 294 | if (v > 3) v = 0; |
Jasper | 4:7087ea3d13c1 | 295 | if (h > 19) h = 0; |
Jasper | 4:7087ea3d13c1 | 296 | vfd_pos(h, v); |
Jasper | 4:7087ea3d13c1 | 297 | bufpos = 0; |
Jasper | 4:7087ea3d13c1 | 298 | break; |
Jasper | 4:7087ea3d13c1 | 299 | case VfdClear: |
Jasper | 4:7087ea3d13c1 | 300 | vfd_init(); |
Jasper | 4:7087ea3d13c1 | 301 | break; |
Jasper | 4:7087ea3d13c1 | 302 | default: |
Jasper | 4:7087ea3d13c1 | 303 | printf("no command given\r\n"); |
Jasper | 4:7087ea3d13c1 | 304 | } |
Jasper | 4:7087ea3d13c1 | 305 | state = Looking; |
Jasper | 4:7087ea3d13c1 | 306 | cmd = None; |
Jasper | 4:7087ea3d13c1 | 307 | } |
Jasper | 4:7087ea3d13c1 | 308 | if (state == Number) { |
Jasper | 4:7087ea3d13c1 | 309 | if (got >= '0' || got <= '9') { |
Jasper | 4:7087ea3d13c1 | 310 | tmp = (got - 48); |
Jasper | 4:7087ea3d13c1 | 311 | num = (num * 10) + tmp; |
Jasper | 4:7087ea3d13c1 | 312 | } else { |
Jasper | 4:7087ea3d13c1 | 313 | printf("expected a number, got %c\r\n", got); |
Jasper | 4:7087ea3d13c1 | 314 | } |
Jasper | 4:7087ea3d13c1 | 315 | } else if (state == String) { |
Jasper | 4:7087ea3d13c1 | 316 | if (bufpos < 127) { |
Jasper | 4:7087ea3d13c1 | 317 | buf[bufpos] = got; |
Jasper | 4:7087ea3d13c1 | 318 | bufpos++; |
Jasper | 4:7087ea3d13c1 | 319 | buf[bufpos] = '\0'; |
Jasper | 4:7087ea3d13c1 | 320 | } else { |
Jasper | 4:7087ea3d13c1 | 321 | printf("buffer full\r\n!"); |
Jasper | 4:7087ea3d13c1 | 322 | } |
Jasper | 4:7087ea3d13c1 | 323 | } |
Jasper | 1:e384e7146746 | 324 | } |
Jasper | 1:e384e7146746 | 325 | } |
Jasper | 1:e384e7146746 | 326 | if (changed) |
Jasper | 0:0a6f193d5344 | 327 | { |
Jasper | 4:7087ea3d13c1 | 328 | printf("changed\r\n"); |
Jasper | 2:81155674a852 | 329 | led1 = led1 ? 0 : 1; |
Jasper | 0:0a6f193d5344 | 330 | strip.show(); |
Jasper | 4:7087ea3d13c1 | 331 | changed = false; |
Jasper | 0:0a6f193d5344 | 332 | } |
Jasper | 3:7fca72f96711 | 333 | |
Jasper | 4:7087ea3d13c1 | 334 | // int size = eth.receive(); |
Jasper | 3:7fca72f96711 | 335 | /* if(size > 0) { |
Jasper | 3:7fca72f96711 | 336 | eth.read(buf, size); |
Jasper | 3:7fca72f96711 | 337 | printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\r\n", |
Jasper | 3:7fca72f96711 | 338 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); |
Jasper | 3:7fca72f96711 | 339 | printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\r\n", |
Jasper | 3:7fca72f96711 | 340 | buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); |
Jasper | 3:7fca72f96711 | 341 | printf("Size: %d\r\n", size); |
Jasper | 3:7fca72f96711 | 342 | }*/ |
Jasper | 3:7fca72f96711 | 343 | |
Jasper | 0:0a6f193d5344 | 344 | } |
Jasper | 0:0a6f193d5344 | 345 | } |