Serial LED-Devices - Support device feedback, show statistics provided by HyperSerial
This commit is contained in:
parent
1ac3aa6e86
commit
b149108589
|
@ -119,7 +119,7 @@ void LedDeviceAdalight::prepareHeader()
|
|||
qToBigEndian<quint16>(static_cast<quint16>(totalLedCount), &_ledBuffer[3]);
|
||||
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
||||
|
||||
Debug( _log, "Adalight header for %d leds: %c%c%c 0x%02x 0x%02x 0x%02x", _ledCount,
|
||||
Debug( _log, "Adalight header for %d leds (size: %d): %c%c%c 0x%02x 0x%02x 0x%02x", _ledCount, _ledBuffer.size(),
|
||||
_ledBuffer[0], _ledBuffer[1], _ledBuffer[2], _ledBuffer[3], _ledBuffer[4], _ledBuffer[5] );
|
||||
}
|
||||
|
||||
|
@ -179,6 +179,44 @@ int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
|
|||
return rc;
|
||||
}
|
||||
|
||||
void LedDeviceAdalight::readFeedback()
|
||||
{
|
||||
if (_streamProtocol == Adalight::AWA)
|
||||
{
|
||||
bool continuousLines {true};
|
||||
while ( _rs232Port.canReadLine() )
|
||||
{
|
||||
QByteArray record = _rs232Port.readLine();
|
||||
|
||||
//qDebug() << "\n[" << record << "]";
|
||||
|
||||
|
||||
if (record.startsWith("FPS:"))
|
||||
{
|
||||
if (continuousLines)
|
||||
{
|
||||
continuousLines = false;
|
||||
}
|
||||
Debug(_log, "Statistics %s", record.trimmed().constData());
|
||||
}
|
||||
else if (record.startsWith("ERR:") )
|
||||
{
|
||||
if (continuousLines)
|
||||
{
|
||||
std::cout << std::endl;
|
||||
continuousLines = false;
|
||||
}
|
||||
std::cout << record.trimmed().toStdString() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << record.toStdString() << std::flush;
|
||||
continuousLines = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LedDeviceAdalight::whiteChannelExtension(uint8_t*& writer)
|
||||
{
|
||||
if (_streamProtocol == Adalight::AWA && _white_channel_calibration)
|
||||
|
|
|
@ -37,6 +37,14 @@ public:
|
|||
/// @return LedDevice constructed
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
private slots:
|
||||
|
||||
///
|
||||
/// @brief Handle feedback provided by the device
|
||||
/// Allows to show statistics and error for the "Awa" protocol, if configured in the ESP-sketch
|
||||
///
|
||||
void readFeedback() override;
|
||||
|
||||
private:
|
||||
|
||||
///
|
||||
|
|
|
@ -86,6 +86,8 @@ int ProviderRs232::open()
|
|||
// open device physically
|
||||
if ( tryOpen(_delayAfterConnect_ms) )
|
||||
{
|
||||
connect(&_rs232Port, &QSerialPort::readyRead, this, &ProviderRs232::readFeedback);
|
||||
|
||||
// Everything is OK, device is ready
|
||||
_isDeviceReady = true;
|
||||
retval = 0;
|
||||
|
@ -106,6 +108,9 @@ int ProviderRs232::close()
|
|||
{
|
||||
Debug(_log,"Flush was successful");
|
||||
}
|
||||
|
||||
disconnect(&_rs232Port, &QSerialPort::readyRead, this, &ProviderRs232::readFeedback);
|
||||
|
||||
Debug(_log,"Close UART: %s", QSTRING_CSTR(_deviceName) );
|
||||
_rs232Port.close();
|
||||
// Everything is OK -> device is closed
|
||||
|
@ -261,6 +266,23 @@ int ProviderRs232::writeBytes(const qint64 size, const uint8_t *data)
|
|||
return rc;
|
||||
}
|
||||
|
||||
void ProviderRs232::readFeedback()
|
||||
{
|
||||
QByteArray readData = _rs232Port.readAll();
|
||||
if (!readData.isEmpty())
|
||||
{
|
||||
//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
|
||||
}
|
||||
}
|
||||
|
||||
QString ProviderRs232::discoverFirst()
|
||||
{
|
||||
// take first available USB serial port - currently no probing!
|
||||
|
|
|
@ -123,6 +123,11 @@ protected slots:
|
|||
///
|
||||
void setInError( const QString& errorMsg) override;
|
||||
|
||||
///
|
||||
/// @brief Handle any feedback provided by the device
|
||||
///
|
||||
virtual void readFeedback();
|
||||
|
||||
private:
|
||||
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue