Receiving serial data / commands is working

This commit is contained in:
Arne van Iterson 2020-05-20 19:54:05 +02:00
parent 12a04887fd
commit 162261e54f

View File

@ -152,7 +152,6 @@ void drawName(String name) {
} }
// Check for button input // Check for button input
// TODO: Add rotary encoder support
void checkInput(unsigned long time) { void checkInput(unsigned long time) {
long newPosition = encoder.read(); long newPosition = encoder.read();
if (newPosition != position) { if (newPosition != position) {
@ -200,7 +199,8 @@ char receivedChars[numChars];
char tempChars[numChars]; char tempChars[numChars];
char command[numChars] = {0}; char command[numChars] = {0};
int data = 0; char data[numChars] = {0};
int intData = 0;
boolean newData = false; boolean newData = false;
@ -211,15 +211,20 @@ void processData() {
strcpy(tempChars, receivedChars); strcpy(tempChars, receivedChars);
char * strtokIndx;
strtokIndx = strtok(tempChars,",");
char * strtokIndx; // this is used by strtok() as an index strcpy(command, strtokIndx);
Serial.print("Command: ");
strtokIndx = strtok(tempChars,","); // get the first part - the string Serial.println(command);
strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off strtokIndx = strtok(NULL, ",");
integerFromPC = atoi(strtokIndx); // convert this part to an integer if (atoi(strtokIndx) > 0) // Integer data
{
intData = atoi(strtokIndx);
} else { // String data
strcpy(data, strtokIndx);
}
newData = false; newData = false;
} }
@ -255,6 +260,8 @@ void checkSerial() {
recvInProgress = true; recvInProgress = true;
} }
} }
processData();
} }
// Init arduino // Init arduino