mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-01-31 23:29:10 +00:00
[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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user