void laser_init() { char init = 'U'; char resp; UART2_Write(&init, 1); while (1) { if (UART2_Read(&resp) == 0) { // Check for response if (resp == ':') { break; } } } }
unsigned int UART2_WriteBuffer(const uint8_t *buffer, const unsigned int bufLen) { unsigned int numBytesWritten = 0; while (numBytesWritten < (bufLen)) { if ((uart2_obj.txStatus.s.full)) { break; } else { UART2_Write(buffer[numBytesWritten++]); } } return numBytesWritten; }
unsigned long laser_read() { char read[] = "B"; UART2_Write(&read, 1); unsigned long temp = 0; while(1){ if(UART2_Read(&read) == 0) { temp |= (read[0] << 24); break; } } while(1){ if(UART2_Read(&read) == 0) { temp |= (read[0] << 16); break; } } while(1){ if(UART2_Read(&read) == 0) { temp |= (read[0] << 8); break; } } while(1){ if(UART2_Read(&read) == 0) { temp |= (read[0]); break; } } while(1){ if(UART2_Read(&read) == 0) break; } while(1){ if(UART2_Read(&read) == 0) break; } return temp; }
/** void DRV_UART2_Write( const uint8_t byte) */ void DRV_UART2_Write( const uint8_t byte) { UART2_Write( byte); }
//UART2 write text and new line (carriage return + line feed) void UART2_Write_Line(char *uart_text) { UART2_Write_Text(uart_text); UART2_Write(13); UART2_Write(10); }
/** * Relays data from Radio to USB/Bluetooth */ void relayFromRadio() { /* UART1 - FTDI USB * UART2 - Bluetooth * UART3 - Radio */ if(!UART3_ReceiveBufferIsEmpty()) //New data on UART3 (Radio) { uint8_t rxByte = UART3_Read(); //Read byte from U3 if(relayUSBConneted()) { // if(!UART1_TransmitBufferIsFull()) //There is free space in U1 tx buffer //commented this out to avoid random loss of connection -D Cironi 2015-05-11 // { UART1_Write(rxByte); //Send to U1 // } } else { if(!UART2_TransmitBufferIsFull()) //There is free space in U2 tx buffer { UART2_Write(rxByte); //Read byte from U3 and send to U2 } } LandChannel = CheckRCLoop(rxByte); //check to see if data from radio is RC_Channel info if(LandChannel != 0 && LandChannel < 1500 && MissionInjectStage == 0 && LandInjected == 0) //Valid reading and the mode we want for landing { MissionInjectStage = 1; } else if (LandChannel != 0 && LandChannel > 1500) //valid reading but not the mode we want { MissionInjectStage = 0; LandInjected = 0; Nop(); } switch(MissionInjectStage) //inject a packet on each cycle { case 0: //do nothing break; case 1: InjectCount(4); break; case 2: InjectWaypoint('h'); break; case 3: InjectWaypoint('1'); break; case 4: InjectWaypoint('2'); break; case 5: InjectWaypoint('3'); break; case 6: InjectAcknowledge(); break; } } }