Skip to content

Commit

Permalink
fix #77, updateBlock() returns bytes written
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Oct 26, 2024
1 parent 8cb180d commit 26c021f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [1.9.1] - 2024-10-26
- fix #77, updateBlock() returns bytes actually written.
- minor edits

## [1.9.0] - 2024-10-09
- Fix #74, memory leak in setBlockVerify() - kudos to cmichailidis

Expand Down
9 changes: 5 additions & 4 deletions I2C_eeprom.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: I2C_eeprom.cpp
// AUTHOR: Rob Tillaart
// VERSION: 1.9.0
// VERSION: 1.9.1
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
// URL: https://github.com/RobTillaart/I2C_EEPROM

Expand Down Expand Up @@ -182,7 +182,7 @@ int I2C_eeprom::updateByte(const uint16_t memoryAddress, const uint8_t data)
}


// returns bytes written.
// returns bytes actually written <= length
uint16_t I2C_eeprom::updateBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length)
{
uint16_t address = memoryAddress;
Expand All @@ -194,10 +194,11 @@ uint16_t I2C_eeprom::updateBlock(const uint16_t memoryAddress, const uint8_t * b
uint8_t count = I2C_BUFFERSIZE;

if (count > len) count = len;
bytes += _ReadBlock(address, buf, count);
_ReadBlock(address, buf, count);
if (memcmp(buffer, buf, count) != 0)
{
_pageBlock(address, buffer, count, true);
bytes += count;
}
address += count;
buffer += count;
Expand Down Expand Up @@ -265,7 +266,7 @@ bool I2C_eeprom::updateByteVerify(const uint16_t memoryAddress, const uint8_t va
// return false if write or verify failed.
bool I2C_eeprom::updateBlockVerify(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length)
{
if (updateBlock(memoryAddress, buffer, length) != length) return false;
updateBlock(memoryAddress, buffer, length);
return verifyBlock(memoryAddress, buffer, length);
}

Expand Down
6 changes: 3 additions & 3 deletions I2C_eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: I2C_eeprom.h
// AUTHOR: Rob Tillaart
// VERSION: 1.9.0
// VERSION: 1.9.1
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
// URL: https://github.com/RobTillaart/I2C_EEPROM

Expand All @@ -11,7 +11,7 @@
#include "Wire.h"


#define I2C_EEPROM_VERSION (F("1.9.0"))
#define I2C_EEPROM_VERSION (F("1.9.1"))

#define I2C_DEVICESIZE_24LC512 65536
#define I2C_DEVICESIZE_24LC256 32768
Expand Down Expand Up @@ -109,7 +109,7 @@ class I2C_eeprom
// updates a block in memory, writes only if there is a new value.
// only to be used when you expect to write same buffer multiple times.
// test your performance gains!
// returns bytes written.
// returns bytes actually written <= length
uint16_t updateBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length);


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ but only if changed.
Returns 0 if value was same or write succeeded.
- **uint16_t updateBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)**
write a buffer starting at the specified memory address, but only if changed.
Returns bytes written.
Returns bytes actually written <= length.


### Read functions
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/I2C_EEPROM.git"
},
"version": "1.9.0",
"version": "1.9.1",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=I2C_EEPROM
version=1.9.0
version=1.9.1
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Library for I2C EEPROMS
Expand Down

0 comments on commit 26c021f

Please sign in to comment.