Skip to content

Commit

Permalink
Ready for first release
Browse files Browse the repository at this point in the history
  • Loading branch information
shuvangkardas committed Mar 28, 2020
1 parent 24ac722 commit 216255f
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 13 deletions.
3 changes: 2 additions & 1 deletion examples/Save_Array/Save_Array.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "RingEEPROM.h"
#define FIRST_ADDR 10
#define FIRST_ADDR 100
#define BUFFER_SIZE 10
#define PARAM_PACKET_SIZE 6

Expand All @@ -12,6 +12,7 @@ void setup()
{
Serial.begin(9600);
Serial.println("Setup Done");
Serial.print(F("Buf Last Addr: "));Serial.println(myeepRom.getBufLastAddr());
}

void loop()
Expand Down
50 changes: 50 additions & 0 deletions examples/Save_Structure/Save_Structure.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "RingEEPROM.h"
#define FIRST_ADDR 0
#define BUFFER_SIZE 4
#define PARAM_PACKET_SIZE 6

typedef struct sensor_t
{
float temp;
float volt;
};
sensor_t sensorWrite,sensorRead;

byte writeBuffer[PARAM_PACKET_SIZE];
byte readBuffer[PARAM_PACKET_SIZE];

RingEEPROM myeepRom(FIRST_ADDR, BUFFER_SIZE, sizeof(sensor_t));

void setup()
{
Serial.begin(9600);
Serial.println("Setup Done");
}

void loop()
{
Serial.println(F("---------------------------------------"));
myeepRom.printStatusBuf();//Ovserve the inititial state of status buffer

measureSensor();//populat sensor data in Sensor structure
//uint8_t
myeepRom.savePacket((byte*)&sensorWrite); //Saving data array into eeprom
Serial.print(F("Param Saved Addr : ")); Serial.println(myeepRom.getParamPtr());
myeepRom.printStatusBuf();//Ovserve the status buffer after writing a data packet

myeepRom.readPacket((byte*)&sensorRead);//Read the last saved data packet
//Print Saved array. match the generated random array and read data array.
Serial.print(F("Saved Temp & Volt : "));
Serial.print(sensorRead.temp);Serial.print(" & ");Serial.println(sensorRead.volt);

delay(5000);
}

void measureSensor()
{
Serial.print(F("Measured Temp & Volt : "));
sensorWrite.temp = random(30,40);
sensorWrite.volt = random(8,14);
Serial.print(sensorWrite.temp);Serial.print(" & ");Serial.println(sensorWrite.volt);
}

8 changes: 5 additions & 3 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
#######################################
# Datatypes (KEYWORD1)
#######################################

RingEEPROM KEYWORD1


#######################################
# Methods and Functions (KEYWORD2)
#######################################


savePacket KEYWORD2
readPacket KEYWORD2
getParamPtr KEYWORD2
printStatusBuf KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ One more thing we need to clarify that 100k write/erase cycle for each cell, not
For solving the eeprom wear out problem, I have developed an Arduino library [RingEEPROM]().

## Solution
The idea is simple. As I cannot write/erase safely each cell more than 100k times. what if multiple cells is used for the same variable. To clarify more, Suppose I want to store a variable in EEPROM. What I will is, at First I will write the variable in first location, second time I will write the variable in the second location.Third time I will write the variable in the third location, Fourth time I will write the variable in the first location. I am repeating the pattern after 3 locatons. Thus I am getting 3 times endurance for a single variable.
The idea is simple. As I cannot write/erase safely each cell more than 100k times. what if multiple cells is used for the same variable. To clarify more, Suppose I want to store a variable in EEPROM. What I will do is, at First I will write the variable in first location, second time I will write the variable in the second location.Third time I will write the variable in the third location, Fourth time I will write the variable in the first location. I am repeating the pattern after 3 locatons. Thus I am getting 3 times endurance for a single variable.

I will store my value in different cells in each write cycle. So let's consider our buffer size i 8. I am planning to write a byte in EEPROM. As I am using 8 cells for a single byte. Now I get 8*100k = 800k write cycles. That's huge. The bigger the buffer size is, the more write cycles I get.

In this library, I will not store a single variable, I have developed the library such a way so that I can handle any size of buffer.

So for saving value in eeprom, we need two types of buffer
So for saving value in eeprom, I need two types of buffer
1. Parameter Buffer : This is the intended value we want to store in EEPROM
2. Status Buffer: This buffer keeps track of my current location in buffer.

Expand Down
18 changes: 16 additions & 2 deletions src/RingEEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
***************************************************************************
Author : Shuvangkar Shuvo
email: sshuvo93[at]gmail.com
Dhaka, Bangladesh
Dhaka, Bangladesh- March 2020
**************************************************************************/


Expand Down Expand Up @@ -119,6 +119,20 @@ void RingEEPROM::readPacket(byte *dataBuf)
//Serial.println();
}

/************************************************************
*This function retunrs the last address of the complete buffers.
* So that use can know what is the end pointer for the eeprom object
*************************************************************/
uint16_t RingEEPROM::getBufLastAddr()
{
uint16_t totalByte = _bufSz + (_bufSz*_paramPacketSz);
totalByte = _initAddr + totalByte;
return totalByte;
}

/************************************************************
*Return the current address of EEPROM parameter
*************************************************************/
uint16_t RingEEPROM::getParamPtr()
{
return _paramPtr;
Expand All @@ -139,7 +153,7 @@ void RingEEPROM::printArray(byte *data, byte len)
{
for (byte i = 0; i < len; i++)
{
debugEep(data[i]); debugEep(" ");
debugEep(*(data+i)); debugEep(" ");
}
debugEepln();
}
Expand Down
9 changes: 4 additions & 5 deletions src/RingEEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ class RingEEPROM
{
public:
RingEEPROM(int addrPtr, byte bufSz, byte paramSize);
void determineAddr();
void savePacket(byte *dataBuf);
void readPacket(byte *dataBuf);
void printStatusBuf();
void printArray(byte *data, byte len);
void populateStatus();
void _clrStatusBuf();

byte _getStatusPtr();
void populateStatus();
uint16_t getParamPtr();
uint16_t getBufLastAddr();
private:
void _clrStatusBuf();
byte _getStatusPtr();

int _initAddr;
byte _bufSz;
Expand Down

0 comments on commit 216255f

Please sign in to comment.