Skip to content

Commit

Permalink
Allow for float values in SD log where supported with FPU
Browse files Browse the repository at this point in the history
  • Loading branch information
noisymime committed Aug 10, 2022
1 parent df2627e commit 16403b4
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 2 deletions.
8 changes: 7 additions & 1 deletion speeduino/SD_logger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,13 @@ void writeSDLogEntry()
//Write the line to the ring buffer
for(byte x=0; x<SD_LOG_NUM_FIELDS; x++)
{
rb.print(getReadableLogEntry(x));
#if FPU_MAX_SIZE >= 32
float entryValue = getReadableFloatLogEntry(x);
if(IS_INTEGER(entryValue)) { rb.print((uint16_t)entryValue); }
else { rb.print(entryValue); }
#else
rb.print(getReadableLogEntry(x));
#endif
if(x < (SD_LOG_NUM_FIELDS - 1)) { rb.print(","); }
}
rb.println("");
Expand Down
1 change: 1 addition & 0 deletions speeduino/board_avr2560.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define COMPARE_TYPE uint16_t
#define COUNTER_TYPE uint16_t
#define SERIAL_BUFFER_SIZE (256+7+1) //Size of the serial buffer used by new comms protocol. The largest single packet is the O2 calibration which is 256 bytes + 7 bytes of overhead
#define FPU_MAX_SIZE 0 //Size of the FPU buffer. 0 means no FPU.
#ifdef USE_SPI_EEPROM
#define EEPROM_LIB_H "src/SPIAsEEPROM/SPIAsEEPROM.h"
typedef uint16_t eeprom_address_t;
Expand Down
1 change: 1 addition & 0 deletions speeduino/board_same51.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define COMPARE_TYPE uint16_t
#define COUNTER_TYPE uint16_t
#define SERIAL_BUFFER_SIZE 257 //Size of the serial buffer used by new comms protocol. Additional 1 byte is for flag
#define FPU_MAX_SIZE 32 //Size of the FPU buffer. 0 means no FPU.
#ifdef USE_SPI_EEPROM
#define EEPROM_LIB_H "src/SPIAsEEPROM/SPIAsEEPROM.h"
typedef uint16_t eeprom_address_t;
Expand Down
1 change: 1 addition & 0 deletions speeduino/board_stm32_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define COMPARE_TYPE uint16_t
#define COUNTER_TYPE uint16_t
#define SERIAL_BUFFER_SIZE 517 //Size of the serial buffer used by new comms protocol. For SD transfers this must be at least 512 + 1 (flag) + 4 (sector)
#define FPU_MAX_SIZE 32 //Size of the FPU buffer. 0 means no FPU.
#define TIMER_RESOLUTION 2
#define micros_safe() micros() //timer5 method is not used on anything but AVR, the micros_safe() macro is simply an alias for the normal micros()
#if defined(SRAM_AS_EEPROM)
Expand Down
1 change: 1 addition & 0 deletions speeduino/board_stm32_official.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define COMPARE_TYPE uint16_t
#define COUNTER_TYPE uint16_t
#define SERIAL_BUFFER_SIZE 517 //Size of the serial buffer used by new comms protocol. For SD transfers this must be at least 512 + 1 (flag) + 4 (sector)
#define FPU_MAX_SIZE 32 //Size of the FPU buffer. 0 means no FPU.
#define micros_safe() micros() //timer5 method is not used on anything but AVR, the micros_safe() macro is simply an alias for the normal micros()
#define TIMER_RESOLUTION 4

Expand Down
1 change: 1 addition & 0 deletions speeduino/board_teensy35.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define COMPARE_TYPE uint16_t
#define COUNTER_TYPE uint16_t
#define SERIAL_BUFFER_SIZE 517 //Size of the serial buffer used by new comms protocol. For SD transfers this must be at least 512 + 1 (flag) + 4 (sector)
#define FPU_MAX_SIZE 32 //Size of the FPU buffer. 0 means no FPU.
#define SD_LOGGING //SD logging enabled by default for Teensy 3.5 as it has the slot built in
#define BOARD_MAX_DIGITAL_PINS 34
#define BOARD_MAX_IO_PINS 34 //digital pins + analog channels + 1
Expand Down
1 change: 1 addition & 0 deletions speeduino/board_teensy41.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define COMPARE_TYPE uint32_t
#define COUNTER_TYPE uint32_t
#define SERIAL_BUFFER_SIZE 517 //Size of the serial buffer used by new comms protocol. For SD transfers this must be at least 512 + 1 (flag) + 4 (sector)
#define FPU_MAX_SIZE 32 //Size of the FPU buffer. 0 means no FPU.
#define BOARD_MAX_DIGITAL_PINS 34
#define BOARD_MAX_IO_PINS 34 //digital pins + analog channels + 1
#define EEPROM_LIB_H <EEPROM.h>
Expand Down
1 change: 1 addition & 0 deletions speeduino/board_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define PORT_TYPE uint32_t //Size of the port variables (Eg inj1_pin_port). Most systems use a byte, but SAMD21 and possibly others are a 32-bit unsigned int
#define PINMASK_TYPE uint32_t
#define SERIAL_BUFFER_SIZE 517 //Size of the serial buffer used by new comms protocol. For SD transfers this must be at least 512 + 1 (flag) + 4 (sector)
#define FPU_MAX_SIZE 0 //Size of the FPU buffer. 0 means no FPU.
#define BOARD_MAX_IO_PINS 52 //digital pins + analog channels + 1
#define BOARD_MAX_DIGITAL_PINS 52 //Pretty sure this isn't right
#define EEPROM_LIB_H <EEPROM.h> //The name of the file that provides the EEPROM class
Expand Down
3 changes: 3 additions & 0 deletions speeduino/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

byte getTSLogEntry(uint16_t);
int16_t getReadableLogEntry(uint16_t);
#if FPU_MAX_SIZE >= 32
float getReadableFloatLogEntry(uint16_t);
#endif
bool is2ByteEntry(uint8_t);

// This array indicates which index values from the log are 2 byte values
Expand Down
33 changes: 32 additions & 1 deletion speeduino/logger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ int16_t getReadableLogEntry(uint16_t logIndex)
case 11: statusValue = currentStatus.iatCorrection; break; //Air temperature Correction (%)
case 12: statusValue = currentStatus.wueCorrection; break; //Warmup enrichment (%)
case 13: statusValue = currentStatus.RPM; break; //rpm HB
case 14: statusValue = currentStatus.AEamount; break; //TPS acceleration enrichment (%) divided by 2 (Can exceed 255)
case 14: statusValue = currentStatus.AEamount; break; //TPS acceleration enrichment (%)
case 15: statusValue = currentStatus.corrections; break; //Total GammaE (%)
case 16: statusValue = currentStatus.VE1; break; //VE 1 (%)
case 17: statusValue = currentStatus.VE2; break; //VE 2 (%)
Expand Down Expand Up @@ -290,6 +290,37 @@ int16_t getReadableLogEntry(uint16_t logIndex)
return statusValue;
}

/**
* An expansion to the @ref getReadableLogEntry function for systems that have an FPU. It will provide a floating point value for any parameter that this is appropriate for, otherwise will return the result of @ref getReadableLogEntry.
* See logger.h for the field names and order
* @param logIndex - The log index required. Note that this is NOT the byte number, but the index in the log
* @return float value of the requested log entry.
*/
#if FPU_MAX_SIZE >= 32
float getReadableFloatLogEntry(uint16_t logIndex)
{
float statusValue = 0.0;

switch(logIndex)
{
case 8: statusValue = currentStatus.battery10 / 10.0; break; //battery voltage
case 9: statusValue = currentStatus.O2 / 10.0; break;
case 18: statusValue = currentStatus.afrTarget / 10.0; break;
case 21: statusValue = currentStatus.TPS / 2.0; break; // TPS (0% to 100% = 0 to 200)
case 33: statusValue = currentStatus.O2_2 / 10.0; break; //O2

case 53: statusValue = currentStatus.PW1 / 1000.0; break; //Pulsewidth 1 Have to convert from uS to mS.
case 54: statusValue = currentStatus.PW2 / 1000.0; break; //Pulsewidth 2 Have to convert from uS to mS.
case 55: statusValue = currentStatus.PW3 / 1000.0; break; //Pulsewidth 3 Have to convert from uS to mS.
case 56: statusValue = currentStatus.PW4 / 1000.0; break; //Pulsewidth 4 Have to convert from uS to mS.

default: statusValue = getReadableLogEntry(logIndex); break; //If logIndex value is NOT a float based one, use the regular function
}

return statusValue;
}
#endif

/**
* Searches the log 2 byte array to determine whether a given index is a regular single byte or a 2 byte field
* Uses a boundless binary search for improved performance, but requires the fsIntIndex to remain in order
Expand Down
1 change: 1 addition & 0 deletions speeduino/maths.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ inline uint32_t div360(uint32_t n) {
}

#define DIV_ROUND_CLOSEST(n, d) ((((n) < 0) ^ ((d) < 0)) ? (((n) - (d)/2)/(d)) : (((n) + (d)/2)/(d)))
#define IS_INTEGER(d) (d == (int32_t)d)

//This is a dedicated function that specifically handles the case of mapping 0-1023 values into a 0 to X range
//This is a common case because it means converting from a standard 10-bit analog input to a byte or 10-bit analog into 0-511 (Eg the temperature readings)
Expand Down

0 comments on commit 16403b4

Please sign in to comment.