EEPROM.ino 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifdef DEBUGMODE
  2. void getEEPROMContent() {
  3. getEEPROMContent(EEPROM_SIZE);
  4. }
  5. void getEEPROMContent(int _len) {
  6. EEPROM.begin(EEPROM_SIZE);
  7. int _eeprom_address = 0;
  8. uint8_t _eeprom_value;
  9. Serial.print(F("EEPROM length: "));
  10. Serial.println(EEPROM.length());
  11. Serial.println(F("EEPROM data:"));
  12. //sprintf(logBuf, F("EEPROM-Data:"));
  13. //sendLog(logBuf);
  14. delay(20);
  15. //Serial.println(F("ADDR\t0\t1\t2\t3\t4\t5\t6\t7"));
  16. //Serial.println(F("ADDR"));
  17. //delay(1);
  18. //Serial.println();
  19. int _col = 0;
  20. if (_len == 0) _len = EEPROM.length();
  21. for (int _i = 0; _i < _len; _i++) {
  22. _eeprom_value = EEPROM.read(_eeprom_address);
  23. if (_col == 0) {
  24. //Serial.print(_eeprom_address);
  25. Serial.print("0x");
  26. if (_eeprom_address < 16) Serial.print("0");
  27. Serial.print(_eeprom_address, HEX);
  28. //Serial.print("\t");
  29. Serial.print(": ");
  30. }
  31. if (_eeprom_value < 16) Serial.print("0");
  32. Serial.print(_eeprom_value, HEX);
  33. //Serial.print(_eeprom_value, DEC);
  34. //Serial.print("\t");
  35. Serial.print(" ");
  36. _eeprom_address = _eeprom_address + 1;
  37. if (_col >= 15) {
  38. _col = 0;
  39. Serial.println();
  40. delay(20); // otherwise ESP UART cannot receive correctly
  41. }
  42. else _col++;
  43. }
  44. EEPROM.end();
  45. }
  46. #endif
  47. void formatEEPROMArea(int _from, int _len) {
  48. EEPROM.begin(EEPROM_SIZE);
  49. int _to;
  50. _to = _from + _len - 1;
  51. if(_to >= EEPROM_SIZE) _to = EEPROM_SIZE;
  52. Serial.print(F("EEPROM - formatting area from "));
  53. Serial.print(_from);
  54. Serial.print(F(" to "));
  55. Serial.println(_to);
  56. for (int i = _from; i <= _to; i++) {
  57. Serial.print(".");
  58. EEPROM.write(i, 0);
  59. }
  60. Serial.println("DONE");
  61. EEPROM.commit();
  62. EEPROM.end();
  63. }
  64. void formatEEPROM_AllData() {
  65. formatEEPROMArea(0, EEPROM_SIZE);
  66. }
  67. void clearSecrets_EEPROM() {
  68. sendLog(F("CONF: clearing Secrets from EEPROM."));
  69. formatEEPROMArea(EEPROM_STARTADDR_SECRETS, sizeof(confSecrets) + 2);
  70. }