Increased range of tariff thresholds

This commit is contained in:
Gunnar Skjold
2023-02-21 15:29:10 +01:00
parent 98309ea532
commit 062068eacd
4 changed files with 42 additions and 9 deletions

View File

@@ -556,7 +556,7 @@ bool AmsConfiguration::getEnergyAccountingConfig(EnergyAccountingConfig& config)
EEPROM.begin(EEPROM_SIZE);
EEPROM.get(CONFIG_ENERGYACCOUNTING_START, config);
EEPROM.end();
if(config.thresholds[9] != 255) {
if(config.thresholds[9] != 0xFFFF) {
clearEnergyAccountingConfig(config);
}
if(config.hours > 5) config.hours = 5;
@@ -576,7 +576,7 @@ bool AmsConfiguration::setEnergyAccountingConfig(EnergyAccountingConfig& config)
energyAccountingChanged = true;
}
}
config.thresholds[9] = 255;
config.thresholds[9] = 0xFFFF;
energyAccountingChanged |= config.hours != existing.hours;
} else {
energyAccountingChanged = true;
@@ -598,7 +598,7 @@ void AmsConfiguration::clearEnergyAccountingConfig(EnergyAccountingConfig& confi
config.thresholds[6] = 75;
config.thresholds[7] = 100;
config.thresholds[8] = 150;
config.thresholds[9] = 255;
config.thresholds[9] = 0xFFFF;
config.hours = 3;
}
@@ -756,6 +756,14 @@ bool AmsConfiguration::hasConfig() {
configVersion = 0;
return false;
}
case 101:
configVersion = -1; // Prevent loop
if(relocateConfig101()) {
configVersion = 102;
} else {
configVersion = 0;
return false;
}
case EEPROM_CHECK_SUM:
return true;
default:
@@ -958,6 +966,25 @@ bool AmsConfiguration::relocateConfig100() {
return ret;
}
bool AmsConfiguration::relocateConfig101() {
EEPROM.begin(EEPROM_SIZE);
EnergyAccountingConfig config;
EnergyAccountingConfig101 config101;
EEPROM.get(CONFIG_ENERGYACCOUNTING_START, config101);
for(uint8_t i = 0; i < 9; i++) {
config.thresholds[i] = config101.thresholds[i];
}
config.thresholds[9] = 0xFFFF;
config.hours = config101.hours;
EEPROM.put(CONFIG_ENERGYACCOUNTING_START, config);
EEPROM.put(EEPROM_CONFIG_ADDRESS, 102);
bool ret = EEPROM.commit();
EEPROM.end();
return ret;
}
bool AmsConfiguration::save() {
EEPROM.begin(EEPROM_SIZE);
EEPROM.put(EEPROM_CONFIG_ADDRESS, EEPROM_CHECK_SUM);