Skip to content

Commit

Permalink
Fix HyperX Cloud Alpha (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteLoopGameDev authored Sep 21, 2023
1 parent bd8aed3 commit 5515590
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/devices/hyperx_calphaw.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ void calphaw_init(struct device** device)
*device = &device_calphaw;
}

int calphaw_request_connection(hid_device* device_handle)
{
int r = 0;
// request charge info
uint8_t data_request[31] = { 0x21, 0xbb, 0x03 };

r = hid_write(device_handle, data_request, sizeof(data_request) / sizeof(data_request[0]));
if (r < 0)
return r;

uint8_t data_read[31];
r = hid_read_timeout(device_handle, data_read, 20, TIMEOUT);
if (r < 0)
return r;
if (r == 0) // timeout
return HSC_ERROR;

if (r == 0xf || r == 0x14) {
return data_read[3];
}

return HSC_ERROR;
}

int calphaw_request_charge(hid_device* device_handle)
{
int r = 0;
Expand Down Expand Up @@ -78,6 +102,9 @@ int calphaw_request_charge(hid_device* device_handle)

static int calphaw_request_battery(hid_device* device_handle)
{
if (calphaw_request_connection(device_handle) == 1)
return BATTERY_UNAVAILABLE;

if (calphaw_request_charge(device_handle) == 1)
return BATTERY_CHARGING;

Expand Down Expand Up @@ -157,4 +184,4 @@ static int calphaw_switch_voice_prompts(hid_device* device_handle, uint8_t on)

return hid_write(device_handle, data_request, sizeof(data_request) / sizeof(data_request[0]));
;
}
}

0 comments on commit 5515590

Please sign in to comment.