mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
migrate std::string to qstring + add sysinfo via json (#412)
* std::string -> qstring part 1 * more string migration * more string migration ... * ... * more qstring mogrations add sysinfo via json * remove unneccessary includes * integrate sysinfo into webui
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include <QDir>
|
||||
|
||||
LedDeviceRegistry LedDevice::_ledDeviceMap = LedDeviceRegistry();
|
||||
std::string LedDevice::_activeDevice = "";
|
||||
QString LedDevice::_activeDevice = "";
|
||||
int LedDevice::_ledCount = 0;
|
||||
int LedDevice::_ledRGBCount = 0;
|
||||
int LedDevice::_ledRGBWCount= 0;
|
||||
@@ -34,7 +34,7 @@ int LedDevice::open()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LedDevice::addToDeviceMap(std::string name, LedDeviceCreateFuncType funcPtr)
|
||||
int LedDevice::addToDeviceMap(QString name, LedDeviceCreateFuncType funcPtr)
|
||||
{
|
||||
_ledDeviceMap.emplace(name,funcPtr);
|
||||
return 0;
|
||||
@@ -45,7 +45,7 @@ const LedDeviceRegistry& LedDevice::getDeviceMap()
|
||||
return _ledDeviceMap;
|
||||
}
|
||||
|
||||
void LedDevice::setActiveDevice(std::string dev)
|
||||
void LedDevice::setActiveDevice(QString dev)
|
||||
{
|
||||
_activeDevice = dev;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ QJsonObject LedDevice::getLedDeviceSchemas()
|
||||
|
||||
if (!schemaData.open(QIODevice::ReadOnly))
|
||||
{
|
||||
Error(Logger::getInstance("LedDevice"), "Schema not found: %s", item.toUtf8().constData());
|
||||
Error(Logger::getInstance("LedDevice"), "Schema not found: %s", QSTRING_CSTR(item));
|
||||
throw std::runtime_error("ERROR: Schema not found: " + item.toStdString());
|
||||
}
|
||||
|
||||
@@ -97,10 +97,9 @@ QJsonObject LedDevice::getLedDeviceSchemas()
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream sstream;
|
||||
sstream << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn;
|
||||
Error(Logger::getInstance("LedDevice"), "LedDevice JSON schema error in %s (%s)", item.toUtf8().constData(), sstream.str().c_str());
|
||||
throw std::runtime_error("ERROR: Json schema wrong: " + sstream.str());
|
||||
QString errorMsg = error.errorString() + " at Line: " + QString::number(errorLine) + ", Column: " + QString::number(errorColumn);
|
||||
Error(Logger::getInstance("LedDevice"), "LedDevice JSON schema error in %s (%s)", QSTRING_CSTR(item), QSTRING_CSTR(errorMsg));
|
||||
throw std::runtime_error("ERROR: Json schema wrong: " + errorMsg.toStdString());
|
||||
}
|
||||
|
||||
schemaJson = doc.object();
|
||||
|
@@ -6,13 +6,10 @@
|
||||
#include <QEventLoop>
|
||||
#include <QtNetwork>
|
||||
#include <QNetworkReply>
|
||||
#include <QStringList>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
AtmoOrbLight::AtmoOrbLight(unsigned int id) {
|
||||
AtmoOrbLight::AtmoOrbLight(unsigned int id)
|
||||
{
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
@@ -38,28 +35,20 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
|
||||
_multiCastGroupPort = deviceConfig["port"].toInt(49692);
|
||||
_numLeds = deviceConfig["numLeds"].toInt(24);
|
||||
|
||||
const std::string orbId = deviceConfig["orbIds"].toString().toStdString();
|
||||
const QStringList orbIds = deviceConfig["orbIds"].toString().simplified().remove(" ").split(",", QString::SkipEmptyParts);
|
||||
_orbIds.clear();
|
||||
|
||||
// If we find multiple Orb ids separate them and add to list
|
||||
const std::string separator (",");
|
||||
if (orbId.find(separator) != std::string::npos)
|
||||
foreach(auto & id_str, orbIds)
|
||||
{
|
||||
std::stringstream ss(orbId);
|
||||
std::vector<int> output;
|
||||
unsigned int i;
|
||||
while (ss >> i)
|
||||
{
|
||||
_orbIds.push_back(i);
|
||||
if (ss.peek() == ',' || ss.peek() == ' ') ss.ignore();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_orbIds.push_back(atoi(orbId.c_str()));
|
||||
bool ok;
|
||||
int id = id_str.toInt(&ok);
|
||||
if (ok)
|
||||
_orbIds.append(id);
|
||||
else
|
||||
Error(_log, "orb id '%s' is not a number", QSTRING_CSTR(id_str));
|
||||
}
|
||||
|
||||
return true;
|
||||
return _orbIds.size() > 0;
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceAtmoOrb::construct(const QJsonObject &deviceConfig)
|
||||
@@ -104,7 +93,7 @@ int LedDeviceAtmoOrb::write(const std::vector <ColorRgb> &ledValues)
|
||||
abs(color.green - lastGreen) >= _skipSmoothingDiff))
|
||||
{
|
||||
// Skip Orb smoothing when using (command type 4)
|
||||
for (unsigned int i = 0; i < _orbIds.size(); i++)
|
||||
for (int i = 0; i < _orbIds.size(); i++)
|
||||
{
|
||||
if (_orbIds[i] == idx)
|
||||
{
|
||||
@@ -115,7 +104,7 @@ int LedDeviceAtmoOrb::write(const std::vector <ColorRgb> &ledValues)
|
||||
else
|
||||
{
|
||||
// Send color
|
||||
for (unsigned int i = 0; i < _orbIds.size(); i++)
|
||||
for (int i = 0; i < _orbIds.size(); i++)
|
||||
{
|
||||
if (_orbIds[i] == idx)
|
||||
{
|
||||
|
@@ -5,6 +5,8 @@
|
||||
#include <QString>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QHostAddress>
|
||||
#include <QMap>
|
||||
#include <QVector>
|
||||
|
||||
// Leddevice includes
|
||||
#include <leddevice/LedDevice.h>
|
||||
@@ -101,7 +103,7 @@ private:
|
||||
QUdpSocket * _udpSocket;
|
||||
|
||||
/// Array of the orb ids.
|
||||
std::vector<unsigned int> _orbIds;
|
||||
QVector<unsigned int> _orbIds;
|
||||
|
||||
///
|
||||
/// Set Orbcolor
|
||||
|
@@ -17,14 +17,14 @@ bool LedDeviceDMX::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderRs232::init(deviceConfig);
|
||||
|
||||
std::string _dmxString = deviceConfig["dmxdevice"].toString("invalid").toStdString();
|
||||
if (_dmxString == "raw")
|
||||
QString dmxString = deviceConfig["dmxdevice"].toString("invalid");
|
||||
if (dmxString == "raw")
|
||||
{
|
||||
_dmxDeviceType = 0;
|
||||
_dmxStart = 1;
|
||||
_dmxSlotsPerLed = 3;
|
||||
}
|
||||
else if (_dmxString == "McCrypt")
|
||||
else if (dmxString == "McCrypt")
|
||||
{
|
||||
_dmxDeviceType = 1;
|
||||
_dmxStart = 1;
|
||||
@@ -32,10 +32,10 @@ bool LedDeviceDMX::init(const QJsonObject &deviceConfig)
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(_log, "unknown dmx device type %s", _dmxString.c_str());
|
||||
Error(_log, "unknown dmx device type %s", QSTRING_CSTR(dmxString));
|
||||
}
|
||||
|
||||
Debug(_log, "_dmxString \"%s\", _dmxDeviceType %d", _dmxString.c_str(), _dmxDeviceType );
|
||||
Debug(_log, "_dmxString \"%s\", _dmxDeviceType %d", QSTRING_CSTR(dmxString), _dmxDeviceType );
|
||||
_rs232Port.setStopBits(QSerialPort::TwoStop);
|
||||
|
||||
_dmxLedCount = std::min(_ledCount, 512/_dmxSlotsPerLed);
|
||||
|
@@ -1,7 +1,4 @@
|
||||
// Stl includes
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <map>
|
||||
|
||||
@@ -60,13 +57,12 @@ LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig, const
|
||||
QString ss(config.toJson(QJsonDocument::Indented));
|
||||
Info(log, "configuration: %s ", ss.toUtf8().constData());
|
||||
|
||||
std::string type = deviceConfig["type"].toString("UNSPECIFIED").toStdString();
|
||||
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
||||
QString type = deviceConfig["type"].toString("UNSPECIFIED").toLower();
|
||||
|
||||
// set amount of led to leddevice
|
||||
LedDevice::setLedCount(ledCount);
|
||||
|
||||
#define REGISTER(className) LedDevice::addToDeviceMap(QString(#className).toLower().toStdString(), LedDevice##className::construct);
|
||||
#define REGISTER(className) LedDevice::addToDeviceMap(QString(#className).toLower(), LedDevice##className::construct);
|
||||
// rs232 devices
|
||||
REGISTER(Adalight);
|
||||
REGISTER(Sedu);
|
||||
@@ -126,21 +122,21 @@ LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig, const
|
||||
{
|
||||
device = dev.second(deviceConfig);
|
||||
LedDevice::setActiveDevice(dev.first);
|
||||
Info(log,"LedDevice '%s' configured.", dev.first.c_str());
|
||||
Info(log,"LedDevice '%s' configured.", QSTRING_CSTR(dev.first));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (device == nullptr)
|
||||
{
|
||||
Error(log, "Dummy device used, because configured device '%s' is unknown", type.c_str() );
|
||||
Error(log, "Dummy device used, because configured device '%s' is unknown", QSTRING_CSTR(type) );
|
||||
throw std::runtime_error("unknown device");
|
||||
}
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
|
||||
Error(log, "Dummy device used, because configured device '%s' throws error '%s'", type.c_str(), e.what());
|
||||
Error(log, "Dummy device used, because configured device '%s' throws error '%s'", QSTRING_CSTR(type), e.what());
|
||||
const QJsonObject dummyDeviceConfig;
|
||||
device = LedDeviceFile::construct(QJsonObject());
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ bool LedDeviceFadeCandy::init(const QJsonObject &deviceConfig)
|
||||
return false;
|
||||
}
|
||||
|
||||
_host = deviceConfig["output"].toString("127.0.0.1").toStdString();
|
||||
_host = deviceConfig["output"].toString("127.0.0.1");
|
||||
_port = deviceConfig["port"].toInt(7890);
|
||||
_channel = deviceConfig["channel"].toInt(0);
|
||||
_gamma = deviceConfig["gamma"].toDouble(1.0);
|
||||
@@ -74,10 +74,10 @@ bool LedDeviceFadeCandy::isConnected()
|
||||
bool LedDeviceFadeCandy::tryConnect()
|
||||
{
|
||||
if ( _client.state() == QAbstractSocket::UnconnectedState ) {
|
||||
_client.connectToHost( _host.c_str(), _port);
|
||||
_client.connectToHost( _host, _port);
|
||||
if ( _client.waitForConnected(1000) )
|
||||
{
|
||||
Info(_log,"fadecandy/opc: connected to %s:%i on channel %i", _host.c_str(), _port, _channel);
|
||||
Info(_log,"fadecandy/opc: connected to %s:%i on channel %i", QSTRING_CSTR(_host), _port, _channel);
|
||||
if (_setFcConfig)
|
||||
{
|
||||
sendFadeCandyConfiguration();
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
// STL/Qt includes
|
||||
#include <QTcpSocket>
|
||||
#include <QString>
|
||||
|
||||
// Leddevice includes
|
||||
#include <leddevice/LedDevice.h>
|
||||
@@ -65,7 +66,7 @@ public:
|
||||
|
||||
private:
|
||||
QTcpSocket _client;
|
||||
std::string _host;
|
||||
QString _host;
|
||||
uint16_t _port;
|
||||
unsigned _channel;
|
||||
QByteArray _opc_data;
|
||||
|
@@ -25,8 +25,8 @@ bool LedDeviceFile::init(const QJsonObject &deviceConfig)
|
||||
_refresh_timer_interval = 0;
|
||||
LedDevice::init(deviceConfig);
|
||||
|
||||
std::string fileName = deviceConfig["output"].toString("/dev/null").toStdString();
|
||||
_ofs.open( fileName.c_str() );
|
||||
QString fileName = deviceConfig["output"].toString("/dev/null");
|
||||
_ofs.open( QSTRING_CSTR(fileName) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
// Static constants which define the Hyperion Usbasp device
|
||||
uint16_t LedDeviceHyperionUsbasp::_usbVendorId = 0x16c0;
|
||||
uint16_t LedDeviceHyperionUsbasp::_usbProductId = 0x05dc;
|
||||
std::string LedDeviceHyperionUsbasp::_usbProductDescription = "Hyperion led controller";
|
||||
QString LedDeviceHyperionUsbasp::_usbProductDescription = "Hyperion led controller";
|
||||
|
||||
|
||||
LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(const QJsonObject &deviceConfig)
|
||||
@@ -41,7 +41,7 @@ bool LedDeviceHyperionUsbasp::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
LedDevice::init(deviceConfig);
|
||||
|
||||
std::string ledType = deviceConfig["output"].toString("ws2801").toStdString();
|
||||
QString ledType = deviceConfig["output"].toString("ws2801");
|
||||
if (ledType != "ws2801" && ledType != "ws2812")
|
||||
{
|
||||
throw std::runtime_error("HyperionUsbasp: invalid output; must be 'ws2801' or 'ws2812'.");
|
||||
@@ -94,7 +94,7 @@ int LedDeviceHyperionUsbasp::open()
|
||||
|
||||
if (_deviceHandle == nullptr)
|
||||
{
|
||||
Error(_log, "No %s has been found", _usbProductDescription.c_str());
|
||||
Error(_log, "No %s has been found", QSTRING_CSTR(_usbProductDescription));
|
||||
}
|
||||
|
||||
return _deviceHandle == nullptr ? -1 : 0;
|
||||
@@ -119,18 +119,18 @@ int LedDeviceHyperionUsbasp::testAndOpen(libusb_device * device)
|
||||
int busNumber = libusb_get_bus_number(device);
|
||||
int addressNumber = libusb_get_device_address(device);
|
||||
|
||||
Info(_log, "%s found: bus=%d address=%d", _usbProductDescription.c_str(), busNumber, addressNumber);
|
||||
Info(_log, "%s found: bus=%d address=%d", QSTRING_CSTR(_usbProductDescription), busNumber, addressNumber);
|
||||
|
||||
try
|
||||
{
|
||||
_deviceHandle = openDevice(device);
|
||||
Info(_log, "%s successfully opened", _usbProductDescription.c_str() );
|
||||
Info(_log, "%s successfully opened", QSTRING_CSTR(_usbProductDescription) );
|
||||
return 0;
|
||||
}
|
||||
catch(int e)
|
||||
{
|
||||
_deviceHandle = nullptr;
|
||||
Error(_log, "Unable to open %s. Searching for other device(%d): %s", _usbProductDescription.c_str(), e, libusb_error_name(e));
|
||||
Error(_log, "Unable to open %s. Searching for other device(%d): %s", QSTRING_CSTR(_usbProductDescription), e, libusb_error_name(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ int LedDeviceHyperionUsbasp::write(const std::vector<ColorRgb> &ledValues)
|
||||
// Disabling interupts for a little while on the device results in a PIPE error. All seems to keep functioning though...
|
||||
if(nbytes < 0 && nbytes != LIBUSB_ERROR_PIPE)
|
||||
{
|
||||
Error(_log, "Error while writing data to %s (%s)", _usbProductDescription.c_str(), libusb_error_name(nbytes));
|
||||
Error(_log, "Error while writing data to %s (%s)", QSTRING_CSTR(_usbProductDescription), libusb_error_name(nbytes));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ libusb_device_handle * LedDeviceHyperionUsbasp::openDevice(libusb_device *device
|
||||
return handle;
|
||||
}
|
||||
|
||||
std::string LedDeviceHyperionUsbasp::getString(libusb_device * device, int stringDescriptorIndex)
|
||||
QString LedDeviceHyperionUsbasp::getString(libusb_device * device, int stringDescriptorIndex)
|
||||
{
|
||||
libusb_device_handle * handle = nullptr;
|
||||
|
||||
@@ -214,5 +214,5 @@ std::string LedDeviceHyperionUsbasp::getString(libusb_device * device, int strin
|
||||
}
|
||||
|
||||
libusb_close(handle);
|
||||
return std::string(buffer, error);
|
||||
return QString(QByteArray(buffer, error));
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@
|
||||
// stl includes
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
// libusb include
|
||||
#include <libusb.h>
|
||||
@@ -71,7 +70,7 @@ protected:
|
||||
|
||||
static libusb_device_handle * openDevice(libusb_device * device);
|
||||
|
||||
static std::string getString(libusb_device * device, int stringDescriptorIndex);
|
||||
static QString getString(libusb_device * device, int stringDescriptorIndex);
|
||||
|
||||
/// command to write the leds
|
||||
uint8_t _writeLedsCommand;
|
||||
@@ -85,5 +84,5 @@ protected:
|
||||
/// Usb device identifiers
|
||||
static uint16_t _usbVendorId;
|
||||
static uint16_t _usbProductId;
|
||||
static std::string _usbProductDescription;
|
||||
static QString _usbProductDescription;
|
||||
};
|
||||
|
@@ -32,7 +32,7 @@ enum DATA_VERSION_INDEXES{
|
||||
INDEX_FW_VER_MINOR
|
||||
};
|
||||
|
||||
LedDeviceLightpack::LedDeviceLightpack(const std::string & serialNumber)
|
||||
LedDeviceLightpack::LedDeviceLightpack(const QString & serialNumber)
|
||||
: LedDevice()
|
||||
, _libusbContext(nullptr)
|
||||
, _deviceHandle(nullptr)
|
||||
@@ -72,7 +72,7 @@ LedDeviceLightpack::~LedDeviceLightpack()
|
||||
bool LedDeviceLightpack::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
LedDevice::init(deviceConfig);
|
||||
_serialNumber = deviceConfig["output"].toString("").toStdString();
|
||||
_serialNumber = deviceConfig["output"].toString("");
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -118,20 +118,20 @@ int LedDeviceLightpack::open()
|
||||
|
||||
if (_deviceHandle == nullptr)
|
||||
{
|
||||
if (_serialNumber.empty())
|
||||
if (_serialNumber.isEmpty())
|
||||
{
|
||||
Warning(_log, "No Lightpack device has been found");
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(_log,"No Lightpack device has been found with serial %s", _serialNumber.c_str());
|
||||
Error(_log,"No Lightpack device has been found with serial %s", QSTRING_CSTR(_serialNumber));
|
||||
}
|
||||
}
|
||||
|
||||
return _deviceHandle == nullptr ? -1 : 0;
|
||||
}
|
||||
|
||||
int LedDeviceLightpack::testAndOpen(libusb_device * device, const std::string & requestedSerialNumber)
|
||||
int LedDeviceLightpack::testAndOpen(libusb_device * device, const QString & requestedSerialNumber)
|
||||
{
|
||||
libusb_device_descriptor deviceDescriptor;
|
||||
int error = libusb_get_device_descriptor(device, &deviceDescriptor);
|
||||
@@ -151,7 +151,7 @@ int LedDeviceLightpack::testAndOpen(libusb_device * device, const std::string &
|
||||
int addressNumber = libusb_get_device_address(device);
|
||||
|
||||
// get the serial number
|
||||
std::string serialNumber;
|
||||
QString serialNumber;
|
||||
if (deviceDescriptor.iSerialNumber != 0)
|
||||
{
|
||||
try
|
||||
@@ -165,10 +165,10 @@ int LedDeviceLightpack::testAndOpen(libusb_device * device, const std::string &
|
||||
}
|
||||
}
|
||||
|
||||
Debug(_log,"Lightpack device found: bus=%d address=%d serial=%s", busNumber, addressNumber, serialNumber.c_str());
|
||||
Debug(_log,"Lightpack device found: bus=%d address=%d serial=%s", busNumber, addressNumber, QSTRING_CSTR(serialNumber));
|
||||
|
||||
// check if this is the device we are looking for
|
||||
if (requestedSerialNumber.empty() || requestedSerialNumber == serialNumber)
|
||||
if (requestedSerialNumber.isEmpty() || requestedSerialNumber == serialNumber)
|
||||
{
|
||||
// This is it!
|
||||
try
|
||||
@@ -231,7 +231,7 @@ int LedDeviceLightpack::testAndOpen(libusb_device * device, const std::string &
|
||||
_ledBuffer[0] = CMD_UPDATE_LEDS;
|
||||
|
||||
// return success
|
||||
Debug(_log, "Lightpack device opened: bus=%d address=%d serial=%s version=%s.%s.", _busNumber, _addressNumber, _serialNumber.c_str(), _firmwareVersion.majorVersion, _firmwareVersion.minorVersion );
|
||||
Debug(_log, "Lightpack device opened: bus=%d address=%d serial=%s version=%s.%s.", _busNumber, _addressNumber, QSTRING_CSTR(_serialNumber), _firmwareVersion.majorVersion, _firmwareVersion.minorVersion );
|
||||
return 0;
|
||||
}
|
||||
catch(int e)
|
||||
@@ -279,7 +279,7 @@ int LedDeviceLightpack::switchOff()
|
||||
return writeBytes(buf, sizeof(buf)) == sizeof(buf);
|
||||
}
|
||||
|
||||
const std::string &LedDeviceLightpack::getSerialNumber() const
|
||||
const QString &LedDeviceLightpack::getSerialNumber() const
|
||||
{
|
||||
return _serialNumber;
|
||||
}
|
||||
@@ -352,7 +352,7 @@ libusb_device_handle * LedDeviceLightpack::openDevice(libusb_device *device)
|
||||
return handle;
|
||||
}
|
||||
|
||||
std::string LedDeviceLightpack::getString(libusb_device * device, int stringDescriptorIndex)
|
||||
QString LedDeviceLightpack::getString(libusb_device * device, int stringDescriptorIndex)
|
||||
{
|
||||
libusb_device_handle * handle = nullptr;
|
||||
|
||||
@@ -371,5 +371,5 @@ std::string LedDeviceLightpack::getString(libusb_device * device, int stringDesc
|
||||
}
|
||||
|
||||
libusb_close(handle);
|
||||
return std::string(buffer, error);
|
||||
return QString(QByteArray(buffer, error));
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ public:
|
||||
///
|
||||
/// @param serialNumber serial output device
|
||||
///
|
||||
LedDeviceLightpack(const std::string & serialNumber = "");
|
||||
LedDeviceLightpack(const QString & serialNumber = "");
|
||||
///
|
||||
/// Constructs specific LedDevice
|
||||
///
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
virtual int switchOff();
|
||||
|
||||
/// Get the serial of the Lightpack
|
||||
const std::string & getSerialNumber() const;
|
||||
const QString & getSerialNumber() const;
|
||||
|
||||
/// Get the number of leds
|
||||
int getLedCount() const;
|
||||
@@ -88,7 +88,7 @@ private:
|
||||
///
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
int testAndOpen(libusb_device * device, const std::string & requestedSerialNumber);
|
||||
int testAndOpen(libusb_device * device, const QString & requestedSerialNumber);
|
||||
|
||||
/// write bytes to the device
|
||||
int writeBytes(uint8_t *data, int size);
|
||||
@@ -103,7 +103,7 @@ private:
|
||||
};
|
||||
|
||||
static libusb_device_handle * openDevice(libusb_device * device);
|
||||
static std::string getString(libusb_device * device, int stringDescriptorIndex);
|
||||
static QString getString(libusb_device * device, int stringDescriptorIndex);
|
||||
|
||||
/// libusb context
|
||||
libusb_context * _libusbContext;
|
||||
@@ -118,7 +118,7 @@ private:
|
||||
int _addressNumber;
|
||||
|
||||
/// device serial number
|
||||
std::string _serialNumber;
|
||||
QString _serialNumber;
|
||||
|
||||
/// firmware version of the device
|
||||
Version _firmwareVersion;
|
||||
|
@@ -40,13 +40,13 @@ LedDevice* LedDeviceMultiLightpack::construct(const QJsonObject &deviceConfig)
|
||||
int LedDeviceMultiLightpack::open()
|
||||
{
|
||||
// retrieve a list with Lightpack serials
|
||||
std::list<std::string> serialList = getLightpackSerials();
|
||||
QStringList serialList = getLightpackSerials();
|
||||
|
||||
// sort the list of Lightpacks based on the serial to get a fixed order
|
||||
std::sort(_lightpacks.begin(), _lightpacks.end(), compareLightpacks);
|
||||
|
||||
// open each lightpack device
|
||||
for (const std::string & serial : serialList)
|
||||
foreach (auto serial , serialList)
|
||||
{
|
||||
LedDeviceLightpack * device = new LedDeviceLightpack(serial);
|
||||
int error = device->open();
|
||||
@@ -57,7 +57,7 @@ int LedDeviceMultiLightpack::open()
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(_log, "Error while creating Lightpack device with serial %s", serial.c_str());
|
||||
Error(_log, "Error while creating Lightpack device with serial %s", QSTRING_CSTR(serial));
|
||||
delete device;
|
||||
}
|
||||
}
|
||||
@@ -109,9 +109,9 @@ int LedDeviceMultiLightpack::switchOff()
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::list<std::string> LedDeviceMultiLightpack::getLightpackSerials()
|
||||
QStringList LedDeviceMultiLightpack::getLightpackSerials()
|
||||
{
|
||||
std::list<std::string> serialList;
|
||||
QStringList serialList;
|
||||
Logger * log = Logger::getInstance("LedDevice");
|
||||
Debug(log, "Getting list of Lightpack serials");
|
||||
|
||||
@@ -148,7 +148,7 @@ std::list<std::string> LedDeviceMultiLightpack::getLightpackSerials()
|
||||
Info(log, "Found a lightpack device. Retrieving serial...");
|
||||
|
||||
// get the serial number
|
||||
std::string serialNumber;
|
||||
QString serialNumber;
|
||||
if (deviceDescriptor.iSerialNumber != 0)
|
||||
{
|
||||
try
|
||||
@@ -162,8 +162,8 @@ std::list<std::string> LedDeviceMultiLightpack::getLightpackSerials()
|
||||
}
|
||||
}
|
||||
|
||||
Error(log, "Lightpack device found with serial %s", serialNumber.c_str());;
|
||||
serialList.push_back(serialNumber);
|
||||
Error(log, "Lightpack device found with serial %s", QSTRING_CSTR(serialNumber));;
|
||||
serialList.append(serialNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ std::list<std::string> LedDeviceMultiLightpack::getLightpackSerials()
|
||||
return serialList;
|
||||
}
|
||||
|
||||
std::string LedDeviceMultiLightpack::getString(libusb_device * device, int stringDescriptorIndex)
|
||||
QString LedDeviceMultiLightpack::getString(libusb_device * device, int stringDescriptorIndex)
|
||||
{
|
||||
libusb_device_handle * handle = nullptr;
|
||||
|
||||
@@ -193,5 +193,5 @@ std::string LedDeviceMultiLightpack::getString(libusb_device * device, int strin
|
||||
}
|
||||
|
||||
libusb_close(handle);
|
||||
return std::string(buffer, error);
|
||||
return QString(QByteArray(buffer, error));
|
||||
}
|
||||
|
@@ -3,8 +3,8 @@
|
||||
// stl includes
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <QStringList>
|
||||
#include <QString>
|
||||
|
||||
// libusb include
|
||||
#include <libusb.h>
|
||||
@@ -56,8 +56,8 @@ private:
|
||||
///
|
||||
virtual int write(const std::vector<ColorRgb>& ledValues);
|
||||
|
||||
static std::list<std::string> getLightpackSerials();
|
||||
static std::string getString(libusb_device * device, int stringDescriptorIndex);
|
||||
static QStringList getLightpackSerials();
|
||||
static QString getString(libusb_device * device, int stringDescriptorIndex);
|
||||
|
||||
/// buffer for led data
|
||||
std::vector<LedDeviceLightpack *> _lightpacks;
|
||||
|
@@ -44,7 +44,7 @@ bool LedDevicePiBlaster::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
LedDevice::init(deviceConfig);
|
||||
|
||||
_deviceName = deviceConfig["output"].toString("/dev/pi-blaster").toStdString();
|
||||
QString _deviceName = deviceConfig["output"].toString("/dev/pi-blaster");
|
||||
QJsonArray gpioMapping = deviceConfig["gpiomap"].toArray();
|
||||
|
||||
if (gpioMapping.isEmpty())
|
||||
@@ -82,24 +82,24 @@ int LedDevicePiBlaster::open()
|
||||
if (_fid != nullptr)
|
||||
{
|
||||
// The file pointer is already open
|
||||
Error( _log, "Device (%s) is already open.", _deviceName.c_str() );
|
||||
Error( _log, "Device (%s) is already open.", QSTRING_CSTR(_deviceName) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!QFile::exists(_deviceName.c_str()))
|
||||
if (!QFile::exists(_deviceName))
|
||||
{
|
||||
Error( _log, "The device (%s) does not yet exist.", _deviceName.c_str() );
|
||||
Error( _log, "The device (%s) does not yet exist.",QSTRING_CSTR(_deviceName) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
_fid = fopen(_deviceName.c_str(), "w");
|
||||
_fid = fopen(QSTRING_CSTR(_deviceName), "w");
|
||||
if (_fid == nullptr)
|
||||
{
|
||||
Error( _log, "Failed to open device (%s). Error message: %s", _deviceName.c_str(), strerror(errno) );
|
||||
Error( _log, "Failed to open device (%s). Error message: %s", QSTRING_CSTR(_deviceName), strerror(errno) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
Info( _log, "Connected to device(%s)", _deviceName.c_str());
|
||||
Info( _log, "Connected to device(%s)", QSTRING_CSTR(_deviceName));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -48,7 +48,7 @@ private:
|
||||
int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// The name of the output device (very likely '/dev/pi-blaster')
|
||||
std::string _deviceName;
|
||||
QString _deviceName;
|
||||
|
||||
int _gpio_to_led[64];
|
||||
char _gpio_to_color[64];
|
||||
|
@@ -21,15 +21,15 @@ LedDevice* LedDeviceSk6812SPI::construct(const QJsonObject &deviceConfig)
|
||||
|
||||
bool LedDeviceSk6812SPI::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
std::string whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off").toStdString();
|
||||
QString whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off");
|
||||
_whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm);
|
||||
|
||||
if (_whiteAlgorithm == RGBW::INVALID)
|
||||
{
|
||||
Error(_log, "unknown whiteAlgorithm %s", whiteAlgorithm.c_str());
|
||||
Error(_log, "unknown whiteAlgorithm %s", QSTRING_CSTR(whiteAlgorithm));
|
||||
return false;
|
||||
}
|
||||
Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str());
|
||||
Debug( _log, "whiteAlgorithm : %s", QSTRING_CSTR(whiteAlgorithm));
|
||||
|
||||
_baudRate_Hz = 3000000;
|
||||
if ( !ProviderSpi::init(deviceConfig) )
|
||||
|
@@ -35,9 +35,9 @@ bool LedDeviceTinkerforge::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
LedDevice::init(deviceConfig);
|
||||
|
||||
_host = deviceConfig["output"].toString("127.0.0.1").toStdString();
|
||||
_host = deviceConfig["output"].toString("127.0.0.1");
|
||||
_port = deviceConfig["port"].toInt(4223);
|
||||
_uid = deviceConfig["uid"].toString().toStdString();
|
||||
_uid = deviceConfig["uid"].toString();
|
||||
_interval = deviceConfig["rate"].toInt();
|
||||
|
||||
if ((unsigned)_ledCount > MAX_NUM_LEDS)
|
||||
@@ -75,16 +75,16 @@ int LedDeviceTinkerforge::open()
|
||||
_ipConnection = new IPConnection;
|
||||
ipcon_create(_ipConnection);
|
||||
|
||||
int connectionStatus = ipcon_connect(_ipConnection, _host.c_str(), _port);
|
||||
int connectionStatus = ipcon_connect(_ipConnection, QSTRING_CSTR(_host), _port);
|
||||
if (connectionStatus < 0)
|
||||
{
|
||||
Warning(_log, "Attempt to connect to master brick (%s:%d) failed with status %d", _host.c_str(), _port, connectionStatus);
|
||||
Warning(_log, "Attempt to connect to master brick (%s:%d) failed with status %d", QSTRING_CSTR(_host), _port, connectionStatus);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create the 'LedStrip'
|
||||
_ledStrip = new LEDStrip;
|
||||
led_strip_create(_ledStrip, _uid.c_str(), _ipConnection);
|
||||
led_strip_create(_ledStrip, QSTRING_CSTR(_uid), _ipConnection);
|
||||
|
||||
int frameStatus = led_strip_set_frame_duration(_ledStrip, _interval);
|
||||
if (frameStatus < 0)
|
||||
|
@@ -3,6 +3,8 @@
|
||||
// STL includes
|
||||
#include <cstdio>
|
||||
|
||||
#include <QString>
|
||||
|
||||
// Hyperion-Leddevice includes
|
||||
#include <leddevice/LedDevice.h>
|
||||
|
||||
@@ -56,13 +58,13 @@ private:
|
||||
int transferLedData(LEDStrip *ledstrip, unsigned int index, unsigned int length, uint8_t *redChannel, uint8_t *greenChannel, uint8_t *blueChannel);
|
||||
|
||||
/// The host of the master brick
|
||||
std::string _host;
|
||||
QString _host;
|
||||
|
||||
/// The port of the master brick
|
||||
uint16_t _port;
|
||||
|
||||
/// The uid of the led strip bricklet
|
||||
std::string _uid;
|
||||
QString _uid;
|
||||
|
||||
/// The interval/rate
|
||||
unsigned _interval;
|
||||
|
@@ -16,16 +16,16 @@ bool LedDeviceUdpE131::init(const QJsonObject &deviceConfig)
|
||||
_port = 5568;
|
||||
ProviderUdp::init(deviceConfig);
|
||||
_e131_universe = deviceConfig["universe"].toInt(1);
|
||||
_e131_source_name = deviceConfig["source-name"].toString("hyperion on "+QHostInfo::localHostName()).toStdString();
|
||||
_e131_source_name = deviceConfig["source-name"].toString("hyperion on "+QHostInfo::localHostName());
|
||||
QString _json_cid = deviceConfig["cid"].toString("");
|
||||
|
||||
if (_json_cid.isEmpty())
|
||||
{
|
||||
_e131_cid = QUuid::createUuid();
|
||||
Debug( _log, "e131 no cid found, generated %s", _e131_cid.toString().toStdString().c_str());
|
||||
Debug( _log, "e131 no cid found, generated %s", QSTRING_CSTR(_e131_cid.toString()));
|
||||
} else {
|
||||
_e131_cid = QUuid(_json_cid);
|
||||
Debug( _log, "e131 cid found, using %s", _e131_cid.toString().toStdString().c_str());
|
||||
Debug( _log, "e131 cid found, using %s", QSTRING_CSTR(_e131_cid.toString()));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -53,7 +53,7 @@ void LedDeviceUdpE131::prepare(const unsigned this_universe, const unsigned this
|
||||
/* Frame Layer */
|
||||
e131_packet.frame_flength = htons(0x7000 | (88+this_dmxChannelCount));
|
||||
e131_packet.frame_vector = htonl(VECTOR_E131_DATA_PACKET);
|
||||
snprintf (e131_packet.source_name, sizeof(e131_packet.source_name), "%s", _e131_source_name.c_str() );
|
||||
snprintf (e131_packet.source_name, sizeof(e131_packet.source_name), "%s", QSTRING_CSTR(_e131_source_name) );
|
||||
e131_packet.priority = 100;
|
||||
e131_packet.reserved = htons(0);
|
||||
e131_packet.options = 0; // Bit 7 = Preview_Data
|
||||
|
@@ -133,6 +133,6 @@ private:
|
||||
uint8_t _e131_seq = 0;
|
||||
uint8_t _e131_universe = 1;
|
||||
uint8_t _acn_id[12] = {0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00 };
|
||||
std::string _e131_source_name;
|
||||
QString _e131_source_name;
|
||||
QUuid _e131_cid;
|
||||
};
|
||||
|
@@ -20,12 +20,12 @@ bool LedDeviceWS281x::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
LedDevice::init(deviceConfig);
|
||||
|
||||
std::string whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off").toStdString();
|
||||
QString whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off");
|
||||
_whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm);
|
||||
Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str());
|
||||
Debug( _log, "whiteAlgorithm : %s", QSTRING_CSTR(whiteAlgorithm));
|
||||
if (_whiteAlgorithm == RGBW::INVALID)
|
||||
{
|
||||
Error(_log, "unknown whiteAlgorithm %s", whiteAlgorithm.c_str());
|
||||
Error(_log, "unknown whiteAlgorithm %s", QSTRING_CSTR(whiteAlgorithm));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -35,7 +35,7 @@ bool ProviderSpi::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
LedDevice::init(deviceConfig);
|
||||
|
||||
_deviceName = deviceConfig["output"].toString(QString::fromStdString(_deviceName)).toStdString();
|
||||
_deviceName = deviceConfig["output"].toString(_deviceName);
|
||||
_baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz);
|
||||
_latchTime_ns = deviceConfig["latchtime"].toInt(_latchTime_ns);
|
||||
_spiMode = deviceConfig["spimode"].toInt(_spiMode);
|
||||
@@ -51,11 +51,11 @@ int ProviderSpi::open()
|
||||
|
||||
const int bitsPerWord = 8;
|
||||
|
||||
_fid = ::open(_deviceName.c_str(), O_RDWR);
|
||||
_fid = ::open(QSTRING_CSTR(_deviceName), O_RDWR);
|
||||
|
||||
if (_fid < 0)
|
||||
{
|
||||
Error( _log, "Failed to open device (%s). Error message: %s", _deviceName.c_str(), strerror(errno) );
|
||||
Error( _log, "Failed to open device (%s). Error message: %s", QSTRING_CSTR(_deviceName), strerror(errno) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@@ -49,7 +49,7 @@ protected:
|
||||
int writeBytes(const unsigned size, const uint8_t *data);
|
||||
|
||||
/// The name of the output device
|
||||
std::string _deviceName;
|
||||
QString _deviceName;
|
||||
|
||||
/// The used baudrate of the output device
|
||||
int _baudRate_Hz;
|
||||
|
Reference in New Issue
Block a user