Skip to content

Commit

Permalink
Fixes and Clean-up after clang-tidy report
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-Grey committed Jul 3, 2020
1 parent b1d10a1 commit 5ffd10c
Show file tree
Hide file tree
Showing 26 changed files with 221 additions and 119 deletions.
4 changes: 2 additions & 2 deletions include/leddevice/LedDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class LedDevice : public QObject
///
/// @param[in] params Parameters to address device
///
virtual void identify(const QJsonObject& params) {};
virtual void identify(const QJsonObject& params) {}

///
/// @brief Check, if device is properly initialised
Expand Down Expand Up @@ -262,7 +262,7 @@ public slots:
/// @param[in] numberOfWrites Write Black given number of times
/// @return Zero on success else negative
///
virtual int writeBlack(int numberOfWrites=1);
virtual int writeBlack(int numberOfBlack=1);

///
/// @brief Switch the LEDs on.
Expand Down
3 changes: 2 additions & 1 deletion libsrc/leddevice/LedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ LedDevice::LedDevice(const QJsonObject& deviceConfig, QObject* parent)
, _refreshTimerInterval_ms(0)
, _latchTime_ms(0)
, _isRestoreOrigState(false)
, _orignalStateValues()
, _isEnabled(false)
, _isDeviceInitialised(false)
, _isDeviceReady(false)
Expand Down Expand Up @@ -414,7 +413,9 @@ void LedDevice::printLedValues(const std::vector<ColorRgb>& ledValues)
QString LedDevice::uint8_t_to_hex_string(const uint8_t * data, const qint64 size, qint64 number) const
{
if ( number <= 0 || number > size)
{
number = size;
}

QByteArray bytes (reinterpret_cast<const char*>(data), number);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
Expand Down
1 change: 0 additions & 1 deletion libsrc/leddevice/LedDeviceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig)
{
Logger * log = Logger::getInstance("LEDDEVICE");
QJsonDocument config(deviceConfig);
QString ss(config.toJson(QJsonDocument::Indented));

QString type = deviceConfig["type"].toString("UNSPECIFIED").toLower();

Expand Down
4 changes: 0 additions & 4 deletions libsrc/leddevice/LedDeviceTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ LedDeviceTemplate::LedDeviceTemplate(const QJsonObject &deviceConfig)
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
}

LedDeviceTemplate::~LedDeviceTemplate()
{
}

LedDevice* LedDeviceTemplate::construct(const QJsonObject &deviceConfig)
{
return new LedDeviceTemplate(deviceConfig);
Expand Down
5 changes: 0 additions & 5 deletions libsrc/leddevice/LedDeviceTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ class LedDeviceTemplate : public LedDevice
///
explicit LedDeviceTemplate(const QJsonObject &deviceConfig);

///
/// @brief Destructor of the LedDevice
///
virtual ~LedDeviceTemplate() override;

///
/// @brief Constructs the LED-device
///
Expand Down
2 changes: 1 addition & 1 deletion libsrc/leddevice/dev_hid/LedDeviceHyperionUsbasp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int LedDeviceHyperionUsbasp::write(const std::vector<ColorRgb> &ledValues)
{
int nbytes = libusb_control_transfer(
_deviceHandle, // device handle
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT, // request type
static_cast<uint8_t>( LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT ), // request type
_writeLedsCommand, // request
0, // value
0, // index
Expand Down
16 changes: 11 additions & 5 deletions libsrc/leddevice/dev_hid/LedDeviceLightpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ int LedDeviceLightpack::testAndOpen(libusb_device * device, const QString & requ
uint8_t buffer[256];
error = libusb_control_transfer(
_deviceHandle,
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
static_cast<uint8_t>( LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE),
0x01,
0x0100,
0,
Expand Down Expand Up @@ -283,12 +283,12 @@ int LedDeviceLightpack::testAndOpen(libusb_device * device, const QString & requ

int LedDeviceLightpack::write(const std::vector<ColorRgb> &ledValues)
{
return write(ledValues.data(), ledValues.size());
return write(ledValues.data(), static_cast<int>(ledValues.size()));
}

int LedDeviceLightpack::write(const ColorRgb * ledValues, int size)
{
int count = qMin(_hwLedCount, static_cast<int>( _ledCount));
int count = qMin(_hwLedCount, static_cast<int>( size ));

for (int i = 0; i < count ; ++i)
{
Expand Down Expand Up @@ -331,7 +331,7 @@ int LedDeviceLightpack::writeBytes(uint8_t *data, int size)
// std::cout << std::endl;

int error = libusb_control_transfer(_deviceHandle,
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
static_cast<uint8_t>( LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE ),
0x09,
(2 << 8),
0x00,
Expand All @@ -349,7 +349,13 @@ int LedDeviceLightpack::writeBytes(uint8_t *data, int size)
int LedDeviceLightpack::disableSmoothing()
{
unsigned char buf[2] = {CMD_SET_SMOOTH_SLOWDOWN, 0};
return writeBytes(buf, sizeof(buf)) == sizeof(buf);

int rc = 0;
if ( writeBytes(buf, sizeof(buf)) == sizeof(buf) )
{
rc = 1;
}
return rc;
}

libusb_device_handle * LedDeviceLightpack::openDevice(libusb_device *device)
Expand Down
8 changes: 5 additions & 3 deletions libsrc/leddevice/dev_hid/LedDeviceMultiLightpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ LedDeviceMultiLightpack::~LedDeviceMultiLightpack()
for (LedDeviceLightpack * device : _lightpacks)
{
if ( device != nullptr)
{
delete device;
}
}
}

Expand All @@ -55,7 +57,7 @@ bool LedDeviceMultiLightpack::init(const QJsonObject &deviceConfig)
std::sort(_lightpacks.begin(), _lightpacks.end(), compareLightpacks);

// open each Lightpack device
foreach (auto serial , serialList)
for (auto serial : serialList)
{
QJsonObject devConfig;
devConfig["serial"] = serial;
Expand All @@ -76,7 +78,7 @@ bool LedDeviceMultiLightpack::init(const QJsonObject &deviceConfig)
}
}

if (_lightpacks.size() == 0)
if (_lightpacks.empty())
{
//Warning(_log, "No Lightpack devices were found");
QString errortext = QString ("No Lightpack devices were found");
Expand Down Expand Up @@ -226,7 +228,7 @@ QStringList LedDeviceMultiLightpack::getLightpackSerials()
}
}

Info(log, "Lightpack device found with serial %s", QSTRING_CSTR(serialNumber));;
Info(log, "Lightpack device found with serial %s", QSTRING_CSTR(serialNumber));
serialList.append(serialNumber);
}
}
Expand Down
34 changes: 19 additions & 15 deletions libsrc/leddevice/dev_hid/ProviderHID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,27 @@ QJsonObject ProviderHID::discover()

// Discover HID Devices
auto devs = hid_enumerate(0x00, 0x00);
auto cur_dev = devs;
while (cur_dev)

if ( devs != nullptr )
{
QJsonObject deviceInfo;
deviceInfo.insert("manufacturer",QString::fromWCharArray(cur_dev->manufacturer_string));
deviceInfo.insert("path",cur_dev->path);
deviceInfo.insert("productIdentifier", QString("0x%1").arg(static_cast<ushort>(cur_dev->product_id),0,16));
deviceInfo.insert("release_number",QString("0x%1").arg(static_cast<ushort>(cur_dev->release_number),0,16));
deviceInfo.insert("serialNumber",QString::fromWCharArray(cur_dev->serial_number));
deviceInfo.insert("usage_page", QString("0x%1").arg(static_cast<ushort>(cur_dev->usage_page),0,16));
deviceInfo.insert("vendorIdentifier", QString("0x%1").arg(static_cast<ushort>(cur_dev->vendor_id),0,16));
deviceInfo.insert("interface_number",cur_dev->interface_number);
deviceList.append(deviceInfo);

cur_dev = cur_dev->next;
auto cur_dev = devs;
while (cur_dev)
{
QJsonObject deviceInfo;
deviceInfo.insert("manufacturer",QString::fromWCharArray(cur_dev->manufacturer_string));
deviceInfo.insert("path",cur_dev->path);
deviceInfo.insert("productIdentifier", QString("0x%1").arg(static_cast<ushort>(cur_dev->product_id),0,16));
deviceInfo.insert("release_number",QString("0x%1").arg(static_cast<ushort>(cur_dev->release_number),0,16));
deviceInfo.insert("serialNumber",QString::fromWCharArray(cur_dev->serial_number));
deviceInfo.insert("usage_page", QString("0x%1").arg(static_cast<ushort>(cur_dev->usage_page),0,16));
deviceInfo.insert("vendorIdentifier", QString("0x%1").arg(static_cast<ushort>(cur_dev->vendor_id),0,16));
deviceInfo.insert("interface_number",cur_dev->interface_number);
deviceList.append(deviceInfo);

cur_dev = cur_dev->next;
}
hid_free_enumeration(devs);
}
hid_free_enumeration(devs);

devicesDiscovered.insert("devices", deviceList);
return devicesDiscovered;
Expand Down
14 changes: 10 additions & 4 deletions libsrc/leddevice/dev_net/LedDeviceAtmoOrb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,28 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)

_orbIds.clear();

foreach(auto & id_str, orbIds)
for (auto & id_str : orbIds)
{
bool ok;
int id = id_str.toInt(&ok);
if (ok)
{
if ( id < 1 || id > 255 )
{
Warning(_log, "Skip orb id '%d'. IDs must be in range 1-255", id);
}
else
{
_orbIds.append(id);
}
}
else
{
Error(_log, "orb id '%s' is not a number", QSTRING_CSTR(id_str));
}
}

if ( _orbIds.size() == 0 )
if ( _orbIds.empty() )
{
this->setInError("No valid OrbIds found!");
isInitOK = false;
Expand All @@ -99,15 +105,15 @@ int LedDeviceAtmoOrb::open()
_groupAddress = QHostAddress(_multicastGroup);
if ( !_udpSocket->bind(QHostAddress::AnyIPv4, _multiCastGroupPort, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint) )
{
QString errortext = QString ("(%1) %2, MulticastGroup: (%3)").arg(_udpSocket->error()).arg(_udpSocket->errorString()).arg(_multicastGroup);
QString errortext = QString ("(%1) %2, MulticastGroup: (%3)").arg(_udpSocket->error()).arg(_udpSocket->errorString(), _multicastGroup);
this->setInError( errortext );
}
else
{
_joinedMulticastgroup = _udpSocket->joinMulticastGroup(_groupAddress);
if ( !_joinedMulticastgroup )
{
QString errortext = QString ("(%1) %2, MulticastGroup: (%3)").arg(_udpSocket->error()).arg(_udpSocket->errorString()).arg(_multicastGroup);
QString errortext = QString ("(%1) %2, MulticastGroup: (%3)").arg(_udpSocket->error()).arg(_udpSocket->errorString(), _multicastGroup);
this->setInError( errortext );
}
else
Expand Down
2 changes: 1 addition & 1 deletion libsrc/leddevice/dev_net/LedDeviceFadeCandy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ LedDeviceFadeCandy::LedDeviceFadeCandy(const QJsonObject &deviceConfig)

LedDeviceFadeCandy::~LedDeviceFadeCandy()
{
if ( _client == nullptr )
if ( _client != nullptr )
{
_client->deleteLater();
}
Expand Down
2 changes: 1 addition & 1 deletion libsrc/leddevice/dev_net/LedDeviceFadeCandy.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LedDeviceFadeCandy : public LedDevice
///
/// @brief Destructor of the LedDevice
///
virtual ~LedDeviceFadeCandy();
~LedDeviceFadeCandy() override;

///
/// @brief Constructs the LED-device
Expand Down
36 changes: 30 additions & 6 deletions libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,24 @@ bool LedDeviceNanoleaf::init(const QJsonObject &deviceConfig)

// Read panel organisation configuration
if ( deviceConfig[ CONFIG_PANEL_ORDER_TOP_DOWN ].isString() )
_topDown = deviceConfig[ CONFIG_PANEL_ORDER_TOP_DOWN ].toString().toInt() == 0 ? true : false;
{
_topDown = deviceConfig[ CONFIG_PANEL_ORDER_TOP_DOWN ].toString().toInt() == 0;
}
else
_topDown = deviceConfig[ CONFIG_PANEL_ORDER_TOP_DOWN ].toInt() == 0 ? true : false;
{
_topDown = deviceConfig[ CONFIG_PANEL_ORDER_TOP_DOWN ].toInt() == 0;
}

if ( deviceConfig[ CONFIG_PANEL_ORDER_LEFT_RIGHT ].isString() )
_leftRight = deviceConfig[ CONFIG_PANEL_ORDER_LEFT_RIGHT ].toString().toInt() == 0 ? true : false;
{
_leftRight = deviceConfig[ CONFIG_PANEL_ORDER_LEFT_RIGHT ].toString().toInt() == 0;
}
else
_leftRight = deviceConfig[ CONFIG_PANEL_ORDER_LEFT_RIGHT ].toInt() == 0 ? true : false;
{
_leftRight = deviceConfig[ CONFIG_PANEL_ORDER_LEFT_RIGHT ].toInt() == 0;
}

_startPos = deviceConfig[ CONFIG_PANEL_START_POS ].toInt(0);
_startPos = static_cast<uint>( deviceConfig[ CONFIG_PANEL_START_POS ].toInt(0) );

// TODO: Allow to handle port dynamically

Expand Down Expand Up @@ -224,7 +232,7 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
std::map<uint, std::map<uint, uint>> panelMap;

// Loop over all children.
foreach (const QJsonValue & value, positionData)
for (const QJsonValue value : positionData)
{
QJsonObject panelObj = value.toObject();

Expand Down Expand Up @@ -258,9 +266,13 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
DebugIf(verbose3, _log, "panelMap[%u][%u]=%u", posY->first, posX->first, posX->second );

if ( _topDown )
{
_panelIds.push_back(posX->second);
}
else
{
_panelIds.push_front(posX->second);
}
}
}
else
Expand All @@ -271,9 +283,13 @@ bool LedDeviceNanoleaf::initLedsConfiguration()
DebugIf(verbose3, _log, "panelMap[%u][%u]=%u", posY->first, posX->first, posX->second );

if ( _topDown )
{
_panelIds.push_back(posX->second);
}
else
{
_panelIds.push_front(posX->second);
}
}
}
}
Expand Down Expand Up @@ -413,9 +429,13 @@ QJsonObject LedDeviceNanoleaf::getProperties(const QJsonObject& params)
int apiPort;

if ( addressparts.size() > 1)
{
apiPort = addressparts[1].toInt();
}
else
{
apiPort = API_DEFAULT_PORT;
}

initRestAPI(apiHost, apiPort, authToken);
_restApi->setPath(filter);
Expand Down Expand Up @@ -457,9 +477,13 @@ void LedDeviceNanoleaf::identify(const QJsonObject& params)
int apiPort;

if ( addressparts.size() > 1)
{
apiPort = addressparts[1].toInt();
}
else
{
apiPort = API_DEFAULT_PORT;
}

initRestAPI(apiHost, apiPort, authToken);
_restApi->setPath("identify");
Expand Down
Loading

0 comments on commit 5ffd10c

Please sign in to comment.