SSI OpComms 3 CM TX
Dependencies: mbed
Fork of Optical3cmTXnucleo by
Diff: main.cpp
- Revision:
- 4:024257aaea1e
- Parent:
- 2:eb6621f41f07
- Child:
- 5:4bf7b8f3fd58
diff -r eb6621f41f07 -r 024257aaea1e main.cpp --- a/main.cpp Sun Nov 08 00:58:35 2015 +0000 +++ b/main.cpp Tue Nov 10 06:26:27 2015 +0000 @@ -1,11 +1,11 @@ -#include "mbed.h" + #include "mbed.h" DigitalOut tx(D15); Serial pc(USBTX, USBRX); // tx, rx -const int PULSE_LENGTH = 1000; const int PPM = 4; const int PACKET_LENGTH = 98; +int PULSE_LENGTH = 0; //Function Prototypes void blink_packet(char* buffer, int len); @@ -71,6 +71,20 @@ int main() { pc.printf("3 CM Link Board - Transmit\r\n"); + pc.printf("Enter pulse length in microseconds (10e-6), enter for 1000\r\n"); + while(1) { + char d = pc.getc(); + if(d != '\n') { + PULSE_LENGTH = PULSE_LENGTH*10 + (d-'0'); + } + else { + if (PULSE_LENGTH == 0) PULSE_LENGTH = 1000; + pc.printf("Pulse length is "); + pc.printf("%d", PULSE_LENGTH); + pc.printf("\r\n"); + break; + } + } //Packet char buffer[PACKET_LENGTH + 2]; @@ -79,15 +93,20 @@ char a = pc.getc(); //Fills buffer then transmits - if(a != '\n' && idx < PACKET_LENGTH){ + if (a == '~') { + tx = tx ^ 1; + while (pc.getc() != '~'); + } + else if(a != '\n' && idx < PACKET_LENGTH){ buffer[idx] = a; idx++; - }else{ + } + else { //Adds ending characters -// buffer[idx] = '\r'; -// idx++; -// buffer[idx] = '\n'; -// idx++; + buffer[idx] = '\r'; + idx++; + buffer[idx] = '\n'; + idx++; //Transmits packet blink_packet(buffer, idx);