33 lines
851 B
C++
33 lines
851 B
C++
#include "EEPROMUtils.h"
|
|
#include <EEPROM.h>
|
|
#include <Arduino.h>
|
|
|
|
|
|
// Statická metoda pro čtení řetězce z EEPROM
|
|
String EEPROMUtils::readString(int addr, int length)
|
|
{
|
|
String data;
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
char onedata = char(EEPROM.read(addr + i)); // read one byte at a time
|
|
if (onedata == '\n')
|
|
return data;
|
|
data += onedata;
|
|
}
|
|
return data;
|
|
}
|
|
|
|
// Statická metoda pro zápis řetězce do EEPROM
|
|
void EEPROMUtils::writeString(int addr, String data, int limit)
|
|
{
|
|
int numBytes = data.length(); // get length of the string
|
|
for (int i = 0; i < numBytes && i < limit; i++)
|
|
{
|
|
EEPROM.write(addr + i, data[i]); // write one byte at a time
|
|
}
|
|
if (numBytes < limit)
|
|
{
|
|
EEPROM.write(addr + numBytes, '\n'); // add newline character at the end
|
|
}
|
|
}
|