Add CodeQL for GitHub code scanning (#1548)

* Create codeql.yml

* Addressing codeql findings
This commit is contained in:
LordGrey
2022-12-27 08:36:10 +01:00
committed by GitHub
parent 1189f86c1a
commit 6fa7bab6f7
83 changed files with 1984 additions and 2094 deletions

View File

@@ -234,8 +234,6 @@ void LedDevice::startRefreshTimer()
connect(_refreshTimer, &QTimer::timeout, this, &LedDevice::rewriteLEDs);
}
_refreshTimer->setInterval(_refreshTimerInterval_ms);
//Debug(_log, "Start refresh timer with interval = %ims", _refreshTimer->interval());
_refreshTimer->start();
}
else
@@ -249,11 +247,9 @@ void LedDevice::stopRefreshTimer()
{
if (_refreshTimer != nullptr)
{
//Debug(_log, "Stopping refresh timer");
_refreshTimer->stop();
delete _refreshTimer;
_refreshTimer = nullptr;
}
}
@@ -302,7 +298,7 @@ int LedDevice::updateLeds(std::vector<ColorRgb> ledValues)
int retval = 0;
if (!_isEnabled || !_isOn || !_isDeviceReady || _isDeviceInError)
{
//std::cout << "LedDevice::updateLeds(), LedDevice NOT ready! ";
// LedDevice NOT ready!
retval = -1;
}
else
@@ -310,7 +306,6 @@ int LedDevice::updateLeds(std::vector<ColorRgb> ledValues)
qint64 elapsedTimeMs = _lastWriteTime.msecsTo(QDateTime::currentDateTime());
if (_latchTime_ms == 0 || elapsedTimeMs >= _latchTime_ms)
{
//std::cout << "LedDevice::updateLeds(), Elapsed time since last write (" << elapsedTimeMs << ") ms > _latchTime_ms (" << _latchTime_ms << ") ms" << std::endl;
retval = write(ledValues);
_lastWriteTime = QDateTime::currentDateTime();
@@ -323,7 +318,7 @@ int LedDevice::updateLeds(std::vector<ColorRgb> ledValues)
}
else
{
//std::cout << "LedDevice::updateLeds(), Skip write. elapsedTime (" << elapsedTimeMs << ") ms < _latchTime_ms (" << _latchTime_ms << ") ms" << std::endl;
// Skip write as elapsedTime < latchTime
if (_isRefreshEnabled)
{
//Stop timer to allow for next non-refresh update
@@ -340,14 +335,6 @@ int LedDevice::rewriteLEDs()
if (_isEnabled && _isOn && _isDeviceReady && !_isDeviceInError)
{
// qint64 elapsedTimeMs = _lastWriteTime.msecsTo(QDateTime::currentDateTime());
// std::cout << "LedDevice::rewriteLEDs(): Rewrite LEDs now, elapsedTime [" << elapsedTimeMs << "] ms" << std::endl;
// //:TESTING: Inject "white" output records to differentiate from normal writes
// _lastLedValues.clear();
// _lastLedValues.resize(static_cast<unsigned long>(_ledCount), ColorRgb::WHITE);
// printLedValues(_lastLedValues);
// //:TESTING:
if (!_lastLedValues.empty())
{
retval = write(_lastLedValues);
@@ -490,12 +477,15 @@ bool LedDevice::storeState()
{
bool rc{ true };
#if 0
if (_isRestoreOrigState)
{
// Save device's original state
// _originalStateValues = get device's state;
// store original power on/off state, if available
}
#endif
return rc;
}
@@ -503,12 +493,14 @@ bool LedDevice::restoreState()
{
bool rc{ true };
#if 0
if (_isRestoreOrigState)
{
// Restore device's original state
// update device using _originalStateValues
// update original power on/off state, if supported
}
#endif
return rc;
}
@@ -699,4 +691,3 @@ QString LedDevice::getColorOrder() const
bool LedDevice::componentState() const {
return _isEnabled;
}

View File

@@ -69,12 +69,14 @@ int LedDeviceTemplate::close()
int retval = 0;
_isDeviceReady = false;
#if 0
// Test, if device requires closing
if ( true /*If device is still open*/ )
{
// Close device
// Everything is OK -> device is closed
}
#endif
return retval;
}

View File

@@ -63,7 +63,9 @@ bool LedDeviceHyperionUsbasp::init(const QJsonObject &deviceConfig)
else
{
Debug(_log, "USB context initialized");
//libusb_set_debug(_libusbContext, 3);
#if 0
libusb_set_debug(_libusbContext, 3);
#endif
// retrieve the list of USB devices
libusb_device ** deviceList;

View File

@@ -331,8 +331,6 @@ const QString &LedDeviceLightpack::getSerialNumber() const
int LedDeviceLightpack::writeBytes(uint8_t *data, int size)
{
int rc = 0;
//Debug( _log, "[%s]", QSTRING_CSTR(uint8_t_to_hex_string(data, size, 32)) );
int error = libusb_control_transfer(_deviceHandle,
static_cast<uint8_t>( LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE ),
0x09,

View File

@@ -73,8 +73,8 @@ int ProviderHID::open()
// Failed to open the device
this->setInError( "Failed to open HID device. Maybe your PID/VID setting is wrong? Make sure to add a udev rule/use sudo." );
#if 0
// http://www.signal11.us/oss/hidapi/
/*
std::cout << "Showing a list of all available HID devices:" << std::endl;
auto devs = hid_enumerate(0x00, 0x00);
auto cur_dev = devs;
@@ -88,7 +88,8 @@ int ProviderHID::open()
cur_dev = cur_dev->next;
}
hid_free_enumeration(devs);
*/
#endif
}
else
{

View File

@@ -45,7 +45,6 @@ const char PANEL_NUM[] = "numPanels";
const char PANEL_ID[] = "panelId";
const char PANEL_POSITIONDATA[] = "positionData";
const char PANEL_SHAPE_TYPE[] = "shapeType";
//const char PANEL_ORIENTATION[] = "0";
const char PANEL_POS_X[] = "x";
const char PANEL_POS_Y[] = "y";
@@ -72,7 +71,6 @@ const quint16 STREAM_CONTROL_DEFAULT_PORT = 60222;
const int API_DEFAULT_PORT = 16021;
const char API_BASE_PATH[] = "/api/v1/%1/";
const char API_ROOT[] = "";
//const char API_EXT_MODE_STRING_V1[] = "{\"write\" : {\"command\" : \"display\", \"animType\" : \"extControl\"}}";
const char API_EXT_MODE_STRING_V2[] = "{\"write\" : {\"command\" : \"display\", \"animType\" : \"extControl\", \"extControlVersion\" : \"v2\"}}";
const char API_STATE[] = "state";
const char API_PANELLAYOUT[] = "panelLayout";
@@ -243,7 +241,6 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
int panelX = panelObj[PANEL_POS_X].toInt();
int panelY = panelObj[PANEL_POS_Y].toInt();
int panelshapeType = panelObj[PANEL_SHAPE_TYPE].toInt();
//int panelOrientation = panelObj[PANEL_ORIENTATION].toInt();
DebugIf(verbose,_log, "Panel [%d] (%d,%d) - Type: [%d]", panelId, panelX, panelY, panelshapeType);
@@ -613,16 +610,16 @@ bool LedDeviceNanoleaf::storeState()
// effect
_restApi->setPath(API_EFFECT);
httpResponse response = _restApi->get();
if ( response.error() )
httpResponse responseEffects = _restApi->get();
if ( responseEffects.error() )
{
QString errorReason = QString("Storing device state failed with error: '%1'").arg(response.getErrorReason());
QString errorReason = QString("Storing device state failed with error: '%1'").arg(responseEffects.getErrorReason());
setInError(errorReason);
rc = false;
}
else
{
QJsonObject effects = response.getBody().object();
QJsonObject effects = responseEffects.getBody().object();
DebugIf(verbose, _log, "effects: [%s]", QString(QJsonDocument(_originalStateProperties).toJson(QJsonDocument::Compact)).toUtf8().constData() );
_originalEffect = effects[API_EFFECT_SELECT].toString();
_originalIsDynEffect = _originalEffect == "*Dynamic*" || _originalEffect == "*Solid*";
@@ -774,7 +771,7 @@ int LedDeviceNanoleaf::write(const std::vector<ColorRgb>& ledValues)
}
else
{
// Set panels not configured to black;
// Set panels not configured to black
color = ColorRgb::BLACK;
DebugIf(verbose3, _log, "[%d] >= panelLedCount [%d] => Set to BLACK", panelCounter, _panelLedCount);
}

View File

@@ -38,7 +38,6 @@ const char CONFIG_VERBOSE[] = "verbose";
const char DEV_DATA_BRIDGEID[] = "bridgeid";
const char DEV_DATA_MODEL[] = "modelid";
const char DEV_DATA_NAME[] = "name";
//const char DEV_DATA_MANUFACTURER[] = "manufacturer";
const char DEV_DATA_FIRMWAREVERSION[] = "swversion";
const char DEV_DATA_APIVERSION[] = "apiversion";
@@ -65,7 +64,6 @@ const char API_STREAM_RESPONSE_FORMAT[] = "/%1/%2/%3/%4";
// List of resources
const char API_XY_COORDINATES[] = "xy";
const char API_BRIGHTNESS[] = "bri";
//const char API_SATURATION[] = "sat";
const char API_TRANSITIONTIME[] = "transitiontime";
const char API_MODEID[] = "modelid";
@@ -188,7 +186,6 @@ CiColor CiColor::rgbToCiColor(double red, double green, double blue, const CiCol
}
if (dBC < lowest)
{
//lowest = dBC;
closestPoint = pBC;
}
// Change the xy value to a value which is within the reach of the lamp.
@@ -1089,7 +1086,7 @@ bool LedDevicePhilipsHue::init(const QJsonObject &deviceConfig)
if( _groupId == 0 )
{
Error(_log, "Disabling usage of HueEntertainmentAPI: Group-ID is invalid", "%d", _groupId);
Error(_log, "Disabling usage of HueEntertainmentAPI: Group-ID [%d] is invalid", _groupId);
_useHueEntertainmentAPI = false;
}
}

View File

@@ -141,10 +141,6 @@ bool LedDeviceRazer::checkApiError(const httpResponse& response)
else
{
QString errorReason;
QString strJson(response.getBody().toJson(QJsonDocument::Compact));
//DebugIf(verbose, _log, "Reply: [%s]", strJson.toUtf8().constData());
QJsonObject jsonObj = response.getBody().object();
if (!jsonObj[API_RESULT].isNull())

View File

@@ -20,15 +20,20 @@ const ushort E131_DEFAULT_PORT = 5568;
/* defined parameters from http://tsp.esta.org/tsp/documents/docs/BSR_E1-31-20xx_CP-2014-1009r2.pdf */
const uint32_t VECTOR_ROOT_E131_DATA = 0x00000004;
//#define VECTOR_ROOT_E131_EXTENDED 0x00000008
const uint8_t VECTOR_DMP_SET_PROPERTY = 0x02;
const uint32_t VECTOR_E131_DATA_PACKET = 0x00000002;
//#define VECTOR_E131_EXTENDED_SYNCHRONIZATION 0x00000001
//#define VECTOR_E131_EXTENDED_DISCOVERY 0x00000002
//#define VECTOR_UNIVERSE_DISCOVERY_UNIVERSE_LIST 0x00000001
//#define E131_E131_UNIVERSE_DISCOVERY_INTERVAL 10 // seconds
//#define E131_NETWORK_DATA_LOSS_TIMEOUT 2500 // milli econds
//#define E131_DISCOVERY_UNIVERSE 64214
#if 0
#define VECTOR_ROOT_E131_EXTENDED 0x00000008
#define VECTOR_E131_EXTENDED_SYNCHRONIZATION 0x00000001
#define VECTOR_E131_EXTENDED_DISCOVERY 0x00000002
#define VECTOR_UNIVERSE_DISCOVERY_UNIVERSE_LIST 0x00000001
#define E131_E131_UNIVERSE_DISCOVERY_INTERVAL 10 // seconds
#define E131_NETWORK_DATA_LOSS_TIMEOUT 2500 // milli econds
#define E131_DISCOVERY_UNIVERSE 64214
#endif
const int DMX_MAX = 512; // 512 usable slots
}

View File

@@ -20,28 +20,30 @@
**/
/* E1.31 Packet Offsets */
//#define E131_ROOT_PREAMBLE_SIZE 0
//#define E131_ROOT_POSTAMBLE_SIZE 2
//#define E131_ROOT_ID 4
//#define E131_ROOT_FLENGTH 16
//#define E131_ROOT_VECTOR 18
//#define E131_ROOT_CID 22
#if 0
#define E131_ROOT_PREAMBLE_SIZE 0
#define E131_ROOT_POSTAMBLE_SIZE 2
#define E131_ROOT_ID 4
#define E131_ROOT_FLENGTH 16
#define E131_ROOT_VECTOR 18
#define E131_ROOT_CID 22
//#define E131_FRAME_FLENGTH 38
//#define E131_FRAME_VECTOR 40
//#define E131_FRAME_SOURCE 44
//#define E131_FRAME_PRIORITY 108
//#define E131_FRAME_RESERVED 109
//#define E131_FRAME_SEQ 111
//#define E131_FRAME_OPT 112
//#define E131_FRAME_UNIVERSE 113
#define E131_FRAME_FLENGTH 38
#define E131_FRAME_VECTOR 40
#define E131_FRAME_SOURCE 44
#define E131_FRAME_PRIORITY 108
#define E131_FRAME_RESERVED 109
#define E131_FRAME_SEQ 111
#define E131_FRAME_OPT 112
#define E131_FRAME_UNIVERSE 113
//#define E131_DMP_FLENGTH 115
//#define E131_DMP_VECTOR 117
//#define E131_DMP_TYPE 118
//#define E131_DMP_ADDR_FIRST 119
//#define E131_DMP_ADDR_INC 121
//#define E131_DMP_COUNT 123
#define E131_DMP_FLENGTH 115
#define E131_DMP_VECTOR 117
#define E131_DMP_TYPE 118
#define E131_DMP_ADDR_FIRST 119
#define E131_DMP_ADDR_INC 121
#define E131_DMP_COUNT 123
#endif
const unsigned int E131_DMP_DATA=125;
/* E1.31 Packet Structure */

View File

@@ -40,7 +40,6 @@ const char WLED_VERSION_DDP[] = "0.11.0";
const int API_DEFAULT_PORT = -1; //Use default port per communication scheme
const char API_BASE_PATH[] = "/json/";
//const char API_PATH_INFO[] = "info";
const char API_PATH_STATE[] = "state";
// List of State Information
@@ -415,7 +414,7 @@ QJsonObject LedDeviceWled::getProperties(const QJsonObject& params)
}
else
{
Info(_log, "DDP streaming is supported by your WLED device version [%s]. No limitation in number of LEDs.", currentVersion.getVersion().c_str(), ddpVersion.getVersion().c_str());
Info(_log, "DDP streaming is supported by your WLED device version [%s]. No limitation in number of LEDs.", currentVersion.getVersion().c_str());
}
}
properties.insert("properties", propertiesDetails);

View File

@@ -82,7 +82,6 @@ const char API_PROP_BRIGHT[] = "bright";
// List of Result Information
const char API_RESULT_ID[] = "id";
const char API_RESULT[] = "result";
//const char API_RESULT_OK[] = "OK";
// List of Error Information
const char API_ERROR[] = "error";
@@ -383,8 +382,6 @@ bool YeelightLight::streamCommand( const QJsonDocument &command )
{
log ( 2, "Info:", "Skip write. Device is in error");
}
//log (2,"streamCommand() rc","%d, isON[%d], isInMusicMode[%d]", rc, _isOn, _isInMusicMode );
return rc;
}
@@ -392,8 +389,6 @@ YeelightResponse YeelightLight::handleResponse(int correlationID, QByteArray con
{
log (3,"handleResponse()","" );
//std::cout << _name.toStdString() <<"| Response: [" << response.toStdString() << "]" << std::endl << std::flush;
YeelightResponse yeeResponse;
QString errorReason;
@@ -446,8 +441,6 @@ YeelightResponse YeelightLight::handleResponse(int correlationID, QByteArray con
else
{
int id = jsonObj[API_RESULT_ID].toInt();
//log ( 3, "Correlation ID:", "%d", id );
if ( id != correlationID && TEST_CORRELATION_IDS)
{
errorReason = QString ("%1| API is out of sync, received ID [%2], expected [%3]").
@@ -528,9 +521,6 @@ QJsonObject YeelightLight::getProperties()
log (3,"getProperties()","" );
QJsonObject properties;
//Selected properties
//QJsonArray propertyList = { API_PROP_NAME, API_PROP_MODEL, API_PROP_POWER, API_PROP_RGB, API_PROP_BRIGHT, API_PROP_CT, API_PROP_FWVER };
//All properties
QJsonArray propertyList = {"power","bright","ct","rgb","hue","sat","color_mode","flowing","delayoff","music_on","name","bg_power","bg_flowing","bg_ct","bg_bright","bg_hue","bg_sat","bg_rgb","nl_br","active_mode" };
@@ -579,9 +569,6 @@ bool YeelightLight::identify()
*/
QJsonArray colorflowParams = { API_PROP_COLORFLOW, 6, 0, "500,1,100,100,500,1,16711696,10"};
//Blink White
//QJsonArray colorflowParams = { API_PROP_COLORFLOW, 6, 0, "500,2,4000,1,500,2,4000,50"};
QJsonDocument command = getCommand( API_METHOD_SETSCENE, colorflowParams );
if ( writeCommand( command ) < 0 )
@@ -819,7 +806,6 @@ bool YeelightLight::setColorRGB(const ColorRgb &color)
rc = false;
}
}
//log (2,"setColorRGB() rc","%d, isON[%d], isInMusicMode[%d]", rc, _isOn, _isInMusicMode );
return rc;
}
@@ -914,7 +900,7 @@ bool YeelightLight::setColorHSV(const ColorRgb &colorRGB)
}
else
{
//log ( 3, "setColorHSV", "Skip update. Same Color as before");
// Skip update. Same Color as before
}
log( 3,
"setColorHSV() rc",
@@ -1471,7 +1457,6 @@ void LedDeviceYeelight::identify(const QJsonObject& params)
int LedDeviceYeelight::write(const std::vector<ColorRgb> & ledValues)
{
//DebugIf(verbose, _log, "enabled [%d], _isDeviceReady [%d]", _isEnabled, _isDeviceReady);
int rc = -1;
//Update on all Yeelights by iterating through lights and set colors.
@@ -1545,8 +1530,5 @@ int LedDeviceYeelight::write(const std::vector<ColorRgb> & ledValues)
// Minimum one Yeelight device is working, continue updating devices
rc = 0;
}
//DebugIf(verbose, _log, "rc [%d]", rc );
return rc;
}

View File

@@ -24,7 +24,6 @@ const char API_METHOD_MUSIC_MODE[] = "set_music";
const int API_METHOD_MUSIC_MODE_ON = 1;
const int API_METHOD_MUSIC_MODE_OFF = 0;
const char API_METHOD_SETRGB[] = "set_rgb";
const char API_METHOD_SETSCENE[] = "set_scene";
const char API_METHOD_GETPROP[] = "get_prop";

View File

@@ -16,10 +16,12 @@ namespace {
const QChar ONE_SLASH = '/';
const int HTTP_STATUS_NO_CONTENT = 204;
const int HTTP_STATUS_BAD_REQUEST = 400;
const int HTTP_STATUS_UNAUTHORIZED = 401;
const int HTTP_STATUS_NOT_FOUND = 404;
enum HttpStatusCode {
NoContent = 204,
BadRequest = 400,
UnAuthorized = 401,
NotFound = 404
};
constexpr std::chrono::milliseconds DEFAULT_REST_TIMEOUT{ 400 };
@@ -303,13 +305,13 @@ httpResponse ProviderRestApi::getResponse(QNetworkReply* const& reply)
{
httpResponse response;
int httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
HttpStatusCode httpStatusCode = static_cast<HttpStatusCode>(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
response.setHttpStatusCode(httpStatusCode);
response.setNetworkReplyError(reply->error());
if (reply->error() == QNetworkReply::NoError)
{
if ( httpStatusCode != HTTP_STATUS_NO_CONTENT ){
if ( httpStatusCode != HttpStatusCode::NoContent ){
QByteArray replyData = reply->readAll();
if (!replyData.isEmpty())
@@ -320,13 +322,11 @@ httpResponse ProviderRestApi::getResponse(QNetworkReply* const& reply)
if (error.error != QJsonParseError::NoError)
{
//Received not valid JSON response
//std::cout << "Response: [" << replyData.toStdString() << "]" << std::endl;
response.setError(true);
response.setErrorReason(error.errorString());
}
else
{
//std::cout << "Response: [" << QString(jsonDoc.toJson(QJsonDocument::Compact)).toStdString() << "]" << std::endl;
response.setBody(jsonDoc);
}
}
@@ -344,13 +344,13 @@ httpResponse ProviderRestApi::getResponse(QNetworkReply* const& reply)
QString httpReason = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
QString advise;
switch ( httpStatusCode ) {
case HTTP_STATUS_BAD_REQUEST:
case HttpStatusCode::BadRequest:
advise = "Check Request Body";
break;
case HTTP_STATUS_UNAUTHORIZED:
case HttpStatusCode::UnAuthorized:
advise = "Check Authentication Token (API Key)";
break;
case HTTP_STATUS_NOT_FOUND:
case HttpStatusCode::NotFound:
advise = "Check Resource given";
break;
default:

View File

@@ -92,9 +92,6 @@ int LedDeviceFile::close()
int LedDeviceFile::write(const std::vector<ColorRgb> & ledValues)
{
QTextStream out(_file);
//printLedValues (ledValues);
if ( _printTimeStamp )
{
QDateTime now = QDateTime::currentDateTime();

View File

@@ -179,8 +179,6 @@ int LedDevicePiBlaster::write(const std::vector<ColorRgb> & ledValues)
continue;
}
// fprintf(_fid, "%i=%f\n", iPins[iPin], pwmDutyCycle);
if ( (fprintf(_fid, "%i=%f\n", i, pwmDutyCycle) < 0) || (fflush(_fid) < 0))
{
if (_fid != nullptr)

View File

@@ -42,7 +42,6 @@ bool LedDeviceDMX::init(const QJsonObject &deviceConfig)
}
else
{
//Error(_log, "unknown dmx device type %s", QSTRING_CSTR(dmxString));
QString errortext = QString ("unknown dmx device type: %1").arg(dmxTypeString);
this->setInError(errortext);
return false;

View File

@@ -24,7 +24,6 @@ bool LedDeviceKarate::init(const QJsonObject& deviceConfig)
{
if (_ledCount != 8 && _ledCount != 16)
{
//Error( _log, "%d channels configured. This should always be 16!", _ledCount);
QString errortext = QString("%1 channels configured. This should always be 8 or 16!").arg(_ledCount);
this->setInError(errortext);
isInitOK = false;

View File

@@ -40,7 +40,6 @@ bool LedDeviceSedu::init(const QJsonObject &deviceConfig)
if (_ledBuffer.empty())
{
//Warning(_log, "More rgb-channels required then available");
QString errortext = "More rgb-channels required then available";
this->setInError(errortext);
}

View File

@@ -273,13 +273,6 @@ void ProviderRs232::readFeedback()
{
//Output as received
std::cout << readData.toStdString();
//Output as Hex
//#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
// std::cout << readData.toHex(':').toStdString();
//#else
// std::cout << readData.toHex().toStdString();
//#endif
}
}

View File

@@ -117,10 +117,6 @@ void LedDeviceSK9822::bufferWithAdjustedCurrent(std::vector<uint8_t> &txBuf, con
txBuf[b + 1] = red;
txBuf[b + 2] = green;
txBuf[b + 3] = blue;
//if(iLed == 0) {
// std::cout << std::to_string((int)rgb.red) << "," << std::to_string((int)rgb.green) << "," << std::to_string((int)rgb.blue) << ": " << std::to_string(maxValue) << (maxValue >= threshold ? " >= " : " < ") << std::to_string(threshold) << " -> " << std::to_string((int)(level&SK9822_GBC_MAX_LEVEL))<< "@" << std::to_string((int)red) << "," << std::to_string((int)green) << "," << std::to_string((int)blue) << std::endl;
//}
}
}

View File

@@ -67,8 +67,6 @@ bool LedDeviceSk6822SPI::init(const QJsonObject &deviceConfig)
WarningIf(( _baudRate_Hz < 2000000 || _baudRate_Hz > 2460000 ), _log, "SPI rate %d outside recommended range (2000000 -> 2460000)", _baudRate_Hz);
_ledBuffer.resize( (_ledRGBCount * SPI_BYTES_PER_COLOUR) + (_ledCount * SPI_BYTES_WAIT_TIME ) + SPI_FRAME_END_LATCH_BYTES, 0x00);
// Debug(_log, "_ledBuffer.resize(_ledRGBCount:%d * SPI_BYTES_PER_COLOUR:%d) + ( _ledCount:%d * SPI_BYTES_WAIT_TIME:%d ) + SPI_FRAME_END_LATCH_BYTES:%d, 0x00)", _ledRGBCount, SPI_BYTES_PER_COLOUR, _ledCount, SPI_BYTES_WAIT_TIME, SPI_FRAME_END_LATCH_BYTES);
isInitOK = true;
}
@@ -95,7 +93,7 @@ int LedDeviceSk6822SPI::write(const std::vector<ColorRgb> &ledValues)
spi_ptr += SPI_BYTES_WAIT_TIME; // the wait between led time is all zeros
}
/*
#if 0
// debug the whole SPI packet
char debug_line[2048];
int ptr=0;
@@ -114,7 +112,7 @@ int LedDeviceSk6822SPI::write(const std::vector<ColorRgb> &ledValues)
ptr = 0;
}
}
*/
#endif
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}