[Linux] Move all device related properties to new class (#135)

* Clean up code

* Move all device releated properties to new class
This commit is contained in:
Tim Gromeyer
2025-06-03 09:07:30 +02:00
committed by GitHub
parent b783b86b7a
commit 8a69dbe173
6 changed files with 314 additions and 223 deletions

View File

@@ -18,22 +18,12 @@ namespace ControlCommand
return packet;
}
// Parse activated/not activated
inline std::optional<bool> parseActive(const QByteArray &data)
inline std::optional<char> parseActive(const QByteArray &data)
{
if (!data.startsWith(ControlCommand::HEADER))
return std::nullopt;
quint8 statusByte = static_cast<quint8>(data.at(7));
switch (statusByte)
{
case 0x01: // Enabled
return true;
case 0x02: // Disabled
return false;
default:
return std::nullopt;
}
return static_cast<quint8>(data.at(7));
}
}
@@ -54,6 +44,19 @@ struct BasicControlCommand
// Basically returns the byte at the index 7
static std::optional<bool> parseState(const QByteArray &data)
{
switch (ControlCommand::parseActive(data).value_or(0x00))
{
case 0x01: // Enabled
return true;
case 0x02: // Disabled
return false;
default:
return std::nullopt;
}
}
static std::optional<char> getValue(const QByteArray &data)
{
return ControlCommand::parseActive(data);
}