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
|
// 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,",");
|
||||||
|
strcpy(command, strtokIndx);
|
||||||
|
Serial.print("Command: ");
|
||||||
|
Serial.println(command);
|
||||||
|
|
||||||
char * strtokIndx; // this is used by strtok() as an index
|
strtokIndx = strtok(NULL, ",");
|
||||||
|
if (atoi(strtokIndx) > 0) // Integer data
|
||||||
strtokIndx = strtok(tempChars,","); // get the first part - the string
|
{
|
||||||
strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC
|
intData = atoi(strtokIndx);
|
||||||
|
} else { // String data
|
||||||
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
|
strcpy(data, strtokIndx);
|
||||||
integerFromPC = atoi(strtokIndx); // convert this part to an integer
|
}
|
||||||
|
|
||||||
newData = false;
|
newData = false;
|
||||||
}
|
}
|
||||||
@ -255,6 +260,8 @@ void checkSerial() {
|
|||||||
recvInProgress = true;
|
recvInProgress = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init arduino
|
// Init arduino
|
||||||
|
Loading…
Reference in New Issue
Block a user