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

@ -4,7 +4,7 @@
#include "Arduino.h"
#define EEPROM_SIZE 1024*3
#define EEPROM_CHECK_SUM 101 // Used to check if config is stored. Change if structure changes
#define EEPROM_CHECK_SUM 102 // Used to check if config is stored. Change if structure changes
#define EEPROM_CLEARED_INDICATOR 0xFC
#define EEPROM_CONFIG_ADDRESS 0
#define EEPROM_TEMP_CONFIG_ADDRESS 2048
@ -175,6 +175,11 @@ struct EntsoeConfig {
}; // 62
struct EnergyAccountingConfig {
uint16_t thresholds[10];
uint8_t hours;
}; // 21
struct EnergyAccountingConfig101 {
uint8_t thresholds[10];
uint8_t hours;
}; // 11
@ -298,6 +303,7 @@ private:
bool relocateConfig95(); // 2.1.4
bool relocateConfig96(); // 2.1.14
bool relocateConfig100(); // 2.2-dev
bool relocateConfig101(); // 2.2.0 through 2.2.8
void saveToFs();
bool loadFromFs(uint8_t version);

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);

File diff suppressed because one or more lines are too long

View File

@ -540,7 +540,7 @@
{#each {length: 9} as _, i}
<label class="flex w-40 m-1">
<span class="in-pre">{i+1}</span>
<input name="t{i}" bind:value={configuration.t.t[i]} type="number" min="0" max="255" class="in-txt w-full"/>
<input name="t{i}" bind:value={configuration.t.t[i]} type="number" min="0" max="65535" class="in-txt w-full"/>
<span class="in-post">kWh</span>
</label>
{/each}