More logging cleanup on led devices (#47)

This commit is contained in:
penfold42 2016-06-25 22:44:52 +10:00 committed by brindosch
parent 56ae551cbd
commit 33f1ef457b
5 changed files with 25 additions and 42 deletions

View File

@ -27,9 +27,6 @@ int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
const unsigned int endFrameSize = std::max<unsigned int>(((max_leds + 15) / 16), 4); const unsigned int endFrameSize = std::max<unsigned int>(((max_leds + 15) / 16), 4);
const unsigned int APAbufferSize = (max_leds * 4) + startFrameSize + endFrameSize; const unsigned int APAbufferSize = (max_leds * 4) + startFrameSize + endFrameSize;
//printf ("_mLedCount %d _HW_ledcount %d max_leds %d APAbufferSize %d\n",
// _mLedCount, _HW_ledcount, max_leds, APAbufferSize);
if(_ledBuffer.size() != APAbufferSize){ if(_ledBuffer.size() != APAbufferSize){
_ledBuffer.resize(APAbufferSize, 0xFF); _ledBuffer.resize(APAbufferSize, 0xFF);
_ledBuffer[0] = 0x00; _ledBuffer[0] = 0x00;
@ -54,15 +51,6 @@ int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
_ledBuffer[4+iLed*4+3] = 0x00; _ledBuffer[4+iLed*4+3] = 0x00;
} }
/*
for (unsigned i=0; i< _ledBuffer.size(); i+=4) {
printf ("i %2d led %2d RGB 0x0%02x%02x%02x%02x\n",i, i/4-1,
_ledBuffer[i+0],
_ledBuffer[i+1],
_ledBuffer[i+2],
_ledBuffer[i+3]);
}
*/
return writeBytes(_ledBuffer.size(), _ledBuffer.data()); return writeBytes(_ledBuffer.size(), _ledBuffer.data());
} }

View File

@ -16,7 +16,8 @@
LedDevicePiBlaster::LedDevicePiBlaster(const std::string & deviceName, const Json::Value & gpioMapping) : LedDevicePiBlaster::LedDevicePiBlaster(const std::string & deviceName, const Json::Value & gpioMapping) :
_deviceName(deviceName), _deviceName(deviceName),
_fid(nullptr) _fid(nullptr),
_log(Logger::getInstance("LedDevice"))
{ {
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
@ -39,13 +40,13 @@ LedDevicePiBlaster::LedDevicePiBlaster(const std::string & deviceName, const Jso
const int gpio = gpioMap.get("gpio",-1).asInt(); const int gpio = gpioMap.get("gpio",-1).asInt();
const int ledindex = gpioMap.get("ledindex",-1).asInt(); const int ledindex = gpioMap.get("ledindex",-1).asInt();
const std::string ledcolor = gpioMap.get("ledcolor","z").asString(); const std::string ledcolor = gpioMap.get("ledcolor","z").asString();
// printf ("got gpio %d ledindex %d color %c\n", gpio,ledindex, ledcolor[0]);
// ignore missing/invalid settings // ignore missing/invalid settings
if ( (gpio >= 0) && (gpio < signed(TABLE_SZ)) && (ledindex >= 0) ){ if ( (gpio >= 0) && (gpio < signed(TABLE_SZ)) && (ledindex >= 0) ){
_gpio_to_led[gpio] = ledindex; _gpio_to_led[gpio] = ledindex;
_gpio_to_color[gpio] = ledcolor[0]; // 1st char of string _gpio_to_color[gpio] = ledcolor[0]; // 1st char of string
} else { } else {
printf ("IGNORING gpio %d ledindex %d color %c\n", gpio,ledindex, ledcolor[0]); Warning( _log, "IGNORING gpio %d ledindex %d color %c", gpio,ledindex, ledcolor[0]);
} }
} }
} }
@ -67,7 +68,7 @@ int LedDevicePiBlaster::open(bool report)
// The file pointer is already open // The file pointer is already open
if (report) if (report)
{ {
std::cerr << "Attempt to open allready opened device (" << _deviceName << ")" << std::endl; Error( _log, "Device (%s) is already open.", _deviceName.c_str() );
} }
return -1; return -1;
} }
@ -76,7 +77,7 @@ int LedDevicePiBlaster::open(bool report)
{ {
if (report) if (report)
{ {
std::cerr << "The device(" << _deviceName << ") does not yet exist, can not connect (yet)." << std::endl; Error( _log, "The device (%s) does not yet exist.", _deviceName.c_str() );
} }
return -1; return -1;
} }
@ -86,12 +87,12 @@ int LedDevicePiBlaster::open(bool report)
{ {
if (report) if (report)
{ {
std::cerr << "Failed to open device (" << _deviceName << "). Error message: " << strerror(errno) << std::endl; Error( _log, "Failed to open device (%s). Error message: %s", _deviceName.c_str(), strerror(errno) );
} }
return -1; return -1;
} }
std::cout << "Connect to device(" << _deviceName << ")" << std::endl; Info( _log, "Connected to device(%s)", _deviceName.c_str());
return 0; return 0;
} }
@ -111,7 +112,6 @@ int LedDevicePiBlaster::write(const std::vector<ColorRgb> & ledValues)
if ( (valueIdx >= 0) && (valueIdx < (signed) ledValues.size()) ) if ( (valueIdx >= 0) && (valueIdx < (signed) ledValues.size()) )
{ {
double pwmDutyCycle = 0.0; double pwmDutyCycle = 0.0;
// printf ("iPin %d valueIdx %d color %c\n", iPin, valueIdx, _gpio_to_color[ iPins[iPin] ] ) ;
switch (_gpio_to_color[ i ]) switch (_gpio_to_color[ i ])
{ {
case 'r': case 'r':

View File

@ -9,6 +9,7 @@
// Hyperion-Leddevice includes // Hyperion-Leddevice includes
#include <leddevice/LedDevice.h> #include <leddevice/LedDevice.h>
#include <utils/Logger.h>
class LedDevicePiBlaster : public LedDevice class LedDevicePiBlaster : public LedDevice
{ {
@ -58,4 +59,7 @@ private:
/// File-Pointer to the PiBlaster device /// File-Pointer to the PiBlaster device
FILE * _fid; FILE * _fid;
/// logger instance
Logger* _log;
}; };

View File

@ -3,6 +3,7 @@
#include <cstring> #include <cstring>
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
#include <cerrno>
// Linux includes // Linux includes
#include <fcntl.h> #include <fcntl.h>
@ -10,6 +11,7 @@
// Local Hyperion includes // Local Hyperion includes
#include "LedSpiDevice.h" #include "LedSpiDevice.h"
#include <utils/Logger.h>
LedSpiDevice::LedSpiDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns) : LedSpiDevice::LedSpiDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns) :
@ -34,7 +36,7 @@ int LedSpiDevice::open()
if (mFid < 0) if (mFid < 0)
{ {
std::cerr << "Failed to open device('" << mDeviceName << "') " << std::endl; Error( Logger::getInstance("LedDevice"), "Failed to open device (%s). Error message: %s", mDeviceName.c_str(), strerror(errno) );
return -1; return -1;
} }

View File

@ -18,8 +18,7 @@
LedUdpDevice::LedUdpDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns) : LedUdpDevice::LedUdpDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns) :
mDeviceName(outputDevice), mDeviceName(outputDevice),
mBaudRate_Hz(baudrate), mBaudRate_Hz(baudrate),
mLatchTime_ns(latchTime_ns), mLatchTime_ns(latchTime_ns)
mFid(-1)
{ {
udpSocket = new QUdpSocket(); udpSocket = new QUdpSocket();
QString str = QString::fromStdString(mDeviceName); QString str = QString::fromStdString(mDeviceName);
@ -38,38 +37,26 @@ LedUdpDevice::LedUdpDevice(const std::string& outputDevice, const unsigned baudr
LedUdpDevice::~LedUdpDevice() LedUdpDevice::~LedUdpDevice()
{ {
// close(mFid); udpSocket->close();
} }
int LedUdpDevice::open() int LedUdpDevice::open()
{ {
udpSocket->bind(QHostAddress::Any, 7755); QHostAddress _localAddress = QHostAddress::Any;
quint16 _localPort = 0;
WarningIf( !udpSocket->bind(_localAddress, _localPort),
/* Logger::getInstance("LedDevice"), "LedUdpDevice: Couldnt bind local address: %s", strerror(errno));
if (mFid < 0)
{
std::cerr << "Failed to open device('" << mDeviceName << "') " << std::endl;
return -1;
}
*/
return 0; return 0;
} }
int LedUdpDevice::writeBytes(const unsigned size, const uint8_t * data) int LedUdpDevice::writeBytes(const unsigned size, const uint8_t * data)
{ {
/*
if (mFid < 0)
{
return -1;
}
*/
// int retVal = udpSocket->writeDatagram((const char *)data,size,QHostAddress::LocalHost,9998); qint64 retVal = udpSocket->writeDatagram((const char *)data,size,_address,_port);
int retVal = udpSocket->writeDatagram((const char *)data,size,_address,_port);
if (retVal == 0 && mLatchTime_ns > 0) if (retVal >= 0 && mLatchTime_ns > 0)
{ {
// The 'latch' time for latching the shifted-value into the leds // The 'latch' time for latching the shifted-value into the leds
timespec latchTime; timespec latchTime;
@ -78,6 +65,8 @@ int LedUdpDevice::writeBytes(const unsigned size, const uint8_t * data)
// Sleep to latch the leds (only if write succesfull) // Sleep to latch the leds (only if write succesfull)
nanosleep(&latchTime, NULL); nanosleep(&latchTime, NULL);
} else {
Warning( Logger::getInstance("LedDevice"), "LedUdpDevice: Error sending: %s", strerror(errno));
} }
return retVal; return retVal;