diff --git a/Software/data/index.htm b/Software/data/index.htm index 419b0e0..f3c7934 100644 --- a/Software/data/index.htm +++ b/Software/data/index.htm @@ -75,13 +75,25 @@ - - - + + + + %DTC_TABLE%
TimestampDTCactiveZeitstempelFehlercodeSchwereAktiv
+

+ +

+
+
+ +
+

diff --git a/Software/data/static/dtc.txt b/Software/data/static/dtc.txt new file mode 100644 index 0000000..fc23474 --- /dev/null +++ b/Software/data/static/dtc.txt @@ -0,0 +1,12 @@ +1 - TANK_EMPTY +2 - DTC_TANK_LOW +3 - DTC_NO_EEPROM_FOUND +4 - DTC_EEPROM_CFG_BAD +5 - DTC_EEPROM_PDS_BAD +6 - DTC_EEPROM_PDSADRESS_BAD +7 - DTC_EEPROM_VERSION_BAD +8 - DTC_FLASHFS_ERROR +9 - DTC_FLASHFS_VERSION_ERROR +10 - DTC_NO_GPS_SERIAL +11 - DTC_CAN_TRANSCEIVER_FAILED +12 - DTC_NO_CAN_SIGNAL diff --git a/Software/data/static/img/critical.png b/Software/data/static/img/critical.png new file mode 100644 index 0000000..82325ff Binary files /dev/null and b/Software/data/static/img/critical.png differ diff --git a/Software/data/static/img/info.png b/Software/data/static/img/info.png new file mode 100644 index 0000000..1fb0c51 Binary files /dev/null and b/Software/data/static/img/info.png differ diff --git a/Software/data/static/img/warn.png b/Software/data/static/img/warn.png new file mode 100644 index 0000000..1b0cd43 Binary files /dev/null and b/Software/data/static/img/warn.png differ diff --git a/Software/src/can.cpp b/Software/src/can.cpp index de0eb13..512e468 100644 --- a/Software/src/can.cpp +++ b/Software/src/can.cpp @@ -7,7 +7,7 @@ void Init_CAN() { if (CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) != CAN_OK) - MaintainDTC(DTC_CAN_TRANSCEIVER_FAILED, true); + MaintainDTC(DTC_CAN_TRANSCEIVER_FAILED, DTC_CRITICAL, true); CAN0.init_Mask(0, 0, 0x07FF0000); // Init first mask... CAN0.init_Mask(1, 0, 0x07FF0000); // Init second mask... @@ -39,7 +39,7 @@ uint32_t Process_CAN_WheelSpeed() return milimeters_to_add; } - MaintainDTC(DTC_NO_CAN_SIGNAL, (millis() > lastRecTimestamp + 10000 ? true : false)); + MaintainDTC(DTC_NO_CAN_SIGNAL, DTC_CRITICAL, (millis() > lastRecTimestamp + 10000 ? true : false)); return 0; } diff --git a/Software/src/config.cpp b/Software/src/config.cpp index a3dd961..fc56ba3 100644 --- a/Software/src/config.cpp +++ b/Software/src/config.cpp @@ -84,8 +84,7 @@ void GetConfig_EEPROM() if (Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig)) != checksum) { - MaintainDTC(DTC_EEPROM_CFG_BAD, true); - FormatConfig_EEPROM(); + MaintainDTC(DTC_EEPROM_CFG_BAD, DTC_CRITICAL, true); } LubeConfig.checksum = checksum; } @@ -118,7 +117,7 @@ void GetPersistence_EEPROM() { MovePersistencePage_EEPROM(true); FormatPersistence_EEPROM(); - MaintainDTC(DTC_EEPROM_PDSADRESS_BAD, true); + MaintainDTC(DTC_EEPROM_PDSADRESS_BAD, DTC_CRITICAL, true); } else { @@ -129,7 +128,7 @@ void GetPersistence_EEPROM() if (Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData)) != checksum) { - MaintainDTC(DTC_EEPROM_PDS_BAD, true); + MaintainDTC(DTC_EEPROM_PDS_BAD, DTC_CRITICAL, true); } PersistenceData.checksum = checksum; } @@ -224,10 +223,10 @@ boolean checkEEPROMavailable() { if (!ee.isConnected()) { - MaintainDTC(DTC_NO_EEPROM_FOUND, true); + MaintainDTC(DTC_NO_EEPROM_FOUND, DTC_CRITICAL, true); globals.systemStatus = sysStat_Error; return false; } - MaintainDTC(DTC_NO_EEPROM_FOUND, false); + MaintainDTC(DTC_NO_EEPROM_FOUND, DTC_CRITICAL, false); return true; } \ No newline at end of file diff --git a/Software/src/dtc.cpp b/Software/src/dtc.cpp index 2b45fb6..0676036 100644 --- a/Software/src/dtc.cpp +++ b/Software/src/dtc.cpp @@ -2,7 +2,7 @@ DTCEntry_s DTCStorage[MAX_DTC_STORAGE]; -void MaintainDTC(DTCNums_t DTC_no, boolean active) +void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active) { for (int i = 0; i < MAX_DTC_STORAGE; i++) { @@ -13,6 +13,7 @@ void MaintainDTC(DTCNums_t DTC_no, boolean active) Serial.printf("DTC gone active: %d\n", DTC_no); DTCStorage[i].timestamp = millis(); DTCStorage[i].active = DTC_ACTIVE; + DTCStorage[i].severity = DTC_severity; } if (!active && DTCStorage[i].active == DTC_ACTIVE) { @@ -81,5 +82,25 @@ DTCNums_t getlastDTC(boolean only_active) } } + return pointer >= 0 ? DTCStorage[pointer].Number : DTC_LAST_DTC; +} + +DTCNums_t getlastDTC_Severity(boolean only_active, DTCSeverity_t severity) +{ + int8_t pointer = -1; + uint32_t lasttimestamp = 0; + + for (int i = 0; i < MAX_DTC_STORAGE; i++) + { + if (DTCStorage[i].Number > 0 && DTCStorage[i].timestamp > lasttimestamp) + { + if ((only_active == false || DTCStorage[i].active == DTC_ACTIVE) && DTCStorage[i].severity == severity) + { + pointer = i; + lasttimestamp = DTCStorage[i].timestamp; + } + } + } + return pointer >= 0 ? DTCStorage[pointer].Number : DTC_LAST_DTC; } \ No newline at end of file diff --git a/Software/src/dtc.h b/Software/src/dtc.h index 320b833..a3de2a0 100644 --- a/Software/src/dtc.h +++ b/Software/src/dtc.h @@ -8,6 +8,7 @@ typedef enum DTCNums_e { DTC_TANK_EMPTY = 1, + DTC_TANK_LOW, DTC_NO_EEPROM_FOUND, DTC_EEPROM_CFG_BAD, DTC_EEPROM_PDS_BAD, @@ -31,17 +32,26 @@ typedef enum DTCActive_e DTC_PREVIOUS } DTCActive_t; +typedef enum DTCSeverity_e +{ + DTC_INFO, + DTC_WARN, + DTC_CRITICAL +} DTCSeverity_t; + typedef struct DTCEntry_s { DTCNums_t Number; uint32_t timestamp; DTCActive_t active; + DTCSeverity_t severity; } DTCEntry_t; -void MaintainDTC(DTCNums_t DTC_no, boolean active); +void MaintainDTC(DTCNums_t DTC_no, DTCSeverity_t DTC_severity, boolean active); void ClearDTC(DTCNums_t DTC_no); void ClearAllDTC(); DTCNums_t getlastDTC(boolean only_active); +DTCNums_t getlastDTC_Severity(boolean only_active, DTCSeverity_t severity); extern DTCEntry_s DTCStorage[MAX_DTC_STORAGE]; #endif \ No newline at end of file diff --git a/Software/src/globals.h b/Software/src/globals.h index 711550f..a131760 100644 --- a/Software/src/globals.h +++ b/Software/src/globals.h @@ -33,6 +33,8 @@ typedef struct Globals_s char DeviceName[33]; uint32_t FlashVersion; uint16_t eePersistanceAdress; + uint8_t TankPercentage; + bool hasDTC; } Globals_t; extern Globals_t globals; diff --git a/Software/src/gps.cpp b/Software/src/gps.cpp index 7356e8a..7c82c11 100644 --- a/Software/src/gps.cpp +++ b/Software/src/gps.cpp @@ -51,7 +51,7 @@ uint32_t Process_GPS_WheelSpeed() } } - MaintainDTC(DTC_NO_GPS_SERIAL, (millis() > lastRecTimestamp + 10000)); + MaintainDTC(DTC_NO_GPS_SERIAL,DTC_CRITICAL, (millis() > lastRecTimestamp + 10000)); return 0; } diff --git a/Software/src/lubeapp.cpp b/Software/src/lubeapp.cpp index d927962..3844559 100644 --- a/Software/src/lubeapp.cpp +++ b/Software/src/lubeapp.cpp @@ -5,23 +5,35 @@ uint32_t lubePulseTimestamp = 0; void RunLubeApp(uint32_t add_milimeters) { - MaintainDTC(DTC_TANK_EMPTY, (PersistenceData.tankRemain_µl < LubeConfig.amountPerDose_µl)); + globals.TankPercentage = PersistenceData.tankRemain_µl / (LubeConfig.tankCapacity_ml * 1000); + + MaintainDTC(DTC_TANK_EMPTY, DTC_CRITICAL, (PersistenceData.tankRemain_µl < LubeConfig.amountPerDose_µl)); + MaintainDTC(DTC_TANK_LOW, DTC_WARN, (globals.TankPercentage < LubeConfig.TankRemindAtPercentage)); static tSystem_Status preserverSysStatusError; - if (globals.systemStatus != sysStat_Error) - preserverSysStatusError = globals.systemStatus; - - if (getlastDTC(true) < DTC_LAST_DTC) + if (getlastDTC(false) < DTC_LAST_DTC) { - globals.systemStatus = sysStat_Error; + globals.hasDTC = true; + if (getlastDTC_Severity(true, DTC_CRITICAL) < DTC_LAST_DTC) + { + if (globals.systemStatus != sysStat_Error) + { + preserverSysStatusError = globals.systemStatus; + } + globals.systemStatus = sysStat_Error; + } + else + { + if (globals.systemStatus == sysStat_Error) + { + globals.systemStatus = preserverSysStatusError; + } + } } else { - if (globals.systemStatus == sysStat_Error) - { - globals.systemStatus = preserverSysStatusError; - } + globals.hasDTC = false; } // Add traveled Distance in mm diff --git a/Software/src/main.cpp b/Software/src/main.cpp index 52123b1..7d86a15 100644 --- a/Software/src/main.cpp +++ b/Software/src/main.cpp @@ -506,14 +506,12 @@ void LED_Process(uint8_t override, CRGB SetColor) oldSysStatus = globals.systemStatus; } - uint32_t percentage = PersistenceData.tankRemain_µl / (LubeConfig.tankCapacity_ml * 1000); - switch (LED_Status) { case LED_Startup: FastLED.setBrightness(255); - if (percentage < LubeConfig.TankRemindAtPercentage) + if (globals.TankPercentage < LubeConfig.TankRemindAtPercentage) leds[0] = CRGB::OrangeRed; else leds[0] = CRGB::White; diff --git a/Software/src/webui.cpp b/Software/src/webui.cpp index a2fe890..e18dcd3 100644 --- a/Software/src/webui.cpp +++ b/Software/src/webui.cpp @@ -16,7 +16,7 @@ void initWebUI() if (!LittleFS.begin()) { Serial.println("An Error has occurred while mounting LittleFS"); - MaintainDTC(DTC_FLASHFS_ERROR, true); + MaintainDTC(DTC_FLASHFS_ERROR, DTC_CRITICAL, true); return; } @@ -117,7 +117,7 @@ String processor(const String &var) return "hidden"; #endif if (var == "SHOW_DTC_TABLE") - return globals.systemStatus == sysStat_Error ? "" : "hidden"; + return globals.hasDTC ? "" : "hidden"; if (var == "DTC_TABLE") { @@ -137,6 +137,20 @@ String processor(const String &var) temp = temp + "" + String(buff_timestamp); temp = temp + "" + String(DTCStorage[i].Number) + ""; + temp = temp + ""; if (DTCStorage[i].active == DTC_ACTIVE) temp = temp + "active";