mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
LED Device Features, Fixes and Refactoring (Resubmit PR855) (#875)
* Refactor LedDevices - Initial version * Small renamings * Add WLED as own device * Lpd8806 Remove open() method * remove dependency on Qt 5.10 * Lpd8806 Remove open() method * Update WS281x * Update WS2812SPI * Add writeBlack for WLED powerOff * WLED remove extra bracket * Allow different Nanoleaf panel numbering sequence (Feature req.#827) * build(deps): bump websocket-extensions from 0.1.3 to 0.1.4 in /docs (#826) * Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4. - [Release notes](https://github.com/faye/websocket-extensions-node/releases) - [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md) - [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4) * Fix typos * Nanoleaf clean-up * Yeelight support, generalize wizard elements * Update Yeelight to handle quota in music mode * Yeelight extend rage for extraTimeDarkness for testing * Clean-up - Add commentary, Remove development debug statements * Fix brightnessSwitchOffOnMinimum typo and default value * Yeelight support restoreOriginalState, additional Fixes * WLED - Remove UDP-Port, as it is not configurable * Fix merging issue * Remove QHostAddress::operator=(const QString&)' is deprecated * Windows compile errors and (Qt 5.15 deprecation) warnings * Fix order includes * LedDeviceFile Support Qt5.7 and greater * Windows compatibility and other Fixes * Fix Qt Version compatability * Rs232 - Resolve portname from unix /dev/ style, fix DMX sub-type support * Disable WLED Wizard Button (until Wizard is available) * Yeelight updates * Add wrong log-type as per #505 * Fixes and Clean-up after clang-tidy report * Fix udpe131 not enabled for generated CID * Change timer into dynamic for Qt Thread-Affinity * Hue clean-up and diyHue workaround * Updates after review feedback by m-seker * Add "chrono" includes
This commit is contained in:
@@ -33,13 +33,21 @@ ProviderSpi::~ProviderSpi()
|
||||
|
||||
bool ProviderSpi::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
bool isInitOK = LedDevice::init(deviceConfig);
|
||||
bool isInitOK = false;
|
||||
|
||||
_deviceName = deviceConfig["output"].toString(_deviceName);
|
||||
_baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz);
|
||||
_spiMode = deviceConfig["spimode"].toInt(_spiMode);
|
||||
_spiDataInvert = deviceConfig["invert"].toBool(_spiDataInvert);
|
||||
// Initialise sub-class
|
||||
if ( LedDevice::init(deviceConfig) )
|
||||
{
|
||||
_deviceName = deviceConfig["output"].toString(_deviceName);
|
||||
_baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz);
|
||||
_spiMode = deviceConfig["spimode"].toInt(_spiMode);
|
||||
_spiDataInvert = deviceConfig["invert"].toBool(_spiDataInvert);
|
||||
|
||||
Debug(_log, "_baudRate_Hz [%d], _latchTime_ms [%d]", _baudRate_Hz, _latchTime_ms);
|
||||
Debug(_log, "_spiDataInvert [%d], _spiMode [%d]", _spiDataInvert, _spiMode);
|
||||
|
||||
isInitOK = true;
|
||||
}
|
||||
return isInitOK;
|
||||
}
|
||||
|
||||
@@ -47,77 +55,74 @@ int ProviderSpi::open()
|
||||
{
|
||||
int retval = -1;
|
||||
QString errortext;
|
||||
_deviceReady = false;
|
||||
_isDeviceReady = false;
|
||||
|
||||
if ( init(_devConfig) )
|
||||
const int bitsPerWord = 8;
|
||||
|
||||
_fid = ::open(QSTRING_CSTR(_deviceName), O_RDWR);
|
||||
|
||||
if (_fid < 0)
|
||||
{
|
||||
|
||||
Debug(_log, "_baudRate_Hz [%d], _latchTime_ms [%d]", _baudRate_Hz, _latchTime_ms);
|
||||
Debug(_log, "_spiDataInvert [%d], _spiMode [%d]", _spiDataInvert, _spiMode);
|
||||
|
||||
const int bitsPerWord = 8;
|
||||
|
||||
_fid = ::open(QSTRING_CSTR(_deviceName), O_RDWR);
|
||||
|
||||
if (_fid < 0)
|
||||
errortext = QString ("Failed to open device (%1). Error message: %2").arg(_deviceName, strerror(errno));
|
||||
retval = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ioctl(_fid, SPI_IOC_WR_MODE, &_spiMode) == -1 || ioctl(_fid, SPI_IOC_RD_MODE, &_spiMode) == -1)
|
||||
{
|
||||
errortext = QString ("Failed to open device (%1). Error message: %2").arg(_deviceName, strerror(errno));
|
||||
retval = -1;
|
||||
retval = -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ioctl(_fid, SPI_IOC_WR_MODE, &_spiMode) == -1 || ioctl(_fid, SPI_IOC_RD_MODE, &_spiMode) == -1)
|
||||
if (ioctl(_fid, SPI_IOC_WR_BITS_PER_WORD, &bitsPerWord) == -1 || ioctl(_fid, SPI_IOC_RD_BITS_PER_WORD, &bitsPerWord) == -1)
|
||||
{
|
||||
retval = -2;
|
||||
retval = -4;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ioctl(_fid, SPI_IOC_WR_BITS_PER_WORD, &bitsPerWord) == -1 || ioctl(_fid, SPI_IOC_RD_BITS_PER_WORD, &bitsPerWord) == -1)
|
||||
if (ioctl(_fid, SPI_IOC_WR_MAX_SPEED_HZ, &_baudRate_Hz) == -1 || ioctl(_fid, SPI_IOC_RD_MAX_SPEED_HZ, &_baudRate_Hz) == -1)
|
||||
{
|
||||
retval = -4;
|
||||
retval = -6;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ioctl(_fid, SPI_IOC_WR_MAX_SPEED_HZ, &_baudRate_Hz) == -1 || ioctl(_fid, SPI_IOC_RD_MAX_SPEED_HZ, &_baudRate_Hz) == -1)
|
||||
{
|
||||
retval = -6;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Everything OK -> enable device
|
||||
_deviceReady = true;
|
||||
setEnable(true);
|
||||
retval = 0;
|
||||
}
|
||||
// Everything OK -> enable device
|
||||
_isDeviceReady = true;
|
||||
retval = 0;
|
||||
}
|
||||
}
|
||||
if ( retval < 0 )
|
||||
{
|
||||
errortext = QString ("Failed to open device (%1). Error Code: %2").arg(_deviceName).arg(retval);
|
||||
}
|
||||
}
|
||||
|
||||
if ( retval < 0 )
|
||||
{
|
||||
this->setInError( errortext );
|
||||
errortext = QString ("Failed to open device (%1). Error Code: %2").arg(_deviceName).arg(retval);
|
||||
}
|
||||
}
|
||||
|
||||
if ( retval < 0 )
|
||||
{
|
||||
this->setInError( errortext );
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void ProviderSpi::close()
|
||||
int ProviderSpi::close()
|
||||
{
|
||||
LedDevice::close();
|
||||
// LedDevice specific closing activities
|
||||
int retval = 0;
|
||||
_isDeviceReady = false;
|
||||
|
||||
// Device specific closing activites
|
||||
// Test, if device requires closing
|
||||
if ( _fid > -1 )
|
||||
{
|
||||
// Close device
|
||||
if ( ::close(_fid) != 0 )
|
||||
{
|
||||
Error( _log, "Failed to close device (%s). Error message: %s", QSTRING_CSTR(_deviceName), strerror(errno) );
|
||||
retval = -1;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int ProviderSpi::writeBytes(const unsigned size, const uint8_t * data)
|
||||
|
Reference in New Issue
Block a user