Fix LiPo battery level and sensor pad
This commit is contained in:
parent
c202554c5c
commit
9dc857056b
|
@ -277,8 +277,8 @@ void initKeys(CommonData &commonData) {
|
||||||
starttime = millis(); // Start key pressed
|
starttime = millis(); // Start key pressed
|
||||||
keycodeold = keycode;
|
keycodeold = keycode;
|
||||||
}
|
}
|
||||||
// If key pressed longer than 200ms
|
// If key pressed longer than 100ms
|
||||||
if(millis() > starttime + 200 && keycode == keycodeold) {
|
if(millis() > starttime + 100 && keycode == keycodeold) {
|
||||||
if (use_syspage and keycode == 3) {
|
if (use_syspage and keycode == 3) {
|
||||||
keystatus = 12;
|
keystatus = 12;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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
|
float rawVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
|
||||||
#endif
|
#endif
|
||||||
sensors.batteryVoltage = rawVoltage * vslope + voffset; // Calibration
|
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%
|
// 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
|
// Limiter
|
||||||
if(sensors.batteryLevelLiPo > 100){
|
if(sensors.batteryLevelLiPo > 100){
|
||||||
sensors.batteryLevelLiPo = 100;
|
sensors.batteryLevelLiPo = 100;
|
||||||
|
@ -483,22 +489,14 @@ void sensorTask(void *param){
|
||||||
if(sensors.batteryLevelLiPo < 0){
|
if(sensors.batteryLevelLiPo < 0){
|
||||||
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
|
// Charging detection
|
||||||
float deltaV = sensors.batteryVoltage - sensors.batteryVoltage10;
|
float deltaV = sensors.batteryVoltage - sensors.batteryVoltage10;
|
||||||
if(deltaV > 0.03){
|
if(deltaV > 0.045){
|
||||||
sensors.BatteryChargeStatus = 1; // Charging active
|
sensors.BatteryChargeStatus = 1; // Charging active
|
||||||
}
|
}
|
||||||
if(deltaV < -0.03){
|
if(deltaV < -0.04){
|
||||||
sensors.BatteryChargeStatus = 0; // Discharging
|
sensors.BatteryChargeStatus = 0; // Discharging
|
||||||
}
|
}
|
||||||
#ifdef BOARD_OBP40S3
|
|
||||||
// Send to NMEA200 bus as instance 10
|
// Send to NMEA200 bus as instance 10
|
||||||
if(!isnan(sensors.batteryVoltage)){
|
if(!isnan(sensors.batteryVoltage)){
|
||||||
SetN2kDCBatStatus(N2kMsg, 10, sensors.batteryVoltage, N2kDoubleNA, N2kDoubleNA, 0);
|
SetN2kDCBatStatus(N2kMsg, 10, sensors.batteryVoltage, N2kDoubleNA, N2kDoubleNA, 0);
|
||||||
|
|
|
@ -205,7 +205,7 @@ public:
|
||||||
getdisplay().setCursor(20, 100);
|
getdisplay().setCursor(20, 100);
|
||||||
getdisplay().print(name1); // Value name
|
getdisplay().print(name1); // Value name
|
||||||
|
|
||||||
#ifdef BOARD_OBP40S3
|
#if defined BOARD_OBP40S3 && defined LIPO_ACCU_1200 && defined VOLTAGE_SENSOR
|
||||||
// Show charge status
|
// Show charge status
|
||||||
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
getdisplay().setFont(&Ubuntu_Bold8pt7b);
|
||||||
getdisplay().setCursor(185, 100);
|
getdisplay().setCursor(185, 100);
|
||||||
|
@ -228,7 +228,7 @@ public:
|
||||||
#ifdef BOARD_OBP60S3
|
#ifdef BOARD_OBP60S3
|
||||||
getdisplay().print(batType);
|
getdisplay().print(batType);
|
||||||
#endif
|
#endif
|
||||||
#ifdef BOARD_OBP40S3
|
#if defined BOARD_OBP40S3 && defined LIPO_ACCU_1200 && defined VOLTAGE_SENSOR
|
||||||
getdisplay().print("LiPo");
|
getdisplay().print("LiPo");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue