refactor: Modernize Qt connections (#914)

This commit is contained in:
Murat Seker
2020-08-02 22:32:00 +02:00
committed by GitHub
parent d1a2b77ce3
commit 031b9a6b7c
22 changed files with 86 additions and 77 deletions

View File

@@ -245,7 +245,7 @@ int LedDevice::writeBlack(int numberOfBlack)
{
// Wait latch time before writing black
QEventLoop loop;
QTimer::singleShot( _latchTime_ms, &loop, SLOT( quit() ) );
QTimer::singleShot(_latchTime_ms, &loop, &QEventLoop::quit);
loop.exec();
}
rc = write(std::vector<ColorRgb>(static_cast<unsigned long>(_ledCount), ColorRgb::BLACK ));

View File

@@ -128,7 +128,7 @@ httpResponse ProviderRestApi::get(const QUrl &url)
QNetworkReply* reply = _networkManager->get(request);
// Connect requestFinished signal to quit slot of the loop.
QEventLoop loop;
loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
loop.connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
// Go into the loop until the request is finished.
loop.exec();
@@ -156,7 +156,7 @@ httpResponse ProviderRestApi::put(const QUrl &url, const QString &body)
QNetworkReply* reply = _networkManager->put(request, body.toUtf8());
// Connect requestFinished signal to quit slot of the loop.
QEventLoop loop;
loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
loop.connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
// Go into the loop until the request is finished.
loop.exec();

View File

@@ -17,8 +17,6 @@ LedDevicePiBlaster::LedDevicePiBlaster(const QJsonObject &deviceConfig)
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
signal(SIGPIPE, SIG_IGN);
// initialise the mapping tables
// -1 is invalid
// z is also meaningless

View File

@@ -1,5 +1,7 @@
#include "LedDeviceAdalight.h"
#include <cassert>
LedDeviceAdalight::LedDeviceAdalight(const QJsonObject &deviceConfig)
: ProviderRs232()
, _headerSize(6)
@@ -78,7 +80,9 @@ int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
}
else
{
memcpy(_headerSize + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
assert(_headerSize + ledValues.size() * sizeof(ColorRgb) <= _ledBuffer.size());
memcpy(_headerSize + _ledBuffer.data(), ledValues.data(), ledValues.size() * sizeof(ColorRgb));
}
int rc = writeBytes(_ledBuffer.size(), _ledBuffer.data());

View File

@@ -44,7 +44,7 @@ private:
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> & ledValues) override;
const short _headerSize;
bool _ligthBerryAPA102Mode;
};

View File

@@ -50,7 +50,6 @@ int LedDeviceKarate::write(const std::vector<ColorRgb> &ledValues)
{
for (signed iLed=0; iLed< static_cast<int>(_ledCount); iLed++)
{
const ColorRgb& rgb = ledValues[iLed];
_ledBuffer[iLed*3+4] = rgb.green;
_ledBuffer[iLed*3+5] = rgb.blue;

View File

@@ -12,8 +12,7 @@
// Constants
constexpr std::chrono::milliseconds WRITE_TIMEOUT{1000}; // device write timeout in ms
constexpr std::chrono::milliseconds OPEN_TIMEOUT{5000}; // device open timeout in ms
const int MAX_WRITE_TIMEOUTS = 5; // maximum number of allowed timeouts
const int MAX_WRITE_TIMEOUTS = 5; // Maximum number of allowed timeouts
const int NUM_POWEROFF_WRITE_BLACK = 2; // Number of write "BLACK" during powering off
ProviderRs232::ProviderRs232()
@@ -43,9 +42,9 @@ bool ProviderRs232::init(const QJsonObject &deviceConfig)
// If device name was given as unix /dev/ system-location, get port name
if ( _deviceName.startsWith(QLatin1String("/dev/")) )
_deviceName = _deviceName.mid(5);
_deviceName = _deviceName.mid(5);
_isAutoDeviceName = _deviceName.toLower() == "auto";
_isAutoDeviceName = _deviceName.toLower() == "auto";
_baudRate_Hz = deviceConfig["rate"].toInt();
_delayAfterConnect_ms = deviceConfig["delayAfterConnect"].toInt(1500);
@@ -174,7 +173,7 @@ bool ProviderRs232::tryOpen(const int delayAfterConnect_ms)
// Wait delayAfterConnect_ms before allowing write
QEventLoop loop;
QTimer::singleShot( delayAfterConnect_ms, &loop, SLOT( quit() ) );
QTimer::singleShot(delayAfterConnect_ms, &loop, &QEventLoop::quit);
loop.exec();
Debug(_log, "delayAfterConnect for %d ms - finished", delayAfterConnect_ms);