Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: serial.cpp
- Revision:
- 4:179fc666147c
- Parent:
- 3:655f4fed48d7
--- a/serial.cpp Mon Dec 05 21:31:39 2016 +0000 +++ b/serial.cpp Tue Dec 06 19:55:30 2016 +0000 @@ -1,5 +1,5 @@ -#include "mbed.h" -#include "rtos.h" +//#include "mbed.h" +//#include "rtos.h" #include <string> #include <sstream> @@ -8,8 +8,7 @@ Serial pc(USBTX, USBRX); Thread *RX_THREAD_POINTER; string test; -string* paramArray = new string[25]; -int index=0; +bool flag=true; // Rx Interupt routine void Rx_interrupt(void){ @@ -25,50 +24,39 @@ Thread::signal_wait(0x1); while (pc.readable()) { //pc.putc(pc.getc()); // read data from UART - pc.printf("\r\nInput: \r\n"); + //pc.printf("\r\nInput: \r\n"); stringstream ss; char temp; temp = pc.getc(); - pc.putc(temp); + //pc.putc(temp); while (temp != '*'){ ss << temp; temp = pc.getc(); - pc.putc(temp); + //pc.putc(temp); } ss >> test; - if(index<25){ - //in_Array[i] = temp; - //pc.printf("%s\r\n", test); - //pc.printf("\r\n"); - led2=!led2; - paramArray[index++] = test; - } else { - //i = 0; - pc.attach(&Rx_interrupt); - //return; - } + flag = false; + pc.attach(&Rx_interrupt); } pc.attach(&Rx_interrupt); // Enable Rx interrupt } } -string* recieve(){ - paramArray = new string[24]; - index=0; +string recieve(){ Thread t_rx(rx_thread); RX_THREAD_POINTER = &t_rx; // Set thread pointer as globally-accessible t_rx.set_priority(osPriorityHigh); pc.attach(Rx_interrupt); //pc.printf("\r\nStart\r\n"); - while(test != "DONE"){ + while(flag){ led1=!led1; //pc.printf("%s\r\n",test); Thread::wait(1000); } - return paramArray; + return test; } void send(string input){