Skip to content

Commit

Permalink
renamed and modified files
Browse files Browse the repository at this point in the history
  • Loading branch information
shuvangkardas committed Mar 28, 2020
1 parent 9501153 commit 24ac722
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 79 deletions.
47 changes: 47 additions & 0 deletions examples/Save_Array/Save_Array.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "RingEEPROM.h"
#define FIRST_ADDR 10
#define BUFFER_SIZE 10
#define PARAM_PACKET_SIZE 6

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

RingEEPROM myeepRom(FIRST_ADDR, BUFFER_SIZE, PARAM_PACKET_SIZE);

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

void loop()
{
Serial.println(F("---------------------------------------"));
myeepRom.printStatusBuf();//Ovserve the inititial state of status buffer
// byte ptr = myeepRom._getStatusPtr();//get current position
// Serial.print(F("Current Status ptr: ")); Serial.println(ptr);

populateArray(writeBuffer, PARAM_PACKET_SIZE);//Generate a random data array to write
myeepRom.savePacket(writeBuffer); //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(readBuffer);//Read the last saved data packet
//Print Saved array. match the generated random array and read data array.
Serial.print(F("Saved Data : "));
myeepRom.printArray(readBuffer, PARAM_PACKET_SIZE);

delay(5000);
}

void populateArray(byte *buffer, byte bufSize)
{
Serial.print(F("Generated Data : "));
for (byte i = 0; i < bufSize; i++)
{
*(buffer + i) = random(1, 100);
Serial.print(*(buffer + i) ); Serial.print(" ");
}
Serial.println();
}

63 changes: 0 additions & 63 deletions examples/example1/example1.ino

This file was deleted.

31 changes: 18 additions & 13 deletions src/eep.cpp → src/RingEEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Dhaka, Bangladesh
**************************************************************************/


#include "eep.h"
#include "RingEEPROM.h"
#include <EEPROM.h>


//#define EEP_DEBUG
#define EEP_DEBUG
#ifdef EEP_DEBUG
#define debugEep(...) Serial.print(__VA_ARGS__)
#define debugEepln(...) Serial.println(__VA_ARGS__)
Expand All @@ -34,7 +34,7 @@ Dhaka, Bangladesh
#endif


EEProm::EEProm(int addrPtr, byte bufSz, byte paramSize)
RingEEPROM::RingEEPROM(int addrPtr, byte bufSz, byte paramSize)
{
_initAddr = addrPtr; //First address of the buffer
_bufSz = bufSz; //Total number of buffer
Expand All @@ -45,7 +45,7 @@ EEProm::EEProm(int addrPtr, byte bufSz, byte paramSize)
/*************************************************************
* When status buffer becomes full, this method clears the status buffer
*************************************************************/
void EEProm::_clrStatusBuf()
void RingEEPROM::_clrStatusBuf()
{

for (byte i = 0; i < _bufSz; i++) {
Expand All @@ -60,7 +60,7 @@ void EEProm::_clrStatusBuf()
*This methods scan the status buffer and find out the current
*location to write
*************************************************************/
byte EEProm::_getStatusPtr()
byte RingEEPROM::_getStatusPtr()
{
byte ptr;
byte i = 0;
Expand All @@ -75,7 +75,7 @@ byte EEProm::_getStatusPtr()
/************************************************************
*user call this methods to save the parameter packet
*************************************************************/
void EEProm::savePacket(byte *dataBuf)
void RingEEPROM::savePacket(byte *dataBuf)
{
byte statusPtr = _getStatusPtr();
if (statusPtr > _bufSz)
Expand All @@ -90,11 +90,11 @@ void EEProm::savePacket(byte *dataBuf)
byte index = statusPtr - 1;
//Status pointer address ends, param pointer address starts
int paramInitAddr = _initAddr + _bufSz;
int paramPtr = paramInitAddr + (index * _paramPacketSz);
debugEep(F("Data Save Addr: ")); debugEepln(paramPtr);
_paramPtr = paramInitAddr + (index * _paramPacketSz);
//debugEep(F("Data Save Addr: ")); debugEepln(_paramPtr);
for (byte i = 0; i < _paramPacketSz; i++)
{
int addr = paramPtr + i;
int addr = _paramPtr + i;
EEPROM.write(addr, dataBuf[i]);
}
EEPROM.write(_initAddr + index, statusPtr); // update status pointer
Expand All @@ -103,7 +103,7 @@ void EEProm::savePacket(byte *dataBuf)
/************************************************************
*user call this methods to read last saved value
*************************************************************/
void EEProm::readPacket(byte *dataBuf)
void RingEEPROM::readPacket(byte *dataBuf)
{
byte statusPtr = _getStatusPtr();
byte index = statusPtr - 2;
Expand All @@ -119,9 +119,14 @@ void EEProm::readPacket(byte *dataBuf)
//Serial.println();
}

uint16_t RingEEPROM::getParamPtr()
{
return _paramPtr;
}

void EEProm::printStatusBuf()
void RingEEPROM::printStatusBuf()
{
Serial.print(F("Status Buf: "));
byte value;
for (byte i = 0; i < _bufSz; i++)
{
Expand All @@ -130,7 +135,7 @@ void EEProm::printStatusBuf()
}
Serial.println();
}
void EEProm::printArray(byte *data, byte len)
void RingEEPROM::printArray(byte *data, byte len)
{
for (byte i = 0; i < len; i++)
{
Expand All @@ -139,7 +144,7 @@ void EEProm::printArray(byte *data, byte len)
debugEepln();
}

void EEProm::populateStatus()
void RingEEPROM::populateStatus()
{

for (byte i = 0; i < _bufSz - 3; i++)
Expand Down
10 changes: 7 additions & 3 deletions src/eep.h → src/RingEEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@
#define _H_EEP_H_
#include <Arduino.h>

class EEProm
class RingEEPROM
{
public:
EEProm(int addrPtr, byte bufSz, byte paramSize);
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();
byte _getStatusPtr();
void _clrStatusBuf();

byte _getStatusPtr();
uint16_t getParamPtr();
private:

int _initAddr;
byte _bufSz;
byte _paramPacketSz;

uint16_t _paramPtr;

};

Expand Down

0 comments on commit 24ac722

Please sign in to comment.