128 lines
3.8 KiB
C++
128 lines
3.8 KiB
C++
|
|
#include "LOGIC/Lgc_Core_Private.h"
|
|||
|
|
|
|||
|
|
#include <Windows.h>
|
|||
|
|
|
|||
|
|
void Lgc_Core_Init(Lgc_Core_Struct_State* p_State)
|
|||
|
|
{
|
|||
|
|
*p_State = Lgc_Core_Struct_State();
|
|||
|
|
|
|||
|
|
p_State->DeviceConfig = Mid_Struct_DeviceConfig();
|
|||
|
|
p_State->TextConnection = QStringLiteral("未连接,等待枚举设备。");
|
|||
|
|
p_State->TextFunctionStatus = QStringLiteral("等待功能键动作。");
|
|||
|
|
|
|||
|
|
Lgc_Core_ClearAllKeyStates(p_State);
|
|||
|
|
|
|||
|
|
p_State->IsSystemNumLockOn = (GetKeyState(VK_NUMLOCK) & 0x0001) != 0;
|
|||
|
|
Lgc_Core_FillMaskAllEnabled(&p_State->FunctionMaskBitmap);
|
|||
|
|
Lgc_Core_FillMaskAllEnabled(&p_State->KeyboardMaskBitmap);
|
|||
|
|
|
|||
|
|
p_State->FunctionButtonConfig = Lgc_FunctionButton_Config();
|
|||
|
|
Lgc_Core_ApplyFunctionConfig(p_State);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Lgc_Core_SetWindowHandle(Lgc_Core_Struct_State* p_State, void* WindowHandle)
|
|||
|
|
{
|
|||
|
|
p_State->WindowHandle = WindowHandle;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Lgc_Core_HandleNativeMessage(Lgc_Core_Struct_State* p_State, void* p_Message)
|
|||
|
|
{
|
|||
|
|
QString TextStatus;
|
|||
|
|
Dri_NkroRaw_HandleMessage(&p_State->DriNkroPort, p_Message, &TextStatus);
|
|||
|
|
Lgc_Core_AppendStatusLog(p_State, TextStatus);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Lgc_Core_Start(Lgc_Core_Struct_State* p_State)
|
|||
|
|
{
|
|||
|
|
if (p_State->IsStarted)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
p_State->IsStarted = true;
|
|||
|
|
Lgc_Core_RefreshDevice(p_State);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Lgc_Core_Close(Lgc_Core_Struct_State* p_State)
|
|||
|
|
{
|
|||
|
|
Lgc_Core_CloseAllPorts(p_State);
|
|||
|
|
|
|||
|
|
p_State->TextConnection = QStringLiteral("未连接,等待枚举设备。");
|
|||
|
|
p_State->TextFunctionStatus = QStringLiteral("等待功能键动作。");
|
|||
|
|
p_State->ActiveSendTransport = Lgc_Core_Enum_SendTransport_None;
|
|||
|
|
p_State->IsConnected = false;
|
|||
|
|
p_State->IsStarted = false;
|
|||
|
|
|
|||
|
|
Lgc_Core_ClearAllKeyStates(p_State);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Lgc_Core_RefreshDevice(Lgc_Core_Struct_State* p_State)
|
|||
|
|
{
|
|||
|
|
QString TextStatus;
|
|||
|
|
|
|||
|
|
Lgc_Core_CloseAllPorts(p_State);
|
|||
|
|
Lgc_Core_ClearAllKeyStates(p_State);
|
|||
|
|
|
|||
|
|
TextStatus.clear();
|
|||
|
|
Dri_NkroRaw_Init(&p_State->DriNkroPort, p_State->DeviceConfig, p_State->WindowHandle, &TextStatus);
|
|||
|
|
Lgc_Core_AppendStatusLog(p_State, TextStatus);
|
|||
|
|
|
|||
|
|
TextStatus.clear();
|
|||
|
|
Dri_Consumer_Init(&p_State->DriConsumerPort, p_State->DeviceConfig, &TextStatus);
|
|||
|
|
Lgc_Core_AppendStatusLog(p_State, TextStatus);
|
|||
|
|
|
|||
|
|
TextStatus.clear();
|
|||
|
|
Dri_Vendor_Init(&p_State->DriVendorPort, p_State->DeviceConfig, &TextStatus);
|
|||
|
|
Lgc_Core_AppendStatusLog(p_State, TextStatus);
|
|||
|
|
|
|||
|
|
TextStatus.clear();
|
|||
|
|
Dri_Ble_Init(&p_State->DriBlePort, p_State->DeviceConfig, &TextStatus);
|
|||
|
|
Lgc_Core_AppendStatusLog(p_State, TextStatus);
|
|||
|
|
|
|||
|
|
Lgc_Core_NormalizeSendTransport(p_State);
|
|||
|
|
Lgc_Core_SendCurrentMask(p_State);
|
|||
|
|
|
|||
|
|
if (p_State->DriVendorPort.ReadPort.IsOpened)
|
|||
|
|
{
|
|||
|
|
Lgc_Core_SendTimeSync(p_State);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Lgc_Core_SyncSystemState(p_State);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Lgc_Core_ClearLog(Lgc_Core_Struct_State* p_State)
|
|||
|
|
{
|
|||
|
|
p_State->TextLog.clear();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool Lgc_Core_Poll(Lgc_Core_Struct_State* p_State)
|
|||
|
|
{
|
|||
|
|
bool IsChanged = false;
|
|||
|
|
Mid_Struct_RawPacket Packet;
|
|||
|
|
const auto PollPort = [&](auto ReadFunc, auto HandleFunc, auto* p_Port)
|
|||
|
|
{
|
|||
|
|
QString TextStatus;
|
|||
|
|
if (ReadFunc(p_Port, &Packet, &TextStatus))
|
|||
|
|
{
|
|||
|
|
HandleFunc(p_State, Packet);
|
|||
|
|
IsChanged = true;
|
|||
|
|
}
|
|||
|
|
if (!TextStatus.isEmpty())
|
|||
|
|
{
|
|||
|
|
Lgc_Core_AppendStatusLog(p_State, TextStatus);
|
|||
|
|
IsChanged = true;
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
PollPort(Dri_NkroRaw_Read, Lgc_Core_HandleNkroPacket, &p_State->DriNkroPort);
|
|||
|
|
PollPort(Dri_Consumer_Read, Lgc_Core_HandleConsumerPacket, &p_State->DriConsumerPort);
|
|||
|
|
PollPort(Dri_Vendor_Read, Lgc_Core_HandleVendorPacket, &p_State->DriVendorPort);
|
|||
|
|
PollPort(Dri_Ble_Read, Lgc_Core_HandleBlePacket, &p_State->DriBlePort);
|
|||
|
|
|
|||
|
|
IsChanged |= Lgc_Core_HandleFunctionButtons(p_State);
|
|||
|
|
IsChanged |= Lgc_Core_SyncSystemState(p_State);
|
|||
|
|
return IsChanged;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|