Skip to content

Commit

Permalink
Process non-array inputs before array inputs
Browse files Browse the repository at this point in the history
Some keyboards have the same usage as both non-array and array inputs
in their report descriptor (and only use one or the other to send
those usages).

By reading the non-array ones first we get the right result regardless
of which they actually use.
  • Loading branch information
jfedor2 committed Jan 9, 2024
1 parent 24dc49f commit 0a2ec45
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion firmware/src/remapper.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
Expand Down Expand Up @@ -50,7 +51,7 @@ std::vector<reverse_mapping_t> reverse_mapping_layers;
std::unordered_map<uint8_t, std::unordered_map<uint32_t, usage_def_t>> our_usages; // report_id -> usage -> usage_def
std::unordered_map<uint32_t, usage_def_t> our_usages_flat;

std::unordered_map<uint16_t, std::unordered_map<uint8_t, std::vector<usage_usage_def_t>>> their_used_usages; // dev_addr+interface -> report_id -> (usage, usage_def)
std::unordered_map<uint16_t, std::unordered_map<uint8_t, std::vector<usage_usage_def_t>>> their_used_usages; // dev_addr+interface -> report_id -> (usage, usage_def) vector
std::unordered_map<uint16_t, std::unordered_map<uint8_t, std::vector<int32_t*>>> array_range_usages; // dev_addr+interface -> report_id -> input_state ptr vector
std::unordered_map<uint16_t, std::unordered_map<uint8_t, std::vector<usage_def_t>>> rollover_usages; // dev_addr+interface -> report_id -> usage_def vector

Expand Down Expand Up @@ -1452,6 +1453,17 @@ void update_their_descriptor_derivates() {
}
}
}

// Some keyboards have the same usage as both non-array and array inputs.
// By reading the non-array ones first we get the right result regardless of which they actually use.
for (auto& [interface, report_id_usages_map] : their_used_usages) {
for (auto& [report_id, usages_vector] : report_id_usages_map) {
std::sort(usages_vector.begin(), usages_vector.end(),
[](const usage_usage_def_t& a, const usage_usage_def_t& b) {
return (a.usage_def.is_array < b.usage_def.is_array);
});
}
}
}

void parse_our_descriptor() {
Expand Down

0 comments on commit 0a2ec45

Please sign in to comment.