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-Storage.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_STORAGE_H
21#define EEPROM_STORAGE_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-Base.h"
39
49template <typename T>
50class EEPROMStorage : public EEPROMBase<T>
51{
52 public:
57 EEPROMStorage(const uint address) : EEPROMBase<T>(address)
58 {
59 }
60
66 EEPROMStorage(const uint address, T defaultValue) : EEPROMBase<T>(address, defaultValue)
67 {
68 }
69
78 {
79 this->set(value);
80 return *this;
81 }
82
90 {
91 this->set(item.get());
92 return *this;
93 }
94
99 T get() const
100 {
101 return this->read();
102 }
103
109 T set(T const& value)
110 {
111 this->write(value);
112 return this->get();
113 }
114};
115#endif
This file contains the EEPROMBase<T> definition.
Base class to wrap an EEPROM variable.
Definition EEPROM-Base.h:54
void write(T const &value) const
Write the value to the EEPROM using the address in this instance.
T read() const
Read the variable value from the EEPROM using the address in this variable.
Provides direct access to an EEPROM variable.
EEPROMStorage(const uint address, T defaultValue)
Initialize an instance of EEPROMBase with the specified address and default value.
EEPROMStorage(const uint address)
Initialize an instance of EEPROMStorage<T> with the specified address.
T get() const
Get the variable value.
T set(T const &value)
Set the variable value.
EEPROMStorage< T > & operator=(T const &value)
Allows assignment of a variable of type T value to be this instance's value.