Skip to content

Commit

Permalink
Return only up-to-date module properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
kareltucek committed Feb 11, 2025
1 parent d1996b7 commit 5de39d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 10 additions & 1 deletion right/src/usb_commands/usb_command_get_device_property.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void UsbCommand_GetDeviceProperty(const uint8_t *GenericHidOutBuffer, uint8_t *G
checksum = ModuleMD5Checksums[moduleId];
} else {
SetUsbTxBufferUint8(0, UsbStatusCode_GetDeviceProperty_InvalidArgument);
return;
}
break;
case DEVICE_ID_UHK80_LEFT:
Expand All @@ -100,8 +101,16 @@ void UsbCommand_GetDeviceProperty(const uint8_t *GenericHidOutBuffer, uint8_t *G
case ModuleId_Dongle:
checksum = DeviceMD5Checksums[DeviceId_Uhk_Dongle];
break;
case ModuleId_TouchpadRight:
// return empty buffer
return;
default:
checksum = ModuleMD5Checksums[moduleId];
if (moduleId < ModuleId_ModuleCount) {
checksum = ModuleMD5Checksums[moduleId];
} else {
SetUsbTxBufferUint8(0, UsbStatusCode_GetDeviceProperty_InvalidArgument);
return;
}
break;
}
break;
Expand Down
11 changes: 7 additions & 4 deletions right/src/usb_commands/usb_command_get_module_property.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,37 @@ void UsbCommand_GetModuleProperty(const uint8_t *GenericHidOutBuffer, uint8_t *G
{
slot_t slotId = GetUsbRxBufferUint8(1);

uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId);

if (!IS_VALID_MODULE_SLOT(slotId)) {
SetUsbTxBufferUint8(0, UsbStatusCode_GetModuleProperty_InvalidModuleSlotId);
}

if (!ModuleConnectionStates[moduleDriverId].moduleId || ModuleConnectionStates[moduleDriverId].moduleId == ModuleId_TouchpadRight) {
// return empty buffer
return;
}

module_property_id_t modulePropertyId = GetUsbRxBufferUint8(2);
switch (modulePropertyId) {
case ModulePropertyId_VersionNumbers: {
uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId);
uhk_module_state_t *moduleState = UhkModuleStates + moduleDriverId;
GenericHidInBuffer[1] = moduleState->moduleId;
memcpy(GenericHidInBuffer + 2, &moduleState->moduleProtocolVersion, sizeof(version_t));
memcpy(GenericHidInBuffer + 8, &moduleState->firmwareVersion, sizeof(version_t));
break;
}
case ModulePropertyId_GitTag: {
uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId);
uhk_module_state_t *moduleState = UhkModuleStates + moduleDriverId;
Utils_SafeStrCopy(((char*)GenericHidInBuffer) + 1, moduleState->gitTag, USB_GENERIC_HID_IN_BUFFER_LENGTH - 1);
break;
}
case ModulePropertyId_GitRepo: {
uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId);
uhk_module_state_t *moduleState = UhkModuleStates + moduleDriverId;
Utils_SafeStrCopy(((char*)GenericHidInBuffer) + 1, moduleState->gitRepo, USB_GENERIC_HID_IN_BUFFER_LENGTH - 1);
break;
}
case ModulePropertyId_RemoteFirmwareChecksumBySlotId: {
uint8_t moduleDriverId = UhkModuleSlaveDriver_SlotIdToDriverId(slotId);
uhk_module_state_t *moduleState = UhkModuleStates + moduleDriverId;
Utils_SafeStrCopy(((char*)GenericHidInBuffer) + 1, moduleState->firmwareChecksum, MD5_CHECKSUM_LENGTH + 1);
break;
Expand Down

0 comments on commit 5de39d3

Please sign in to comment.