添加项目文件。
This commit is contained in:
71
LOGIC/Lgc_Vendor.cpp
Normal file
71
LOGIC/Lgc_Vendor.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "LOGIC/Lgc_Vendor.h"
|
||||
|
||||
void Lgc_Vendor_Func_Parse(const QByteArray& ByteArray, Lgc_Vendor_Struct_Result* p_Result)
|
||||
{
|
||||
// 当前调用链内部固定传有效结果对象,这里直接回到默认状态。
|
||||
*p_Result = Lgc_Vendor_Struct_Result();
|
||||
|
||||
// 没有包时直接返回提示。
|
||||
if (ByteArray.isEmpty())
|
||||
{
|
||||
p_Result->TextExplain = QStringLiteral("Vendor 端口没有收到数据。");
|
||||
return;
|
||||
}
|
||||
|
||||
// 第 0 字节不是 0x04,就不是当前要解析的 Vendor 镜像包。
|
||||
if (static_cast<quint8>(ByteArray.at(0)) != Mid_Enum_ReportId_Vendor)
|
||||
{
|
||||
p_Result->TextExplain = QStringLiteral("这不是 report id 0x04。");
|
||||
return;
|
||||
}
|
||||
|
||||
p_Result->IsMatch = true;
|
||||
|
||||
// 当前固件里的 0x04 固定长度也是 31 字节。
|
||||
if (ByteArray.size() != MID_CONST_PACKET_SIZE_VENDOR)
|
||||
{
|
||||
p_Result->TextExplain = QStringLiteral("0x04 包长度不对。");
|
||||
return;
|
||||
}
|
||||
|
||||
p_Result->IsLengthOk = true;
|
||||
p_Result->VendorState.IsValid = true;
|
||||
|
||||
// 第 1 字节是物理 modifier。
|
||||
p_Result->VendorState.Modifier = static_cast<quint8>(ByteArray.at(1));
|
||||
|
||||
// 第 2~30 字节是物理 usage 位图。
|
||||
p_Result->VendorState.UsageBitmap = ByteArray.mid(2, MID_CONST_USAGE_BITMAP_SIZE);
|
||||
|
||||
// 展开位图,得到当前物理按下的 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->VendorState.UsageBitmap.at(ByteIndex));
|
||||
|
||||
if ((Value & static_cast<quint8>(1U << BitIndex)) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
p_Result->VendorState.UsageList.append(Usage);
|
||||
p_Result->VendorState.UsageTextList.append(Mid_Func_GetKeyboardUsageText(Usage));
|
||||
}
|
||||
|
||||
// 这里整理的是面向教学和调试窗口的中文解释。
|
||||
QStringList ExplainList;
|
||||
ExplainList.append(QStringLiteral("0x04 Vendor 物理镜像态"));
|
||||
ExplainList.append(QStringLiteral("物理修饰键:%1").arg(Mid_Func_GetModifierText(p_Result->VendorState.Modifier)));
|
||||
|
||||
if (p_Result->VendorState.UsageTextList.isEmpty())
|
||||
{
|
||||
ExplainList.append(QStringLiteral("物理按下:无"));
|
||||
}
|
||||
else
|
||||
{
|
||||
ExplainList.append(QStringLiteral("物理按下:%1").arg(p_Result->VendorState.UsageTextList.join(QStringLiteral(", "))));
|
||||
}
|
||||
|
||||
p_Result->TextExplain = ExplainList.join(QLatin1Char('\n'));
|
||||
}
|
||||
Reference in New Issue
Block a user