本文整理汇总了C++中EEPROMClass类的典型用法代码示例。如果您正苦于以下问题:C++ EEPROMClass类的具体用法?C++ EEPROMClass怎么用?C++ EEPROMClass使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EEPROMClass类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
uint8_t EEPROMWearLeveler::read( uint16_t address )
{
if ( _num_of_vars == AVR_EEPROM_SIZE )
{
// Revert back to EEPROM class if the nubmer of variables is
// greater than AVR_EEPROM_SIZE/4
return EEPROM.read( address );
}
else
{
uint16_t write_offset = findNextWriteAddress( address );
uint16_t pb_start_addr = parameterBufferAddress( address );
uint16_t read_addr = pb_start_addr + write_offset;
if ( read_addr == pb_start_addr )
{
std::cout << read_addr << " BBBBBBBB\n";
read_addr += _buffer_len - 1;
}
else
{
read_addr -= 1;
std::cout << "AAAAAA\n";
}
std::cout << "read address: " << read_addr << std::endl;
std::cout << "pb_start_addr: " << pb_start_addr << std::endl;
std::cout << "write_offset: " << write_offset << std::endl;
std::cout << "address: " << address << std::endl;
return EEPROM.read( read_addr );
}
}
示例2: findNextWriteAddress
uint16_t EEPROMWearLeveler::findNextWriteAddress( int address )
{
uint16_t sb_start_addr = statusBufferAddress( address );
uint16_t i;
for ( i = sb_start_addr; i < ( _buffer_len + sb_start_addr ); i++ )
{
uint16_t prev_index;
// Wrap around case
if ( i == sb_start_addr )
{
prev_index = sb_start_addr + _buffer_len - 1;
}
else
prev_index = i - 1;
uint8_t prev_elem = EEPROM.read( prev_index );
uint8_t curr_elem = EEPROM.read( i );
// Must truncate the addition because the index tracking relies of wrap around
if ( ( ( prev_elem + 1 ) & 0xFF ) != curr_elem )
{
// Return the relative write position
uint16_t offset = i - sb_start_addr;
return offset;
}
}
//exit(0);
// Should never get here. Just in case return first index
return 0;
}
示例3: int
// retrieve an integer from the EEPROM at nOffset.
// return the integer
int R5EEPROM::getIntAtOffset(const unsigned int nOffset)
{
unsigned int byte1 = EEPROM.read(nOffset);
unsigned int byte2 = EEPROM.read(nOffset+1);
return int(byte1+(byte2 << 8));
示例4: read
uint8_t EEPROMWearLeveler::read( uint16_t address )
{
if ( _num_of_vars == AVR_EEPROM_SIZE )
{
// Revert back to EEPROM class if the nubmer of variables is
// greater than AVR_EEPROM_SIZE/4
return EEPROM.read( address );
}
else
{
uint16_t write_offset = findNextWriteAddress( address );
uint16_t pb_start_addr = parameterBufferAddress( address );
uint16_t read_addr = pb_start_addr + write_offset;
if ( read_addr == pb_start_addr )
{
read_addr += _buffer_len - 1;
}
else
{
read_addr -= 1;
}
return EEPROM.read( read_addr );
}
}
示例5:
// write an integer to the EEPROM at nOffset.
// return true/false
unsigned char R5EEPROM::setIntAtOffset(const int nValue, const unsigned int nOffset)
{
unsigned char byte1 = nValue & 0xFF;
unsigned char byte2 = (nValue & 0xFF00) >> 8;
EEPROM.update(nOffset, byte1);
EEPROM.update(nOffset+1, byte2);
return true;
示例6: findNextWriteAddress
uint16_t EEPROMWearLeveler::findNextWriteAddress( int address )
{
uint16_t sb_start_addr = statusBufferAddress( address );
std::cout << "sb_start_addr: " << (int)sb_start_addr << std::endl;
uint16_t i;
for ( i = sb_start_addr; i < ( _buffer_len + sb_start_addr ); i++ )
{
uint16_t prev_index;
// Wrap around case
if ( i == sb_start_addr )
{
prev_index = sb_start_addr + _buffer_len - 1;
}
else
prev_index = i - 1;
uint8_t prev_elem = EEPROM.read( prev_index );
uint8_t curr_elem = EEPROM.read( i );
#if 0
std::cout << "prev_index: " << (int)prev_index << std::endl;
std::cout << "prev_elem: " << (int)prev_elem << std::endl;
std::cout << "curr_index: " << (int)i << std::endl;
std::cout << "curr_elem: " << (int)curr_elem << std::endl << std::endl;
#endif
// Must truncate the addition because the index tracking relies of wrap around
if ( ( ( prev_elem + 1 ) & 0xFF ) != curr_elem )
{
// Return the relative write position
uint16_t offset = i - sb_start_addr;
std::cout << "prev_elem + 1: " << prev_elem + 1 << " curr_elem: " << (int)curr_elem << std::endl;
std::cout << "prev_index: " << (int)prev_index << std::endl;
std::cout << "prev_elem: " << (int)prev_elem << std::endl;
std::cout << "curr_index: " << (int)i << std::endl;
std::cout << "curr_elem: " << (int)curr_elem << std::endl ;
std::cout << "offset: " << (int)offset << std::endl << std::endl;
return offset;
}
}
std::cout << "ERROR!!!!!!!!!!!!!!!!!!!!" << std::endl;
//exit(0);
// Should never get here. Just in case return first index
return 0;
}
示例7: write
void EEPROMWearLeveler::write( uint16_t address, uint8_t value )
{
if ( _num_of_vars == AVR_EEPROM_SIZE )
{
// Revert back to EEPROM class if the nubmer of variables is
// greater than AVR_EEPROM_SIZE/4
EEPROM.write( address, value );
}
else
{
// bounds check
if ( address >= _num_of_vars )
{
std::cout << " BAD address \n";
return;
}
uint16_t write_offset = findNextWriteAddress( address );
std::cout << "write_offset: " << write_offset << std::endl;
uint16_t pb_start_addr = parameterBufferAddress( address );
std::cout << "pb_start_addr: " << pb_start_addr << std::endl;
std::cout << "write address: " << pb_start_addr + write_offset << std::endl;
// Write value to paramater buffer
EEPROM.write( pb_start_addr + write_offset, value );
// Update status buffer
uint16_t sb_start_addr = statusBufferAddress( address );
uint16_t curr_index = sb_start_addr + write_offset;
uint16_t prev_index;
std::cout << "curr_index: " << (int)curr_index << std::endl;
std::cout << "sb_start_addr: " << (int)sb_start_addr << std::endl;
std::cout << "write_offset: " << (int)write_offset << std::endl;
// Wrap around case
if ( curr_index == sb_start_addr )
prev_index = sb_start_addr + _buffer_len - 1;
else
prev_index = curr_index - 1;
uint16_t sb_val = EEPROM.read(prev_index) + 1;
std::cout << "write status buffer at: " << (int)curr_index << std::endl;
std::cout << "\tstatus buffer value: " << (int)sb_val << std::endl;
EEPROM.write( curr_index, sb_val );
}
}
示例8: clear
void EEPROMWearLeveler::clear()
{
for (int i = 0; i < AVR_EEPROM_SIZE; i++)
{
EEPROM.write(i, 0);
}
}
示例9: saveToEEPROM
//------------------------------------------------------------------
bool StateMachine::saveToEEPROM() {
Serial.println(" Save to EEPROMprom!");
EEPROM.write(CHANELSADDRES , c1.threshold);
EEPROM.write(CHANELSADDRES + 1, c1.timeS);
EEPROM.write(CHANELSADDRES + 2, c1.timeBan);
EEPROM.write(CHANELSADDRES + 3, c2.threshold);
EEPROM.write(CHANELSADDRES + 4, c2.timeS);
EEPROM.write(CHANELSADDRES + 5, c2.timeBan);
EEPROM.write(CHANELSADDRES + 6, c3.threshold);
EEPROM.write(CHANELSADDRES + 7, c3.timeS);
EEPROM.write(CHANELSADDRES + 8, c3.timeBan);
}
示例10:
// save data to EEPROM
// return: the size saved, 0 for error
static uint32_t EEPROM_Save(uint32_t addr, uint8_t * data, uint32_t size)
{
// the EEPROM size is 1K (0x000-0x3FF)
if (addr + size < 0x400)
{
for (int i = 0; i < size; ++i)
{
EEPROM.write(addr + i, data[i]);
}
return size;
}
else
{
return 0;
}
}
示例11: sizeof
// write the plan to the EEPROM
unsigned char R5EEPROM::writeData(Instinct::CmdPlanner *pPlan, const unsigned int uiDataLen, unsigned char *pData)
{
Instinct::PlanNode sPlanNode;
Instinct::instinctID bPlanElements[INSTINCT_NODE_TYPES];
Instinct::instinctID bElemCount = pPlan->planSize(); // total number of elements;
unsigned int nPlanMemoryUsage = pPlan->planUsage(NULL); // total space used in RAM
// calculate how much EEPROM we will use and return false if not enough
unsigned int nEEPROMUsage = nPlanMemoryUsage + (bElemCount * sizeof(sPlanNode.bNodeType)) + uiDataLen;
if (EEPROM.length() < (nEEPROMUsage + sizeof(EEPROMStorageType)))
return false;
Instinct::instinctID bMaxElementID = pPlan->maxElementID();
EEPROMStorageType *pEEPROM = 0;
// first we store the number of Node structures we are going to write out
pPlan->planSize(bPlanElements); // get the array of element counts from the plan
setBytesAtOffset(bPlanElements, sizeof(bPlanElements), (int)&pEEPROM->bPlanElements);
setIntAtOffset(pPlan->getPlanID(), (int)&pEEPROM->nPlanID);
int nAddr = (int)&pEEPROM->bPlan;
// read each element from the plan into a buffer and then write it to EEPROM
for ( Instinct::instinctID i = 0; i < bMaxElementID; i++)
{
if (pPlan->getNode(&sPlanNode, i+1))
{
int nSize = pPlan->sizeFromNodeType(sPlanNode.bNodeType);
if (!nSize) // some bad thing has happened
return false;
nSize += sizeof(sPlanNode.bNodeType);
nAddr += setBytesAtOffset((unsigned char *)&sPlanNode, nSize, nAddr);
}
}
if (pData && uiDataLen)
{
// store the binary data at the end
setBytesAtOffset(pData, uiDataLen, nAddr);
setIntAtOffset(uiDataLen, (int)&pEEPROM->uiDataLen);
}
return true;
示例12: LoadFromEEPROM
//---------------------------------------------------------------------
bool StateMachine::LoadFromEEPROM() {
c1.threshold = EEPROM.read(CHANELSADDRES);
c1.timeS = EEPROM.read(CHANELSADDRES + 1);
c1.timeBan = EEPROM.read(CHANELSADDRES + 2);
c2.threshold = EEPROM.read(CHANELSADDRES + 3);
c2.timeS = EEPROM.read(CHANELSADDRES + 4);
c2.timeBan = EEPROM.read(CHANELSADDRES + 5);
c3.threshold = EEPROM.read(CHANELSADDRES + 6);
c3.timeS = EEPROM.read(CHANELSADDRES + 7);
c3.timeBan = EEPROM.read(CHANELSADDRES + 8);
}