123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- void loadConfig() {
- Serial.println();
- //Serial.println(F("LOADING CONFIG..."));
- uint16_t tmpint = 0;
- byte tmpbyte;
- Serial.println(F("loading global conf:"));
- EEPROM.get(eeprom_addr_debug, tmpbyte);
- Serial.print(F("debuglevel: "));
- if (tmpbyte == 0 || tmpbyte == 1) {
- debuglevel = tmpbyte;
- Serial.print(debuglevel);
- if (debuglevel == 0) debug = false;
- else if (debuglevel == 1) debug = true;
- }
- else {
- Serial.print(tmpbyte);
- Serial.println(F(" - invalid value stored"));
- }
- Serial.println();
- EEPROM.get(eeprom_addr_output_json, tmpbyte);
- Serial.print(F("json: "));
- if (tmpbyte == 0 || tmpbyte == 1) {
- Serial.println(tmpbyte);
- if (tmpbyte == 1) output_json = true;
- else if (tmpbyte == 0) output_json = false;
- }
- else {
- Serial.print(tmpbyte);
- Serial.println(F(" - invalid value stored"));
- }
- EEPROM.get(eeprom_addr_debounce1, tmpint);
- Serial.print(F("debounce1: "));
- if (tmpint >= 0 && tmpint <= 200) {
- debounceDelay = tmpint;
- Serial.println(debounceDelay);
- }
- else {
- Serial.println(F("invalid value stored"));
- }
- EEPROM.get(eeprom_addr_debounce2, tmpint);
- Serial.print(F("debounce2: "));
- if (tmpint >= 0 && tmpint <= 500) {
- debounceRecoveryDelay = tmpint;
- Serial.println(debounceRecoveryDelay);
- }
- else {
- Serial.println(F("invalid value stored"));
- }
- EEPROM.get(eeprom_addr_powerGoodMinValue, tmpint);
- Serial.print(F("pwrGood: "));
- if (tmpint >= 0 && tmpint <= 1023) {
- powerGoodMinValue = tmpint;
- Serial.println(powerGoodMinValue);
- }
- else {
- Serial.println(F("invalid value stored"));
- }
- Serial.println();
- // per counter
- Serial.println(F("loading counters conf:"));
- for (byte i = 0; i < COUNTERS_COUNT; i++) {
- Serial.println();
- Serial.print("C");
- Serial.print(i + 1);
- Serial.print(": ");
- EEPROM.get(eeprom_addr_impPerUnit[i], tmpint);
- Serial.print(F("impPerUnit="));
- Serial.print(tmpint);
- if (tmpint == 10 || tmpint == 100 || tmpint == 1000) {
- meter_impPerUnit[i] = tmpint;
- }
- else {
- Serial.println();
- Serial.print(F("WARNING: C"));
- Serial.print(i + 1);
- Serial.println(F(" config impPerUnit is invalid!"));
- Serial.print("C");
- Serial.print(i + 1);
- Serial.print(": ");
- }
- EEPROM.get(eeprom_addr_noImpTout[i], tmpint);
- Serial.print(F(", noImpTout="));
- Serial.print(tmpint);
- if (tmpint >= 0 && tmpint <= 3600) {
- meter_noImpulseTimeout_seconds[i] = tmpint;
- }
- else {
- Serial.println();
- Serial.print(F("WARNING: C"));
- Serial.print(i + 1);
- Serial.println(F(" config noImpTout is invalid (out of range 0-3600)!"));
- Serial.print("C");
- Serial.print(i + 1);
- Serial.print(": ");
- }
- EEPROM.get(eeprom_addr_saveInt[i], tmpint);
- Serial.print(F(", saveInt="));
- Serial.print(tmpint);
- if (tmpint >= 0 && tmpint <= 3600) {
- meter_savePulsesOnInterval_mins[i] = tmpint;
- }
- else {
- Serial.println();
- Serial.print(F("WARNING: C"));
- Serial.print(i + 1);
- Serial.println(F(" config saveInt is invalid (out of range 0-3600)!"));
- Serial.print("C");
- Serial.print(i + 1);
- Serial.print(": ");
- }
- }
- Serial.println();
- }
- void printCounterConf(byte _cNum) {
- Serial.print(F("CONF C"));
- Serial.print(_cNum + 1);
- Serial.print(F(": impPerUnit="));
- Serial.print(meter_impPerUnit[_cNum]);
- Serial.print(F(", noImpTout="));
- Serial.print(meter_noImpulseTimeout_seconds[_cNum]);
- Serial.print(F(", saveInt="));
- Serial.print(meter_savePulsesOnInterval_mins[_cNum]);
- Serial.println();
- }
- void printGlobalConf() {
- Serial.print(F("CONF GLOB: debuglevel="));
- Serial.print(debuglevel);
- Serial.print(F(", debounce="));
- Serial.print(debounceDelay);
- Serial.print(F(", debRecov="));
- Serial.print(debounceRecoveryDelay);
- Serial.print(F(", pwrGood="));
- Serial.print(powerGoodMinValue);
- Serial.println();
- }
- void saveGlobalConfig() {
- Serial.println(F("SAVING GLOBAL CONFIG"));
- if (debounceDelay >= 0 && debounceDelay <= 200) {
- EEPROM.put(eeprom_addr_debounce1, debounceDelay);
- }
- if (debounceRecoveryDelay >= 0 && debounceRecoveryDelay <= 500) {
- EEPROM.put(eeprom_addr_debounce2, debounceRecoveryDelay);
- }
- if (powerGoodMinValue >= 0 && powerGoodMinValue <= 1023) {
- EEPROM.put(eeprom_addr_powerGoodMinValue, powerGoodMinValue);
- }
- }
- void saveCountersConfig() {
- for (byte i = 0; i < COUNTERS_COUNT; i++) {
- Serial.print(F("SAVING C"));
- Serial.print(i + 1);
- Serial.print(F(" - impPerUnit="));
- Serial.println(meter_impPerUnit[i]);
- if (meter_impPerUnit[i] == 10 || meter_impPerUnit[i] == 100 || meter_impPerUnit[i] == 1000) {
- EEPROM.put(eeprom_addr_impPerUnit[i], meter_impPerUnit[i]);
- }
- else {
- Serial.print(F("WARNING: C"));
- Serial.print(i + 1);
- Serial.println(F(" config 'impPerUnit' invalid! Did not save."));
- }
- Serial.print(F("SAVING C"));
- Serial.print(i + 1);
- Serial.print(F(" - noImpTout="));
- Serial.println(meter_noImpulseTimeout_seconds[i]);
- if (meter_noImpulseTimeout_seconds[i] >= 0 && meter_noImpulseTimeout_seconds[i] <= 3600) {
- EEPROM.put(eeprom_addr_noImpTout[i], meter_noImpulseTimeout_seconds[i]);
- }
- else {
- Serial.print(F("WARNING: C"));
- Serial.print(i + 1);
- Serial.println(F(" config 'noImpTout' invalid! Did not save."));
- }
- Serial.print(F("SAVING C"));
- Serial.print(i + 1);
- Serial.print(F(" - noImpTout="));
- Serial.println(meter_savePulsesOnInterval_mins[i]);
- if (meter_savePulsesOnInterval_mins[i] >= 0 && meter_savePulsesOnInterval_mins[i] <= 3600) {
- EEPROM.put(eeprom_addr_saveInt[i], meter_savePulsesOnInterval_mins[i]);
- }
- else {
- Serial.print(F("WARNING: C"));
- Serial.print(i + 1);
- Serial.println(F(" config 'noImpTout' invalid! Did not save."));
- }
- }
- }
|