Command line interface for UART.
UARTでコマンドラインインターフェースを実現するためのライブラリです。
UARTからコマンドが入力されるとReadLine関数をコールバックします。
コマンドのデリミタはCR(0x0d)です。
コマンドはバックスペースで消去できます。
#include "mbed.h" #include "MjLineSerial.h" using namespace matsujirushi; RawSerial pc(USBTX, USBRX); MjLineSerial line(&pc); void readLineFunc(const char *str) { if (strcmp(str, "apple") == 0) { line.puts("RINGO"); } else if (strcmp(str, "orange") == 0) { line.puts("MIKAN"); } else { line.puts("unknown."); } line.puts("\r\n"); line.putc('>'); } int main() { pc.baud(115200); line.attachReadLine(readLineFunc); line.putc('>'); for (;;) { line.task(); } }
MjLineSerial.h@0:40d65405e747, 2014-11-18 (annotated)
- Committer:
- matsujirushi
- Date:
- Tue Nov 18 14:43:37 2014 +0000
- Revision:
- 0:40d65405e747
- Child:
- 1:833745ae8a7e
Create MjLineSerial class.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
matsujirushi | 0:40d65405e747 | 1 | #ifndef MJ_LINE_SERIAL_H |
matsujirushi | 0:40d65405e747 | 2 | #define MJ_LINE_SERIAL_H |
matsujirushi | 0:40d65405e747 | 3 | |
matsujirushi | 0:40d65405e747 | 4 | #include "mbed.h" |
matsujirushi | 0:40d65405e747 | 5 | |
matsujirushi | 0:40d65405e747 | 6 | namespace matsujirushi { |
matsujirushi | 0:40d65405e747 | 7 | |
matsujirushi | 0:40d65405e747 | 8 | class MjLineSerial |
matsujirushi | 0:40d65405e747 | 9 | { |
matsujirushi | 0:40d65405e747 | 10 | public: |
matsujirushi | 0:40d65405e747 | 11 | MjLineSerial(RawSerial *serial); |
matsujirushi | 0:40d65405e747 | 12 | int getc(); |
matsujirushi | 0:40d65405e747 | 13 | int putc(int c); |
matsujirushi | 0:40d65405e747 | 14 | int printf(const char *format, ...); |
matsujirushi | 0:40d65405e747 | 15 | |
matsujirushi | 0:40d65405e747 | 16 | private: |
matsujirushi | 0:40d65405e747 | 17 | RawSerial *baseSerial; |
matsujirushi | 0:40d65405e747 | 18 | |
matsujirushi | 0:40d65405e747 | 19 | }; |
matsujirushi | 0:40d65405e747 | 20 | |
matsujirushi | 0:40d65405e747 | 21 | } // namespace matsujirushi |
matsujirushi | 0:40d65405e747 | 22 | |
matsujirushi | 0:40d65405e747 | 23 | #endif |