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
Revision 3:7fca72f96711, committed 2012-08-23
- Comitter:
- Jasper
- Date:
- Thu Aug 23 00:17:04 2012 +0000
- Parent:
- 2:81155674a852
- Child:
- 4:7087ea3d13c1
- Commit message:
- got the vfd working
Changed in this revision
--- a/LPD8806.lib Sun Jun 10 23:05:12 2012 +0000 +++ b/LPD8806.lib Thu Aug 23 00:17:04 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/ehbmbed2/libraries/LPD8806/m2abi7 \ No newline at end of file +http://mbed.org/users/ehbmbed2/code/LPD8806/#6ebd3ac910b6
--- a/main.cpp Sun Jun 10 23:05:12 2012 +0000 +++ b/main.cpp Thu Aug 23 00:17:04 2012 +0000 @@ -1,12 +1,16 @@ #include "mbed.h" +#include "ctype.h" #include "LPD8806.h" +#include "vfd.h" DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); +Ethernet eth; + /* talk to the world */ Serial pc(USBTX, USBRX); @@ -66,6 +70,11 @@ setPixelsBottom(14, quantity < 16 ? quantity : 16, strip.Color(127, 0, 0)); } +void emf_blue() { + setPixelsBottom(0, 15, strip.Color(0, 161, 228)); + setPixelsTop(0, 15, strip.Color(0, 161, 228)); +} + #define s_looking 1 #define s_top 2 #define s_bottom 3 @@ -75,6 +84,28 @@ int i, state = s_looking, tmp = 0, col = 1; bool changed = false; char got; + char buf[0x600]; + char mad[6]; + + pc.printf("Hello!\r\n"); + + vfd_init(); + wait_ms(1); + + for (i = 'a'; i < 'a' + 25 ; i++){ + vfd_data(i); + } + for (i = 'a'; i < 'a' + 25 ; i++){ + vfd_data(i); + } + for (i = 'a'; i < 'a' + 25 ; i++){ + vfd_data(i); + } + +/* eth.init(); + eth.connect(); + printf("IP Address is %s\n", eth.getIPAddress()); + eth.disconnect();*/ strip.begin(); @@ -89,8 +120,9 @@ if (pc.readable()) { got = pc.getc(); - pc.putc(got); // remote echo - + if (isprint(got)) + pc.putc(got); // remote echo + vfd_data(got); changed = false; if (got == '\n' || got == '\r') { @@ -103,12 +135,21 @@ col = 1; if (t > 16) t = 16; if (b > 16) b = 16; - printf("t: %d b: %d\n", t, b); + printf("t: %d b: %d\r\n", t, b); changed = true; + printf("link: %d\r\n", eth.link()); + if (eth.link()) { + eth.address(mad); + printf("mymac: %02X:%02X:%02X:%02X:%02X:%02X\r\n", + mad[0], mad[1], mad[2], mad[3], mad[4], mad[5]); + } } else if (got == 'b') { state = s_bottom; } else if (got == 't') { state = s_top; + } else if (got == 'e') { + emf_blue(); + strip.show(); } else if (got <= '9' and got >= '0') { tmp += (got - '0') * col; col = col * 10; @@ -121,5 +162,16 @@ bottom_strip(b); strip.show(); } + + int size = eth.receive(); +/* if(size > 0) { + eth.read(buf, size); + printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\r\n", + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); + printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\r\n", + buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); + printf("Size: %d\r\n", size); + }*/ + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Aug 23 00:17:04 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6 \ No newline at end of file
--- a/mbed.lib Sun Jun 10 23:05:12 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/projects/libraries/svn/mbed/trunk@43 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/picojson.lib Thu Aug 23 00:17:04 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mimil/code/picojson/#2bb500b021e2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vfd.cpp Thu Aug 23 00:17:04 2012 +0000 @@ -0,0 +1,141 @@ +/* + * The VFD code + * + * for a futuba M204LD01AA + * + * + * p27 -> input, busy + * p28 -> serial data in + * p29 -> clock + * p30 -> latch + * + * + */ + +#include "mbed.h" +#include "vfd.h" + +// InturruptIn busy_intr(p27) + +DigitalIn vfd_p_busy(p27); +DigitalOut vfd_p_data(p28); +DigitalOut vfd_p_clock(p29); +DigitalOut vfd_p_latch(p30); + +/* current state */ +int c_data; +bool c_a0; +bool c_blank; + +void vfd_shift_clock(void) { + vfd_p_clock = 0; + wait_us(100); + vfd_p_clock = 1; + wait_us(100); +} + +void vfd_doit(int data, int mode, int wr, int ss) { + int i, bit; + + vfd_p_data = 0; // nc + vfd_shift_clock(); + vfd_p_data = 0; // nc + vfd_shift_clock(); + + vfd_p_data = 1; // reset, 0 = in reset + vfd_shift_clock(); + + vfd_p_data = c_blank; // Blank, 0 = blanked + vfd_shift_clock(); + + vfd_p_data = ss; // SS, clockish + vfd_shift_clock(); + + vfd_p_data = 1; // rd + vfd_shift_clock(); + + vfd_p_data = mode; // A0, data/command + vfd_shift_clock(); + + vfd_p_data = wr; // WR + vfd_shift_clock(); + + for (i = 0 ; i < 8; i++) { + bit = (data & (1 << i)) >> i; + vfd_p_data = bit; + vfd_shift_clock(); + } + + vfd_p_latch = 0; + wait_us(10); + vfd_p_latch = 1; + wait_us(10); +} + +/* mode == 1 if command */ +void vfd_send(int data, int mode) +{ + data = data & 0xff; + c_data = data; + c_blank = 1; + + if (vfd_p_busy) + printf("pre, busy: %d\r\n", vfd_p_busy.read()); + + if (vfd_p_busy) + { + wait_ms(4); // should loop, 3.1 ms is max according to the data sheet. + if (vfd_p_busy) + { + printf("still busy :(\r\n"); + return; + } + } + + /* wr,ss */ + vfd_doit(data, mode, 0, 0); + wait_us(1); + vfd_doit(data, mode, 1, 0); + wait_us(1); + vfd_doit(data, mode, 1, 1); + wait_us(1); + + if (vfd_p_busy) + printf("post1, busy: %d\r\n", vfd_p_busy.read()); + + vfd_doit(data, mode, 0, 0); + wait_ms(1); // loop and wait for not busy + + if (vfd_p_busy) + printf("post2, busy: %d\r\n", vfd_p_busy.read()); + + while (vfd_p_busy) { + wait_us(250); + printf("post-while, busy: %d\r\n", vfd_p_busy.read()); + } +} + +void vfd_command(int data) { + vfd_send(data, 1); +} + +void vfd_data(int data) { + vfd_send(data, 0); +} + +void vfd_init(void) { + vfd_data(0x0c); // clear + vfd_data(0x1b); // esc + vfd_data(0); // v pos + vfd_data(0); // h pos +} + +void vfd_blank(void) { + /* blank */ +} + +void vfd_show(void) { + /* unblank */ +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vfd.h Thu Aug 23 00:17:04 2012 +0000 @@ -0,0 +1,7 @@ + +void vfd_command(int data); +void vfd_data(int data); +void vfd_blank(void); +void vfd_status(void); +void vfd_init(void); +