mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
More logging cleanup on led devices (#47)
This commit is contained in:
parent
56ae551cbd
commit
33f1ef457b
@ -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 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){
|
||||
_ledBuffer.resize(APAbufferSize, 0xFF);
|
||||
_ledBuffer[0] = 0x00;
|
||||
@ -54,15 +51,6 @@ int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
|
||||
_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());
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
LedDevicePiBlaster::LedDevicePiBlaster(const std::string & deviceName, const Json::Value & gpioMapping) :
|
||||
_deviceName(deviceName),
|
||||
_fid(nullptr)
|
||||
_fid(nullptr),
|
||||
_log(Logger::getInstance("LedDevice"))
|
||||
{
|
||||
|
||||
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 ledindex = gpioMap.get("ledindex",-1).asInt();
|
||||
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
|
||||
if ( (gpio >= 0) && (gpio < signed(TABLE_SZ)) && (ledindex >= 0) ){
|
||||
_gpio_to_led[gpio] = ledindex;
|
||||
_gpio_to_color[gpio] = ledcolor[0]; // 1st char of string
|
||||
} 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
|
||||
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;
|
||||
}
|
||||
@ -76,7 +77,7 @@ int LedDevicePiBlaster::open(bool 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;
|
||||
}
|
||||
@ -86,12 +87,12 @@ int LedDevicePiBlaster::open(bool 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;
|
||||
}
|
||||
|
||||
std::cout << "Connect to device(" << _deviceName << ")" << std::endl;
|
||||
Info( _log, "Connected to device(%s)", _deviceName.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -111,7 +112,6 @@ int LedDevicePiBlaster::write(const std::vector<ColorRgb> & ledValues)
|
||||
if ( (valueIdx >= 0) && (valueIdx < (signed) ledValues.size()) )
|
||||
{
|
||||
double pwmDutyCycle = 0.0;
|
||||
// printf ("iPin %d valueIdx %d color %c\n", iPin, valueIdx, _gpio_to_color[ iPins[iPin] ] ) ;
|
||||
switch (_gpio_to_color[ i ])
|
||||
{
|
||||
case 'r':
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
// Hyperion-Leddevice includes
|
||||
#include <leddevice/LedDevice.h>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
class LedDevicePiBlaster : public LedDevice
|
||||
{
|
||||
@ -58,4 +59,7 @@ private:
|
||||
|
||||
/// File-Pointer to the PiBlaster device
|
||||
FILE * _fid;
|
||||
|
||||
/// logger instance
|
||||
Logger* _log;
|
||||
};
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cerrno>
|
||||
|
||||
// Linux includes
|
||||
#include <fcntl.h>
|
||||
@ -10,6 +11,7 @@
|
||||
|
||||
// Local Hyperion includes
|
||||
#include "LedSpiDevice.h"
|
||||
#include <utils/Logger.h>
|
||||
|
||||
|
||||
LedSpiDevice::LedSpiDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns) :
|
||||
@ -34,7 +36,7 @@ int LedSpiDevice::open()
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,7 @@
|
||||
LedUdpDevice::LedUdpDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns) :
|
||||
mDeviceName(outputDevice),
|
||||
mBaudRate_Hz(baudrate),
|
||||
mLatchTime_ns(latchTime_ns),
|
||||
mFid(-1)
|
||||
mLatchTime_ns(latchTime_ns)
|
||||
{
|
||||
udpSocket = new QUdpSocket();
|
||||
QString str = QString::fromStdString(mDeviceName);
|
||||
@ -38,38 +37,26 @@ LedUdpDevice::LedUdpDevice(const std::string& outputDevice, const unsigned baudr
|
||||
|
||||
LedUdpDevice::~LedUdpDevice()
|
||||
{
|
||||
// close(mFid);
|
||||
udpSocket->close();
|
||||
}
|
||||
|
||||
int LedUdpDevice::open()
|
||||
{
|
||||
udpSocket->bind(QHostAddress::Any, 7755);
|
||||
QHostAddress _localAddress = QHostAddress::Any;
|
||||
quint16 _localPort = 0;
|
||||
|
||||
|
||||
/*
|
||||
if (mFid < 0)
|
||||
{
|
||||
std::cerr << "Failed to open device('" << mDeviceName << "') " << std::endl;
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
WarningIf( !udpSocket->bind(_localAddress, _localPort),
|
||||
Logger::getInstance("LedDevice"), "LedUdpDevice: Couldnt bind local address: %s", strerror(errno));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
int retVal = udpSocket->writeDatagram((const char *)data,size,_address,_port);
|
||||
qint64 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
|
||||
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)
|
||||
nanosleep(&latchTime, NULL);
|
||||
} else {
|
||||
Warning( Logger::getInstance("LedDevice"), "LedUdpDevice: Error sending: %s", strerror(errno));
|
||||
}
|
||||
|
||||
return retVal;
|
||||
|
Loading…
Reference in New Issue
Block a user