diff --git a/drivers/Linux/SoftEeprom.cpp b/drivers/Linux/SoftEeprom.cpp index 46e4b81..8a07ee5 100644 --- a/drivers/Linux/SoftEeprom.cpp +++ b/drivers/Linux/SoftEeprom.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "log.h" #include "SoftEeprom.h" @@ -31,7 +32,7 @@ SoftEeprom::SoftEeprom(const char *fileName, size_t length) _fileName = strdup(fileName); if (_fileName == NULL) { - perror("Error: "); + logError("Error: %s\n", strerror(errno)); exit(1); } @@ -67,6 +68,17 @@ SoftEeprom::SoftEeprom(const char *fileName, size_t length) } } +SoftEeprom::SoftEeprom(const SoftEeprom& other) +{ + _fileName = strdup(other._fileName); + + _length = other._length; + _values = new uint8_t[_length]; + for (size_t i = 0; i < _length; ++i) { + _values[i] = other._values[i]; + } +} + SoftEeprom::~SoftEeprom() { delete[] _values; @@ -128,3 +140,17 @@ void SoftEeprom::writeByte(int addr, uint8_t value) writeBlock(&value, reinterpret_cast(addr), 1); } } + +SoftEeprom& SoftEeprom::operator=(const SoftEeprom& other) +{ + if (this != &other) { + _fileName = strdup(other._fileName); + + _length = other._length; + _values = new uint8_t[_length]; + for (size_t i = 0; i < _length; ++i) { + _values[i] = other._values[i]; + } + } + return *this; +} diff --git a/drivers/Linux/SoftEeprom.h b/drivers/Linux/SoftEeprom.h index 70ad72c..7b096e5 100644 --- a/drivers/Linux/SoftEeprom.h +++ b/drivers/Linux/SoftEeprom.h @@ -43,6 +43,10 @@ public: * @brief SoftEeprom constructor. */ SoftEeprom(const char *fileName, size_t length); + /** + * @brief SoftEeprom copy constructor. + */ + SoftEeprom(const SoftEeprom& other); /** * @brief SoftEeprom destructor. */ @@ -77,6 +81,11 @@ public: * @param value to write. */ void writeByte(int addr, uint8_t value); + /** + * @brief Overloaded assign operator. + * + */ + SoftEeprom& operator=(const SoftEeprom& other); }; #endif diff --git a/drivers/RPi/rpi_util.cpp b/drivers/RPi/rpi_util.cpp index 3981575..5c24d8b 100644 --- a/drivers/RPi/rpi_util.cpp +++ b/drivers/RPi/rpi_util.cpp @@ -96,7 +96,7 @@ int get_gpio_number(uint8_t physPin, uint8_t *gpio) void *interruptHandler(void *args) { - int fd, ret; + int fd; struct pollfd polls; char c; struct ThreadArgs *arguments = (struct ThreadArgs *)args; @@ -117,7 +117,7 @@ void *interruptHandler(void *args) while (1) { // Wait for it ... - ret = poll(&polls, 1, -1); + int ret = poll(&polls, 1, -1); if (ret < 0) { logError("Error waiting for interrupt: %s\n", strerror(errno)); break; @@ -232,7 +232,7 @@ void rpi_util::attachInterrupt(uint8_t physPin, void (*func)(), uint8_t mode) snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/direction", gpioPin) ; if ((fd = fopen (fName, "w")) == NULL) { - fprintf (stderr, "attachInterrupt: Unable to open GPIO direction interface for pin %d: %s\n", + logError("attachInterrupt: Unable to open GPIO direction interface for pin %d: %s\n", physPin, strerror(errno)); exit(1) ; } @@ -241,7 +241,7 @@ void rpi_util::attachInterrupt(uint8_t physPin, void (*func)(), uint8_t mode) snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/edge", gpioPin) ; if ((fd = fopen(fName, "w")) == NULL) { - fprintf (stderr, "attachInterrupt: Unable to open GPIO edge interface for pin %d: %s\n", physPin, + logError("attachInterrupt: Unable to open GPIO edge interface for pin %d: %s\n", physPin, strerror(errno)); exit(1) ; } @@ -268,7 +268,7 @@ void rpi_util::attachInterrupt(uint8_t physPin, void (*func)(), uint8_t mode) if (sysFds[gpioPin] == -1) { snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/value", gpioPin); if ((sysFds[gpioPin] = open(fName, O_RDWR)) < 0) { - fprintf (stderr, "Error reading pin %d: %s\n", physPin, strerror(errno)); + logError("Error reading pin %d: %s\n", physPin, strerror(errno)); exit(1); } }