CaryCoders
/
demo_SX1276_standalone
standalone sx1276 demo program
Fork of SX1276_GPS by
Diff: utilities.cpp
- Revision:
- 29:0ea07cc7124b
- Child:
- 31:2c813f321db7
diff -r fbcd3bac0cd7 -r 0ea07cc7124b utilities.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utilities.cpp Tue Jun 16 11:53:20 2015 +0000 @@ -0,0 +1,56 @@ +#include "mbed.h" +#include "sx1276-hal.h" +#include "main.h" +#include "debug.h" +#include "vt100.h" +#include "serial_api.h" + +int get_kbd_str(char* buf, int size) +{ + char c; + int i; + static int prev_len; + + for (i = 0;;) { + if (pc.readable()) { + c = pc.getc(); + if (c == 8 && i > 0) { + pc.putc(8); + pc.putc(' '); + pc.putc(8); + i--; + } else if (c == '\r') { + if (i == 0) { + if (app == APP_CHAT) + return 0; + else + return prev_len; // repeat previous + } else { + buf[i] = 0; // null terminate + prev_len = i; + return i; + } + } else if (c == 3) { + // ctrl-C abort + return -1; + } else if (i < size) { + buf[i++] = c; + pc.putc(c); + } + } else { + if (app == APP_PING) + ping_pong(); + if (app == APP_HELLO) + hello(); + if (app == APP_GPS) + check_gps(); + #if 1 + if (app == APP_CHAT) + { + // printf("utility call to console chat\r\n"); + check_rx_chat(); + } + #endif + } + } // ...for() +}