From fc40efcc4fa03eb7d18936e16c0032db589798f2 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Tue, 1 Mar 2022 22:13:35 +0100 Subject: [PATCH] Battery Voltage on NMEA2000 bus --- lib/obp60task/PageVoltage.cpp | 38 +++++++++++++++++++++++++++---- lib/obp60task/obp60task.cpp | 42 ++++++++++++++++++++++++++++------- 2 files changed, 68 insertions(+), 12 deletions(-) diff --git a/lib/obp60task/PageVoltage.cpp b/lib/obp60task/PageVoltage.cpp index 05d3b0a..f4a035e 100644 --- a/lib/obp60task/PageVoltage.cpp +++ b/lib/obp60task/PageVoltage.cpp @@ -39,13 +39,37 @@ public: // Optical warning by limit violation if(String(flashLED) == "Limit Violation"){ // Limits for Pb battery - if(String(batType) == "Pb" && (value1 < 11.0 || value1 > 14.5)){ + if(String(batType) == "Pb" && (value1 < 11.8 || value1 > 14.8)){ setBlinkingLED(true); } - if(String(batType) == "Pb" && (value1 >= 11.0 && value1 <= 14.5)){ + if(String(batType) == "Pb" && (value1 >= 11.8 && value1 <= 14.8)){ setBlinkingLED(false); setPortPin(OBP_FLASH_LED, false); - } + } + // Limits for Gel battery + if(String(batType) == "Gel" && (value1 < 11.8 || value1 > 14.4)){ + setBlinkingLED(true); + } + if(String(batType) == "Gel" && (value1 >= 11.8 && value1 <= 14.4)){ + setBlinkingLED(false); + setPortPin(OBP_FLASH_LED, false); + } + // Limits for AGM battery + if(String(batType) == "AGM" && (value1 < 11.8 || value1 > 14.7)){ + setBlinkingLED(true); + } + if(String(batType) == "AGM" && (value1 >= 11.8 && value1 <= 14.7)){ + setBlinkingLED(false); + setPortPin(OBP_FLASH_LED, false); + } + // Limits for LiFePo4 battery + if(String(batType) == "LiFePo4" && (value1 < 12.0 || value1 > 14.6)){ + setBlinkingLED(true); + } + if(String(batType) == "LiFePo4" && (value1 >= 12.0 && value1 <= 14.6)){ + setBlinkingLED(false); + setPortPin(OBP_FLASH_LED, false); + } } // Logging voltage value @@ -81,7 +105,13 @@ public: display.setTextColor(textcolor); display.setFont(&Ubuntu_Bold20pt7b); display.setCursor(270, 100); - display.print("V"); + display.print("V"); + + // Show batery type + display.setTextColor(textcolor); + display.setFont(&Ubuntu_Bold8pt7b); + display.setCursor(295, 100); + display.print(batType); // Reading bus data or using simulation data display.setTextColor(textcolor); diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index c9b2d17..531a81b 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -6,7 +6,9 @@ #include // Timer Lib for timer interrupts #include // I2C connections #include // MCP23017 extension Port -#include +#include // NMEA2000 +#include +#include // NMEA0183 #include #include #include // GxEPD lib for E-Ink displays @@ -285,6 +287,9 @@ void OBP60Task(GwApi *api){ GwConfigHandler *config=api->getConfig(); PageList allPages; registerAllPages(allPages); + + tN2kMsg N2kMsg; + LOG_DEBUG(GwLog::LOG,"obp60task started"); for (auto it=allPages.pages.begin();it != allPages.pages.end();it++){ LOG_DEBUG(GwLog::LOG,"found registered page %s",(*it)->pageName.c_str()); @@ -413,12 +418,18 @@ void OBP60Task(GwApi *api){ GwApi::BoatValue *date = boatValues.findValueOrCreate("GpsDate"); // Load GpsDate GwApi::BoatValue *time = boatValues.findValueOrCreate("GpsTime"); // Load GpsTime + // Internal sensor values + double batteryVoltage = 0; + LOG_DEBUG(GwLog::LOG,"obp60task: start mainloop"); int pageNumber=0; int lastPage=pageNumber; + long firststart = millis(); // First start long starttime0 = millis(); // Mainloop - long starttime1 = millis(); // Full display refresh - long starttime2 = millis(); // Display update + long starttime1 = millis(); // Full display refresh for the first 5 min (more often as normal) + long starttime2 = millis(); // Full display refresh after 5 min + long starttime3 = millis(); // Display update all 1s + while (true){ Timer1.update(); // Update for Timer1 @@ -487,16 +498,31 @@ void OBP60Task(GwApi *api){ LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber); } - // Subtask E-Ink full refresh - if(millis() > starttime1 + FULL_REFRESH_TIME * 1000){ + // Subtask E-Ink full refresh all 1 min for the first 5min after power on or restart + // This needs for a better display contrast after power on in cold or warm environments + if(millis() < firststart + (5 * 60 * 1000) && millis() > starttime1 + (60 * 1000)){ starttime1 = millis(); + LOG_DEBUG(GwLog::DEBUG,"E-Ink full refresh first 5 min"); + display.update(); // Full update + } + + // Subtask E-Ink full refresh + if(millis() > starttime2 + FULL_REFRESH_TIME * 1000){ + starttime2 = millis(); LOG_DEBUG(GwLog::DEBUG,"E-Ink full refresh"); display.update(); // Full update } - // Refresh display data - if(millis() > starttime2 + 1000){ - starttime2 = millis(); + // Send supplay voltage value + if(millis() > starttime3 + 1000){ + batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 + SetN2kDCBatStatus(N2kMsg, 0, batteryVoltage, N2kDoubleNA, N2kDoubleNA, 1); + api->sendN2kMessage(N2kMsg); + } + + // Refresh display data all 1s + if(millis() > starttime3 + 1000){ + starttime3 = millis(); //refresh data from api api->getBoatDataValues(boatValues.numValues,boatValues.allBoatValues); api->getStatus(commonData.status);