Skip to content

Commit

Permalink
Updates after review feedback by m-seker
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-Grey committed Jul 9, 2020
1 parent a0a59b0 commit a5a1707
Show file tree
Hide file tree
Showing 31 changed files with 400 additions and 391 deletions.
2 changes: 1 addition & 1 deletion include/leddevice/LedDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class LedDevice : public QObject
///
/// @brief Destructor of the LED-device
///
virtual ~LedDevice();
~LedDevice() override;

///
/// @brief Get color order of device.
Expand Down
2 changes: 1 addition & 1 deletion include/leddevice/LedDeviceWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LedDeviceWrapper : public QObject
///
/// @brief Return the last enable state
///
const bool & enabled();
bool enabled();

///
/// @brief Get the current colorOrder from device
Expand Down
2 changes: 1 addition & 1 deletion include/ssdp/SSDPDiscover.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static const int DEFAULT_SEARCH_PORT = 1900;
static const char DEFAULT_FILTER[] = ".*";
static const char DEFAULT_FILTER_HEADER[] = "ST";

const int DEFAULT_SSDP_TIMEOUT = 5000; // timeout in ms
constexpr std::chrono::milliseconds DEFAULT_SSDP_TIMEOUT{5000}; // timeout in ms

///
/// @brief Search for SSDP sessions, used by stand-alone capture binaries
Expand Down
42 changes: 42 additions & 0 deletions include/utils/QStringUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef QSTRINGUTILS_H
#define QSTRINGUTILS_H

#include <QString>
#include <QStringList>

namespace QStringUtils {

enum class SplitBehavior {
KeepEmptyParts,
SkipEmptyParts,
};

inline QStringList split (const QString &string, const QString &sep, SplitBehavior behavior = SplitBehavior::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, Qt::SkipEmptyParts , cs) : string.split(sep, Qt::KeepEmptyParts , cs);
#else
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, QString::SkipEmptyParts , cs) : string.split(sep, QString::KeepEmptyParts , cs);
#endif
}

inline QStringList split (const QString &string, QChar sep, SplitBehavior behavior = SplitBehavior::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, Qt::SkipEmptyParts , cs) : string.split(sep, Qt::KeepEmptyParts , cs);
#else
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, QString::SkipEmptyParts , cs) : string.split(sep, QString::KeepEmptyParts , cs);
#endif
}

inline QStringList split (const QString &string, const QRegExp &rx, SplitBehavior behavior = SplitBehavior::KeepEmptyParts)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return behavior == SplitBehavior::SkipEmptyParts ? string.split(rx, Qt::SkipEmptyParts) : string.split(rx, Qt::KeepEmptyParts);
#else
return behavior == SplitBehavior::SkipEmptyParts ? string.split(rx, QString::SkipEmptyParts) : string.split(rx, QString::KeepEmptyParts);
#endif
}
}

#endif // QSTRINGUTILS_H
12 changes: 4 additions & 8 deletions libsrc/boblightserver/BoblightClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <hyperion/ImageProcessor.h>
#include "HyperionConfig.h"
#include <hyperion/Hyperion.h>
#include <utils/QStringUtils.h>

// project includes
#include "BoblightClientConnection.h"
Expand Down Expand Up @@ -81,7 +82,7 @@ void BoblightClientConnection::readData()
void BoblightClientConnection::socketClosed()
{
// clear the current channel
if (_priority != 0 && _priority >= 128 && _priority < 254)
if (_priority >= 128 && _priority < 254)
_hyperion->clear(_priority);

emit connectionClosed(this);
Expand All @@ -90,12 +91,7 @@ void BoblightClientConnection::socketClosed()
void BoblightClientConnection::handleMessage(const QString & message)
{
//std::cout << "boblight message: " << message.toStdString() << std::endl;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QStringList messageParts = message.split(" ", Qt::SkipEmptyParts);
#else
QStringList messageParts = message.split(" ", QString::SkipEmptyParts);
#endif

QStringList messageParts = QStringUtils::split(message," ",QStringUtils::SplitBehavior::SkipEmptyParts);
if (messageParts.size() > 0)
{
if (messageParts[0] == "hello")
Expand Down Expand Up @@ -217,7 +213,7 @@ void BoblightClientConnection::handleMessage(const QString & message)
}
else if (messageParts[0] == "sync")
{
if (_priority != 0 && _priority >= 128 && _priority < 254)
if ( _priority >= 128 && _priority < 254)
_hyperion->setInput(_priority, _ledColors); // send current color values to hyperion

return;
Expand Down
2 changes: 1 addition & 1 deletion libsrc/leddevice/LedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ LedDevice::LedDevice(const QJsonObject& deviceConfig, QObject* parent)

LedDevice::~LedDevice()
{
_refreshTimer->deleteLater();
delete _refreshTimer;
}

void LedDevice::start()
Expand Down
2 changes: 1 addition & 1 deletion libsrc/leddevice/LedDeviceWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ unsigned int LedDeviceWrapper::getLedCount() const
return _ledDevice->getLedCount();
}

const bool & LedDeviceWrapper::enabled()
bool LedDeviceWrapper::enabled()
{
return _enabled;
}
Expand Down
10 changes: 6 additions & 4 deletions libsrc/leddevice/dev_hid/LedDeviceHyperionUsbasp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
// Local Hyperion includes
#include "LedDeviceHyperionUsbasp.h"

// Static constants which define the Hyperion USBasp device
uint16_t LedDeviceHyperionUsbasp::_usbVendorId = 0x16c0;
uint16_t LedDeviceHyperionUsbasp::_usbProductId = 0x05dc;
QString LedDeviceHyperionUsbasp::_usbProductDescription = "Hyperion led controller";
// Constants which define the Hyperion USBasp device
namespace {
uint16_t _usbVendorId = 0x16c0;
uint16_t _usbProductId = 0x05dc;
QString _usbProductDescription = "Hyperion led controller";
}

LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(const QJsonObject &deviceConfig)
: LedDevice()
Expand Down
5 changes: 0 additions & 5 deletions libsrc/leddevice/dev_hid/LedDeviceHyperionUsbasp.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ public slots:

/// libusb device handle
libusb_device_handle * _deviceHandle;

/// Usb device identifiers
static uint16_t _usbVendorId;
static uint16_t _usbProductId;
static QString _usbProductDescription;
};

#endif // LEDEVICEHYPERIONUSBASP_H
2 changes: 1 addition & 1 deletion libsrc/leddevice/dev_hid/LedDeviceMultiLightpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class LedDeviceMultiLightpack : public LedDevice
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> & ledValues) override;
int write(const std::vector<ColorRgb> & ledValues) override;

private:

Expand Down
10 changes: 3 additions & 7 deletions libsrc/leddevice/dev_net/LedDeviceAtmoOrb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Local-Hyperion includes
#include "LedDeviceAtmoOrb.h"
#include <utils/QStringUtils.h>

// qt includes
#include <QUdpSocket>
Expand Down Expand Up @@ -33,7 +34,7 @@ LedDeviceAtmoOrb::~LedDeviceAtmoOrb()
{
if ( _udpSocket != nullptr )
{
_udpSocket->deleteLater();
delete _udpSocket;
}
}

Expand All @@ -51,12 +52,7 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
_multiCastGroupPort = static_cast<quint16>(deviceConfig["port"].toInt(MULTICAST_GROUPL_DEFAULT_PORT));
_numLeds = deviceConfig["numLeds"].toInt(LEDS_DEFAULT_NUMBER);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
const QStringList orbIds = deviceConfig["orbIds"].toString().simplified().remove(" ").split(",", Qt::SkipEmptyParts);
#else
const QStringList orbIds = deviceConfig["orbIds"].toString().simplified().remove(" ").split(",", QString::SkipEmptyParts);
#endif

QStringList orbIds = QStringUtils::split(deviceConfig["orbIds"].toString().simplified().remove(" "),",", QStringUtils::SplitBehavior::SkipEmptyParts);
_orbIds.clear();

for (auto & id_str : orbIds)
Expand Down
15 changes: 10 additions & 5 deletions libsrc/leddevice/dev_net/LedDeviceFadeCandy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
typedef SSIZE_T ssize_t;
#endif

static const signed MAX_NUM_LEDS = 10000; // OPC can handle 21845 LEDs - in theory, fadecandy device should handle 10000 LEDs
static const unsigned OPC_SET_PIXELS = 0; // OPC command codes
static const unsigned OPC_SYS_EX = 255; // OPC command codes
static const unsigned OPC_HEADER_SIZE = 4; // OPC header size
// Constants
namespace {

const signed MAX_NUM_LEDS = 10000; // OPC can handle 21845 LEDs - in theory, fadecandy device should handle 10000 LEDs
const unsigned OPC_SET_PIXELS = 0; // OPC command codes
const unsigned OPC_SYS_EX = 255; // OPC command codes
const unsigned OPC_HEADER_SIZE = 4; // OPC header size

} //End of constants

// TCP elements
const quint16 STREAM_DEFAULT_PORT = 7890;
Expand All @@ -30,7 +35,7 @@ LedDeviceFadeCandy::~LedDeviceFadeCandy()
{
if ( _client != nullptr )
{
_client->deleteLater();
delete _client;
}
}

Expand Down
102 changes: 48 additions & 54 deletions libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Local-Hyperion includes
#include "LedDeviceNanoleaf.h"

// ssdp discover
#include <ssdp/SSDPDiscover.h>
#include <utils/QStringUtils.h>

// Qt includes
#include <QEventLoop>
Expand All @@ -12,62 +12,66 @@
#include <sstream>
#include <iomanip>

//
static const bool verbose = false;
static const bool verbose3 = false;
// Constants
namespace {

const bool verbose = false;
const bool verbose3 = false;

// Configuration settings
static const char CONFIG_ADDRESS[] = "host";
//static const char CONFIG_PORT[] = "port";
static const char CONFIG_AUTH_TOKEN[] ="token";
const char CONFIG_ADDRESS[] = "host";
//const char CONFIG_PORT[] = "port";
const char CONFIG_AUTH_TOKEN[] ="token";

static const char CONFIG_PANEL_ORDER_TOP_DOWN[] ="panelOrderTopDown";
static const char CONFIG_PANEL_ORDER_LEFT_RIGHT[] ="panelOrderLeftRight";
static const char CONFIG_PANEL_START_POS[] ="panelStartPos";
const char CONFIG_PANEL_ORDER_TOP_DOWN[] ="panelOrderTopDown";
const char CONFIG_PANEL_ORDER_LEFT_RIGHT[] ="panelOrderLeftRight";
const char CONFIG_PANEL_START_POS[] ="panelStartPos";

// Panel configuration settings
static const char PANEL_LAYOUT[] = "layout";
static const char PANEL_NUM[] = "numPanels";
static const char PANEL_ID[] = "panelId";
static const char PANEL_POSITIONDATA[] = "positionData";
static const char PANEL_SHAPE_TYPE[] = "shapeType";
//static const char PANEL_ORIENTATION[] = "0";
static const char PANEL_POS_X[] = "x";
static const char PANEL_POS_Y[] = "y";
const char PANEL_LAYOUT[] = "layout";
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";

// List of State Information
static const char STATE_ON[] = "on";
static const char STATE_ONOFF_VALUE[] = "value";
static const char STATE_VALUE_TRUE[] = "true";
static const char STATE_VALUE_FALSE[] = "false";
const char STATE_ON[] = "on";
const char STATE_ONOFF_VALUE[] = "value";
const char STATE_VALUE_TRUE[] = "true";
const char STATE_VALUE_FALSE[] = "false";

// Device Data elements
static const char DEV_DATA_NAME[] = "name";
static const char DEV_DATA_MODEL[] = "model";
static const char DEV_DATA_MANUFACTURER[] = "manufacturer";
static const char DEV_DATA_FIRMWAREVERSION[] = "firmwareVersion";
const char DEV_DATA_NAME[] = "name";
const char DEV_DATA_MODEL[] = "model";
const char DEV_DATA_MANUFACTURER[] = "manufacturer";
const char DEV_DATA_FIRMWAREVERSION[] = "firmwareVersion";

// Nanoleaf Stream Control elements
//static const char STREAM_CONTROL_IP[] = "streamControlIpAddr";
static const char STREAM_CONTROL_PORT[] = "streamControlPort";
//static const char STREAM_CONTROL_PROTOCOL[] = "streamControlProtocol";
//const char STREAM_CONTROL_IP[] = "streamControlIpAddr";
const char STREAM_CONTROL_PORT[] = "streamControlPort";
//const char STREAM_CONTROL_PROTOCOL[] = "streamControlProtocol";
const quint16 STREAM_CONTROL_DEFAULT_PORT = 60222; //Fixed port for Canvas;

// Nanoleaf OpenAPI URLs
static const int API_DEFAULT_PORT = 16021;
static const char API_BASE_PATH[] = "/api/v1/%1/";
static const char API_ROOT[] = "";
//static const char API_EXT_MODE_STRING_V1[] = "{\"write\" : {\"command\" : \"display\", \"animType\" : \"extControl\"}}";
static const char API_EXT_MODE_STRING_V2[] = "{\"write\" : {\"command\" : \"display\", \"animType\" : \"extControl\", \"extControlVersion\" : \"v2\"}}";
static const char API_STATE[] ="state";
static const char API_PANELLAYOUT[] = "panelLayout";
static const char API_EFFECT[] = "effects";
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";
const char API_EFFECT[] = "effects";

// Nanoleaf ssdp services
static const char SSDP_ID[] = "ssdp:all";
static const char SSDP_FILTER_HEADER[] = "ST";
static const char SSDP_CANVAS[] = "nanoleaf:nl29";
static const char SSDP_LIGHTPANELS[] = "nanoleaf_aurora:light";
const char SSDP_ID[] = "ssdp:all";
const char SSDP_FILTER_HEADER[] = "ST";
const char SSDP_CANVAS[] = "nanoleaf:nl29";
const char SSDP_LIGHTPANELS[] = "nanoleaf_aurora:light";

} //End of constants

// Nanoleaf Panel Shapetypes
enum SHAPETYPES {
Expand Down Expand Up @@ -419,12 +423,7 @@ QJsonObject LedDeviceNanoleaf::getProperties(const QJsonObject& params)
QString filter = params["filter"].toString("");

// Resolve hostname and port (or use default API port)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QStringList addressparts = host.split(":", Qt::SkipEmptyParts);
#else
QStringList addressparts = host.split(":", QString::SkipEmptyParts);
#endif

QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts);
QString apiHost = addressparts[0];
int apiPort;

Expand Down Expand Up @@ -467,13 +466,8 @@ void LedDeviceNanoleaf::identify(const QJsonObject& params)
QString authToken = params["token"].toString("");

// Resolve hostname and port (or use default API port)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QStringList addressparts = host.split(":", Qt::SkipEmptyParts);
#else
QStringList addressparts = host.split(":", QString::SkipEmptyParts);
#endif

QString apiHost = addressparts[0];
QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts);
QString apiHost = addressparts[0];
int apiPort;

if ( addressparts.size() > 1)
Expand Down
Loading

0 comments on commit a5a1707

Please sign in to comment.