1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-14 06:23:07 +01:00

Fix charge status, add to PageVoltage

This commit is contained in:
norbert-walter
2025-01-25 16:19:10 +01:00
parent 26e551c616
commit df81e6e443
8 changed files with 586 additions and 32 deletions

View File

@@ -100,8 +100,8 @@ void displayFooter(CommonData &commonData);
SunData calcSunsetSunrise(GwApi *api, double time, double date, double latitude, double longitude, double timezone); // Calulate sunset and sunrise
void batteryGraphic(uint x, uint y, float percent, int pcolor, int bcolor); // Battery graphic with fill level
void solarGraphic(uint x, uint y, int pcolor, int bcolor); // Solar graphic with fill level
void generatorGraphic(uint x, uint y, int pcolor, int bcolor); // Generator graphic with fill level
void solarGraphic(uint x, uint y, int pcolor, int bcolor); // Solar graphic
void generatorGraphic(uint x, uint y, int pcolor, int bcolor); // Generator graphic
void startLedTask(GwApi *api);
void doImageRequest(GwApi *api, int *pageno, const PageStruct pages[MAX_PAGE_NUMBER], AsyncWebServerRequest *request);

View File

@@ -89,11 +89,11 @@ void sensorTask(void *param){
double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat();
if(String(powsensor1) == "off"){
#ifdef VOLTAGE_SENSOR
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
float rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
#else
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
float rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
#endif
sensors.batteryVoltage = sensors.batteryVoltage * vslope + voffset; // Calibration
sensors.batteryVoltage = rawVoltage * vslope + voffset; // Calibration
#ifdef LIPO_ACCU_1200
sensors.BatteryChargeStatus = 0; // Set to discharging
sensors.batteryLevelLiPo = 0; // Level 0...100%
@@ -468,20 +468,14 @@ void sensorTask(void *param){
if(millis() > starttime5 + 1000 && String(powsensor1) == "off"){
starttime5 = millis();
#ifdef VOLTAGE_SENSOR
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
float rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
#else
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
float rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
#endif
sensors.batteryVoltage = sensors.batteryVoltage * vslope + voffset; // Calibration
sensors.batteryVoltage = rawVoltage * vslope + voffset; // Calibration
#ifdef LIPO_ACCU_1200
if(sensors.batteryVoltage > 4.1){
sensors.BatteryChargeStatus = 1; // Charging active
}
else{
sensors.BatteryChargeStatus = 0; // Discharging
}
// Polynomfit for LiPo capacity calculation for 3,7V LiPo accus, 0...100%
sensors.batteryLevelLiPo = sensors.batteryVoltage * sensors.batteryVoltage * 174.9513 + sensors.batteryVoltage * 1147,7686 + 1868.5120;
sensors.batteryLevelLiPo = sensors.batteryVoltage * sensors.batteryVoltage * 174.9513 + sensors.batteryVoltage * 1147.7686 + 1868.5120;
// Limiter
if(sensors.batteryLevelLiPo > 100){
sensors.batteryLevelLiPo = 100;
@@ -496,11 +490,28 @@ void sensorTask(void *param){
sensors.batteryVoltage10 = batV.getAvg(10) / 100.0;
sensors.batteryVoltage60 = batV.getAvg(60) / 100.0;
sensors.batteryVoltage300 = batV.getAvg(300) / 100.0;
// Charging detection
float deltaV = sensors.batteryVoltage - sensors.batteryVoltage10;
if(deltaV > 0.03){
sensors.BatteryChargeStatus = 1; // Charging active
}
if(deltaV < -0.03){
sensors.BatteryChargeStatus = 0; // Discharging
}
#ifdef BOARD_OBP40S3
// Send to NMEA200 bus as instance 10
if(!isnan(sensors.batteryVoltage)){
SetN2kDCBatStatus(N2kMsg, 10, sensors.batteryVoltage, N2kDoubleNA, N2kDoubleNA, 0);
api->sendN2kMessage(N2kMsg);
}
#endif
#ifdef BOARD_OBP60S3
// Send to NMEA200 bus
if(!isnan(sensors.batteryVoltage)){
SetN2kDCBatStatus(N2kMsg, 0, sensors.batteryVoltage, N2kDoubleNA, N2kDoubleNA, 1);
api->sendN2kMessage(N2kMsg);
}
#endif
}
// Send data from environment sensor all 2s

View File

@@ -205,6 +205,18 @@ public:
getdisplay().setCursor(20, 100);
getdisplay().print(name1); // Value name
#ifdef BOARD_OBP40S3
// Show charge status
getdisplay().setFont(&Ubuntu_Bold8pt7b);
getdisplay().setCursor(185, 100);
if(commonData->data.BatteryChargeStatus == true){
getdisplay().print("Charge");
}
else{
getdisplay().print("Discharge");
}
#endif
// Show unit
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(270, 100);
@@ -213,7 +225,12 @@ public:
// Show battery type
getdisplay().setFont(&Ubuntu_Bold8pt7b);
getdisplay().setCursor(295, 100);
#ifdef BOARD_OBP60S3
getdisplay().print(batType);
#endif
#ifdef BOARD_OBP40S3
getdisplay().print("LiPo");
#endif
// Show average settings
printAvg(average, 320, 84, true);

View File

@@ -609,10 +609,10 @@
"label": "Undervoltage",
"type": "boolean",
"default": "false",
"description": "Switch off device if voltage drops below 9V [on|off]",
"description": "Switch off device if LiPo voltage drops below 3.65V [on|off]",
"category": "OBP40 Hardware",
"capabilities": {
"obp40": "false"
"obp40":"true"
}
},
{

View File

@@ -309,30 +309,28 @@ void registerAllPages(PageList &list){
// Undervoltage detection for shutdown display
void underVoltageDetection(GwApi *api, CommonData &common){
float actVoltage = 0;
float minVoltage = 0;
// Read settings
float vslope = uint(api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asFloat());
float voffset = uint(api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asFloat());
// Read supply voltage
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200
actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
minVoltage = 3.65; // Absolut minimum volatge for 3,7V LiPo accu
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
float minVoltage = 3.65; // Absolut minimum volatge for 3,7V LiPo accu
#else
actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
minVoltage = MIN_VOLTAGE;
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
float minVoltage = MIN_VOLTAGE;
#endif
actVoltage = actVoltage * vslope + voffset;
if(actVoltage < minVoltage){
float corrVoltage = actVoltage * vslope + voffset; // Calibration
if(corrVoltage < minVoltage){
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200
// Switch off all power lines
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
setFlashLED(false); // Flash LED Off
buzzer(TONE4, 20); // Buzzer tone 4kHz 20ms
// Shutdown EInk display
getdisplay().setFullWindow(); // Set full Refresh
getdisplay().setFullWindow(); // Set full Refresh
//getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update
getdisplay().fillScreen(common.bgcolor); // Clear screen
getdisplay().fillScreen(common.bgcolor);// Clear screen
getdisplay().setTextColor(common.fgcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(65, 150);