71 lines
2.3 KiB
C++
71 lines
2.3 KiB
C++
|
|
#include "LOGIC/Lgc_Nkro.h"
|
||
|
|
|
||
|
|
void Lgc_Nkro_Func_Parse(const QByteArray& ByteArray, Lgc_Nkro_Struct_Result* p_Result)
|
||
|
|
{
|
||
|
|
// 当前调用链内部固定传有效结果对象,这里直接回到默认状态。
|
||
|
|
*p_Result = Lgc_Nkro_Struct_Result();
|
||
|
|
|
||
|
|
// 没有新包时直接返回提示。
|
||
|
|
if (ByteArray.isEmpty())
|
||
|
|
{
|
||
|
|
p_Result->TextExplain = QStringLiteral("NKRO 端口没有收到数据。");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 先校验 report id。
|
||
|
|
if (static_cast<quint8>(ByteArray.at(0)) != Mid_Enum_ReportId_Nkro)
|
||
|
|
{
|
||
|
|
p_Result->TextExplain = QStringLiteral("这不是 report id 0x01。");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
p_Result->IsMatch = true;
|
||
|
|
|
||
|
|
// 当前固件里的 0x01 包固定长度是 31 字节。
|
||
|
|
if (ByteArray.size() != MID_CONST_PACKET_SIZE_NKRO)
|
||
|
|
{
|
||
|
|
p_Result->TextExplain = QStringLiteral("0x01 包长度不对。");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
p_Result->IsLengthOk = true;
|
||
|
|
|
||
|
|
// 第 1 字节是 modifier。
|
||
|
|
p_Result->Modifier = static_cast<quint8>(ByteArray.at(1));
|
||
|
|
|
||
|
|
// 后面 29 字节是 usage 位图。
|
||
|
|
p_Result->UsageBitmap = ByteArray.mid(2, MID_CONST_USAGE_BITMAP_SIZE);
|
||
|
|
|
||
|
|
// 逐 bit 扫描位图,得到所有按下的 HID usage。
|
||
|
|
for (quint16 Usage = 0; Usage <= MID_CONST_KEYBOARD_USAGE_MAX; ++Usage)
|
||
|
|
{
|
||
|
|
const int ByteIndex = Usage / 8;
|
||
|
|
const int BitIndex = Usage % 8;
|
||
|
|
const quint8 Value = static_cast<quint8>(p_Result->UsageBitmap.at(ByteIndex));
|
||
|
|
|
||
|
|
if ((Value & static_cast<quint8>(1U << BitIndex)) == 0)
|
||
|
|
{
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
p_Result->UsageList.append(Usage);
|
||
|
|
p_Result->UsageTextList.append(Mid_Func_GetKeyboardUsageText(Usage));
|
||
|
|
}
|
||
|
|
|
||
|
|
// 这里整理的是适合调试窗口直接阅读的教学化文本。
|
||
|
|
QStringList ExplainList;
|
||
|
|
ExplainList.append(QStringLiteral("0x01 NKRO 可见键盘态"));
|
||
|
|
ExplainList.append(QStringLiteral("修饰键:%1").arg(Mid_Func_GetModifierText(p_Result->Modifier)));
|
||
|
|
|
||
|
|
if (p_Result->UsageTextList.isEmpty())
|
||
|
|
{
|
||
|
|
ExplainList.append(QStringLiteral("按下:无"));
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ExplainList.append(QStringLiteral("按下:%1").arg(p_Result->UsageTextList.join(QStringLiteral(", "))));
|
||
|
|
}
|
||
|
|
|
||
|
|
p_Result->TextExplain = ExplainList.join(QLatin1Char('\n'));
|
||
|
|
}
|