Created
March 23, 2015 10:15
-
-
Save bitdivision/0f261d32c11000c93b9b to your computer and use it in GitHub Desktop.
SuperSerial Long Running Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int runSingleSlaveProcess() { | |
ACKResponse_t resp = {0,0,0,{0},0}; | |
int slaveTarget = 100; | |
SuperSerial.pollUntilComplete(&resp, SLAVE_ID, 'A', 2, &slaveTarget); | |
if (resp.packetType != PACKET_NONE) { | |
Serial.print("Slave returned with data: "); | |
Serial.println((int)(((int *)resp.data)[0])); | |
return 1; | |
} | |
else { | |
Serial.println("Error: command timed out"); | |
return -1; | |
} | |
} | |
int runMultipleSlaveProcesses() { | |
ACKResponse_t resp_slave_0 = {0,0,0,{0},0}; | |
ACKResponse_t resp_slave_1 = {0,0,0,{0},0}; | |
int slave_0_target = 100; | |
int slave_1_target = 1000; | |
bool errorFlag = false; | |
unsigned long startTime = millis(); | |
while ((resp_slave_0.packetType != PACKET_COMPLETE) || (resp_slave_1.packetType != PACKET_COMPLETE)) { | |
if (resp_slave_0.packetType != PACKET_COMPLETE) { | |
SuperSerial.poll(&resp_slave_0, SLAVE_0_ID, 'A', 2, &slave_0_target); | |
} | |
if (resp_slave_1.packetType != PACKET_COMPLETE) { | |
SuperSerial.poll(&resp_slave_1, SLAVE_1_ID, 'A', 2, &slave_1_target); | |
} | |
delay(200); | |
if ((millis() - startTime) > POLL_COMPLETE_TIMEOUT) { | |
errorFlag = true; | |
break; | |
} | |
} | |
if (!errorFlag) { | |
Serial.println(F("Command complete for slaves 0 and 1")); | |
return 1; | |
} | |
else { | |
Serial.println(F("Error: command timed out")); | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment