Anders Hörnfeldt
/
coniolib
Port of Conio.h
hw_mbed.c@0:6c1bc9b3a347, 2010-04-19 (annotated)
- Committer:
- hornfeldt
- Date:
- Mon Apr 19 20:20:10 2010 +0000
- Revision:
- 0:6c1bc9b3a347
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hornfeldt | 0:6c1bc9b3a347 | 1 | #include "mbed.h" |
hornfeldt | 0:6c1bc9b3a347 | 2 | #include "conio.h" |
hornfeldt | 0:6c1bc9b3a347 | 3 | |
hornfeldt | 0:6c1bc9b3a347 | 4 | Serial pc(USBTX, USBRX); |
hornfeldt | 0:6c1bc9b3a347 | 5 | |
hornfeldt | 0:6c1bc9b3a347 | 6 | int get_esc_sec () { |
hornfeldt | 0:6c1bc9b3a347 | 7 | int ch; |
hornfeldt | 0:6c1bc9b3a347 | 8 | if (pc.scanf("\x1b\x5b%c",ch) == 0) |
hornfeldt | 0:6c1bc9b3a347 | 9 | return 0; |
hornfeldt | 0:6c1bc9b3a347 | 10 | else |
hornfeldt | 0:6c1bc9b3a347 | 11 | return ch; |
hornfeldt | 0:6c1bc9b3a347 | 12 | } |
hornfeldt | 0:6c1bc9b3a347 | 13 | |
hornfeldt | 0:6c1bc9b3a347 | 14 | int _kbhit (void) { |
hornfeldt | 0:6c1bc9b3a347 | 15 | return pc.readable(); |
hornfeldt | 0:6c1bc9b3a347 | 16 | } |
hornfeldt | 0:6c1bc9b3a347 | 17 | |
hornfeldt | 0:6c1bc9b3a347 | 18 | |
hornfeldt | 0:6c1bc9b3a347 | 19 | void _putch (char ch) { |
hornfeldt | 0:6c1bc9b3a347 | 20 | pc.putc(ch); |
hornfeldt | 0:6c1bc9b3a347 | 21 | } |
hornfeldt | 0:6c1bc9b3a347 | 22 | |
hornfeldt | 0:6c1bc9b3a347 | 23 | int _getch (void) { |
hornfeldt | 0:6c1bc9b3a347 | 24 | int ret; |
hornfeldt | 0:6c1bc9b3a347 | 25 | |
hornfeldt | 0:6c1bc9b3a347 | 26 | while (!_kbhit()); //wait and read new char |
hornfeldt | 0:6c1bc9b3a347 | 27 | ret = pc.getc(); |
hornfeldt | 0:6c1bc9b3a347 | 28 | if (ret==0) { |
hornfeldt | 0:6c1bc9b3a347 | 29 | while (!_kbhit()); //wait and read new char |
hornfeldt | 0:6c1bc9b3a347 | 30 | ret = pc.getc(); |
hornfeldt | 0:6c1bc9b3a347 | 31 | ret = ret | 0x100; |
hornfeldt | 0:6c1bc9b3a347 | 32 | } |
hornfeldt | 0:6c1bc9b3a347 | 33 | |
hornfeldt | 0:6c1bc9b3a347 | 34 | return ret; |
hornfeldt | 0:6c1bc9b3a347 | 35 | } |
hornfeldt | 0:6c1bc9b3a347 | 36 | |
hornfeldt | 0:6c1bc9b3a347 | 37 | |
hornfeldt | 0:6c1bc9b3a347 | 38 | void MCU_Init(void) { |
hornfeldt | 0:6c1bc9b3a347 | 39 | pc.baud(19200); |
hornfeldt | 0:6c1bc9b3a347 | 40 | } |