From efabac4b8ec9e1b56b2616f6d78f98ddc8416dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Sun, 6 Apr 2025 21:26:04 +0300 Subject: [PATCH] Add negative SOC scaling --- Software/Software.ino | 6 ++++++ Software/src/datalayer/datalayer.h | 2 +- Software/src/devboard/webserver/settings_html.cpp | 7 ++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Software/Software.ino b/Software/Software.ino index f779ed5d..4666a031 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -427,6 +427,12 @@ void update_calculated_values() { calc_soc = 10000 * (calc_soc - datalayer.battery.settings.min_percentage); calc_soc = calc_soc / (datalayer.battery.settings.max_percentage - datalayer.battery.settings.min_percentage); datalayer.battery.status.reported_soc = calc_soc; + //Extra safety since we allow scaling negatively, if real% is < 1.00%, zero it out + if (datalayer.battery.status.real_soc < 100) { + datalayer.battery.status.reported_soc = 0; + } else { + datalayer.battery.status.reported_soc = calc_soc; + } // Calculate the scaled remaining capacity in Wh if (datalayer.battery.info.total_capacity_Wh > 0 && datalayer.battery.status.real_soc > 0) { diff --git a/Software/src/datalayer/datalayer.h b/Software/src/datalayer/datalayer.h index e9fc9867..9ce97676 100644 --- a/Software/src/datalayer/datalayer.h +++ b/Software/src/datalayer/datalayer.h @@ -113,7 +113,7 @@ typedef struct { /** Minimum percentage setting. Set this value to the lowest real SOC * you want the inverter to be able to use. At this real SOC, the inverter * will "see" 0% */ - uint16_t min_percentage = BATTERY_MINPERCENTAGE; + int16_t min_percentage = BATTERY_MINPERCENTAGE; /** Maximum percentage setting. Set this value to the highest real SOC * you want the inverter to be able to use. At this real SOC, the inverter * will "see" 100% */ diff --git a/Software/src/devboard/webserver/settings_html.cpp b/Software/src/devboard/webserver/settings_html.cpp index 0fc0dae9..2735a362 100644 --- a/Software/src/devboard/webserver/settings_html.cpp +++ b/Software/src/devboard/webserver/settings_html.cpp @@ -209,10 +209,11 @@ String settings_processor(const String& var) { "100.0');}}}"; content += "function editSocMin(){var value=prompt('Inverter will see completely discharged (0pct)SOC when this value is " - "reached. Enter new minimum SOC value that battery will discharge to " - "(0-50.0):');if(value!==null){if(value>=0&&value<=50){var xhr=new " + "reached. Advanced users can set to negative values. Enter new minimum SOC value that battery will discharge " + "to " + "(-10.0to50.0):');if(value!==null){if(value>=-10&&value<=50){var xhr=new " "XMLHttpRequest();xhr.onload=editComplete;xhr.onerror=editError;xhr.open('GET','/" - "updateSocMin?value='+value,true);xhr.send();}else{alert('Invalid value. Please enter a value between 0 and " + "updateSocMin?value='+value,true);xhr.send();}else{alert('Invalid value. Please enter a value between -10 and " "50.0');}}}"; content += "function editMaxChargeA(){var value=prompt('Some inverters needs to be artificially limited. Enter new "