Skip to content

Commit

Permalink
Update UART Arduino poc code
Browse files Browse the repository at this point in the history
Reflect changes to the ESP32 drive UART implementation
  • Loading branch information
nepfaff authored May 26, 2021
1 parent 780aaf2 commit 61a13f8
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions control/poc/uart/arduino/arduino_code.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ void loop() {
processNewUARTData();

unsigned long currentMillis = millis();
if (currentMillis - previousMillis > 1000) {
if (currentMillis - previousMillis > 5000) {
previousMillis = currentMillis;
Serial.println("<Data from Arduino>");
Serial.print("R"); // Ready for next instruction signal => should be send after finished with current drive instruction
}
}

Expand All @@ -33,8 +33,7 @@ void recvUARTWithStartEndMarkers() {

if (recvInProgress) {
if (received != endMarker) {
receivedUARTChars[idx] = received;
idx++;
receivedUARTChars[idx++] = received;

if (idx >= numUARTChars) {
idx = numUARTChars - 1;
Expand All @@ -54,25 +53,28 @@ void recvUARTWithStartEndMarkers() {

void processNewUARTData() {
if (newUARTDataAvailable) {
// Read and pop key
const char key = receivedUARTChars[strlen(receivedUARTChars)-1];
// Read and pop instruction key
const char instructionKey = receivedUARTChars[strlen(receivedUARTChars)-1];
receivedUARTChars[strlen(receivedUARTChars)-1] = '\0';

// Data encoding defined in esp32 => Will probably want both way data encoding
switch(key) {
switch(instructionKey) {
case 'F':
Serial.print("FORWARD VALUE: ");
Serial.print(receivedUARTChars);
break;
case 'T':
Serial.print("TURN VALUE: ");
case 'R':
Serial.print("TURN RIGHT VALUE: ");
Serial.print(receivedUARTChars);
break;
case 'L':
Serial.print("TURN LEFT VALUE: ");
Serial.print(receivedUARTChars);
break;
default:
Serial.print("INVALID KEY\n");
Serial.print("INVALID INSTRUCTION KEY\n");
break;
}

newUARTDataAvailable = false;
}
}

0 comments on commit 61a13f8

Please sign in to comment.