EEPROM-Storage Library
The EEPROM Storage library provides the ability to access variables stored in EEPROM just as if they were stored in RAM.
 
Loading...
Searching...
No Matches
EEPROM-Util.h
Go to the documentation of this file.
1// Copyright © 2017-2025 Daniel Porrey. All Rights Reserved.
2//
3// This file is part of the EEPROM-Storage library.
4//
5// EEPROM-Storage library is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// EEPROM-Storage library is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with EEPROM-Storage library. If not,
17// see http://www.gnu.org/licenses/.
18//
19#pragma once
20#ifndef EEPROM_UTIL_H
21#define EEPROM_UTIL_H
22
28//
29// Cross-compatable with Arduino, GNU C++ for tests, and Particle.
30//
31#if defined(ARDUINO) && ARDUINO >= 100
32 #include <Arduino.h>
33 #include <EEPROM.h>
34#elif defined(PARTICLE)
35 #include <Particle.h>
36#endif
37
38#include "EEPROM-Vars.h"
39
45{
46 public:
55 void clearEEPROM(uint value = UNSET_VALUE)
56 {
57 for (uint i = 0; i < EEPROM.length(); i++)
58 {
59 this->updateEEPROM(i, value);
60 }
61 }
62
71 void updateEEPROM(uint address, byte value)
72 {
73 if (address < EEPROM.length())
74 {
75 #if defined(ESP8266)
76 EEPROM.write(address, value);
77 #else
78 EEPROM.update(address, value);
79 #endif
80 }
81 }
82};
83
87static EEPROMUtilClass EEPROMUtil;
88#endif
#define UNSET_VALUE
Defines the default value used when clearing the EEPROM memory.
Definition EEPROM-Vars.h:39
Provides the ability to clear the EEPROM memory.
Definition EEPROM-Util.h:45
void clearEEPROM(uint value=UNSET_VALUE)
Resets the contents of EEPROM to the value specified.
Definition EEPROM-Util.h:55
void updateEEPROM(uint address, byte value)
Provides a unified method od writing to the EEPROM on multiple platforms.alignas.
Definition EEPROM-Util.h:71