Skip to content

Commit

Permalink
Properly handle padded input report data on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Dec 2, 2024
1 parent 6d85f48 commit f94596f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 0 additions & 1 deletion soup/HidReportDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ NAMESPACE_SOUP
++pUsageId;
}
}
br.finishByte(); // It seems like in the case of a "Hat Switch", the high nibble is unused.
continue;
}
else if (f.size == 16 && f.logical_max != 0)
Expand Down
19 changes: 19 additions & 0 deletions soup/hwHid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ NAMESPACE_SOUP
return a.bit_index < b.bit_index;
});

uint32_t bit_index = 8;
for (uint32_t i = 0; i != pp_data->header.input_item_count; ++i)
{
//std::cout << "report_id: " << (int)pp_data->items[i].report_id << std::endl;
Expand All @@ -765,6 +766,22 @@ NAMESPACE_SOUP
result.report_ids.emplace(pp_data->items[i].report_id);
}

const uint32_t this_item_bit_index = (pp_data->items[i].byte_index * 8) + pp_data->items[i].bit_index;
if (this_item_bit_index > bit_index)
{
const auto pad_bits = this_item_bit_index - bit_index;
//std::cout << "inserting " << pad_bits << " bits of padding" << std::endl;
result.input_report_fields.emplace_back(HidReportDescriptor::ReportField{
1,
pad_bits,
0,
false,
0,
{}
});
bit_index = this_item_bit_index;
}

std::vector<uint16_t> usage_ids{};
for (uint32_t usage = pp_data->items[i].usage_minimum; usage != (pp_data->items[i].usage_maximum + 1); ++usage)
{
Expand All @@ -778,6 +795,8 @@ NAMESPACE_SOUP
pp_data->items[i].usage_page,
std::move(usage_ids)
});

bit_index += pp_data->items[i].bit_size * pp_data->items[i].report_count;
}

HidD_FreePreparsedData(_pp_data);
Expand Down

0 comments on commit f94596f

Please sign in to comment.