From 93de5eecda3bc288394da73b998331080694e877 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Mon, 4 Oct 2021 00:09:53 +1100 Subject: [PATCH] Initial work on common SDFat library. Implements much of the layout and settings from #543 --- reference/speeduino.ini | 139 ++++++++++++++++++- speeduino/SD_logger.h | 17 ++- speeduino/SD_logger.ino | 70 +++++++--- speeduino/acc_mc33810.ino | 3 +- speeduino/board_teensy35.h | 1 + speeduino/comms.cpp | 171 +---------------------- speeduino/comms.h | 1 - speeduino/globals.h | 43 +++++- speeduino/logger.h | 2 +- speeduino/logger.ino | 271 +++++++++++++++++++++---------------- speeduino/rtc_common.ino | 8 +- speeduino/utilities.ino | 5 +- 12 files changed, 402 insertions(+), 329 deletions(-) diff --git a/reference/speeduino.ini b/reference/speeduino.ini index 88ff42e2..0c7a552b 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -1288,7 +1288,30 @@ page = 13 secondCompType7 = bits, U08, 89, [3:5], $comparator_def bitwise7 = bits, U08, 89, [6:7], $bitwise_def candID = array, U16, 90, [ 8], "", 1.0, 0.0, 0.0, 255.0, 0 - unused12_106_127= array, U08, 106, [ 22], "%", 1.0, 0.0, 0.0, 255, 0 + unused12_106_115= array, U08, 106, [ 10], "%", 1.0, 0.0, 0.0, 255, 0 + + ;RTC and onboard logging stuff + onboard_log_csv_separator = bits, U08, 116, [0:1], ";", ",", "tab", "space" + onboard_log_file_style = bits, U08, 116, [2:3], "Disabled", "CSV", "Binary", "INVALID" ;Future maybe more file types. + onboard_log_file_rate = bits, U08, 116, [4:5], "1Hz", "4Hz", "10Hz", "30Hz" + onboard_log_filenaming = bits, U08, 116, [6:7], "Overwrite", "Date-time", "Sequential", "INVALID" + onboard_log_storage = bits, U08, 117, [0:1], "sd-card", "INVALID", "INVALID", "INVALID" ;In the future maybe an onboard spi flash can be used, or switch between SDIO vs SPI sd card interfaces. + onboard_log_trigger_boot = bits, U08, 117, [2:2], "Disabled", "On boot" + onboard_log_trigger_RPM = bits, U08, 117, [3:3], "Disabled", "Enabled" + onboard_log_trigger_prot = bits, U08, 117, [4:4], "Disabled", "Enabled" + onboard_log_trigger_Vbat = bits, U08, 117, [5:5], "Disabled", "Enabled" + onboard_log_trigger_Epin = bits, U08, 117, [6:7], "Disabled", "polling", "toggle" , "INVALID" + onboard_log_tr2_thr_on = scalar, U08, 118, "RPM", 100.0, 0.0, 0, 10000, 0 + onboard_log_tr2_thr_off = scalar, U08, 119, "RPM", 100.0, 0.0, 0, 10000, 0 + onboard_log_tr3_thr_RPM = bits, U08, 120, [0:0], "Disabled", "Enabled" + onboard_log_tr3_thr_MAP = bits, U08, 120, [1:1], "Disabled", "Enabled" + onboard_log_tr3_thr_Oil = bits, U08, 120, [2:2], "Disabled", "Enabled" + onboard_log_tr3_thr_AFR = bits, U08, 120, [3:3], "Disabled", "Enabled" + onboard_log_tr4_thr_on = scalar, U08, 121, "V", 0.1, 0.0, 0.0, 15.90, 2 ; * ( 1 byte) + onboard_log_tr4_thr_off = scalar, U08, 122, "V", 0.1, 0.0, 0.0, 14.90, 2 ; * ( 1 byte) + onboard_log_tr5_thr_on = scalar, U08, 123, "pin", 1.0, 0.0, 0.0, 255, 0 ; + + unused12_125_127 = array, U08, 124, [4], "%", 1.0, 0.0, 0.0, 255, 0 ;-------------------------------------------------- ;Second ignition map (Page 14) @@ -1530,6 +1553,27 @@ page = 14 defaultValue = fuel2LoadMax, 511 defaultValue = ign2LoadMax, 511 + ;SD / RTC related + defaultValue = rtc_mode, 0 + defaultValue = onboard_log_file_rate, 4 + defaultValue = onboard_log_filenaming, 0 + defaultValue = onboard_log_storage, 0 + defaultValue = onboard_log_trigger_boot, 0 + defaultValue = onboard_log_trigger_RPM, 0 + defaultValue = onboard_log_trigger_prot, 0 + defaultValue = onboard_log_trigger_Vbat, 0 + defaultValue = onboard_log_trigger_Epin, 0 + defaultValue = onboard_log_tr2_thr_on, 600 + defaultValue = onboard_log_tr2_thr_off,400 + defaultValue = onboard_log_tr3_thr_RPM, 0 + defaultValue = onboard_log_tr3_thr_MAP, 0 + defaultValue = onboard_log_tr3_thr_Oil, 0 + defaultValue = onboard_log_tr3_thr_AFR, 0 + defaultValue = onboard_log_tr4_thr_on, 12.5 + defaultValue = onboard_log_tr4_thr_off, 7.0 + defaultValue = onboard_log_tr5_thr_on, 0 + defaultValue = onboard_log_csv_separator, 0 + ;VSS related settings defaultValue = vssRatio1, 10.0 defaultValue = vssRatio2, 16.0 @@ -1731,8 +1775,10 @@ menuDialog = main subMenu = sensorFilters, "Set analog sensor filters" menu = "Data Logging" - ;subMenu = sdcard_datalog, "SD Card Datalogging" - ;subMenu = std_ms3SdConsole, "Browse / Import SD Card", { boardHasRTC > 0 } + ;subMenu = sdcard_datalog, "SD Card Datalogging" + ;subMenu = std_ms3SdConsole, "Browse / Import SD Card", { boardHasRTC > 0 } + subMenu = rtc_settings, "Setup realtime clock" + subMenu = onboard_log_setup, "Setup onboard logger" menuDialog = main menu = "3D &Tuning Maps" @@ -2111,6 +2157,27 @@ menuDialog = main #endif resetControlPin = "The Arduino pin used to control resets." + rtc_mode = "Enables the real time clock for time keeping" + onboard_log_file_style = "Sdcard datalogger can be Disabled, CSV=Comma seperated values, Binary is a Binary format equal to the A comand style current status" + onboard_log_file_rate = "Rate at wich data is recorded to the logger storage" + onboard_log_filenaming = "[Overwrite] the file is over written every time the a new log is started, [Date-time] creates a new file in the format YYMMDD-HHMMSS every datalog start, [Seqential] numbers the filenames + 1 on every datalog start" + onboard_log_storage = "Only [sd-card] as datastorage is implemented at the moment, A FAT16 or FAT32 formatted sd card can be used" + onboard_log_trigger_boot = "[On boot] the logger is started immediately on boot of the board" + onboard_log_trigger_RPM = "[RPM] the logger is started when RPM is above the on treshold and stopped below the off threshold" + onboard_log_trigger_prot = "[engine protection] the logger is started one of the corresponding bits in the engine protection is set" + onboard_log_trigger_Vbat = "[Battery Voltage] the logger is started when the battery voltage is above the on treshold and stopped below the off threshold" + onboard_log_trigger_Epin = "[Ext pin [polling]] the logger is running for as long the chosen pin is high and stopped when it is low. When set to [Ext pin [toggle]] the logger is toggled on/off with a pulse on this chosen pin number" + onboard_log_tr2_thr_on = "When the engine RPM is above this threshold the datalogger is started" + onboard_log_tr2_thr_off = "When the engine RPM is below this threshold the datalogger is stopped" + onboard_log_tr3_thr_RPM = "When the bits of the RPM engine protetion function are set the datalogger is started when no set anymore the logger is stopped" + onboard_log_tr3_thr_MAP = "When the bits of the MAP engine protetion function are set the datalogger is started when no set anymore the logger is stopped" + onboard_log_tr3_thr_Oil = "When the bits of the Oil engine protetion function are set the datalogger is started when no set anymore the logger is stopped" + onboard_log_tr3_thr_AFR = "When the bits of the AFR engine protetion function are set the datalogger is started when no set anymore the logger is stopped" + onboard_log_tr4_thr_on = "When the measured battery voltage is above this threshold the datalogger is started" + onboard_log_tr4_thr_off = "When the measured battery voltage is below this threshold the datalogger is stopped" + onboard_log_tr5_thr_on = "The pin to trigger the datalogger start/stop" + onboard_log_csv_separator = "Choose what character is used for the CSV separator between fields" + battVCorMode = "The Battery Voltage Correction value from the table below can either be applied on the whole injection Pulse Width value, or only on the Open Time value." dwellTable = "Sets the dwell time in milliseconds based on RPM/load. This can be used to reduce stress/wear on ignition system where long dwell is not needed. And other areas can use longer dwell value if needed for stronger spark. Battery voltage correction is applied for these dwell values." useDwellMap = "In normal operation mode this is set to No and speeduino will use fixed running dwell value. But if different dwell values are required across engine RPM/load range, this can be set to Yes and separate Dwell table defines running dwell value." @@ -3875,9 +3942,63 @@ menuDialog = main field = "Real Time Clock mode", rtc_mode field = "Real Time Clock Trim +/-", rtc_trim, {rtc_mode} - dialog = rtc_settings, "Real Time Clock" - panel = rtc_setup - panel = std_ms3Rtc +; dialog = rtc_settings, "Real Time Clock" +; panel = rtc_setup +; panel = std_ms3Rtc + + dialog = onboard_log_basic_setup, "Basics" + field = "Logger type", onboard_log_file_style + field = "CSV separator", onboard_log_csv_separator {onboard_log_file_style == 1} + field = "Log rate", onboard_log_file_rate {onboard_log_file_style} + field = "Filename", onboard_log_filenaming {onboard_log_file_style} + ; field = "Storage", onboard_log_storage {onboard_log_file_style} + + dialog = onboard_log_trigger_boot, "On boot" + field = "Boot", onboard_log_trigger_boot {onboard_log_file_style} + +; dialog = onboard_log_trigger_RPM, "RPM" +; field = "RPM", onboard_log_trigger_RPM {onboard_log_file_style && !onboard_log_trigger_boot} +; field = "ON threshold", onboard_log_tr2_thr_on {onboard_log_file_style && onboard_log_trigger_RPM} +; field = "OFF threshold", onboard_log_tr2_thr_off {onboard_log_file_style && onboard_log_trigger_RPM} + +; dialog = onboard_log_trigger_prot, "Engine protection" +; field = "Engine protection", onboard_log_trigger_prot {onboard_log_file_style&& !onboard_log_trigger_boot} +; field = "RPM", onboard_log_tr3_thr_RPM {onboard_log_file_style && onboard_log_trigger_prot} +; field = "MAP", onboard_log_tr3_thr_MAP {onboard_log_file_style && onboard_log_trigger_prot} +; field = "Oil", onboard_log_tr3_thr_Oil {onboard_log_file_style && onboard_log_trigger_prot} +; field = "AFR", onboard_log_tr3_thr_AFR {onboard_log_file_style && onboard_log_trigger_prot} + +; dialog = onboard_log_trigger_Vbat, "Battery voltage" +; field = "Battery voltage", onboard_log_trigger_Vbat {onboard_log_file_style&& !onboard_log_trigger_boot} +; field = "ON threshold", onboard_log_tr4_thr_on {onboard_log_file_style && onboard_log_trigger_Vbat} +; field = "OFF threshold", onboard_log_tr4_thr_off {onboard_log_file_style && onboard_log_trigger_Vbat} + +; dialog = onboard_log_trigger_Epin, "Board pin" +; field = "Board pin", onboard_log_trigger_Epin {onboard_log_file_style&& !onboard_log_trigger_boot} +; field = "Pin number", onboard_log_tr5_thr_on {onboard_log_file_style && onboard_log_trigger_Epin} + + dialog = rtc_settings, "Real Time Clock" + field = "Mode", rtc_mode + panel = std_ms3Rtc {rtc_mode} + + dialog = onboard_log_trigger, "Triggers" + field = "On Boot", onboard_log_trigger_boot + field = "Above RPM", onboard_log_trigger_RPM + field = "With Engine Protection", onboard_log_trigger_prot + field = "With battery", onboard_log_trigger_Vbat + + dialog = onboard_log_setup, "On-board logger", border + panel = onboard_log_basic_setup, North + panel = onboard_log_trigger, South + + dialog = engine_constants, "", border + panel = engine_constants_warning, North + panel = engine_constants_west, West + panel = engine_constants_east, East + +; dialog = sdcard_datalog, "SD Card Datalogging", yAxis +; panel = sdcard_top +; panel = dataLogFieldSelector ;------------------------------------------------------------------------------- @@ -4602,6 +4723,12 @@ cmdVSSratio6 = "E\x99\x06" indicator = { outputsStatus6 }, "Programmable out 7 Off", "Programmable out 7 ON", white, black, green, black indicator = { outputsStatus7 }, "Programmable out 8 Off", "Programmable out 8 ON", white, black, green, black + ;sd card indicators + indicator = { sd_status & 1}, "SD ready", "SD ready", white, black, green, black + indicator = { sd_status & 2}, "no SD", "SD in", white, black, green, black + indicator = { sd_status & 4}, "SD Log", "SD Log", white, black, green, black + indicator = { sd_status & 8}, "SD Err", "SD Err", white, black, red, black + ;------------------------------------------------------------------------------- [OutputChannels] diff --git a/speeduino/SD_logger.h b/speeduino/SD_logger.h index cc7fc91a..a1cd013a 100644 --- a/speeduino/SD_logger.h +++ b/speeduino/SD_logger.h @@ -3,14 +3,18 @@ #ifdef SD_LOGGING -#include #include +#include "RingBuf.h" #define SD_STATUS_OFF 0 #define SD_STATUS_READY 1 #define SD_STATUS_ERROR_NO_CARD 2 #define SD_STATUS_ERROR_NO_FS 3 #define SD_STATUS_ERROR_NO_WRITE 4 +#define SD_STATUS_ERROR_NO_SPACE 5 +#define SD_STATUS_ERROR_WRITE_FAIL 6 + +#define SD_SECTOR_SIZE 512 // Standard SD sector size #ifdef CORE_TEENSY #define SD_CS_PIN BUILTIN_SDCARD @@ -18,9 +22,8 @@ #define SD_CS_PIN 10 //This is a made up value for now #endif -Sd2Card SD_card; -SdVolume SD_volume; -File logFile; +SdFs sd; +FsFile logFile; uint8_t SD_status = SD_STATUS_OFF; @@ -29,5 +32,11 @@ void writeSDLogEntry(); void endSD(); void setTS_SD_status(); +//Test values only +#define SD_LOG_FILE_SIZE 10000000 //Defuault 10mb file size +#define LOG_FILENAME "SdioLogger.csv" +#define RING_BUF_CAPACITY SD_LOG_ENTRY_SIZE * 10 //Allow for 10 entries in the ringbuffer. Will need tuning +RingBuf rb; + #endif //SD_LOGGING #endif //SD_H diff --git a/speeduino/SD_logger.ino b/speeduino/SD_logger.ino index 5f7eeb58..5d176b3f 100644 --- a/speeduino/SD_logger.ino +++ b/speeduino/SD_logger.ino @@ -6,22 +6,31 @@ void initSD() { - //Init the SPI connection to the card reader - //if (SD_card.begin(SD_CS_PIN)) - if (SD_card.init(SPI_HALF_SPEED, SD_CS_PIN)) + //Set default state to ready. If any stage of the init fails, this will be changed + SD_status = SD_STATUS_READY; + + // Initialize the SD. + if (!sd.begin(SD_CONFIG)) { - //Check for usable FAT32 volume - if (SD_volume.init(SD_card)) - { - //Attempt to create a log file for writing - //logFile = SD_card.open("datalog.csv", FILE_WRITE); - //if(!logFile) { SD_status = SD_STATUS_ERROR_NO_WRITE; } //Cannot write to SD card - //else { SD_status = SD_STATUS_READY; - SD_status = SD_STATUS_READY; - } - else { SD_status = SD_STATUS_ERROR_NO_FS; } - } - else { SD_status = SD_STATUS_ERROR_NO_CARD; } + //sd.initErrorHalt(&Serial); + //if (sdErrorCode() == SD_CARD_ERROR_CMD0) { SD_status = SD_STATUS_ERROR_NO_CARD; + SD_status = SD_STATUS_ERROR_NO_CARD; + } + + // Open or create file - truncate existing file. + if (!logFile.open(LOG_FILENAME, O_RDWR | O_CREAT | O_TRUNC)) + { + SD_status = SD_STATUS_ERROR_NO_WRITE; + } + + //Perform pre-allocation on card. This dramatically inproves write speed + if (!logFile.preAllocate(SD_LOG_FILE_SIZE)) + { + SD_status = SD_STATUS_ERROR_NO_SPACE; + } + + //initialize the RingBuf. + rb.begin(&logFile); //Write a header row if(SD_status == SD_STATUS_READY) @@ -35,19 +44,38 @@ void initSD() void endSD() { - + // Write any RingBuf data to file. + rb.sync(); + logFile.truncate(); + logFile.rewind(); + logFile.close(); } void writeSDLogEntry() { - //uint8_t logEntry[LOG_ENTRY_SIZE]; + //uint8_t logEntry[LOG_ENTRY_SIZE]; - if(SD_status == SD_STATUS_READY) + if(SD_status == SD_STATUS_READY) + { + for(byte x=0; x= SD_SECTOR_SIZE) && !logFile.isBusy() ) + { + uint16_t bytesWritten = rb.writeOut(SD_SECTOR_SIZE); + //Make sure that the entire sector was written successfully + if (SD_SECTOR_SIZE != bytesWritten) + { + SD_status = SD_STATUS_ERROR_WRITE_FAIL; + } + } } //Sets the status variable for TunerStudio diff --git a/speeduino/acc_mc33810.ino b/speeduino/acc_mc33810.ino index c4a041ad..34aa1796 100644 --- a/speeduino/acc_mc33810.ino +++ b/speeduino/acc_mc33810.ino @@ -14,9 +14,8 @@ void initMC33810() pinMode(pinMC33810_2_CS, OUTPUT); SPI.begin(); - //These are the 'correct' SPI settings per the datasheet + //These are the SPI settings per the datasheet SPI.beginTransaction(SPISettings(6000000, MSBFIRST, SPI_MODE0)); - //SPI.beginTransaction(SPISettings(1200000, MSBFIRST, SPI_MODE3)); //This doesn't appear to align with the datasheet (In terms of the SPI mode), but appears to work more reliably. More testing needed //Set the ignition outputs to GPGD mode /* diff --git a/speeduino/board_teensy35.h b/speeduino/board_teensy35.h index ce8956fc..10d1a515 100644 --- a/speeduino/board_teensy35.h +++ b/speeduino/board_teensy35.h @@ -25,6 +25,7 @@ #endif #define RTC_ENABLED #define RTC_LIB_H "TimeLib.h" + #define SD_CONFIG SdioConfig(FIFO_SDIO) //Set Teensy to use SDIO in FIFO mode. This is the fastest SD mode on Teensy as it offloads most of the writes #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 pinIsReserved(pin) ( ((pin) == 0) || ((pin) == 1) || ((pin) == 3) || ((pin) == 4) ) //Forbiden pins like USB diff --git a/speeduino/comms.cpp b/speeduino/comms.cpp index 6b40986d..6d0fc189 100644 --- a/speeduino/comms.cpp +++ b/speeduino/comms.cpp @@ -18,6 +18,7 @@ A full copy of the license may be found in the projects root directory #include "pages.h" #include "page_crc.h" #include "table_iterator.h" +#include "logger.h" #ifdef RTC_ENABLED #include "rtc_common.h" #endif @@ -757,172 +758,6 @@ void command() break; } } -/** Send a numbered byte-field (partial field in case of mul;ti-byte fields) from "current status" structure. - * Notes on fields: - * - Numbered field will be fields from @ref currentStatus, but not at all in the internal order of strct (e.g. field RPM value, number 14 will be - * 2nd field in struct) - * - The fields stored in multi-byte types will be accessed lowbyte and highbyte separately (e.g. PW1 will be broken into numbered byte-fields 75,76) - * @param byteNum - byte-Field number - * @return Field value in 1 byte size struct fields or 1 byte partial value (chunk) on multibyte fields. - */ -byte getStatusEntry(uint16_t byteNum) -{ - byte statusValue = 0; - - switch(byteNum) - { - case 0: statusValue = currentStatus.secl; break; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0) - case 1: statusValue = currentStatus.status1; break; //status1 Bitfield - case 2: statusValue = currentStatus.engine; break; //Engine Status Bitfield - case 3: statusValue = currentStatus.syncLossCounter; break; - case 4: statusValue = lowByte(currentStatus.MAP); break; //2 bytes for MAP - case 5: statusValue = highByte(currentStatus.MAP); break; - case 6: statusValue = (byte)(currentStatus.IAT + CALIBRATION_TEMPERATURE_OFFSET); break; //mat - case 7: statusValue = (byte)(currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); break; //Coolant ADC - case 8: statusValue = currentStatus.batCorrection; break; //Battery voltage correction (%) - case 9: statusValue = currentStatus.battery10; break; //battery voltage - case 10: statusValue = currentStatus.O2; break; //O2 - case 11: statusValue = currentStatus.egoCorrection; break; //Exhaust gas correction (%) - case 12: statusValue = currentStatus.iatCorrection; break; //Air temperature Correction (%) - case 13: statusValue = currentStatus.wueCorrection; break; //Warmup enrichment (%) - case 14: statusValue = lowByte(currentStatus.RPM); break; //rpm HB - case 15: statusValue = highByte(currentStatus.RPM); break; //rpm LB - case 16: statusValue = (byte)(currentStatus.AEamount >> 1); break; //TPS acceleration enrichment (%) divided by 2 (Can exceed 255) - case 17: statusValue = lowByte(currentStatus.corrections); break; //Total GammaE (%) - case 18: statusValue = highByte(currentStatus.corrections); break; //Total GammaE (%) - case 19: statusValue = currentStatus.VE1; break; //VE 1 (%) - case 20: statusValue = currentStatus.VE2; break; //VE 2 (%) - case 21: statusValue = currentStatus.afrTarget; break; - case 22: statusValue = currentStatus.tpsDOT; break; //TPS DOT - case 23: statusValue = currentStatus.advance; break; - case 24: statusValue = currentStatus.TPS; break; // TPS (0% to 100%) - - case 25: - if(currentStatus.loopsPerSecond > 60000) { currentStatus.loopsPerSecond = 60000;} - statusValue = lowByte(currentStatus.loopsPerSecond); - break; - case 26: - if(currentStatus.loopsPerSecond > 60000) { currentStatus.loopsPerSecond = 60000;} - statusValue = highByte(currentStatus.loopsPerSecond); - break; - - case 27: - currentStatus.freeRAM = freeRam(); - statusValue = lowByte(currentStatus.freeRAM); //(byte)((currentStatus.loopsPerSecond >> 8) & 0xFF); - break; - case 28: - currentStatus.freeRAM = freeRam(); - statusValue = highByte(currentStatus.freeRAM); - break; - - case 29: statusValue = (byte)(currentStatus.boostTarget >> 1); break; //Divide boost target by 2 to fit in a byte - case 30: statusValue = (byte)(currentStatus.boostDuty / 100); break; - case 31: statusValue = currentStatus.spark; break; //Spark related bitfield - - //rpmDOT must be sent as a signed integer - case 32: statusValue = lowByte(currentStatus.rpmDOT); break; - case 33: statusValue = highByte(currentStatus.rpmDOT); break; - - case 34: statusValue = currentStatus.ethanolPct; break; //Flex sensor value (or 0 if not used) - case 35: statusValue = currentStatus.flexCorrection; break; //Flex fuel correction (% above or below 100) - case 36: statusValue = currentStatus.flexIgnCorrection; break; //Ignition correction (Increased degrees of advance) for flex fuel - - case 37: statusValue = currentStatus.idleLoad; break; - case 38: statusValue = currentStatus.testOutputs; break; - - case 39: statusValue = currentStatus.O2_2; break; //O2 - case 40: statusValue = currentStatus.baro; break; //Barometer value - - case 41: statusValue = lowByte(currentStatus.canin[0]); break; - case 42: statusValue = highByte(currentStatus.canin[0]); break; - case 43: statusValue = lowByte(currentStatus.canin[1]); break; - case 44: statusValue = highByte(currentStatus.canin[1]); break; - case 45: statusValue = lowByte(currentStatus.canin[2]); break; - case 46: statusValue = highByte(currentStatus.canin[2]); break; - case 47: statusValue = lowByte(currentStatus.canin[3]); break; - case 48: statusValue = highByte(currentStatus.canin[3]); break; - case 49: statusValue = lowByte(currentStatus.canin[4]); break; - case 50: statusValue = highByte(currentStatus.canin[4]); break; - case 51: statusValue = lowByte(currentStatus.canin[5]); break; - case 52: statusValue = highByte(currentStatus.canin[5]); break; - case 53: statusValue = lowByte(currentStatus.canin[6]); break; - case 54: statusValue = highByte(currentStatus.canin[6]); break; - case 55: statusValue = lowByte(currentStatus.canin[7]); break; - case 56: statusValue = highByte(currentStatus.canin[7]); break; - case 57: statusValue = lowByte(currentStatus.canin[8]); break; - case 58: statusValue = highByte(currentStatus.canin[8]); break; - case 59: statusValue = lowByte(currentStatus.canin[9]); break; - case 60: statusValue = highByte(currentStatus.canin[9]); break; - case 61: statusValue = lowByte(currentStatus.canin[10]); break; - case 62: statusValue = highByte(currentStatus.canin[10]); break; - case 63: statusValue = lowByte(currentStatus.canin[11]); break; - case 64: statusValue = highByte(currentStatus.canin[11]); break; - case 65: statusValue = lowByte(currentStatus.canin[12]); break; - case 66: statusValue = highByte(currentStatus.canin[12]); break; - case 67: statusValue = lowByte(currentStatus.canin[13]); break; - case 68: statusValue = highByte(currentStatus.canin[13]); break; - case 69: statusValue = lowByte(currentStatus.canin[14]); break; - case 70: statusValue = highByte(currentStatus.canin[14]); break; - case 71: statusValue = lowByte(currentStatus.canin[15]); break; - case 72: statusValue = highByte(currentStatus.canin[15]); break; - - case 73: statusValue = currentStatus.tpsADC; break; - case 74: statusValue = getNextError(); break; - - case 75: statusValue = lowByte(currentStatus.PW1); break; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS. - case 76: statusValue = highByte(currentStatus.PW1); break; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS. - case 77: statusValue = lowByte(currentStatus.PW2); break; //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS. - case 78: statusValue = highByte(currentStatus.PW2); break; //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS. - case 79: statusValue = lowByte(currentStatus.PW3); break; //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS. - case 80: statusValue = highByte(currentStatus.PW3); break; //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS. - case 81: statusValue = lowByte(currentStatus.PW4); break; //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS. - case 82: statusValue = highByte(currentStatus.PW4); break; //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS. - - case 83: statusValue = currentStatus.status3; break; - case 84: statusValue = currentStatus.engineProtectStatus; break; - case 85: statusValue = lowByte(currentStatus.fuelLoad); break; - case 86: statusValue = highByte(currentStatus.fuelLoad); break; - case 87: statusValue = lowByte(currentStatus.ignLoad); break; - case 88: statusValue = highByte(currentStatus.ignLoad); break; - case 89: statusValue = lowByte(currentStatus.dwell); break; - case 90: statusValue = highByte(currentStatus.dwell); break; - case 91: statusValue = currentStatus.CLIdleTarget; break; - case 92: statusValue = currentStatus.mapDOT; break; - case 93: statusValue = lowByte(currentStatus.vvt1Angle); break; //2 bytes for vvt1Angle - case 94: statusValue = highByte(currentStatus.vvt1Angle); break; - case 95: statusValue = currentStatus.vvt1TargetAngle; break; - case 96: statusValue = (byte)(currentStatus.vvt1Duty); break; - case 97: statusValue = lowByte(currentStatus.flexBoostCorrection); break; - case 98: statusValue = highByte(currentStatus.flexBoostCorrection); break; - case 99: statusValue = currentStatus.baroCorrection; break; - case 100: statusValue = currentStatus.VE; break; //Current VE (%). Can be equal to VE1 or VE2 or a calculated value from both of them - case 101: statusValue = currentStatus.ASEValue; break; //Current ASE (%) - case 102: statusValue = lowByte(currentStatus.vss); break; - case 103: statusValue = highByte(currentStatus.vss); break; - case 104: statusValue = currentStatus.gear; break; - case 105: statusValue = currentStatus.fuelPressure; break; - case 106: statusValue = currentStatus.oilPressure; break; - case 107: statusValue = currentStatus.wmiPW; break; - case 108: statusValue = currentStatus.status4; break; - case 109: statusValue = lowByte(currentStatus.vvt2Angle); break; //2 bytes for vvt2Angle - case 110: statusValue = highByte(currentStatus.vvt2Angle); break; - case 111: statusValue = currentStatus.vvt2TargetAngle; break; - case 112: statusValue = (byte)(currentStatus.vvt2Duty); break; - case 113: statusValue = currentStatus.outputsStatus; break; - case 114: statusValue = (byte)(currentStatus.fuelTemp + CALIBRATION_TEMPERATURE_OFFSET); break; //Fuel temperature from flex sensor - case 115: statusValue = currentStatus.fuelTempCorrection; break; //Fuel temperature Correction (%) - case 116: statusValue = currentStatus.advance1; break; //advance 1 (%) - case 117: statusValue = currentStatus.advance2; break; //advance 2 (%) - case 118: statusValue = currentStatus.TS_SD_Status; break; //SD card status - case 119: statusValue = lowByte(currentStatus.EMAP); break; //2 bytes for EMAP - case 120: statusValue = highByte(currentStatus.EMAP); break; - } - - return statusValue; - - //Each new inclusion here need to be added on speeduino.ini@L78, only list first byte of an integer and second byte as "INVALID" - //Every 2-byte integer added here should have it's lowByte index added to fsIntIndex array on globals.ino@L116 -} /** Send a status record back to tuning/logging SW. * This will "live" information from @ref currentStatus struct. @@ -960,9 +795,9 @@ void sendValues(uint16_t offset, uint16_t packetLength, byte cmd, byte portNum) for(byte x=0; x> 1); //TPS acceleration enrichment (%) divided by 2 (Can exceed 255) - logBuffer[17] = currentStatus.corrections; //Total GammaE (%) - logBuffer[18] = currentStatus.VE; //Current VE (%). Can be equal to VE1 or VE2 or a calculated value from both of them - logBuffer[19] = currentStatus.VE1; //VE 1 (%) - logBuffer[20] = currentStatus.VE2; //VE 2 (%) - logBuffer[21] = currentStatus.afrTarget; - logBuffer[22] = currentStatus.tpsDOT; //TPS DOT - logBuffer[23] = currentStatus.advance; - logBuffer[24] = currentStatus.TPS; // TPS (0% to 100%) - //Need to split the int loopsPerSecond value into 2 bytes - if(currentStatus.loopsPerSecond > 60000) { currentStatus.loopsPerSecond = 60000;} - logBuffer[25] = lowByte(currentStatus.loopsPerSecond); - logBuffer[26] = highByte(currentStatus.loopsPerSecond); + switch(byteNum) + { + case 0: statusValue = currentStatus.secl; break; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0) + case 1: statusValue = currentStatus.status1; break; //status1 Bitfield + case 2: statusValue = currentStatus.engine; break; //Engine Status Bitfield + case 3: statusValue = currentStatus.syncLossCounter; break; + case 4: statusValue = lowByte(currentStatus.MAP); break; //2 bytes for MAP + case 5: statusValue = highByte(currentStatus.MAP); break; + case 6: statusValue = (byte)(currentStatus.IAT + CALIBRATION_TEMPERATURE_OFFSET); break; //mat + case 7: statusValue = (byte)(currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); break; //Coolant ADC + case 8: statusValue = currentStatus.batCorrection; break; //Battery voltage correction (%) + case 9: statusValue = currentStatus.battery10; break; //battery voltage + case 10: statusValue = currentStatus.O2; break; //O2 + case 11: statusValue = currentStatus.egoCorrection; break; //Exhaust gas correction (%) + case 12: statusValue = currentStatus.iatCorrection; break; //Air temperature Correction (%) + case 13: statusValue = currentStatus.wueCorrection; break; //Warmup enrichment (%) + case 14: statusValue = lowByte(currentStatus.RPM); break; //rpm HB + case 15: statusValue = highByte(currentStatus.RPM); break; //rpm LB + case 16: statusValue = (byte)(currentStatus.AEamount >> 1); break; //TPS acceleration enrichment (%) divided by 2 (Can exceed 255) + case 17: statusValue = lowByte(currentStatus.corrections); break; //Total GammaE (%) + case 18: statusValue = highByte(currentStatus.corrections); break; //Total GammaE (%) + case 19: statusValue = currentStatus.VE1; break; //VE 1 (%) + case 20: statusValue = currentStatus.VE2; break; //VE 2 (%) + case 21: statusValue = currentStatus.afrTarget; break; + case 22: statusValue = currentStatus.tpsDOT; break; //TPS DOT + case 23: statusValue = currentStatus.advance; break; + case 24: statusValue = currentStatus.TPS; break; // TPS (0% to 100%) + + case 25: + if(currentStatus.loopsPerSecond > 60000) { currentStatus.loopsPerSecond = 60000;} + statusValue = lowByte(currentStatus.loopsPerSecond); + break; + case 26: + if(currentStatus.loopsPerSecond > 60000) { currentStatus.loopsPerSecond = 60000;} + statusValue = highByte(currentStatus.loopsPerSecond); + break; + + case 27: + currentStatus.freeRAM = freeRam(); + statusValue = lowByte(currentStatus.freeRAM); //(byte)((currentStatus.loopsPerSecond >> 8) & 0xFF); + break; + case 28: + currentStatus.freeRAM = freeRam(); + statusValue = highByte(currentStatus.freeRAM); + break; - //The following can be used to show the amount of free memory - currentStatus.freeRAM = freeRam(); - logBuffer[27] = lowByte(currentStatus.freeRAM); //(byte)((currentStatus.loopsPerSecond >> 8) & 0xFF); - logBuffer[28] = highByte(currentStatus.freeRAM); - - logBuffer[29] = (byte)(currentStatus.boostTarget >> 1); //Divide boost target by 2 to fit in a byte - logBuffer[30] = (byte)(currentStatus.boostDuty / 100); - logBuffer[31] = currentStatus.spark; //Spark related bitfield + case 29: statusValue = (byte)(currentStatus.boostTarget >> 1); break; //Divide boost target by 2 to fit in a byte + case 30: statusValue = (byte)(currentStatus.boostDuty / 100); break; + case 31: statusValue = currentStatus.spark; break; //Spark related bitfield //rpmDOT must be sent as a signed integer - logBuffer[32] = lowByte(currentStatus.rpmDOT); - logBuffer[33] = highByte(currentStatus.rpmDOT); + case 32: statusValue = lowByte(currentStatus.rpmDOT); break; + case 33: statusValue = highByte(currentStatus.rpmDOT); break; - logBuffer[34] = currentStatus.ethanolPct; //Flex sensor value (or 0 if not used) - logBuffer[35] = currentStatus.flexCorrection; //Flex fuel correction (% above or below 100) - logBuffer[36] = currentStatus.flexIgnCorrection; //Ignition correction (Increased degrees of advance) for flex fuel + case 34: statusValue = currentStatus.ethanolPct; break; //Flex sensor value (or 0 if not used) + case 35: statusValue = currentStatus.flexCorrection; break; //Flex fuel correction (% above or below 100) + case 36: statusValue = currentStatus.flexIgnCorrection; break; //Ignition correction (Increased degrees of advance) for flex fuel - logBuffer[37] = currentStatus.idleLoad; - logBuffer[38] = currentStatus.testOutputs; + case 37: statusValue = currentStatus.idleLoad; break; + case 38: statusValue = currentStatus.testOutputs; break; - logBuffer[39] = currentStatus.O2_2; //O2 - logBuffer[40] = currentStatus.baro; //Barometer value + case 39: statusValue = currentStatus.O2_2; break; //O2 + case 40: statusValue = currentStatus.baro; break; //Barometer value - logBuffer[41] = lowByte(currentStatus.canin[0]); - logBuffer[42] = highByte(currentStatus.canin[0]); - logBuffer[43] = lowByte(currentStatus.canin[1]); - logBuffer[44] = highByte(currentStatus.canin[1]); - logBuffer[45] = lowByte(currentStatus.canin[2]); - logBuffer[46] = highByte(currentStatus.canin[2]); - logBuffer[47] = lowByte(currentStatus.canin[3]); - logBuffer[48] = highByte(currentStatus.canin[3]); - logBuffer[49] = lowByte(currentStatus.canin[4]); - logBuffer[50] = highByte(currentStatus.canin[4]); - logBuffer[51] = lowByte(currentStatus.canin[5]); - logBuffer[52] = highByte(currentStatus.canin[5]); - logBuffer[53] = lowByte(currentStatus.canin[6]); - logBuffer[54] = highByte(currentStatus.canin[6]); - logBuffer[55] = lowByte(currentStatus.canin[7]); - logBuffer[56] = highByte(currentStatus.canin[7]); - logBuffer[57] = lowByte(currentStatus.canin[8]); - logBuffer[58] = highByte(currentStatus.canin[8]); - logBuffer[59] = lowByte(currentStatus.canin[9]); - logBuffer[60] = highByte(currentStatus.canin[9]); - logBuffer[61] = lowByte(currentStatus.canin[10]); - logBuffer[62] = highByte(currentStatus.canin[10]); - logBuffer[63] = lowByte(currentStatus.canin[11]); - logBuffer[64] = highByte(currentStatus.canin[11]); - logBuffer[65] = lowByte(currentStatus.canin[12]); - logBuffer[66] = highByte(currentStatus.canin[12]); - logBuffer[67] = lowByte(currentStatus.canin[13]); - logBuffer[68] = highByte(currentStatus.canin[13]); - logBuffer[69] = lowByte(currentStatus.canin[14]); - logBuffer[70] = highByte(currentStatus.canin[14]); - logBuffer[71] = lowByte(currentStatus.canin[15]); - logBuffer[72] = highByte(currentStatus.canin[15]); + case 41: statusValue = lowByte(currentStatus.canin[0]); break; + case 42: statusValue = highByte(currentStatus.canin[0]); break; + case 43: statusValue = lowByte(currentStatus.canin[1]); break; + case 44: statusValue = highByte(currentStatus.canin[1]); break; + case 45: statusValue = lowByte(currentStatus.canin[2]); break; + case 46: statusValue = highByte(currentStatus.canin[2]); break; + case 47: statusValue = lowByte(currentStatus.canin[3]); break; + case 48: statusValue = highByte(currentStatus.canin[3]); break; + case 49: statusValue = lowByte(currentStatus.canin[4]); break; + case 50: statusValue = highByte(currentStatus.canin[4]); break; + case 51: statusValue = lowByte(currentStatus.canin[5]); break; + case 52: statusValue = highByte(currentStatus.canin[5]); break; + case 53: statusValue = lowByte(currentStatus.canin[6]); break; + case 54: statusValue = highByte(currentStatus.canin[6]); break; + case 55: statusValue = lowByte(currentStatus.canin[7]); break; + case 56: statusValue = highByte(currentStatus.canin[7]); break; + case 57: statusValue = lowByte(currentStatus.canin[8]); break; + case 58: statusValue = highByte(currentStatus.canin[8]); break; + case 59: statusValue = lowByte(currentStatus.canin[9]); break; + case 60: statusValue = highByte(currentStatus.canin[9]); break; + case 61: statusValue = lowByte(currentStatus.canin[10]); break; + case 62: statusValue = highByte(currentStatus.canin[10]); break; + case 63: statusValue = lowByte(currentStatus.canin[11]); break; + case 64: statusValue = highByte(currentStatus.canin[11]); break; + case 65: statusValue = lowByte(currentStatus.canin[12]); break; + case 66: statusValue = highByte(currentStatus.canin[12]); break; + case 67: statusValue = lowByte(currentStatus.canin[13]); break; + case 68: statusValue = highByte(currentStatus.canin[13]); break; + case 69: statusValue = lowByte(currentStatus.canin[14]); break; + case 70: statusValue = highByte(currentStatus.canin[14]); break; + case 71: statusValue = lowByte(currentStatus.canin[15]); break; + case 72: statusValue = highByte(currentStatus.canin[15]); break; - logBuffer[73] = currentStatus.tpsADC; - logBuffer[74] = getNextError(); + case 73: statusValue = currentStatus.tpsADC; break; + case 74: statusValue = getNextError(); break; - logBuffer[75] = lowByte(currentStatus.PW1); //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS. - logBuffer[76] = highByte(currentStatus.PW1); //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS. - logBuffer[77] = lowByte(currentStatus.PW2); //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS. - logBuffer[78] = highByte(currentStatus.PW2); //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS. - logBuffer[79] = lowByte(currentStatus.PW3); //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS. - logBuffer[80] = highByte(currentStatus.PW3); //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS. - logBuffer[81] = lowByte(currentStatus.PW4); //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS. - logBuffer[82] = highByte(currentStatus.PW4); //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS. + case 75: statusValue = lowByte(currentStatus.PW1); break; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS. + case 76: statusValue = highByte(currentStatus.PW1); break; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS. + case 77: statusValue = lowByte(currentStatus.PW2); break; //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS. + case 78: statusValue = highByte(currentStatus.PW2); break; //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS. + case 79: statusValue = lowByte(currentStatus.PW3); break; //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS. + case 80: statusValue = highByte(currentStatus.PW3); break; //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS. + case 81: statusValue = lowByte(currentStatus.PW4); break; //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS. + case 82: statusValue = highByte(currentStatus.PW4); break; //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS. - logBuffer[83] = currentStatus.status3; + case 83: statusValue = currentStatus.status3; break; + case 84: statusValue = currentStatus.engineProtectStatus; break; + case 85: statusValue = lowByte(currentStatus.fuelLoad); break; + case 86: statusValue = highByte(currentStatus.fuelLoad); break; + case 87: statusValue = lowByte(currentStatus.ignLoad); break; + case 88: statusValue = highByte(currentStatus.ignLoad); break; + case 89: statusValue = lowByte(currentStatus.dwell); break; + case 90: statusValue = highByte(currentStatus.dwell); break; + case 91: statusValue = currentStatus.CLIdleTarget; break; + case 92: statusValue = currentStatus.mapDOT; break; + case 93: statusValue = lowByte(currentStatus.vvt1Angle); break; //2 bytes for vvt1Angle + case 94: statusValue = highByte(currentStatus.vvt1Angle); break; + case 95: statusValue = currentStatus.vvt1TargetAngle; break; + case 96: statusValue = (byte)(currentStatus.vvt1Duty); break; + case 97: statusValue = lowByte(currentStatus.flexBoostCorrection); break; + case 98: statusValue = highByte(currentStatus.flexBoostCorrection); break; + case 99: statusValue = currentStatus.baroCorrection; break; + case 100: statusValue = currentStatus.VE; break; //Current VE (%). Can be equal to VE1 or VE2 or a calculated value from both of them + case 101: statusValue = currentStatus.ASEValue; break; //Current ASE (%) + case 102: statusValue = lowByte(currentStatus.vss); break; + case 103: statusValue = highByte(currentStatus.vss); break; + case 104: statusValue = currentStatus.gear; break; + case 105: statusValue = currentStatus.fuelPressure; break; + case 106: statusValue = currentStatus.oilPressure; break; + case 107: statusValue = currentStatus.wmiPW; break; + case 108: statusValue = currentStatus.status4; break; + case 109: statusValue = lowByte(currentStatus.vvt2Angle); break; //2 bytes for vvt2Angle + case 110: statusValue = highByte(currentStatus.vvt2Angle); break; + case 111: statusValue = currentStatus.vvt2TargetAngle; break; + case 112: statusValue = (byte)(currentStatus.vvt2Duty); break; + case 113: statusValue = currentStatus.outputsStatus; break; + case 114: statusValue = (byte)(currentStatus.fuelTemp + CALIBRATION_TEMPERATURE_OFFSET); break; //Fuel temperature from flex sensor + case 115: statusValue = currentStatus.fuelTempCorrection; break; //Fuel temperature Correction (%) + case 116: statusValue = currentStatus.advance1; break; //advance 1 (%) + case 117: statusValue = currentStatus.advance2; break; //advance 2 (%) + case 118: statusValue = currentStatus.TS_SD_Status; break; //SD card status + case 119: statusValue = lowByte(currentStatus.EMAP); break; //2 bytes for EMAP + case 120: statusValue = highByte(currentStatus.EMAP); break; + } - logBuffer[84] = currentStatus.nChannels; - logBuffer[85] = lowByte(currentStatus.fuelLoad); - logBuffer[86] = highByte(currentStatus.fuelLoad); - logBuffer[87] = lowByte(currentStatus.ignLoad); - logBuffer[88] = highByte(currentStatus.ignLoad); - logBuffer[89] = lowByte(currentStatus.dwell); - logBuffer[90] = highByte(currentStatus.dwell); - logBuffer[91] = currentStatus.CLIdleTarget; - logBuffer[92] = currentStatus.mapDOT; - logBuffer[93] = currentStatus.vvt1Angle; - logBuffer[94] = currentStatus.vvt1TargetAngle; - logBuffer[95] = (byte) currentStatus.vvt1Duty; - logBuffer[96] = lowByte(currentStatus.flexBoostCorrection); - logBuffer[97] = highByte(currentStatus.flexBoostCorrection); - logBuffer[98] = currentStatus.baroCorrection; - logBuffer[99] = currentStatus.VE; //Current VE (%). Can be equal to VE1 or VE2 or a calculated value from both of them - logBuffer[100] = currentStatus.ASEValue; //Current ASE (%) - logBuffer[101] = lowByte(currentStatus.vss); - logBuffer[102] = highByte(currentStatus.vss); - logBuffer[103] = currentStatus.gear; - logBuffer[104] = currentStatus.fuelPressure; - logBuffer[105] = currentStatus.oilPressure; - logBuffer[106] = currentStatus.wmiPW; - logBuffer[107] = currentStatus.status4; - logBuffer[108] = currentStatus.vvt2Angle; - logBuffer[109] = currentStatus.vvt2TargetAngle; - logBuffer[110] = (byte) currentStatus.vvt2Duty; - logBuffer[111] = currentStatus.advance1; - logBuffer[112] = currentStatus.advance2; + return statusValue; + //Each new inclusion here need to be added on speeduino.ini@L78, only list first byte of an integer and second byte as "INVALID" + //Every 2-byte integer added here should have it's lowByte index added to fsIntIndex array on globals.ino@L116 } \ No newline at end of file diff --git a/speeduino/rtc_common.ino b/speeduino/rtc_common.ino index 6d260355..2334c738 100644 --- a/speeduino/rtc_common.ino +++ b/speeduino/rtc_common.ino @@ -1,6 +1,6 @@ +#include "globals.h" #ifdef RTC_ENABLED #include "rtc_common.h" -#include "globals.h" #include RTC_LIB_H //Defined in each boards .h file void initRTC() @@ -94,7 +94,8 @@ uint16_t rtc_getYear() #if defined(CORE_TEENSY) tempYear = year(); #elif defined(CORE_STM32) - tempYear = rtc.getYear(); + //year in stm32 rtc is a byte. So add year 2000 to make it correct + tempYear = (2000+rtc.getYear()); #endif #endif return tempYear; @@ -107,7 +108,8 @@ void rtc_setTime(byte second, byte minute, byte hour, byte day, byte month, uint setTime(second, minute, hour, day, month, year); #elif defined(CORE_STM32) rtc.setTime(hour, minute, second); - rtc.setDate(day, month, year); + //year in stm32 rtc is a byte. so substract year 2000 to fit + rtc.setDate(day, month, (year-2000)); #endif #endif } diff --git a/speeduino/utilities.ino b/speeduino/utilities.ino index e3f1ce0b..2f41e2ce 100644 --- a/speeduino/utilities.ino +++ b/speeduino/utilities.ino @@ -12,6 +12,7 @@ #include "utilities.h" #include "decoders.h" #include "comms.h" +#include "logger.h" uint8_t ioDelay[sizeof(configPage13.outputPin)]; uint8_t ioOutDelay[sizeof(configPage13.outputPin)]; @@ -266,8 +267,8 @@ int16_t ProgrammableIOGetData(uint16_t index) // Stop at desired field if (pgm_read_byte(&(fsIntIndex[x])) == index) { break; } } - if (x >= sizeof(fsIntIndex)) { result = getStatusEntry(index); } // 8-bit, coerce to 16 bit result - else { result = word(getStatusEntry(index+1), getStatusEntry(index)); } // Assemble 2 bytes to word of 16 bit result + if (x >= sizeof(fsIntIndex)) { result = getLogEntry(index); } // 8-bit, coerce to 16 bit result + else { result = word(getLogEntry(index+1), getLogEntry(index)); } // Assemble 2 bytes to word of 16 bit result //Special cases for temperatures