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