Battery Voltage on NMEA2000 bus
This commit is contained in:
parent
1d1f8ef0db
commit
fc40efcc4f
|
@ -39,13 +39,37 @@ public:
|
||||||
// Optical warning by limit violation
|
// Optical warning by limit violation
|
||||||
if(String(flashLED) == "Limit Violation"){
|
if(String(flashLED) == "Limit Violation"){
|
||||||
// Limits for Pb battery
|
// 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);
|
setBlinkingLED(true);
|
||||||
}
|
}
|
||||||
if(String(batType) == "Pb" && (value1 >= 11.0 && value1 <= 14.5)){
|
if(String(batType) == "Pb" && (value1 >= 11.8 && value1 <= 14.8)){
|
||||||
setBlinkingLED(false);
|
setBlinkingLED(false);
|
||||||
setPortPin(OBP_FLASH_LED, 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
|
// Logging voltage value
|
||||||
|
@ -81,7 +105,13 @@ public:
|
||||||
display.setTextColor(textcolor);
|
display.setTextColor(textcolor);
|
||||||
display.setFont(&Ubuntu_Bold20pt7b);
|
display.setFont(&Ubuntu_Bold20pt7b);
|
||||||
display.setCursor(270, 100);
|
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
|
// Reading bus data or using simulation data
|
||||||
display.setTextColor(textcolor);
|
display.setTextColor(textcolor);
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
#include <Ticker.h> // Timer Lib for timer interrupts
|
#include <Ticker.h> // Timer Lib for timer interrupts
|
||||||
#include <Wire.h> // I2C connections
|
#include <Wire.h> // I2C connections
|
||||||
#include <MCP23017.h> // MCP23017 extension Port
|
#include <MCP23017.h> // MCP23017 extension Port
|
||||||
#include <NMEA0183.h>
|
#include <N2kTypes.h> // NMEA2000
|
||||||
|
#include <N2kMessages.h>
|
||||||
|
#include <NMEA0183.h> // NMEA0183
|
||||||
#include <NMEA0183Msg.h>
|
#include <NMEA0183Msg.h>
|
||||||
#include <NMEA0183Messages.h>
|
#include <NMEA0183Messages.h>
|
||||||
#include <GxEPD.h> // GxEPD lib for E-Ink displays
|
#include <GxEPD.h> // GxEPD lib for E-Ink displays
|
||||||
|
@ -285,6 +287,9 @@ void OBP60Task(GwApi *api){
|
||||||
GwConfigHandler *config=api->getConfig();
|
GwConfigHandler *config=api->getConfig();
|
||||||
PageList allPages;
|
PageList allPages;
|
||||||
registerAllPages(allPages);
|
registerAllPages(allPages);
|
||||||
|
|
||||||
|
tN2kMsg N2kMsg;
|
||||||
|
|
||||||
LOG_DEBUG(GwLog::LOG,"obp60task started");
|
LOG_DEBUG(GwLog::LOG,"obp60task started");
|
||||||
for (auto it=allPages.pages.begin();it != allPages.pages.end();it++){
|
for (auto it=allPages.pages.begin();it != allPages.pages.end();it++){
|
||||||
LOG_DEBUG(GwLog::LOG,"found registered page %s",(*it)->pageName.c_str());
|
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 *date = boatValues.findValueOrCreate("GpsDate"); // Load GpsDate
|
||||||
GwApi::BoatValue *time = boatValues.findValueOrCreate("GpsTime"); // Load GpsTime
|
GwApi::BoatValue *time = boatValues.findValueOrCreate("GpsTime"); // Load GpsTime
|
||||||
|
|
||||||
|
// Internal sensor values
|
||||||
|
double batteryVoltage = 0;
|
||||||
|
|
||||||
LOG_DEBUG(GwLog::LOG,"obp60task: start mainloop");
|
LOG_DEBUG(GwLog::LOG,"obp60task: start mainloop");
|
||||||
int pageNumber=0;
|
int pageNumber=0;
|
||||||
int lastPage=pageNumber;
|
int lastPage=pageNumber;
|
||||||
|
long firststart = millis(); // First start
|
||||||
long starttime0 = millis(); // Mainloop
|
long starttime0 = millis(); // Mainloop
|
||||||
long starttime1 = millis(); // Full display refresh
|
long starttime1 = millis(); // Full display refresh for the first 5 min (more often as normal)
|
||||||
long starttime2 = millis(); // Display update
|
long starttime2 = millis(); // Full display refresh after 5 min
|
||||||
|
long starttime3 = millis(); // Display update all 1s
|
||||||
|
|
||||||
|
|
||||||
while (true){
|
while (true){
|
||||||
Timer1.update(); // Update for Timer1
|
Timer1.update(); // Update for Timer1
|
||||||
|
@ -487,16 +498,31 @@ void OBP60Task(GwApi *api){
|
||||||
LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber);
|
LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtask E-Ink full refresh
|
// Subtask E-Ink full refresh all 1 min for the first 5min after power on or restart
|
||||||
if(millis() > starttime1 + FULL_REFRESH_TIME * 1000){
|
// 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();
|
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");
|
LOG_DEBUG(GwLog::DEBUG,"E-Ink full refresh");
|
||||||
display.update(); // Full update
|
display.update(); // Full update
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh display data
|
// Send supplay voltage value
|
||||||
if(millis() > starttime2 + 1000){
|
if(millis() > starttime3 + 1000){
|
||||||
starttime2 = millis();
|
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
|
//refresh data from api
|
||||||
api->getBoatDataValues(boatValues.numValues,boatValues.allBoatValues);
|
api->getBoatDataValues(boatValues.numValues,boatValues.allBoatValues);
|
||||||
api->getStatus(commonData.status);
|
api->getStatus(commonData.status);
|
||||||
|
|
Loading…
Reference in New Issue