mirror of
https://github.com/nymea/nymea-plugins.git
synced 2026-08-02 03:07:33 +02:00
fixed string splitting
This commit is contained in:
parent
53c9759439
commit
94dbfdbd57
@ -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,52 +335,64 @@ 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('-');
|
||||||
mode.remove(0, 1);
|
if(list.length() >= 2) {
|
||||||
mode.remove("\r\n");
|
QString mode = list.at(1);
|
||||||
qDebug(dcWs2812fx()) << "set mode to:" << mode;
|
mode.remove(0, 1);
|
||||||
device->setStateValue(ws2812fxEffectModeStateTypeId, mode);
|
mode.remove("\r\n");
|
||||||
|
qDebug(dcWs2812fx()) << "set mode to:" << 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(':');
|
||||||
rawBrightness.remove(" ");
|
if(list.length() >= 2) {
|
||||||
rawBrightness.remove("\r\n");
|
QString rawBrightness = list.at(1);;
|
||||||
int brightness = rawBrightness.toInt();
|
rawBrightness.remove(" ");
|
||||||
|
rawBrightness.remove("\r\n");
|
||||||
|
int brightness = rawBrightness.toInt();
|
||||||
|
|
||||||
qDebug(dcWs2812fx()) << "set brightness to:" << brightness;
|
qDebug(dcWs2812fx()) << "set brightness to:" << brightness;
|
||||||
device->setStateValue(ws2812fxBrightnessStateTypeId, brightness);
|
device->setStateValue(ws2812fxBrightnessStateTypeId, brightness);
|
||||||
if (brightness == 0) {
|
if (brightness == 0) {
|
||||||
device->setStateValue(ws2812fxPowerStateTypeId, false);
|
device->setStateValue(ws2812fxPowerStateTypeId, false);
|
||||||
} else {
|
} else {
|
||||||
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(':');
|
||||||
rawSpeed.remove(" ");
|
if(list.length() >= 2) {
|
||||||
rawSpeed.remove("\r\n");
|
QString rawSpeed = list.at(1);
|
||||||
int speed = data.split(':').at(1).toInt();
|
rawSpeed.remove(" ");
|
||||||
|
rawSpeed.remove("\r\n");
|
||||||
|
int speed = data.split(':').at(1).toInt();
|
||||||
|
|
||||||
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(':');
|
||||||
rawColor.remove(" ");
|
if(list.length() >= 2) {
|
||||||
rawColor.remove("0x");
|
QString rawColor = list.at(1);
|
||||||
rawColor.remove("\r\n");
|
rawColor.remove(" ");
|
||||||
rawColor.prepend("#");
|
rawColor.remove("0x");
|
||||||
qDebug(dcWs2812fx()) << "set color to:" << rawColor;
|
rawColor.remove("\r\n");
|
||||||
device->setStateValue(ws2812fxColorStateTypeId, rawColor);
|
rawColor.prepend("#");
|
||||||
|
qDebug(dcWs2812fx()) << "set color to:" << rawColor;
|
||||||
|
device->setStateValue(ws2812fxColorStateTypeId, rawColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user