Skip to content

Commit 9d944c3

Browse files
authored
V2.0.0 (#8)
* Added EEPROMCache<T> * Update simple.ino * Moved random init * Moved random init * rebased class * removed equality * added equality * Added examples * Updates * Updated examples * Update keywords.txt * Update EEPROM-Checksum.h * Update library.properties * Update .gitignore * Delete settings.json * Updated examples * Updated Tests * Update Assert.h * Update types.h * Update types.h * Update EEPROM-Var.h * Delete simple2.ino * Delete simple1.ino * Create simple.ino * Updated references * Update ArithmeticTests.h * Update TestRunner.h * Update tests.ino * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update keywords.txt * Updates * Update Assert.h * Create library.json * Serial Updates * Deleted * Update cloud.ino * Update tests.ino * Update EEPROM-Base.h * Update tests.ino * Update library.json * Added Arduin Debug * Removed Serial * Update verification.txt * Update README.md * Create debug.ino * Updates * Removed "\r\n * #7 * Changed SPARK to PARTICLE * Update arduino.yml * Update arduino.yml * Update arduino.yml * Renamed * Update verification.txt * Update README.md * Update arduino.yml * Update address.ino * Update clear.ino * Updates * Update Assert.h * Updates * Updated * Update RunOnceTest.h * Update verification.txt * Updated for Particle platform * Changed Dependency * Fixed for Particle * Create particle-compile.yml * Update particle-compile.yml * Update particle-compile.yml * Update particle-compile.yml * Update particle-compile.yml * Update README.md * Update library.json * Restore class name * Update arduino.yml * Renamed * Update particle-build.yml * Create project.properties * Update particle-build.yml * Update arduino-build.yml * Update doxygen.yml * Updated * Update EEPROM-Base.h * Update build.sh * Update tests.ino * Update README.md * Update tests.ino * Update EEPROM-Base.h * Update README.md * Updated branch name
1 parent da283ad commit 9d944c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+6099
-2273
lines changed

.github/workflows/arduino-build.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Arduino Build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Install Arduino CLI (Prebuilt)
20+
run: |
21+
wget https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_64bit.tar.gz
22+
tar -xvf arduino-cli_latest_Linux_64bit.tar.gz
23+
sudo mv arduino-cli /usr/local/bin/
24+
25+
- name: Configure Arduino CLI
26+
run: |
27+
arduino-cli config init
28+
arduino-cli core update-index
29+
arduino-cli core install arduino:avr # Install Arduino AVR core
30+
31+
- name: Compile Cache Sketches
32+
run: |
33+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Cache/address/address.ino || exit 1
34+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Cache/advanced-structure/advanced-structure.ino || exit 1
35+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Cache/assignment/assignment.ino || exit 1
36+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Cache/basic-structure/basic-structure.ino || exit 1
37+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Cache/byte-index/byte-index.ino || exit 1
38+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Cache/demo/demo.ino || exit 1
39+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Cache/scope/scope.ino || exit 1
40+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Cache/shadow/shadow.ino || exit 1
41+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Cache/simple/simple.ino || exit 1
42+
43+
- name: Compile General Sketches
44+
run: |
45+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/General/address/address.ino || exit 1
46+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/General/clear/clear.ino || exit 1
47+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/General/debug/debug.ino || exit 1
48+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/General/sizeof/sizeof.ino || exit 1
49+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/General/tests/tests.ino || exit 1
50+
51+
- name: Compile Storage Sketches
52+
run: |
53+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/address/address.ino || exit 1
54+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/advanced-structure/advanced-structure.ino || exit 1
55+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/assignment/assignment.ino || exit 1
56+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/basic-structure/basic-structure.ino || exit 1
57+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/byte-index/byte-index.ino || exit 1
58+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/checksum/checksum.ino || exit 1
59+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/copy-to/copy-to.ino || exit 1
60+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/demo/demo.ino || exit 1
61+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/invalid-address/invalid-address.ino || exit 1
62+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/scope/scope.ino || exit 1
63+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/shadow/shadow.ino || exit 1
64+
arduino-cli compile --fqbn arduino:avr:mega --library src --library $HOME/Arduino/libraries/ examples/Storage/simple/simple.ino || exit 1
65+

.github/workflows/arduino.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

.github/workflows/doxygen.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ name: Generate Doxygen Documentation
33
on:
44
push:
55
branches:
6-
- master # Change to your default branch
6+
- master
7+
pull_request:
8+
branches:
9+
- master
710

811
permissions:
912
contents: write

.github/workflows/particle-build.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Particle Compile
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
compile:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Install Particle CLI
19+
run: |
20+
npm install -g particle-cli
21+
particle --version
22+
23+
- name: Authenticate Particle CLI
24+
run: |
25+
particle login --token ${{ secrets.PARTICLE_ACCESS_TOKEN }}
26+
27+
- name: Compile tests.ino firmware
28+
run: |
29+
particle compile photon examples/General/tests --saveTo firmware.bin || exit 1
30+
31+
- name: Compile cloud.ino firmware
32+
run: |
33+
particle compile photon examples/Particle/cloud --saveTo firmware.bin || exit 1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
*.out
2929
*.app
3030
.DS_Store
31+
/.vscode

README.md

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
![Arduino Build](https://github.com/porrey/EEPROM-Storage/actions/workflows/arduino.yml/badge.svg?branch=master)
2-
![GitHub release](https://img.shields.io/github/v/release/porrey/EEPROM-Storage)
1+
![Arduino Build](https://github.com/porrey/EEPROM-Storage/actions/workflows/arduino-build.yml/badge.svg?branch=master)
2+
![Particle Build](https://github.com/porrey/EEPROM-Storage/actions/workflows/particle-build.yml/badge.svg?branch=master)
3+
![GitHub release](https://img.shields.io/github/v/release/porrey/EEPROM-Storage?label=Latest%20Release)
34

45
# EEPROM-Storage Library
5-
## Overview ##
6+
## Overview
67
The EEPROM Storage library provides the ability to access variables stored in EEPROM just as if they were stored in normal RAM.
78

9+
## EEPROMStorage\<T\> vs EEPROMCache\<T\>
10+
There are two classes that provide the similar access to EEEPROM. The first is the Direct Storage class which reads and writes to directly to and from EEPROM. The second is the Cache Access whichs reads and writes from memory and writes to the EEPROM when directed.
11+
12+
Other than the `restore()` and `commit()` (*see description below*) methods on the cache based class, these objects can be used interchangably.
13+
14+
### Direct Storage (EEPROMStorage\<T\>)
15+
This class writes directly to the EEPROM whenever the variable value is updated and reads directly from EEPROM when the variable value is accessed.
16+
17+
Within the library, examples of how to use this type of access can be found in the **Storage** folder under **Examples**.
18+
19+
### Cached Access (EEPROMCache\<T\>)
20+
This class reads and writes the variable value from RAM and only updates the value from EEPROM when `restore()` is called. Subsequently it only writes to EEPROM when `commit()` is called.
21+
22+
Within the library, examples of how to use this type of access can be found in the **Cache** folder under **Examples**.
23+
24+
## General Usage
825
Once defined, a variable can be used in in the same manner as its underlying type. For example, a variable defined as an integer (int) would be defined as follows:
926

1027
int i = 0;
@@ -17,27 +34,32 @@ To set the value to a specific value we would, for example, use the statement
1734

1835
i = 12;
1936

20-
This is all very obvious to even the novice programmer but is used here to show the simplicity of the EEPROM Storage class. An integer variable stored in EEPROM would be defined in the following manner:
37+
This is all standard coding to even the novice programmer but is used here to show the simplicity of the EEPROM Storage/Cache class. An integer variable stored in EEPROM would be defined in the following manner:
2138

2239
EEPROMStorage<int> i(0, 0);
40+
41+
or
42+
43+
EEPROMCache<int> i(0, 0);
2344

2445
where the first parameter of the constructor defines the address of the variable in EEPROM, and the second parameter defines the default value.
2546

2647
After the definition, the variable `i` can be used in the same manner, `i++` and `i = 12` will work the same way they did before, but now the value is stored and retrieved to and from EEPROM.
2748

28-
## EEPROM Address ##
29-
### Memory Requirement ###
49+
## EEPROM Address
50+
### Memory Requirement
51+
---
3052
When defining an EEPROM Storage variable, it is important to understand the number of bytes required for the underlying type and ensuring that the variables are spaced appropriately so they do not collide.
3153

3254
Each variable requires enough memory to store the underlying type plus one additional byte for a checksum.
3355

3456
Consider the following variable definitions.
3557

36-
EEPROMStorage<uint8_t> v1(0, 0); // 2 bytes (1 + 1 checksum), positions 0 and 1
37-
EEPROMStorage<uint16_t> v2(2, 0); // 3 bytes (2 + 1 checksum), positions 2, 3 and 4
38-
EEPROMStorage<uint32_t> v3(5, 0); // 5 bytes (4 + 1 checksum), positions 5, 6, 6, 8 and 9
39-
EEPROMStorage<float> v4(10, 0.0); // 5 bytes (4 + 1 checksum), positions 10, 11, 12, 13 and 14
40-
EEPROMStorage<bool> v5(15, false); // 2 bytes (1 + 1 checksum), positions 15, 16, 17, 18 and 19
58+
EEPROMStorage<uint8_t> v1(0, 0); // 2 bytes (1 + 1 checksum), positions 0 and 1
59+
EEPROMStorage<uint16_t> v2(2, 0); // 3 bytes (2 + 1 checksum), positions 2, 3 and 4
60+
EEPROMStorage<uint32_t> v3(5, 0); // 5 bytes (4 + 1 checksum), positions 5, 6, 6, 8 and 9
61+
EEPROMStorage<float> v4(10, 0.0); // 5 bytes (4 + 1 checksum), positions 10, 11, 12, 13 and 14
62+
EEPROMStorage<bool> v5(15, false); // 2 bytes (1 + 1 checksum), positions 15, 16, 17, 18 and 19
4163

4264
The best way to think about EEPROM memory is to think about it as a large byte array with a base index of 0. In fact, the Arduino libraries construct access to EEPROM in this manner.
4365

@@ -53,52 +75,57 @@ Using the nextAddress() method will make it easier to align your variables in me
5375

5476
EEPROMStorage<uint8_t> v1(0, 0); // 2 bytes (1 + 1 checksum), positions 0 and 1
5577
EEPROMStorage<uint16_t> v2(v1.nextAddress(), 0); // 3 bytes (2 + 1 checksum), positions 2, 3 and 4
56-
EEPROMStorage<uint32_t> v3(v2.nextAddress(), 0); // 5 bytes (4 + 1 checksum), positions 5, 6, 6, 8 and 9
78+
EEPROMStorage<uint32_t> v3(v2.nextAddress(), 0); // 5 bytes (4 + 1 checksum), positions 5, 6, 6, 8 and 9
5779
EEPROMStorage<float> v4(v3.nextAddress(), 0.0); // 5 bytes (4 + 1 checksum), positions 10, 11, 12, 13 and 14
5880
EEPROMStorage<bool> v5(v4.nextAddress(), false); // 2 bytes (1 + 1 checksum), positions 15, 16, 17, 18 and 19
5981

6082
### Determining Data Type Size ###
83+
---
6184
If you are not sure of the memory requirement for a given data type, you can use the `sizeof` operator. User the Serial port to display the size of any data type.
6285

63-
Serial.print("The size of int is "); Serial.print(sizeof(int)); Serial.println(".");
86+
Serial.print("The size of int is "); Serial.print(sizeof(int)); DEBUG_INFO(".");
6487

6588
When using the `sizeof` operator to determine the number of bytes to preserve remember to add one extra byte for the **checksum**.
6689

6790
To see a full demonstration of this, open the example sketch called **sizeof.ino**.
6891

69-
## EEPROM Storage Initialization ##
92+
## EEPROM Storage Initialization
7093
When data has never been stored EEPROM on a micro-controller the memory is in an uninitialized state. Since each byte of memory must have a value between 0 and 255, it is not always possible to detect an uninitialized byte. This behavior could have unexpected side effects if you define a variable and fail to detect whether the instance has been initialized.
7194

7295
For this reason, the EEPROM Storage library uses a one-byte checksum to determine if the instance has been initialized or not. When an instance is constructed, a default value is specified. This default value is always returned until a value is set thus initializing the location. Each write operation to EEPROM will update the checksum.
7396

74-
## Scope ##
97+
## Scope
7598
It is important to note that since `EEPROMStorage` variables are in fact, stored in the Micro-controllers EEPROM, the scope of these variables is always global. In fact it is possible to instantiate more than one instance using the same address that as a result will keep the two instances in sync.
7699

77100
> The `EEPROMStorage` variable never caches the value internally and will read the value from EEPROM each time it is requested. Similarly, each time the instance value is updated it is written directly to EEPROM.
78101
79-
# Usage #
80-
## Declaration ##
102+
# Usage
103+
## Declaration
81104
An instance of `EEPROMStorage` can be declared globally, within a class or within a function keeping in mind, as stated previously, that the address controls whether two or more instances share the same value.
82105

83106
The syntax for declaration is as follows:
84107

85108
EEPROMStorage<data type> variableName(address, default value);
86109

87-
### Data Type ###
110+
### Data Type
111+
---
88112
Specifies the underlying data type for the given instance.
89113

90-
### Address ###
114+
### Address
115+
---
91116
Specifies the starting index in EEPROM where the value will be stored.
92117

93-
### Default Value ###
118+
### Default Value
119+
---
94120
Specifies the value that will be returned by the instance when the EEPROM memory location has not been initialized (initialization is determined by the checksum).
95121

96-
### Example ###
122+
### Example
123+
---
97124
To initialize an instance with an underlying data type of int located in position 50 of the EEPROM and a default value of 10, the syntax would be as follows:
98125

99126
EEPROMStorage<int> myInt(50, 10);
100127

101-
## Assignment ##
128+
## Assignment
102129
Using the previous example, assigning a value to the instance is as simple as the assignment shown here.
103130

104131
myInt = 100;
@@ -107,20 +134,27 @@ The `EEPROMStorage` class also defines a `set()` method that can be used.
107134

108135
myInt.set(100);
109136

110-
## Retrieving ##
137+
## Retrieving
111138
To get the instance value, simply assign it to a variable, as shown below,
112139

113140
int x = myInt;
114141

115142
or pass it as an argument in any function that takes an int argument as shown below.
116143

117-
Serial.print("myInt = "); Serial.println(myInt);
144+
Serial.print("myInt = "); DEBUG_INFO(myInt);
118145

119146
The `EEPROMStorage` class also defines a `get()` method that can be used.
120147

121148
int x = myInt.get();
122149

123-
## LICENSE
124-
*Copyright 2017-2025 Daniel Porrey*
150+
## Platform/Boards Used in Testing
151+
1. Arduino on Mega 2560
152+
2. Arduino on ESP8266 [ESPino (ESP-12 Module)]
153+
3. Particle on Argon with OS version 6.2.1
154+
4. Particle on Photon with OS version 3.3.1
155+
5. Particle on Electron with OS version 3.3.1
125156

157+
## LICENSE
126158
*Licensed under the GPL-3.0 license*
159+
160+
*Copyright 2017-2025 Daniel Porrey*

0 commit comments

Comments
 (0)