standalone sx1276 demo program

Dependencies:   SX1276Lib mbed

Fork of SX1276_GPS by CaryCoders

utilities.cpp

Committer:
ftagius
Date:
2015-07-14
Revision:
31:2c813f321db7
Parent:
29:0ea07cc7124b
Child:
32:a2472bbe7c92

File content as of revision 31:2c813f321db7:

#include "mbed.h"
#include "sx1276-hal.h"
#include "main.h"
#include "debug.h"
//radfta #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()
}