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-Display.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_DISPLAY_H
21#define EEPROM_DISPLAY_H
22
31#ifndef DEBUG
32 #if defined(ARDUINO) && ARDUINO >= 100
33 #define DEBUG Serial
34 #elif defined(PARTICLE)
35 #define DEBUG USBSerial
36 #endif
37#endif
38
39//
40// Cross-compatable with Arduino, GNU C++ for tests, and Particle.
41//
42#if defined(ARDUINO) && ARDUINO >= 100
43 #include <Arduino.h>
44 #include <EEPROM.h>
45#elif defined(PARTICLE)
46 #include <Particle.h>
47#endif
48
49#include "EEPROM-Base.h"
50#include "EEPROM-Vars.h"
51#include "EEPROM-Debug.h"
52
53#define WIDTH 32
54#define LINE_WIDTH (WIDTH * 3) + 8
55
64{
65 public:
69 void begin()
70 {
73 }
74
78 void displayPaddedHexByte(byte value, bool showPrefix = true)
79 {
80 if (showPrefix)
81 {
82 DEBUG_INFO("0x%2X ", value);
83 }
84 else
85 {
86 DEBUG_INFO("%2X ", value);
87 }
88 }
89
94 {
95 DEBUG_INFO("");
96 DEBUG_INFO("EEPROM Contents:");
97
98 //
99 // Draw a line.
100 //
101 this->drawLine(WIDTH + 2);
102
103 //
104 // Create a buffer for a line of characters.
105 //
106 char buffer[LINE_WIDTH] = " | ";
107
108 //
109 // Add string terminating character.
110 //
111 buffer[LINE_WIDTH - 1] = 0;
112
113 //
114 // Build the header address line.
115 //
116 for(uint i = 0; i < WIDTH; i++)
117 {
118 char b[3];
119 sprintf(b, "%2u ", i);
120 buffer[(i * 3) + 7] = b[0];
121 buffer[(i * 3) + 8] = b[1];
122 buffer[(i * 3) + 9] = b[2];
123 }
124
125 //
126 // Display header addresses.
127 //
128 DEBUG_INFO("%s", buffer);
129
130 //
131 // Draw a line.
132 //
133 this->drawLine(WIDTH + 2);
134
135 //
136 // Get every byte from EEPROM
137 //
138 uint maxLines = EEPROM.length() / WIDTH;
139 uint i = 0;
140
141 for (uint row = 0; row < maxLines; row++)
142 {
143 uint lineNumber = row * WIDTH;
144 sprintf(buffer, "%4d | ", lineNumber);
145
146 for(uint j = 0; j < WIDTH; j++)
147 {
148 char b[3];
149 sprintf(b, "%.2X ", (byte)EEPROM[i++]);
150 buffer[(j * 3) + 7] = b[0];
151 buffer[(j * 3) + 8] = b[1];
152 buffer[(j * 3) + 9] = b[2];
153 }
154
155 DEBUG_INFO("%s", buffer);
156 }
157 }
158
164 template<typename T>
165 void displayVariable(const char* name, EEPROMBase<T> value)
166 {
167 DEBUG_INFO("%s: Variable Size: %2d, Memory Length = %2d, Start Address = %2d, Checksum Address = %2d, Checksum Value = %2d, Initialized = %s",
168 name, value.size(), value.length(), value.getAddress(), value.checksumAddress(), value.checksumByte(), value.isInitialized() ? "Yes" : "No");
169 }
170
175 {
176 //
177 // Display the EEPROM properties.
178 //
179 DEBUG_INFO("");
180 DEBUG_INFO("EEPROM<T> Properties:");
181 this->drawLine(50);
182 }
183
184 private:
185 //
186 // Draw a line using dashes with the given width.
187 //
188 void drawLine(uint width)
189 {
190 //
191 // Create a buffer for a line of characters.
192 //
193 char buffer[LINE_WIDTH];
194
195 //
196 // Add string terminating character.
197 //
198 buffer[LINE_WIDTH - 1] = 0;
199
200 for(uint i = 0; i < LINE_WIDTH - 2; i++)
201 {
202 buffer[i] = '-';
203 }
204
205 DEBUG_INFO("%s", buffer);
206 }
207};
208
212static EEPROMDisplayClass EEPROMDisplay;
213#endif
This file contains the EEPROMBase<T> definition.
EEPROMDebug Debug
#define DEBUG_INFO(fmt,...)
#define WIDTH
Define a Serial port to used for displaying output.
#define LINE_WIDTH
Base class to wrap an EEPROM variable.
Definition EEPROM-Base.h:54
uint checksumAddress() const
Gets the address of the checksum byte in EEPROM for this variable.
bool isInitialized() const
Checks whether the EEPROM variable has been initialized.
uint size() const
Returns the number of EEPROM bytes used by T.
byte checksumByte() const
Gets the stored checksum byte.
uint length() const
Returns the number of EEPROM bytes used.
uint getAddress() const
Get the EEPROM address of the variable.
void debugLabelOff()
void timestampOff()
Provides methods to display EEPROM data for debugging.
void displayPaddedHexByte(byte value, bool showPrefix=true)
Print a byte value in HEX with leading 0x.
void displayEEPROM()
Displays the contents of the EEPROM.
void displayHeader()
Display a header that can be used for listing variable properties.
void displayVariable(const char *name, EEPROMBase< T > value)
Display the properties of a variable.
void begin()
Sets default behavior for the Arduino Debug Utils library.