This is an example program that shows how to use the RadioHeadLite library, and does it using threads.

Dependencies:   RadioHeadLite

main.cpp

Committer:
rlanders73
Date:
2019-05-16
Revision:
2:57fefd8ae87c
Parent:
1:75d533f15c95
Child:
3:fd3a7f10eed3

File content as of revision 2:57fefd8ae87c:

#include "mbed.h"
#include "USBSerial.h"

#define GNSSEN   PC_3
#define GNSSTXD  PA_9
#define GNSSRXD  PA_10
#define GNSSBAUD 9600

/******************** Comms *********************/
USBSerial pc;
//FileHandle* mbed::mbed_override_console(int)
//{   
//    return &pc;
//}

UARTSerial radio(GNSSTXD, GNSSRXD, 9600);


DigitalOut gpsEn(GNSSEN, 1);


Thread myThread;



void sendToModem(void)
{
    char c;
    c = pc.getc();
    radio.write(&c, 1);// push the charcter to the modem   
}

void sendToPC(void)
{
    char c;
    radio.read(&c, 1);
    pc.putc(c);    
}


static void passthroughThread(void)
{
//    pc.attach(&sendToModem);
    
    while (1)
    {
        // Housekeeping - check button
        if (pc.readable())
        {
            sendToModem();
        }

        if (radio.readable())
        {
            sendToPC();
        }
    }
}




void setup(void)
{
    wait(1); // wait just a bit for the USB to enumerate


    pc.set_blocking(false);
    radio.set_blocking(false);

    wait(1);    
}  

int main(void)
{
    setup();

    myThread.start(passthroughThread);

    return 1;
}