diff --git a/speeduino/comms.h b/speeduino/comms.h index f1968309..235b7335 100644 --- a/speeduino/comms.h +++ b/speeduino/comms.h @@ -21,7 +21,7 @@ byte currentCommand; bool cmdPending = false; bool chunkPending = false; uint16_t chunkComplete = 0; -int16_t chunkSize = 0; +uint16_t chunkSize = 0; byte cmdGroup = 0; byte cmdValue = 0; int cmdCombined = 0; //the cmdgroup as high byte and cmdvalue as low byte diff --git a/speeduino/comms.ino b/speeduino/comms.ino index 8a08c9ba..2e518187 100644 --- a/speeduino/comms.ino +++ b/speeduino/comms.ino @@ -243,15 +243,20 @@ void command() length2 = Serial.read(); // Length to be written (Should always be 1) chunkSize = word(length2, length1); - //chunkPending = true; - for(int i = 0; i < chunkSize; i++) - { - while(Serial.available() == 0) { } //For chunk writes, we can safely loop here - receiveValue( (valueOffset + i), Serial.read()); - } - cmdPending = false; + chunkPending = true; + chunkComplete = 0; } } + //This CANNOT be an else of the above if statement as chunkPending gets set to true above + if(chunkPending == true) + { + while( (Serial.available() > 0) && (chunkComplete < chunkSize) ) + { + receiveValue( (valueOffset + chunkComplete), Serial.read()); + chunkComplete++; + } + if(chunkComplete >= chunkSize) { cmdPending = false; chunkPending = false; } + } break; case 'Z': //Totally non-standard testing function. Will be removed once calibration testing is completed. This function takes 1.5kb of program space! :S