2013-07-16 20:09:18 -07:00
/*
This is called when a command is received over serial from TunerStudio / Megatune
It parses the command and calls the relevant function
A detailed description of each call can be found at : http : //www.msextra.com/doc/ms1extra/COM_RS232.htm
*/
2013-07-08 17:43:41 -07:00
void command ( )
{
switch ( Serial . read ( ) )
{
case ' A ' : // send 22 bytes of realtime values
sendValues ( 22 ) ;
break ;
2013-07-16 20:09:18 -07:00
case ' B ' : // Burn current values to eeprom
2013-07-18 04:53:40 -07:00
writeConfig ( ) ;
2013-07-08 17:43:41 -07:00
break ;
2013-07-16 20:09:18 -07:00
case ' C ' : // test communications. This is used by Tunerstudio to see whether there is an ECU on a given serial port
2013-07-08 17:43:41 -07:00
testComm ( ) ;
break ;
case ' P ' : // set the current page
2013-07-16 20:09:18 -07:00
//A 2nd byte of data is required after the 'P' specifying the new page number.
//This loop should never need to run as the byte should already be in the buffer, but is here just in case
while ( Serial . available ( ) = = 0 ) { }
2013-07-09 05:12:35 -07:00
currentPage = Serial . read ( ) ;
2013-07-08 17:43:41 -07:00
break ;
case ' R ' : // send 39 bytes of realtime values
sendValues ( 39 ) ;
break ;
case ' S ' : // send code version
2014-02-06 01:48:19 -08:00
Serial . print ( signature ) ;
2013-07-08 17:43:41 -07:00
break ;
case ' Q ' : // send code version
2014-02-06 01:48:19 -08:00
Serial . print ( signature ) ;
//Serial.write("Speeduino_0_2");
2013-07-08 17:43:41 -07:00
break ;
case ' V ' : // send VE table and constants
sendPage ( ) ;
break ;
case ' W ' : // receive new VE or constant at 'W'+<offset>+<newbyte>
2013-09-15 08:10:16 -07:00
byte offset ;
2013-09-24 06:29:35 -07:00
while ( Serial . available ( ) = = 0 ) { }
2013-09-15 08:10:16 -07:00
offset = Serial . read ( ) ;
while ( Serial . available ( ) = = 0 ) { }
receiveValue ( offset , Serial . read ( ) ) ;
2013-07-08 17:43:41 -07:00
break ;
2014-06-05 18:29:43 -07:00
case ' t ' : // receive new Calibration info. Command structure: "t", <tble_idx> <data array>. This is an MS2/Extra command, NOT part of MS1 spec
2014-05-11 20:42:36 -07:00
byte tableID ;
2014-06-05 18:29:43 -07:00
//byte canID;
2014-05-11 20:42:36 -07:00
2014-05-13 00:46:48 -07:00
//The first 2 bytes sent represent the canID and tableID
while ( Serial . available ( ) = = 0 ) { }
2014-06-05 18:29:43 -07:00
tableID = Serial . read ( ) ; //Not currently used for anything
2014-05-13 00:46:48 -07:00
2014-06-05 18:29:43 -07:00
receiveCalibration ( tableID ) ; //Receive new values and store in memory
2014-05-13 00:46:48 -07:00
writeCalibration ( ) ; //Store received values in EEPROM
2014-05-11 20:42:36 -07:00
break ;
2014-05-13 00:46:48 -07:00
case ' Z ' : //Totally non-standard testing function. Will be removed once calibration testing is completed. This function takes 1.5kb of program space! :S
2014-05-19 22:30:07 -07:00
2014-05-13 00:46:48 -07:00
Serial . println ( " Coolant " ) ;
2014-12-10 15:21:59 -08:00
for ( int x = 0 ; x < CALIBRATION_TABLE_SIZE ; x + + )
2014-05-13 00:46:48 -07:00
{
2014-12-10 15:21:59 -08:00
Serial . print ( x ) ;
2014-05-13 00:46:48 -07:00
Serial . print ( " , " ) ;
2014-12-10 15:21:59 -08:00
Serial . println ( cltCalibrationTable [ x ] ) ;
2014-05-13 00:46:48 -07:00
}
Serial . println ( " Inlet temp " ) ;
2014-12-10 15:21:59 -08:00
for ( int x = 0 ; x < CALIBRATION_TABLE_SIZE ; x + + )
2014-05-11 20:42:36 -07:00
{
2014-12-10 15:21:59 -08:00
Serial . print ( x ) ;
2014-05-13 00:46:48 -07:00
Serial . print ( " , " ) ;
2014-12-10 15:21:59 -08:00
Serial . println ( iatCalibrationTable [ x ] ) ;
2014-05-13 00:46:48 -07:00
}
Serial . println ( " O2 " ) ;
2014-12-10 15:21:59 -08:00
for ( int x = 0 ; x < CALIBRATION_TABLE_SIZE ; x + + )
2014-05-13 00:46:48 -07:00
{
2014-12-10 15:21:59 -08:00
Serial . print ( x ) ;
2014-05-13 00:46:48 -07:00
Serial . print ( " , " ) ;
2014-12-10 15:21:59 -08:00
Serial . println ( o2CalibrationTable [ x ] ) ;
2014-05-11 20:42:36 -07:00
}
2015-01-18 14:10:01 -08:00
Serial . println ( " WUE " ) ;
for ( int x = 0 ; x < 10 ; x + + )
{
Serial . print ( configPage2 . wueBins [ x ] ) ;
Serial . print ( " , " ) ;
Serial . println ( configPage1 . wueValues [ x ] ) ;
}
2014-05-11 20:42:36 -07:00
Serial . flush ( ) ;
break ;
2014-10-11 15:44:42 -07:00
case ' T ' : //Send 256 tooth log entries to Tuner Studios tooth logger
sendToothLog ( false ) ; //Sends tooth log values as ints
break ;
2014-10-02 21:19:37 -07:00
2014-10-11 15:44:42 -07:00
case ' r ' : //Send 256 tooth log entries to a terminal emulator
sendToothLog ( true ) ; //Sends tooth log values as chars
2014-09-21 16:07:34 -07:00
break ;
2013-07-08 17:43:41 -07:00
default :
break ;
}
}
2013-07-16 20:09:18 -07:00
/*
This function returns the current values of a fixed group of variables
*/
2013-07-08 17:43:41 -07:00
void sendValues ( int length )
{
2014-05-12 04:50:02 -07:00
byte packetSize = 28 ;
2014-02-17 22:08:55 -08:00
byte response [ packetSize ] ;
2013-07-08 17:43:41 -07:00
2014-05-08 03:46:38 -07:00
response [ 0 ] = currentStatus . secl ; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0)
2014-01-30 16:52:51 -08:00
response [ 1 ] = currentStatus . squirt ; //Squirt Bitfield
2014-12-22 23:06:00 -08:00
response [ 2 ] = currentStatus . engine ; //Engine Status Bitfield
2013-07-08 17:43:41 -07:00
response [ 3 ] = 0x00 ; //baro
2013-07-09 17:26:16 -07:00
response [ 4 ] = currentStatus . MAP ; //map
2015-01-12 02:23:25 -08:00
response [ 5 ] = ( byte ) ( currentStatus . IAT + CALIBRATION_TEMPERATURE_OFFSET ) ; //mat
response [ 6 ] = ( byte ) ( currentStatus . coolant + CALIBRATION_TEMPERATURE_OFFSET ) ; //Coolant ADC
2014-02-06 01:48:19 -08:00
response [ 7 ] = currentStatus . tpsADC ; //TPS (Raw 0-255)
2014-10-14 17:49:11 -07:00
response [ 8 ] = currentStatus . battery10 ; //battery voltage
2014-09-07 23:56:20 -07:00
response [ 9 ] = currentStatus . O2 ; //O2
2013-07-08 17:43:41 -07:00
response [ 10 ] = 0x00 ; //Exhaust gas correction (%)
response [ 11 ] = 0x00 ; //Air Correction (%)
response [ 12 ] = 0x00 ; //Warmup enrichment (%)
2014-10-09 22:38:34 -07:00
response [ 13 ] = ( byte ) ( div ( currentStatus . RPM , 100 ) . quot ) ; //rpm / 100
response [ 14 ] = ( byte ) ( currentStatus . PW / 200 ) ; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
2013-07-08 17:43:41 -07:00
response [ 15 ] = 0x00 ; //acceleration enrichment (ms)
response [ 16 ] = 0x00 ; //Barometer correction (%)
2014-09-20 15:17:14 -07:00
response [ 17 ] = currentStatus . corrections ; //Total GammaE (%)
2013-07-09 17:26:16 -07:00
response [ 18 ] = currentStatus . VE ; //Current VE 1 (%)
2014-02-06 01:48:19 -08:00
response [ 19 ] = configPage1 . tpsMin ; //Pulsewidth 2 divided by 10 (in ms)
response [ 20 ] = configPage1 . tpsMax ; //Current VE 2 (%)
2014-05-07 05:54:11 -07:00
response [ 21 ] = currentStatus . tpsDOT ; //TPS DOT
2013-09-24 21:56:38 -07:00
response [ 22 ] = currentStatus . advance ;
2014-02-06 01:48:19 -08:00
response [ 23 ] = currentStatus . TPS ; // TPS (0% to 100%)
2014-05-07 05:54:11 -07:00
//Need to split the int loopsPerSecond value into 2 bytes
2014-05-19 22:30:07 -07:00
response [ 24 ] = highByte ( currentStatus . loopsPerSecond ) ;
response [ 25 ] = lowByte ( currentStatus . loopsPerSecond ) ;
2014-05-12 04:50:02 -07:00
2014-05-12 04:27:58 -07:00
//The following can be used to show the amount of free memory
int mem = freeRam ( ) ;
2014-05-12 04:50:02 -07:00
response [ 26 ] = highByte ( mem ) ; //(byte)((currentStatus.loopsPerSecond >> 8) & 0xFF);
response [ 27 ] = lowByte ( mem ) ;
2014-09-08 16:39:20 -07:00
//response[26] = highByte(cltCalibrationTable.axisX16[0]); //(byte)((currentStatus.loopsPerSecond >> 8) & 0xFF);
//response[27] = lowByte(cltCalibrationTable.axisX16[0]);
2013-07-08 17:43:41 -07:00
2014-02-17 22:08:55 -08:00
Serial . write ( response , ( size_t ) packetSize ) ;
2013-09-15 08:10:16 -07:00
Serial . flush ( ) ;
2013-07-08 17:43:41 -07:00
return ;
}
2013-07-18 00:26:24 -07:00
void receiveValue ( byte offset , byte newValue )
{
2013-07-18 03:36:36 -07:00
byte * pnt_configPage ;
switch ( currentPage )
{
case vePage :
2013-07-19 04:02:19 -07:00
pnt_configPage = ( byte * ) & configPage1 ; //Setup a pointer to the relevant config page
2013-07-18 03:36:36 -07:00
if ( offset < 64 ) //New value is part of the fuel map
{
2013-07-19 04:02:19 -07:00
fuelTable . values [ 7 - offset / 8 ] [ offset % 8 ] = newValue ;
2013-09-15 05:39:55 -07:00
return ;
2013-07-18 03:36:36 -07:00
}
else if ( offset < 80 ) //New value is one of the X or Y axis bins
{
2013-07-19 04:02:19 -07:00
//Check whether this is on the X (RPM) or Y (MAP/TPS) axis
if ( offset < 72 )
{
//X Axis
2013-09-15 05:39:55 -07:00
fuelTable . axisX [ ( offset - 64 ) ] = ( int ( newValue ) * 100 ) ; //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct
2013-07-19 04:02:19 -07:00
}
else
{
//Y Axis
offset = 7 - ( offset - 72 ) ; //Need to do a translation to flip the order (Due to us using (0,0) in the top left rather than bottom right
2013-09-15 08:10:16 -07:00
fuelTable . axisY [ offset ] = int ( newValue ) ;
2013-07-19 04:02:19 -07:00
}
2013-09-15 05:39:55 -07:00
return ;
2013-07-18 03:36:36 -07:00
}
else //New value is one of the remaining config items
{
2013-09-15 17:18:33 -07:00
//For some reason, TunerStudio is sending offsets greater than the maximum page size. I'm not sure if it's their bug or mine, but the fix is to only update the config page if the offset is less than the maximum size
if ( offset < page_size )
{
* ( pnt_configPage + byte ( offset - 80 ) ) = newValue ; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages
}
2013-09-15 05:39:55 -07:00
return ;
2013-07-18 03:36:36 -07:00
}
break ;
case ignPage : //Ignition settings page (Page 2)
pnt_configPage = ( byte * ) & configPage2 ;
if ( offset < 64 ) //New value is part of the ignition map
{
2013-07-19 04:02:19 -07:00
ignitionTable . values [ 7 - offset / 8 ] [ offset % 8 ] = newValue ;
2013-09-15 08:10:16 -07:00
return ;
2013-07-18 03:36:36 -07:00
}
else if ( offset < 80 ) //New value is one of the X or Y axis bins
{
2013-07-19 04:02:19 -07:00
//Check whether this is on the X (RPM) or Y (MAP/TPS) axis
if ( offset < 72 )
{
//X Axis
2013-09-15 08:10:16 -07:00
ignitionTable . axisX [ ( offset - 64 ) ] = int ( newValue ) * int ( 100 ) ; //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct
2013-07-19 04:02:19 -07:00
}
else
{
2013-09-15 08:10:16 -07:00
2013-07-19 04:02:19 -07:00
//Y Axis
offset = 7 - ( offset - 72 ) ; //Need to do a translation to flip the order
2013-09-15 08:10:16 -07:00
ignitionTable . axisY [ offset ] = int ( newValue ) ;
2013-07-19 04:02:19 -07:00
}
2013-09-15 08:10:16 -07:00
return ;
2013-07-18 03:36:36 -07:00
}
else //New value is one of the remaining config items
{
2013-09-15 17:18:33 -07:00
//For some reason, TunerStudio is sending offsets greater than the maximum page size. I'm not sure if it's their bug or mine, but the fix is to only update the config page if the offset is less than the maximum size
if ( offset < page_size )
{
* ( pnt_configPage + byte ( offset - 80 ) ) = newValue ; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages
}
2013-09-15 08:10:16 -07:00
return ;
2013-07-18 03:36:36 -07:00
}
break ;
default :
break ;
}
2013-07-18 00:26:24 -07:00
}
2013-08-25 21:11:47 -07:00
/*
sendPage ( ) packs the data within the current page ( As set with the ' P ' command )
into a buffer and sends it .
Note that some translation of the data is required to lay it out in the way Megasqurit / TunerStudio expect it
*/
2013-07-08 17:43:41 -07:00
void sendPage ( )
{
2013-07-18 03:36:36 -07:00
byte response [ page_size ] ;
2013-07-18 00:26:24 -07:00
byte offset ;
byte * pnt_configPage ;
2013-07-08 21:06:45 -07:00
2013-09-14 04:29:21 -07:00
switch ( currentPage )
2013-07-08 21:06:45 -07:00
{
case vePage :
2013-07-09 05:12:35 -07:00
//Need to perform a translation of the values[MAP/TPS][RPM] into the MS expected format
2013-07-16 20:09:18 -07:00
//MS format has origin (0,0) in the bottom left corner, we use the top left for efficiency reasons
2013-08-25 21:11:47 -07:00
for ( byte x = 0 ; x < 64 ; x + + ) { response [ x ] = fuelTable . values [ 7 - x / 8 ] [ x % 8 ] ; } //This is slightly non-intuitive, but essentially just flips the table vertically (IE top line becomes the bottom line etc). Columns are unchanged
2013-09-14 04:29:21 -07:00
for ( byte x = 64 ; x < 72 ; x + + ) { response [ x ] = byte ( fuelTable . axisX [ ( x - 64 ) ] / 100 ) ; } //RPM Bins for VE table (Need to be dvidied by 100)
2013-09-15 08:10:16 -07:00
for ( byte y = 72 ; y < 80 ; y + + ) { response [ y ] = byte ( fuelTable . axisY [ 7 - ( y - 72 ) ] ) ; } //MAP or TPS bins for VE table
2013-07-18 00:26:24 -07:00
//All other bytes can simply be copied from the config table
pnt_configPage = ( byte * ) & configPage1 ; //Create a pointer to Page 1 in memory
offset = 80 ; //Offset is based on the amount already copied above (table + bins)
2013-09-14 04:29:21 -07:00
2013-07-18 03:36:36 -07:00
for ( byte x = offset ; x < page_size ; x + + )
2013-07-18 00:26:24 -07:00
{
2013-09-15 17:18:33 -07:00
response [ x ] = * ( pnt_configPage + byte ( x - offset ) ) ; //Each byte is simply the location in memory of configPage1 + the offset + the variable number (x)
2013-07-18 00:26:24 -07:00
}
2013-07-18 03:36:36 -07:00
Serial . write ( ( byte * ) & response , sizeof ( response ) ) ;
2013-09-15 08:10:16 -07:00
Serial . flush ( ) ;
2013-07-08 21:06:45 -07:00
break ;
2013-07-10 04:18:18 -07:00
2013-07-08 21:06:45 -07:00
case ignPage :
2013-07-09 05:12:35 -07:00
//Need to perform a translation of the values[MAP/TPS][RPM] into the MS expected format
for ( byte x = 0 ; x < 64 ; x + + ) { response [ x ] = ignitionTable . values [ 7 - x / 8 ] [ x % 8 ] ; }
2013-09-15 08:10:16 -07:00
for ( byte x = 64 ; x < 72 ; x + + ) { response [ x ] = byte ( ignitionTable . axisX [ ( x - 64 ) ] / 100 ) ; }
for ( byte y = 72 ; y < 80 ; y + + ) { response [ y ] = byte ( ignitionTable . axisY [ 7 - ( y - 72 ) ] ) ; }
2013-07-08 21:06:45 -07:00
2013-07-18 00:26:24 -07:00
//All other bytes can simply be copied from the config table
2013-07-18 03:36:36 -07:00
pnt_configPage = ( byte * ) & configPage2 ; //Create a pointer to Page 2 in memory
2013-07-18 00:26:24 -07:00
offset = 80 ; //Offset is based on the amount already copied above (table + bins)
2013-07-18 03:36:36 -07:00
for ( byte x = offset ; x < page_size ; x + + )
2013-07-18 00:26:24 -07:00
{
2013-09-17 23:45:53 -07:00
response [ x ] = * ( pnt_configPage + byte ( x - offset ) ) ; //Each byte is simply the location in memory of configPage2 + the offset + the variable number (x)
2013-07-18 00:26:24 -07:00
}
Serial . write ( ( byte * ) & response , sizeof ( response ) ) ;
2013-09-15 08:10:16 -07:00
Serial . flush ( ) ;
2013-07-10 04:18:18 -07:00
break ;
2013-07-08 21:06:45 -07:00
default :
break ;
}
2013-07-08 17:43:41 -07:00
return ;
}
2014-05-11 20:42:36 -07:00
/*
This function is used to store calibration data sent by Tuner Studio .
*/
2014-05-13 00:46:48 -07:00
void receiveCalibration ( byte tableID )
2014-05-11 20:42:36 -07:00
{
2014-12-10 15:21:59 -08:00
byte * pnt_TargetTable ; //Pointer that will be used to point to the required target table
2015-01-09 17:21:14 -08:00
int OFFSET , DIVISION_FACTOR , BYTES_PER_VALUE ;
2014-12-15 05:34:02 -08:00
switch ( tableID )
2014-05-13 00:46:48 -07:00
{
2014-12-15 05:34:02 -08:00
case 0 :
//coolant table
pnt_TargetTable = ( byte * ) & cltCalibrationTable ;
2014-12-22 23:06:00 -08:00
OFFSET = CALIBRATION_TEMPERATURE_OFFSET ; //
DIVISION_FACTOR = 10 ;
2015-01-09 17:21:14 -08:00
BYTES_PER_VALUE = 2 ;
2014-12-15 05:34:02 -08:00
break ;
case 1 :
//Inlet air temp table
pnt_TargetTable = ( byte * ) & iatCalibrationTable ;
2014-12-22 23:06:00 -08:00
OFFSET = CALIBRATION_TEMPERATURE_OFFSET ;
DIVISION_FACTOR = 10 ;
2015-01-09 17:21:14 -08:00
BYTES_PER_VALUE = 2 ;
2014-12-15 05:34:02 -08:00
break ;
case 2 :
//O2 table
pnt_TargetTable = ( byte * ) & o2CalibrationTable ;
2014-12-22 23:06:00 -08:00
OFFSET = 0 ;
DIVISION_FACTOR = 1 ;
2015-01-09 17:21:14 -08:00
o2CalibrationTable [ 10 ] = 123 ;
BYTES_PER_VALUE = 1 ;
2014-12-15 05:34:02 -08:00
break ;
default :
return ; //Should never get here, but if we do, just fail back to main loop
//pnt_TargetTable = (table2D *)&o2CalibrationTable;
//break;
2014-05-13 00:46:48 -07:00
}
2014-12-15 05:34:02 -08:00
2014-12-10 15:21:59 -08:00
//1024 value pairs are sent. We have to receive them all, but only use every second one (We only store 512 calibratino table entries to save on EEPROM space)
//The values are sent as 2 byte ints, but we convert them to single bytes. Any values over 255 are capped at 255.
2014-12-15 05:34:02 -08:00
int tempValue ;
2014-12-22 23:06:00 -08:00
byte tempBuffer [ 2 ] ;
2014-12-10 15:21:59 -08:00
bool every2nd = true ;
2014-12-15 05:34:02 -08:00
int x ;
int counter = 0 ;
2014-12-22 23:06:00 -08:00
pinMode ( 13 , OUTPUT ) ;
2015-01-09 14:56:14 -08:00
2014-12-22 23:06:00 -08:00
digitalWrite ( 13 , LOW ) ;
for ( x = 0 ; x < 1024 ; x + + )
2014-05-13 00:46:48 -07:00
{
2015-01-09 17:21:14 -08:00
//UNlike what is listed in the protocol documentation, the O2 sensor values are sent as bytes rather than ints
if ( BYTES_PER_VALUE = = 1 )
{
while ( Serial . available ( ) < 1 ) { }
tempValue = Serial . read ( ) ;
}
else
{
while ( Serial . available ( ) < 2 ) { }
tempBuffer [ 0 ] = Serial . read ( ) ;
tempBuffer [ 1 ] = Serial . read ( ) ;
tempValue = div ( int ( word ( tempBuffer [ 0 ] , tempBuffer [ 1 ] ) ) , DIVISION_FACTOR ) . quot ; //Read 2 bytes, convert to word (an unsigned int), convert to signed int. These values come through * 10 from Tuner Studio
2015-01-12 04:23:43 -08:00
tempValue = ( ( tempValue - 32 ) * 5 ) / 9 ; //Convert from F to C
2015-01-09 17:21:14 -08:00
}
2014-12-22 23:06:00 -08:00
tempValue = tempValue + OFFSET ;
2014-12-10 15:21:59 -08:00
if ( every2nd ) //Only use every 2nd value
2014-05-13 00:46:48 -07:00
{
2014-12-15 05:34:02 -08:00
if ( tempValue > 255 ) { tempValue = 255 ; } // Cap the maximum value to prevent overflow when converting to byte
if ( tempValue < 0 ) { tempValue = 0 ; }
2015-01-09 17:21:14 -08:00
2015-01-09 14:56:14 -08:00
pnt_TargetTable [ ( x / 2 ) ] = ( byte ) tempValue ;
2014-12-22 23:06:00 -08:00
int y = EEPROM_CALIBRATION_O2 + counter ;
2014-12-15 05:34:02 -08:00
2014-12-10 15:21:59 -08:00
every2nd = false ;
2014-12-22 23:06:00 -08:00
analogWrite ( 13 , ( counter % 50 ) ) ;
2014-12-15 05:34:02 -08:00
counter + + ;
2014-05-13 00:46:48 -07:00
}
2015-01-09 17:21:14 -08:00
else { every2nd = true ; }
2014-12-15 05:34:02 -08:00
2014-05-13 00:46:48 -07:00
}
2015-01-09 14:56:14 -08:00
2014-05-11 20:42:36 -07:00
}
2014-10-11 15:44:42 -07:00
/*
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 ( ) ;
}
2013-07-08 17:43:41 -07:00
void testComm ( )
{
Serial . write ( 1 ) ;
return ;
}