fixed string splitting

This commit is contained in:
nymea 2019-09-21 09:24:52 +02:00
parent 53c9759439
commit 94dbfdbd57

View File

@ -321,6 +321,7 @@ void DevicePluginWs2812fx::deviceRemoved(Device *device)
void DevicePluginWs2812fx::onReadyRead() void DevicePluginWs2812fx::onReadyRead()
{ {
QSerialPort *serialPort = static_cast<QSerialPort*>(sender()); QSerialPort *serialPort = static_cast<QSerialPort*>(sender());
Device *device = m_serialPorts.key(serialPort); Device *device = m_serialPorts.key(serialPort);
if (!device) if (!device)
return; return;
@ -334,17 +335,22 @@ void DevicePluginWs2812fx::onReadyRead()
if (m_pendingActions.contains(CommandType::Mode)) { if (m_pendingActions.contains(CommandType::Mode)) {
emit actionExecutionFinished(m_pendingActions.value(CommandType::Mode), Device::DeviceErrorNoError); emit actionExecutionFinished(m_pendingActions.value(CommandType::Mode), Device::DeviceErrorNoError);
} }
QString mode = data.split('-').at(1); QByteArrayList list = data.split('-');
if(list.length() >= 2) {
QString mode = list.at(1);
mode.remove(0, 1); mode.remove(0, 1);
mode.remove("\r\n"); mode.remove("\r\n");
qDebug(dcWs2812fx()) << "set mode to:" << mode; qDebug(dcWs2812fx()) << "set mode to:" << mode;
device->setStateValue(ws2812fxEffectModeStateTypeId, mode); device->setStateValue(ws2812fxEffectModeStateTypeId, mode);
} }
}
if (data.contains("brightness")) { if (data.contains("brightness")) {
if (m_pendingActions.contains(CommandType::Brightness)) { if (m_pendingActions.contains(CommandType::Brightness)) {
emit actionExecutionFinished(m_pendingActions.value(CommandType::Brightness), Device::DeviceErrorNoError); emit actionExecutionFinished(m_pendingActions.value(CommandType::Brightness), Device::DeviceErrorNoError);
} }
QString rawBrightness = data.split(':').at(1); QByteArrayList list = data.split(':');
if(list.length() >= 2) {
QString rawBrightness = list.at(1);;
rawBrightness.remove(" "); rawBrightness.remove(" ");
rawBrightness.remove("\r\n"); rawBrightness.remove("\r\n");
int brightness = rawBrightness.toInt(); int brightness = rawBrightness.toInt();
@ -357,11 +363,14 @@ void DevicePluginWs2812fx::onReadyRead()
device->setStateValue(ws2812fxPowerStateTypeId, true); device->setStateValue(ws2812fxPowerStateTypeId, true);
} }
} }
}
if (data.contains("speed")) { if (data.contains("speed")) {
if (m_pendingActions.contains(CommandType::Speed)) { if (m_pendingActions.contains(CommandType::Speed)) {
emit actionExecutionFinished(m_pendingActions.value(CommandType::Speed), Device::DeviceErrorNoError); emit actionExecutionFinished(m_pendingActions.value(CommandType::Speed), Device::DeviceErrorNoError);
} }
QString rawSpeed = data.split(':').at(1); QByteArrayList list = data.split(':');
if(list.length() >= 2) {
QString rawSpeed = list.at(1);
rawSpeed.remove(" "); rawSpeed.remove(" ");
rawSpeed.remove("\r\n"); rawSpeed.remove("\r\n");
int speed = data.split(':').at(1).toInt(); int speed = data.split(':').at(1).toInt();
@ -369,11 +378,14 @@ void DevicePluginWs2812fx::onReadyRead()
qDebug(dcWs2812fx()) << "set speed to:" << speed; qDebug(dcWs2812fx()) << "set speed to:" << speed;
device->setStateValue(ws2812fxSpeedStateTypeId, speed); device->setStateValue(ws2812fxSpeedStateTypeId, speed);
} }
}
if (data.contains("color")) { if (data.contains("color")) {
if (m_pendingActions.contains(CommandType::Color)) { if (m_pendingActions.contains(CommandType::Color)) {
emit actionExecutionFinished(m_pendingActions.value(CommandType::Color), Device::DeviceErrorNoError); emit actionExecutionFinished(m_pendingActions.value(CommandType::Color), Device::DeviceErrorNoError);
} }
QString rawColor = data.split(':').at(1); QByteArrayList list = data.split(':');
if(list.length() >= 2) {
QString rawColor = list.at(1);
rawColor.remove(" "); rawColor.remove(" ");
rawColor.remove("0x"); rawColor.remove("0x");
rawColor.remove("\r\n"); rawColor.remove("\r\n");
@ -383,6 +395,7 @@ void DevicePluginWs2812fx::onReadyRead()
} }
} }
} }
}
void DevicePluginWs2812fx::onReconnectTimer() void DevicePluginWs2812fx::onReconnectTimer()
{ {