RPi: Use logError when possible (#689)
This commit is contained in:
committed by
Patrick Fallberg
parent
7e1aa82d6e
commit
707442b257
@@ -22,6 +22,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "SoftEeprom.h"
|
#include "SoftEeprom.h"
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ SoftEeprom::SoftEeprom(const char *fileName, size_t length)
|
|||||||
|
|
||||||
_fileName = strdup(fileName);
|
_fileName = strdup(fileName);
|
||||||
if (_fileName == NULL) {
|
if (_fileName == NULL) {
|
||||||
perror("Error: ");
|
logError("Error: %s\n", strerror(errno));
|
||||||
exit(1);
|
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()
|
SoftEeprom::~SoftEeprom()
|
||||||
{
|
{
|
||||||
delete[] _values;
|
delete[] _values;
|
||||||
@@ -128,3 +140,17 @@ void SoftEeprom::writeByte(int addr, uint8_t value)
|
|||||||
writeBlock(&value, reinterpret_cast<void*>(addr), 1);
|
writeBlock(&value, reinterpret_cast<void*>(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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ public:
|
|||||||
* @brief SoftEeprom constructor.
|
* @brief SoftEeprom constructor.
|
||||||
*/
|
*/
|
||||||
SoftEeprom(const char *fileName, size_t length);
|
SoftEeprom(const char *fileName, size_t length);
|
||||||
|
/**
|
||||||
|
* @brief SoftEeprom copy constructor.
|
||||||
|
*/
|
||||||
|
SoftEeprom(const SoftEeprom& other);
|
||||||
/**
|
/**
|
||||||
* @brief SoftEeprom destructor.
|
* @brief SoftEeprom destructor.
|
||||||
*/
|
*/
|
||||||
@@ -77,6 +81,11 @@ public:
|
|||||||
* @param value to write.
|
* @param value to write.
|
||||||
*/
|
*/
|
||||||
void writeByte(int addr, uint8_t value);
|
void writeByte(int addr, uint8_t value);
|
||||||
|
/**
|
||||||
|
* @brief Overloaded assign operator.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
SoftEeprom& operator=(const SoftEeprom& other);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ int get_gpio_number(uint8_t physPin, uint8_t *gpio)
|
|||||||
|
|
||||||
void *interruptHandler(void *args)
|
void *interruptHandler(void *args)
|
||||||
{
|
{
|
||||||
int fd, ret;
|
int fd;
|
||||||
struct pollfd polls;
|
struct pollfd polls;
|
||||||
char c;
|
char c;
|
||||||
struct ThreadArgs *arguments = (struct ThreadArgs *)args;
|
struct ThreadArgs *arguments = (struct ThreadArgs *)args;
|
||||||
@@ -117,7 +117,7 @@ void *interruptHandler(void *args)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// Wait for it ...
|
// Wait for it ...
|
||||||
ret = poll(&polls, 1, -1);
|
int ret = poll(&polls, 1, -1);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("Error waiting for interrupt: %s\n", strerror(errno));
|
logError("Error waiting for interrupt: %s\n", strerror(errno));
|
||||||
break;
|
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) ;
|
snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/direction", gpioPin) ;
|
||||||
if ((fd = fopen (fName, "w")) == NULL) {
|
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));
|
physPin, strerror(errno));
|
||||||
exit(1) ;
|
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) ;
|
snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/edge", gpioPin) ;
|
||||||
if ((fd = fopen(fName, "w")) == NULL) {
|
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));
|
strerror(errno));
|
||||||
exit(1) ;
|
exit(1) ;
|
||||||
}
|
}
|
||||||
@@ -268,7 +268,7 @@ void rpi_util::attachInterrupt(uint8_t physPin, void (*func)(), uint8_t mode)
|
|||||||
if (sysFds[gpioPin] == -1) {
|
if (sysFds[gpioPin] == -1) {
|
||||||
snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/value", gpioPin);
|
snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/value", gpioPin);
|
||||||
if ((sysFds[gpioPin] = open(fName, O_RDWR)) < 0) {
|
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);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user