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(); } }
Diff: MjLineSerial.h
- Revision:
- 4:14ef86f5de57
- Parent:
- 3:e730a11160d7
- Child:
- 5:b7902dd4ab46
--- a/MjLineSerial.h Wed Nov 19 12:30:26 2014 +0000 +++ b/MjLineSerial.h Thu Nov 20 13:21:03 2014 +0000 @@ -19,6 +19,8 @@ void attachReadLine(void (*func)(const char *str)); void task(); + const char *txDelimiter; + private: RawSerial *baseSerial; vector<char> rxBuffer;