hid: correctly parse consecutive usages
1 parent 4c01ce9 commit 484424cdd9d84417afc94520d2a5e60fab846890
@biosfood biosfood authored on 10 Aug 2023
Showing 2 changed files
View
2
■■■
src/userland/hid/hid.h
typedef struct {
uint32_t padding;
uint32_t currentUsagePage, reportSize, reportCount;
uint32_t totalBits;
uint32_t usageMinimum, usageMaximum;
uint32_t usageMin, usageMax;
uint32_t logicalMin, logicalMax;
ListElement *usages;
} ReportParserState;
 
View
15
src/userland/hid/main.c
// data is constant, no need to keep track of it
for (uint32_t i = 0; i < state->reportCount; i++) {
insertInputReader(state, i, data, inputReaders);
}
} else if (state->currentUsagePage == 0x09) {
printf("%p New input parser has BUTTON usage for all entries\n", state->padding);
// TODO: research exact implementation for this
for (uint32_t i = 0; i < state->reportCount; i++) {
printf("%p Interpreting report %i as button %i\n", state->padding, i, i + 1);
insertInputReader(state, i, data, inputReaders);
}
} else if (usageCount == 1) {
uint8_t currentUsage = U32(listGet(state->usages, 0));
printf("%p New input parser has usage %s for all entries\n",
state->padding,
usage(state->currentUsagePage, U32(currentUsage))
);
insertInputReader(state, U32(currentUsage), data, inputReaders);
});
} else if (usageCount == 0 && (state->usageMax - state->usageMin + 1 == state->reportCount)) {
for (uint32_t currentUsage = state->usageMin; currentUsage <= state->usageMax; currentUsage++) {
insertInputReader(state, currentUsage, data, inputReaders);
}
} else {
printf("%p Input parser cannot deduce the usage of the reports, having %i reports and %i usages\n",
state->padding,
state->reportCount,
state.logicalMax = data;
break;
case 0x06:
printf("%pUsageMinimum(%x)\n", state.padding, data);
state.usageMinimum = data;
state.usageMin = data;
break;
case 0x0A:
printf("%pUsageMaximum(%x)\n", state.padding, data);
state.usageMaximum = data;
state.usageMax = data;
break;
case 0x1D:
printf("%pReportSize(%x)\n", state.padding, data);
state.reportSize = data;