Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1.      void loop(){
  2.       readCommand(computerSerial);      
  3.       if (commandSent){        
  4.         if(!driverSerial.isListening()){          
  5.           driverSerial.listen();
  6.         }
  7.         command = "";
  8.       }        
  9.     }    
  10.    
  11.     void readCommand(Stream &source) {      
  12.       commandSent = false;      
  13.       while (source.available() > 0) {
  14.         char c = source.read();
  15.         if ( (c != '\0') && (c != 10) && (c != 13)){ // if char is not a null or a LF or a CR                
  16.           command += c;
  17.         }
  18.         if  (c == 13)  { //if there is a \n then command is sent
  19.           //command += "\r";
  20.           commandSent = true;
  21.           source.print("command:"); //debug
  22.           source.print(command); //debug
  23.           source.println("END"); //debug
  24.           source.flush();
  25.         }
  26.       }    
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement