From 9dc857056b1d1dd1762e3e92178aba14144346a5 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Sat, 25 Jan 2025 18:04:58 +0100 Subject: [PATCH] Fix LiPo battery level and sensor pad --- lib/obp60task/OBP60Keypad.h | 4 ++-- lib/obp60task/OBPSensorTask.cpp | 22 ++++++++++------------ lib/obp60task/PageVoltage.cpp | 4 ++-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/obp60task/OBP60Keypad.h b/lib/obp60task/OBP60Keypad.h index 937f44e..eafe3a2 100644 --- a/lib/obp60task/OBP60Keypad.h +++ b/lib/obp60task/OBP60Keypad.h @@ -277,8 +277,8 @@ void initKeys(CommonData &commonData) { starttime = millis(); // Start key pressed keycodeold = keycode; } - // If key pressed longer than 200ms - if(millis() > starttime + 200 && keycode == keycodeold) { + // If key pressed longer than 100ms + if(millis() > starttime + 100 && keycode == keycodeold) { if (use_syspage and keycode == 3) { keystatus = 12; } else { diff --git a/lib/obp60task/OBPSensorTask.cpp b/lib/obp60task/OBPSensorTask.cpp index 9fb6d90..cbbfa15 100644 --- a/lib/obp60task/OBPSensorTask.cpp +++ b/lib/obp60task/OBPSensorTask.cpp @@ -473,9 +473,15 @@ void sensorTask(void *param){ float rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60 #endif sensors.batteryVoltage = rawVoltage * vslope + voffset; // Calibration - #ifdef LIPO_ACCU_1200 + // Save new data in average array + batV.reading(int(sensors.batteryVoltage * 100)); + // Calculate the average values for different time lines from integer values + sensors.batteryVoltage10 = batV.getAvg(10) / 100.0; + sensors.batteryVoltage60 = batV.getAvg(60) / 100.0; + sensors.batteryVoltage300 = batV.getAvg(300) / 100.0; + #if defined LIPO_ACCU_1200 && defined VOLTAGE_SENSOR // 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.batteryVoltage60 * 203.8312 -738.1635; // Limiter if(sensors.batteryLevelLiPo > 100){ sensors.batteryLevelLiPo = 100; @@ -483,22 +489,14 @@ void sensorTask(void *param){ if(sensors.batteryLevelLiPo < 0){ sensors.batteryLevelLiPo = 0; } - #endif - // Save new data in average array - batV.reading(int(sensors.batteryVoltage * 100)); - // Calculate the average values for different time lines from integer values - 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){ + if(deltaV > 0.045){ sensors.BatteryChargeStatus = 1; // Charging active } - if(deltaV < -0.03){ + if(deltaV < -0.04){ 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); diff --git a/lib/obp60task/PageVoltage.cpp b/lib/obp60task/PageVoltage.cpp index fe1070b..c98bc96 100644 --- a/lib/obp60task/PageVoltage.cpp +++ b/lib/obp60task/PageVoltage.cpp @@ -205,7 +205,7 @@ public: getdisplay().setCursor(20, 100); getdisplay().print(name1); // Value name - #ifdef BOARD_OBP40S3 + #if defined BOARD_OBP40S3 && defined LIPO_ACCU_1200 && defined VOLTAGE_SENSOR // Show charge status getdisplay().setFont(&Ubuntu_Bold8pt7b); getdisplay().setCursor(185, 100); @@ -228,7 +228,7 @@ public: #ifdef BOARD_OBP60S3 getdisplay().print(batType); #endif - #ifdef BOARD_OBP40S3 + #if defined BOARD_OBP40S3 && defined LIPO_ACCU_1200 && defined VOLTAGE_SENSOR getdisplay().print("LiPo"); #endif