This is an example program that shows how to use the RadioHeadLite library, and does it using threads.
Dependencies: RadioHeadLite
Diff: main.cpp
- Revision:
- 1:75d533f15c95
- Parent:
- 0:f4015c8e84c3
- Child:
- 2:57fefd8ae87c
diff -r f4015c8e84c3 -r 75d533f15c95 main.cpp --- a/main.cpp Sat Nov 24 05:53:37 2018 +0000 +++ b/main.cpp Mon Nov 26 21:01:04 2018 +0000 @@ -2,11 +2,11 @@ #include "USBSerial.h" #include "Geneva.h" -#define PASSTHROUGH 1 +#define PASSTHROUGH 0 /******************** Comms *********************/ USBSerial pc; // moved the pc interface to the USB serial device -Serial modemSerial(MDMTXD, MDMRXD, 115200); +UARTSerial modemUartSerial(MDMTXD, MDMRXD, 115200); DigitalInOut cellRst(MDMRST); @@ -27,9 +27,9 @@ InterruptIn *rxPin; DigitalOut samplePin(PA_0); -Thread passThread; +Thread myThread; - static char scanBuffer[512]; +static char scanBuffer[512]; static bool buttonWasPushed = false; typedef struct @@ -44,81 +44,41 @@ cellContext_t cell; -uint8_t buffer[64]; - -#if PASSTHROUGH -static void passthroughThread(void) -{ - - while (1) - { - // Housekeeping - check button - if (pc.readable()) - { - char c = pc.getc(); // grab the available character - pc.putc(c); // provide local echo - modemSerial.putc(c);// push the charcter to the modem - } - - if (modemSerial.readable()) - { - pc.putc(modemSerial.getc()); - } - } -} -#endif +char buffer[64]; static void buttonPushed(void) { buttonWasPushed = true; } - - - -int main(void) +#if PASSTHROUGH +static void passthroughThread(void) { - // Enable flow control on MDM uart - //modemUartSerial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); - - buttonInt.mode(PullUp); - buttonInt.fall(buttonPushed); - - cellRst.mode(OpenDrainNoPull); - cellRst.output(); - cellRst = 1; - - cellPwrKey.mode(OpenDrainNoPull); - cellPwrKey.output(); - cellPwrKey = 1; + char c; + pc.printf("Passthrough mode\r\n"); + blueLed = 0; - wait(1); // wait just a bit for the USB to enumerate + while (1) + { + // Housekeeping - check button + if (pc.readable()) + { + c = pc.getc(); + modemUartSerial.write(&c, 1);// push the charcter to the modem + } - pc.printf("Modem Test\r\n", 12); - - pc.set_blocking(false); - modemSerial.set_blocking(false); - - // Power up the modem! - cellVcc = 1; - pc.printf("Modem VCC UP\r\n", 14); - wait(3); - - cellPwrKey = 0; - wait(0.9); - cellPwrKey = 1; - pc.printf("Modem Power\r\n", 13); - - redLed = 0; - - wait(5); - -#if PASSTHROUGH - pc.printf("Passthrough mode\r\n", 18); - blueLed = 0; - passThread.start(passthroughThread); + if (modemUartSerial.readable()) + { + modemUartSerial.read(&c, 1); + pc.putc(c); + } + } +} #else + +static void autoModeThread(void) +{ pc.printf("Auto mode\r\n", 11); cell.fileHandle = &modemUartSerial; @@ -193,7 +153,54 @@ } cell.rawParser->send("AT+COPS=2") && cell.rawParser->recv("OK"); +} +#endif +void setup(void) +{ + // Enable flow control on MDM uart + //modemUartSerial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); + buttonInt.mode(PullUp); + buttonInt.fall(buttonPushed); + + cellRst.mode(OpenDrainNoPull); + cellRst.output(); + cellRst = 1; + + cellPwrKey.mode(OpenDrainNoPull); + cellPwrKey.output(); + cellPwrKey = 1; + + wait(1); // wait just a bit for the USB to enumerate + + pc.printf("Modem Test\r\n", 12); + + pc.set_blocking(false); + modemUartSerial.set_blocking(false); + + // Power up the modem! + cellVcc = 1; + pc.printf("Modem VCC UP\r\n", 14); + wait(3); + + cellPwrKey = 0; + wait(0.9); + cellPwrKey = 1; + pc.printf("Modem Power\r\n", 13); + + redLed = 0; + + wait(5); +} + +int main(void) +{ + setup(); + +#if PASSTHROUGH + myThread.start(passthroughThread); +#else + myThread.start(autoModeThread); #endif Thread::wait(osWaitForever);