Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FrameworkArgb/Device.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ Return Value:
deviceContext->CrosEcHandle = INVALID_HANDLE_VALUE;
status = ConnectToEc(&deviceContext->CrosEcHandle);
if (!NT_SUCCESS(status)) {
TraceError("COMBO %!FUNC! ConnectToEc failed %!STATUS!", status);
return status;
TraceError("%!FUNC! ConnectToEc failed %!STATUS!", status);
// Don't fail here, if the EC driver is not available when this driver loads, connect to it later on-demand
}

status = QueueCreate(device,
Expand Down
23 changes: 17 additions & 6 deletions FrameworkArgb/EcCommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@
NTSTATUS ConnectToEc(
_Inout_ HANDLE* Handle
) {
NTSTATUS Status = STATUS_SUCCESS;
if (Handle == NULL) {
TraceError("%!FUNC! Handle pointer is NULL");
return STATUS_INVALID_PARAMETER;
}

if (*Handle != INVALID_HANDLE_VALUE) {
// Already connected
TraceError("%!FUNC! Already connected");
return STATUS_SUCCESS;
}

*Handle = CreateFileW(
LR"(\\.\GLOBALROOT\Device\CrosEC)",
Expand All @@ -33,13 +42,15 @@ NTSTATUS ConnectToEc(
NULL);

if (*Handle == INVALID_HANDLE_VALUE) {
TraceError("%!FUNC! CreateFileW failed %!STATUS!", Status);
TraceError("%!FUNC! CreateFileW failed");
return STATUS_INVALID_HANDLE;
}

return Status;
TraceInformation("%!FUNC! Got Handle");
return STATUS_SUCCESS;
}


int CrosEcSendCommand(
HANDLE Handle,
UINT16 command,
Expand All @@ -54,7 +65,7 @@ int CrosEcSendCommand(
DWORD retb{};
CROSEC_COMMAND cmd{};

if (Handle == NULL || Handle == INVALID_HANDLE_VALUE) {
if (Handle == INVALID_HANDLE_VALUE) {
Status = STATUS_INVALID_HANDLE;
TraceError("%!FUNC! Invalid Handle");
return 0;
Expand Down Expand Up @@ -104,7 +115,7 @@ int CrosEcSendCommand(
TraceError("%!FUNC! inlen is %d. But indata is NULL", inlen);
return 0;
}
RtlCopyMemory(cmd.data, indata, inlen);
RtlCopyMemory(indata, cmd.data, inlen);
}

return cmd.inlen;
Expand All @@ -117,7 +128,7 @@ int CrosEcReadMemU8(HANDLE Handle, unsigned int offset, UINT8* dest)
DWORD retb{};
CROSEC_READMEM rm{};

if (Handle == NULL || Handle == INVALID_HANDLE_VALUE) {
if (Handle == INVALID_HANDLE_VALUE) {
Status = STATUS_INVALID_HANDLE;
TraceError("%!FUNC! Invalid Handle");
return 0;
Expand Down
28 changes: 22 additions & 6 deletions FrameworkArgb/LampArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,21 @@ Module Name:
#include "LampArray.h"
#include "EcCommunication.h"

void CrosEcSetColorRange(HANDLE Handle, UINT16 LampIdStart, UINT16 LampIdEnd, LampColor *Color)
void CrosEcSetColorRange(
PDEVICE_CONTEXT DeviceContext,
UINT16 LampIdStart,
UINT16 LampIdEnd,
LampColor *Color)
{
EC_REQUEST_RGB_KBD_SET_COLOR cmd{};

// Connect on demand, if haven't connected yet
if (DeviceContext->CrosEcHandle == INVALID_HANDLE_VALUE) {
if (!NT_SUCCESS(ConnectToEc(&DeviceContext->CrosEcHandle))) {
return;
}
}

cmd.StartKey = (UINT8) LampIdStart;
cmd.Length = (UINT8) (LampIdEnd - LampIdStart) + 1;
for (UINT8 i = 0; i < cmd.Length; i++) {
Expand All @@ -38,7 +50,7 @@ void CrosEcSetColorRange(HANDLE Handle, UINT16 LampIdStart, UINT16 LampIdEnd, La
}

CrosEcSendCommand(
Handle,
DeviceContext->CrosEcHandle,
EC_CMD_RGBKBD_SET_COLOR,
0,
&cmd,
Expand All @@ -48,9 +60,13 @@ void CrosEcSetColorRange(HANDLE Handle, UINT16 LampIdStart, UINT16 LampIdEnd, La
);
}

void CrosEcSetColor(HANDLE Handle, UINT16 LampId, LampColor *Color)
void CrosEcSetColor(
PDEVICE_CONTEXT DeviceContext,
UINT16 LampId,
LampColor *Color
)
{
CrosEcSetColorRange(Handle, LampId, LampId, Color);
CrosEcSetColorRange(DeviceContext, LampId, LampId, Color);
}

ULONG
Expand Down Expand Up @@ -143,7 +159,7 @@ void SetMultipleLamps(
report->colors[i].blue,
report->colors[i].intensity
);
CrosEcSetColor(DeviceContext->CrosEcHandle, report->lampIds[i], &report->colors[i]);
CrosEcSetColor(DeviceContext, report->lampIds[i], &report->colors[i]);
}
}

Expand All @@ -161,7 +177,7 @@ void SetLampRange(
report->color.blue,
report->color.intensity
);
CrosEcSetColorRange(DeviceContext->CrosEcHandle, report->lampIdStart, report->lampIdEnd, &report->color);
CrosEcSetColorRange(DeviceContext, report->lampIdStart, report->lampIdEnd, &report->color);
}

void SetAutonomousMode(
Expand Down