From 3e4bf3129e08ffa9ea5d02f5cbec4a48b94f66ad Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Sun, 12 Oct 2014 09:44:42 +1100 Subject: [PATCH] Add in a manual tooth logger read for use with a terminal emulator --- comms.h | 2 ++ comms.ino | 58 +++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/comms.h b/comms.h index c201ad88..ac38d2c6 100644 --- a/comms.h +++ b/comms.h @@ -8,4 +8,6 @@ void sendValues(); void receiveValue(byte offset, byte newValue); void saveConfig(); void sendPage(); +void receiveCalibration(byte tableID); +void sendToothLog(bool useChar); void testComm(); diff --git a/comms.ino b/comms.ino index 40a5d95c..784fc9d7 100644 --- a/comms.ino +++ b/comms.ino @@ -93,24 +93,12 @@ void command() Serial.flush(); break; - case 'T': //Send 256 tooth log entries to TunerStudio - - //We need 256 records to send to TunerStudio. If there aren't that many in the buffer (Buffer is 512 long) then we just return and wait for the next call - //if (toothHistoryIndex < 256) { return; } //Don't believe this is the best way to go. Just display whatever is in the buffer - - int tempToothHistory[512]; //Create a temporary array that will contain a copy of what is in the main toothHistory array - - //Copy the working history into the temporary buffer array. This is done so that, if the history loops whilst the values are being sent over serial, it doesn't affect the values - memcpy( (void*)tempToothHistory, (void*)toothHistory, sizeof(tempToothHistory) ); - toothHistoryIndex = 0; //Reset the history index + case 'T': //Send 256 tooth log entries to Tuner Studios tooth logger + sendToothLog(false); //Sends tooth log values as ints + break; - //Loop only needs to go to 256 (Even though the buffer is 512 long) as we only ever send 256 entries at a time - for(int x=0; x<256; x++) - { - Serial.write(highByte(tempToothHistory[x])); - Serial.write(lowByte(tempToothHistory[x])); - } - Serial.flush(); + case 'r': //Send 256 tooth log entries to a terminal emulator + sendToothLog(true); //Sends tooth log values as chars break; default: @@ -372,6 +360,42 @@ void receiveCalibration(byte tableID) } +/* +Send 256 tooth log entries + * if useChar is true, the values are sent as chars to be printed out by a terminal emulator + * if useChar is false, the values are sent as a 2 byte integer which is readable by TunerStudios tooth logger +*/ +void sendToothLog(bool useChar) +{ + + //We need 256 records to send to TunerStudio. If there aren't that many in the buffer (Buffer is 512 long) then we just return and wait for the next call + if (toothHistoryIndex < 256) { return; } //Don't believe this is the best way to go. Just display whatever is in the buffer + int tempToothHistory[512]; //Create a temporary array that will contain a copy of what is in the main toothHistory array + + //Copy the working history into the temporary buffer array. This is done so that, if the history loops whilst the values are being sent over serial, it doesn't affect the values + memcpy( (void*)tempToothHistory, (void*)toothHistory, sizeof(tempToothHistory) ); + toothHistoryIndex = 0; //Reset the history index + + //Loop only needs to go to 256 (Even though the buffer is 512 long) as we only ever send 256 entries at a time + if (useChar) + { + for(int x=0; x<256; x++) + { + Serial.println(tempToothHistory[x]); + } + } + else + { + for(int x=0; x<256; x++) + { + Serial.write(highByte(tempToothHistory[x])); + Serial.write(lowByte(tempToothHistory[x])); + } + } + Serial.flush(); +} + + void testComm() { Serial.write(1);