eeprom_storeRetrieveConfig.ino 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. void loadConfig() {
  2. Serial.println();
  3. //Serial.println(F("LOADING CONFIG..."));
  4. uint16_t tmpint = 0;
  5. byte tmpbyte;
  6. Serial.println(F("loading global conf:"));
  7. EEPROM.get(eeprom_addr_debug, tmpbyte);
  8. Serial.print(F("debuglevel: "));
  9. if (tmpbyte == 0 || tmpbyte == 1) {
  10. debuglevel = tmpbyte;
  11. Serial.print(debuglevel);
  12. if (debuglevel == 0) debug = false;
  13. else if (debuglevel == 1) debug = true;
  14. }
  15. else {
  16. Serial.print(tmpbyte);
  17. Serial.println(F(" - invalid value stored"));
  18. }
  19. Serial.println();
  20. EEPROM.get(eeprom_addr_output_json, tmpbyte);
  21. Serial.print(F("json: "));
  22. if (tmpbyte == 0 || tmpbyte == 1) {
  23. Serial.println(tmpbyte);
  24. if (tmpbyte == 1) output_json = true;
  25. else if (tmpbyte == 0) output_json = false;
  26. }
  27. else {
  28. Serial.print(tmpbyte);
  29. Serial.println(F(" - invalid value stored"));
  30. }
  31. EEPROM.get(eeprom_addr_debounce1, tmpint);
  32. Serial.print(F("debounce1: "));
  33. if (tmpint >= 0 && tmpint <= 200) {
  34. debounceDelay = tmpint;
  35. Serial.println(debounceDelay);
  36. }
  37. else {
  38. Serial.println(F("invalid value stored"));
  39. }
  40. EEPROM.get(eeprom_addr_debounce2, tmpint);
  41. Serial.print(F("debounce2: "));
  42. if (tmpint >= 0 && tmpint <= 500) {
  43. debounceRecoveryDelay = tmpint;
  44. Serial.println(debounceRecoveryDelay);
  45. }
  46. else {
  47. Serial.println(F("invalid value stored"));
  48. }
  49. EEPROM.get(eeprom_addr_powerGoodMinValue, tmpint);
  50. Serial.print(F("pwrGood: "));
  51. if (tmpint >= 0 && tmpint <= 1023) {
  52. powerGoodMinValue = tmpint;
  53. Serial.println(powerGoodMinValue);
  54. }
  55. else {
  56. Serial.println(F("invalid value stored"));
  57. }
  58. Serial.println();
  59. // per counter
  60. Serial.println(F("loading counters conf:"));
  61. for (byte i = 0; i < COUNTERS_COUNT; i++) {
  62. Serial.println();
  63. Serial.print("C");
  64. Serial.print(i + 1);
  65. Serial.print(": ");
  66. EEPROM.get(eeprom_addr_impPerUnit[i], tmpint);
  67. Serial.print(F("impPerUnit="));
  68. Serial.print(tmpint);
  69. if (tmpint == 10 || tmpint == 100 || tmpint == 1000) {
  70. meter_impPerUnit[i] = tmpint;
  71. }
  72. else {
  73. Serial.println();
  74. Serial.print(F("WARNING: C"));
  75. Serial.print(i + 1);
  76. Serial.println(F(" config impPerUnit is invalid!"));
  77. Serial.print("C");
  78. Serial.print(i + 1);
  79. Serial.print(": ");
  80. }
  81. EEPROM.get(eeprom_addr_noImpTout[i], tmpint);
  82. Serial.print(F(", noImpTout="));
  83. Serial.print(tmpint);
  84. if (tmpint >= 0 && tmpint <= 3600) {
  85. meter_noImpulseTimeout_seconds[i] = tmpint;
  86. }
  87. else {
  88. Serial.println();
  89. Serial.print(F("WARNING: C"));
  90. Serial.print(i + 1);
  91. Serial.println(F(" config noImpTout is invalid (out of range 0-3600)!"));
  92. Serial.print("C");
  93. Serial.print(i + 1);
  94. Serial.print(": ");
  95. }
  96. EEPROM.get(eeprom_addr_saveInt[i], tmpint);
  97. Serial.print(F(", saveInt="));
  98. Serial.print(tmpint);
  99. if (tmpint >= 0 && tmpint <= 3600) {
  100. meter_savePulsesOnInterval_mins[i] = tmpint;
  101. }
  102. else {
  103. Serial.println();
  104. Serial.print(F("WARNING: C"));
  105. Serial.print(i + 1);
  106. Serial.println(F(" config saveInt is invalid (out of range 0-3600)!"));
  107. Serial.print("C");
  108. Serial.print(i + 1);
  109. Serial.print(": ");
  110. }
  111. }
  112. Serial.println();
  113. }
  114. void printCounterConf(byte _cNum) {
  115. Serial.print(F("CONF C"));
  116. Serial.print(_cNum + 1);
  117. Serial.print(F(": impPerUnit="));
  118. Serial.print(meter_impPerUnit[_cNum]);
  119. Serial.print(F(", noImpTout="));
  120. Serial.print(meter_noImpulseTimeout_seconds[_cNum]);
  121. Serial.print(F(", saveInt="));
  122. Serial.print(meter_savePulsesOnInterval_mins[_cNum]);
  123. Serial.println();
  124. }
  125. void printGlobalConf() {
  126. Serial.print(F("CONF GLOB: debuglevel="));
  127. Serial.print(debuglevel);
  128. Serial.print(F(", debounce="));
  129. Serial.print(debounceDelay);
  130. Serial.print(F(", debRecov="));
  131. Serial.print(debounceRecoveryDelay);
  132. Serial.print(F(", pwrGood="));
  133. Serial.print(powerGoodMinValue);
  134. Serial.println();
  135. }
  136. void saveGlobalConfig() {
  137. Serial.println(F("SAVING GLOBAL CONFIG"));
  138. if (debounceDelay >= 0 && debounceDelay <= 200) {
  139. EEPROM.put(eeprom_addr_debounce1, debounceDelay);
  140. }
  141. if (debounceRecoveryDelay >= 0 && debounceRecoveryDelay <= 500) {
  142. EEPROM.put(eeprom_addr_debounce2, debounceRecoveryDelay);
  143. }
  144. if (powerGoodMinValue >= 0 && powerGoodMinValue <= 1023) {
  145. EEPROM.put(eeprom_addr_powerGoodMinValue, powerGoodMinValue);
  146. }
  147. }
  148. void saveCountersConfig() {
  149. for (byte i = 0; i < COUNTERS_COUNT; i++) {
  150. Serial.print(F("SAVING C"));
  151. Serial.print(i + 1);
  152. Serial.print(F(" - impPerUnit="));
  153. Serial.println(meter_impPerUnit[i]);
  154. if (meter_impPerUnit[i] == 10 || meter_impPerUnit[i] == 100 || meter_impPerUnit[i] == 1000) {
  155. EEPROM.put(eeprom_addr_impPerUnit[i], meter_impPerUnit[i]);
  156. }
  157. else {
  158. Serial.print(F("WARNING: C"));
  159. Serial.print(i + 1);
  160. Serial.println(F(" config 'impPerUnit' invalid! Did not save."));
  161. }
  162. Serial.print(F("SAVING C"));
  163. Serial.print(i + 1);
  164. Serial.print(F(" - noImpTout="));
  165. Serial.println(meter_noImpulseTimeout_seconds[i]);
  166. if (meter_noImpulseTimeout_seconds[i] >= 0 && meter_noImpulseTimeout_seconds[i] <= 3600) {
  167. EEPROM.put(eeprom_addr_noImpTout[i], meter_noImpulseTimeout_seconds[i]);
  168. }
  169. else {
  170. Serial.print(F("WARNING: C"));
  171. Serial.print(i + 1);
  172. Serial.println(F(" config 'noImpTout' invalid! Did not save."));
  173. }
  174. Serial.print(F("SAVING C"));
  175. Serial.print(i + 1);
  176. Serial.print(F(" - noImpTout="));
  177. Serial.println(meter_savePulsesOnInterval_mins[i]);
  178. if (meter_savePulsesOnInterval_mins[i] >= 0 && meter_savePulsesOnInterval_mins[i] <= 3600) {
  179. EEPROM.put(eeprom_addr_saveInt[i], meter_savePulsesOnInterval_mins[i]);
  180. }
  181. else {
  182. Serial.print(F("WARNING: C"));
  183. Serial.print(i + 1);
  184. Serial.println(F(" config 'noImpTout' invalid! Did not save."));
  185. }
  186. }
  187. }