forked from brmlab/brmbar-github
Add current version of mbed code as stored at mbed.org
This commit is contained in:
parent
9a712ec12c
commit
ddb1399f9a
7 changed files with 155 additions and 1 deletions
18
mbed/PS2Keyboard.cpp
Normal file
18
mbed/PS2Keyboard.cpp
Normal file
|
@ -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];
|
||||||
|
}
|
34
mbed/PS2Keyboard.h
Normal file
34
mbed/PS2Keyboard.h
Normal file
|
@ -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
|
1
mbed/README
Normal file
1
mbed/README
Normal file
|
@ -0,0 +1 @@
|
||||||
|
This is stored and compiled in the wonderful mbed.org cloud.
|
72
mbed/main.cpp
Normal file
72
mbed/main.cpp
Normal file
|
@ -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, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
23
mbed/request.cpp
Normal file
23
mbed/request.cpp
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
6
mbed/request.h
Normal file
6
mbed/request.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef __REQUEST__H
|
||||||
|
#define __REQUEST__H
|
||||||
|
|
||||||
|
bool request(const char *arg, char *response);
|
||||||
|
|
||||||
|
#endif
|
|
@ -24,4 +24,4 @@ div.block {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
padding-top: 8px;
|
padding-top: 8px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue