diff --git a/speeduino/SD_logger.ino b/speeduino/SD_logger.ino index e8f1d485..1b9b05fa 100644 --- a/speeduino/SD_logger.ino +++ b/speeduino/SD_logger.ino @@ -242,7 +242,13 @@ void writeSDLogEntry() //Write the line to the ring buffer for(byte x=0; x= 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(""); diff --git a/speeduino/board_avr2560.h b/speeduino/board_avr2560.h index b22339a7..3cea1d21 100644 --- a/speeduino/board_avr2560.h +++ b/speeduino/board_avr2560.h @@ -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; diff --git a/speeduino/board_same51.h b/speeduino/board_same51.h index 64eeae2f..e2d8b54f 100644 --- a/speeduino/board_same51.h +++ b/speeduino/board_same51.h @@ -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; diff --git a/speeduino/board_stm32_generic.h b/speeduino/board_stm32_generic.h index 0b301359..ce98e3cd 100644 --- a/speeduino/board_stm32_generic.h +++ b/speeduino/board_stm32_generic.h @@ -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) diff --git a/speeduino/board_stm32_official.h b/speeduino/board_stm32_official.h index 969313e5..47dca806 100644 --- a/speeduino/board_stm32_official.h +++ b/speeduino/board_stm32_official.h @@ -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 diff --git a/speeduino/board_teensy35.h b/speeduino/board_teensy35.h index 88dcf0b1..45e0d789 100644 --- a/speeduino/board_teensy35.h +++ b/speeduino/board_teensy35.h @@ -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 diff --git a/speeduino/board_teensy41.h b/speeduino/board_teensy41.h index bfbe8017..2e489725 100644 --- a/speeduino/board_teensy41.h +++ b/speeduino/board_teensy41.h @@ -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 diff --git a/speeduino/board_template.h b/speeduino/board_template.h index 71cccc3b..cdaf6c5d 100644 --- a/speeduino/board_template.h +++ b/speeduino/board_template.h @@ -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 //The name of the file that provides the EEPROM class diff --git a/speeduino/logger.h b/speeduino/logger.h index 8ad2826b..28ddcfbf 100644 --- a/speeduino/logger.h +++ b/speeduino/logger.h @@ -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 diff --git a/speeduino/logger.ino b/speeduino/logger.ino index 8442ed83..13c74120 100644 --- a/speeduino/logger.ino +++ b/speeduino/logger.ino @@ -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 (%) @@ -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 diff --git a/speeduino/maths.h b/speeduino/maths.h index 1f9f69a9..3c447e28 100644 --- a/speeduino/maths.h +++ b/speeduino/maths.h @@ -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)