![](/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
Diff: main.cpp
- Revision:
- 5:24172484b8c5
- Parent:
- 4:7087ea3d13c1
- Child:
- 6:7e7b4c5d0ba6
diff -r 7087ea3d13c1 -r 24172484b8c5 main.cpp --- a/main.cpp Mon Aug 27 01:32:52 2012 +0000 +++ b/main.cpp Sun Oct 21 07:16:07 2012 +0000 @@ -107,14 +107,26 @@ send_text(s); } -void emf_logo(void) { +void logo(void) { const char line0[] = "Welcome to"; - const char line2[] = "EMFCamp!"; + const char line2[] = "London Hackspace"; text_centered(line0, 0); text_centered(line2, 2); } +int hex_char_to_int(char h) { + int ret; + if (h >= '0' || h <= '9') { + ret = h - 48; + } else if (h >= 'A' || h <= 'F') { + ret = (h - 'A') + 10; + } else if (h >= 'a' || h <= 'f') { + ret = (h - 'a') + 10; + } + return ret; +} + int main() { setbuf(stdout, NULL); @@ -126,7 +138,7 @@ wait_ms(10); vfd_init(); wait_ms(10); - emf_logo(); + logo(); wait_ms(10); strip.begin(); @@ -135,23 +147,23 @@ strip.show(); pc.printf("post strip.show\r\n"); - wait_ms(500); - emf_blue(); - strip.show(); +// wait_ms(500); +// emf_blue(); +// strip.show(); - wait_ms(500); - strip_clear(); - strip.show(); +// wait_ms(500); +// strip_clear(); +// strip.show(); - wait_ms(500); - emf_blue(); - strip.show(); +// wait_ms(500); +// emf_blue(); +// strip.show(); - wait_ms(500); - strip_clear(); - strip.show(); +// wait_ms(500); +// strip_clear(); +// strip.show(); - vfd_init(); +// vfd_init(); /* print our mac address & ip (when/if we get it). */ @@ -209,7 +221,7 @@ int bufpos = 0; enum state {Looking, Number, String, Cmd}; - enum cmd {None, Top, Bottom, VfdWrite, VfdPos, Emf, VfdReset, VfdClear}; + enum cmd {None, Top, Bottom, VfdWrite, VfdPos, Emf, VfdReset, VfdClear, SetStrip}; state state; cmd cmd; state = Looking; @@ -220,9 +232,11 @@ if (pc.readable()) { got = pc.getc(); - if (isprint(got)) - pc.putc(got); // remote echo -// vfd_data(got); + if (isprint(got)) { +// pc.putc(got); // remote echo + } else { + pc.printf("%02x ", got); + } changed = false; if (state == Looking) { @@ -237,7 +251,7 @@ num = 0; cmd = Bottom; break; - case 'e': + case 'e': // emf blue... cmd = Emf; state = Cmd; break; @@ -259,6 +273,11 @@ cmd = VfdClear; state = Cmd; break; + case 's': + cmd = SetStrip; + state = String; + bufpos = 0; + break; } } else { // not looking for a command // cr or lf terminates a command. @@ -299,6 +318,28 @@ case VfdClear: vfd_init(); break; + case SetStrip: + bufpos = 0; + printf("SetStrip: %s\r\n", buf); + // buf[0] == t or b for strip + // next 48 chars == HHH rgb * 16 + int p, endp, r, g, b; + if (buf[0] == 't') { + p = 0; endp = p + 16; + } else { + p = 16; endp = p + 16; + } + + + for (;p < endp ; p ++) { + r = hex_char_to_int(buf[(p * 3) + 1]); + g = hex_char_to_int(buf[(p * 3) + 2]); + b = hex_char_to_int(buf[(p * 3) + 3]); + strip.setPixelColor(p, strip.Color(r,g,b)); + } + changed = true; + + break; default: printf("no command given\r\n"); } @@ -319,6 +360,7 @@ buf[bufpos] = '\0'; } else { printf("buffer full\r\n!"); + // XXX state == None here? } } }