Files
0417_QT_code/LOGIC/Lgc_Core.h
2026-03-26 10:45:29 +08:00

86 lines
3.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include "DRI/Dri_Consumer.h"
#include "DRI/Dri_NkroRaw.h"
#include "DRI/Dri_Vendor.h"
#include "LOGIC/Lgc_Consumer.h"
#include "LOGIC/Lgc_Func_Button.h"
#include "LOGIC/Lgc_Nkro.h"
#include "LOGIC/Lgc_Vendor.h"
#include <QtCore/QByteArray>
/*
* Lgc_Core贯穿 UI / LOGIC / DRI 的单一状态容器。
* 高密注释使得学生在不翻源码的情况下即可看懂所有成员职责。
*/
struct Lgc_Core_Struct_State
{
/* DRI 端口:分别承接 RAW NKRO / Consumer / Vendor 通道 */
Dri_NkroRaw_Struct_Port DriNkroPort;
Dri_Consumer_Struct_Port DriConsumerPort;
Dri_Vendor_Struct_Port DriVendorPort;
/* 设备与 UI 文本状态 */
Mid_Struct_DeviceConfig DeviceConfig;
QString TextConnection;
QString TextLog;
QString TextFunctionStatus;
/* 可视化按键UI 模型(来自解析 NKRO/Consumer 结果) */
bool IsVisibleKeyStateValid = false;
quint8 VisibleModifier = 0;
QVector<quint16> VisibleUsageList;
/* 物理按键:直接来自硬件,供 Swap/功能逻辑判断 */
bool IsPhysicalKeyStateValid = false;
quint8 PhysicalModifier = 0;
QVector<quint16> PhysicalUsageList;
QVector<quint16> LastPhysicalUsageList;
/* 键盘模式控制NumLock、功能掩码、Swap 掩码等 */
bool IsSystemNumLockOn = false;
QByteArray FunctionMaskBitmap;
QByteArray SwapMaskBitmap;
QByteArray KeyboardMaskBitmap;
/* 功能键配置及 Swap 对应的运行期状态 */
Lgc_Func_Button_Struct_Config FunctionButtonConfig;
bool IsSwapModeOn = false;
quint16 SwapUsageLeft = 0;
quint16 SwapUsageRight = 0;
bool IsSwapLeftPhysicalPressed = false;
bool IsSwapRightPhysicalPressed = false;
/* 互操作:窗口句柄与核心运行状态 */
void* WindowHandle = nullptr;
bool IsConnected = false;
bool IsStarted = false;
};
/* 初始化核心:清空状态并准备 DRI 端口。 */
void Lgc_Core_Func_Init(Lgc_Core_Struct_State* p_State);
/* 告诉 LGC 使用哪个 HWND 接收 RAWINPUT。 */
void Lgc_Core_Func_SetWindowHandle(Lgc_Core_Struct_State* p_State, void* WindowHandle);
/* 每个 Windows 消息都交给核心处理。 */
void Lgc_Core_Func_HandleNativeMessage(Lgc_Core_Struct_State* p_State, void* p_Message);
/* 启动:打开设备、刷新按键状态并进入轮询。 */
void Lgc_Core_Func_Start(Lgc_Core_Struct_State* p_State);
/* 关闭:释放 DRI 端口与所有资源。 */
void Lgc_Core_Func_Close(Lgc_Core_Struct_State* p_State);
/* 当 VID/PID 变化或用户点击刷新时调用。 */
void Lgc_Core_Func_RefreshDevice(Lgc_Core_Struct_State* p_State);
/* 清空 LOG 文本UI 立即同步。 */
void Lgc_Core_Func_ClearLog(Lgc_Core_Struct_State* p_State);
/* 轮询 DRI 队列,返回“是否发生变化”以供 UI 决定是否刷新。 */
bool Lgc_Core_Func_Poll(Lgc_Core_Struct_State* p_State);
/* 设置单个 Usage 是否是“功能模式” */
bool Lgc_Core_Func_SetUsageFunctionMode(Lgc_Core_Struct_State* p_State, quint16 Usage, bool IsEnabled);
/* 打开/关闭 Swap 模式,并指定左右 Usage */
bool Lgc_Core_Func_SetSwapMode(
Lgc_Core_Struct_State* p_State,
quint16 UsageLeft,
quint16 UsageRight,
bool IsEnabled);
/* 查询给定 Usage 当前是否处于功能模式 */
bool Lgc_Core_Func_IsUsageFunctionMode(const Lgc_Core_Struct_State* p_State, quint16 Usage);