diff --git a/mbed/PS2Keyboard.cpp b/mbed/PS2Keyboard.cpp new file mode 100644 index 0000000..32ab6a3 --- /dev/null +++ b/mbed/PS2Keyboard.cpp @@ -0,0 +1,18 @@ +#include "PS2Keyboard.h" + +PS2Keyboard::PS2Keyboard() : _ps2clk(p12), _ps2din(p11) { } + +unsigned char PS2Keyboard::read(void) { + unsigned int buf = 0x00; + _ps2clk = 0; + _ps2clk.input(); + for (int i = 0; i < 11; i++) { + while (_ps2clk); + while (!_ps2clk); + buf = buf >> 1; + buf |= _ps2din ? 512 : 0; + } + _ps2clk.output(); + buf &= 0xFF; + return ps2KeyMap[buf]; +} diff --git a/mbed/PS2Keyboard.h b/mbed/PS2Keyboard.h new file mode 100644 index 0000000..d395b9b --- /dev/null +++ b/mbed/PS2Keyboard.h @@ -0,0 +1,34 @@ +#ifndef __PS2KEYBOARD_H__ +#define __PS2KEYBOARD_H__ + +#include "mbed.h" + +class PS2Keyboard { + public: + PS2Keyboard(); + unsigned char read(void); + protected: + DigitalInOut _ps2clk; + DigitalIn _ps2din; +}; + +static const unsigned char ps2KeyMap[] = +" ` " // 0 +" Q1 ZSAW2 " // 1 +" CXDE43 VFTR5 " // 2 +" NBHGY6 MJU78 " // 3 +" ,KIO09 ./L;P- " // 4 +" \' [= !] \\ " // 5 +" 1 47 1" // 6 +"0.2568 +3-*9 " // 7 +" " // 8 +" " // 9 +" " // A +" " // B +" " // C +" " // D +"\xE0 " // E +"\xF0 " // F +; + +#endif diff --git a/mbed/README b/mbed/README new file mode 100644 index 0000000..cf5f1d0 --- /dev/null +++ b/mbed/README @@ -0,0 +1 @@ +This is stored and compiled in the wonderful mbed.org cloud. diff --git a/mbed/main.cpp b/mbed/main.cpp new file mode 100644 index 0000000..fa93ad9 --- /dev/null +++ b/mbed/main.cpp @@ -0,0 +1,72 @@ +#include "mbed.h" +#include "EthernetNetIf.h" +#include "KS0108.h" +#include "SystemFont5x7.h" +#include "PS2Keyboard.h" +#include "request.h" + +KS0108 display (p18,p20, p22, p21, p19, p17, p23, p24, p25, p26, p27, p28, p29, p30); +EthernetNetIf eth; +Serial pc(USBTX, USBRX); +PS2Keyboard kbd; + +int main() { + + display.ClearScreen(); + display.SelectFont(System5x7, BLACK, ReadData); + display.PutString(0, 0, "BrmBar"); + + eth.setup(); + display.PutString(0, 35, "online"); + + int i = 0; + unsigned char symbol; + static char code[17] = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; + static char response[128]; + + while (1) { + + symbol = kbd.read(); + if (symbol == 0xE0 || symbol == 0xF0) { + symbol = kbd.read(); + if (symbol == 0xF0) { + symbol = kbd.read(); + } + continue; + } + + if ( i < 16 && ( (symbol >= 'A' && symbol <= 'Z') || (symbol >= '0' && symbol <= '9') ) ) { + code[i++] = symbol; + code[i] = 0; + display.PutString(7, 0, code); + } else if (symbol == '!') { + switch (code[0]) { + case 'U': // user + if (request(code, response)) { + display.PutString(2, 0, response); + } + break; + case 'C': // credit + if (request(code, response)) { + display.PutString(4, 0, response); + } + break; + case 'R': // reset + if (request(code, response)) { + display.PutString(4, 0, response); + } + break; + default: // item + if (request(code, response)) { + display.PutString(4, 0, response); + } + break; + } + code[0] = 0; + i = 0; + display.PutString(7, 0, " "); + } + + } +} + diff --git a/mbed/request.cpp b/mbed/request.cpp new file mode 100644 index 0000000..ec4f4e7 --- /dev/null +++ b/mbed/request.cpp @@ -0,0 +1,23 @@ +#include "request.h" +#include "HTTPClient.h" + +HTTPClient http; +static char url[40]; + +bool request(const char *arg, char *response) { + if (!arg || strlen(arg) < 1) return false; + + sprintf(url, "http://192.168.77.43:45678/code/%s", arg); + //sprintf(url, "http://mbed.org/media/uploads/donatien/hello.txt"); + //sprintf(url, "http://192.168.77.141:3456/"); + + HTTPText text("text/plain"); + HTTPResult r = http.get(url, &text); + if ( r == HTTP_OK ) { + strncpy(response, text.gets(), 128); + return true; + } else { + return false; + } +} + diff --git a/mbed/request.h b/mbed/request.h new file mode 100644 index 0000000..caeb395 --- /dev/null +++ b/mbed/request.h @@ -0,0 +1,6 @@ +#ifndef __REQUEST__H +#define __REQUEST__H + +bool request(const char *arg, char *response); + +#endif diff --git a/server/static/style.css b/server/static/style.css index dffd1e2..628d136 100644 --- a/server/static/style.css +++ b/server/static/style.css @@ -24,4 +24,4 @@ div.block { text-align: center; font-size: 10pt; padding-top: 8px; -} \ No newline at end of file +}