Skip to content

Commit

Permalink
[ADAPTER] Fix HID abs_min/abs_max, calc the same way for sign and uns…
Browse files Browse the repository at this point in the history
…ign axis
  • Loading branch information
darthcloud committed Dec 29, 2024
1 parent 186141d commit 6e06026
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions main/adapter/wireless/hid_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,29 +369,25 @@ static void hid_pad_init(struct hid_report_meta *meta, struct hid_report *report
meta->hid_axes_idx[AXIS_LX] = i;
if (report->usages[i].logical_min >= 0) {
map->meta[AXIS_LX].neutral = report->usages[i].logical_max / 2;
map->meta[AXIS_LX].abs_max = report->usages[i].logical_max - map->meta[AXIS_LX].neutral;
map->meta[AXIS_LX].abs_min = map->meta[AXIS_LX].neutral - report->usages[i].logical_min;
}
else {
map->meta[AXIS_LX].neutral = 0;
map->meta[AXIS_LX].abs_max = report->usages[i].logical_max;
map->meta[AXIS_LX].abs_min = report->usages[i].logical_min;
}
map->meta[AXIS_LX].abs_max = report->usages[i].logical_max - map->meta[AXIS_LX].neutral;
map->meta[AXIS_LX].abs_min = map->meta[AXIS_LX].neutral - report->usages[i].logical_min;
break;
case USAGE_GEN_DESKTOP_Y:
map->mask[0] |= BIT(PAD_LY_DOWN) | BIT(PAD_LY_UP);
map->desc[0] |= BIT(PAD_LY_DOWN) | BIT(PAD_LY_UP);
meta->hid_axes_idx[AXIS_LY] = i;
if (report->usages[i].logical_min >= 0) {
map->meta[AXIS_LY].neutral = report->usages[i].logical_max / 2;
map->meta[AXIS_LY].abs_max = report->usages[i].logical_max - map->meta[AXIS_LY].neutral;
map->meta[AXIS_LY].abs_min = map->meta[AXIS_LY].neutral - report->usages[i].logical_min;
}
else {
map->meta[AXIS_LY].neutral = 0;
map->meta[AXIS_LY].abs_max = report->usages[i].logical_max;
map->meta[AXIS_LY].abs_min = report->usages[i].logical_min;
}
map->meta[AXIS_LY].abs_max = report->usages[i].logical_max - map->meta[AXIS_LY].neutral;
map->meta[AXIS_LY].abs_min = map->meta[AXIS_LY].neutral - report->usages[i].logical_min;
map->meta[AXIS_LY].polarity = 1;
break;
case 0x32 /* USAGE_GEN_DESKTOP_Z */:
Expand All @@ -401,14 +397,12 @@ static void hid_pad_init(struct hid_report_meta *meta, struct hid_report *report
meta->hid_axes_idx[AXIS_RX] = i;
if (report->usages[i].logical_min >= 0) {
map->meta[AXIS_RX].neutral = report->usages[i].logical_max / 2;
map->meta[AXIS_RX].abs_max = report->usages[i].logical_max - map->meta[AXIS_RX].neutral;
map->meta[AXIS_RX].abs_min = map->meta[AXIS_RX].neutral - report->usages[i].logical_min;
}
else {
map->meta[AXIS_RX].neutral = 0;
map->meta[AXIS_RX].abs_max = report->usages[i].logical_max;
map->meta[AXIS_RX].abs_min = report->usages[i].logical_min;
}
map->meta[AXIS_RX].abs_max = report->usages[i].logical_max - map->meta[AXIS_RX].neutral;
map->meta[AXIS_RX].abs_min = map->meta[AXIS_RX].neutral - report->usages[i].logical_min;
}
else {
map->mask[0] |= BIT(PAD_LM);
Expand All @@ -434,14 +428,12 @@ static void hid_pad_init(struct hid_report_meta *meta, struct hid_report *report
meta->hid_axes_idx[AXIS_RX] = i;
if (report->usages[i].logical_min >= 0) {
map->meta[AXIS_RX].neutral = report->usages[i].logical_max / 2;
map->meta[AXIS_RX].abs_max = report->usages[i].logical_max - map->meta[AXIS_RX].neutral;
map->meta[AXIS_RX].abs_min = map->meta[AXIS_RX].neutral - report->usages[i].logical_min;
}
else {
map->meta[AXIS_RX].neutral = 0;
map->meta[AXIS_RX].abs_max = report->usages[i].logical_max;
map->meta[AXIS_RX].abs_min = report->usages[i].logical_min;
}
map->meta[AXIS_RX].abs_max = report->usages[i].logical_max - map->meta[AXIS_RX].neutral;
map->meta[AXIS_RX].abs_min = map->meta[AXIS_RX].neutral - report->usages[i].logical_min;
}
break;
case 0x34 /* USAGE_GEN_DESKTOP_RY */:
Expand All @@ -459,14 +451,12 @@ static void hid_pad_init(struct hid_report_meta *meta, struct hid_report *report
meta->hid_axes_idx[AXIS_RY] = i;
if (report->usages[i].logical_min >= 0) {
map->meta[AXIS_RY].neutral = report->usages[i].logical_max / 2;
map->meta[AXIS_RY].abs_max = report->usages[i].logical_max - map->meta[AXIS_RY].neutral;
map->meta[AXIS_RY].abs_min = map->meta[AXIS_RY].neutral - report->usages[i].logical_min;
}
else {
map->meta[AXIS_RY].neutral = 0;
map->meta[AXIS_RY].abs_max = report->usages[i].logical_max;
map->meta[AXIS_RY].abs_min = report->usages[i].logical_min;
}
map->meta[AXIS_RY].abs_max = report->usages[i].logical_max - map->meta[AXIS_RY].neutral;
map->meta[AXIS_RY].abs_min = map->meta[AXIS_RY].neutral - report->usages[i].logical_min;
map->meta[AXIS_RY].polarity = 1;
}
break;
Expand All @@ -477,14 +467,12 @@ static void hid_pad_init(struct hid_report_meta *meta, struct hid_report *report
meta->hid_axes_idx[AXIS_RY] = i;
if (report->usages[i].logical_min >= 0) {
map->meta[AXIS_RY].neutral = report->usages[i].logical_max / 2;
map->meta[AXIS_RY].abs_max = report->usages[i].logical_max - map->meta[AXIS_RY].neutral;
map->meta[AXIS_RY].abs_min = map->meta[AXIS_RY].neutral - report->usages[i].logical_min;
}
else {
map->meta[AXIS_RY].neutral = 0;
map->meta[AXIS_RY].abs_max = report->usages[i].logical_max;
map->meta[AXIS_RY].abs_min = report->usages[i].logical_min;
}
map->meta[AXIS_RY].abs_max = report->usages[i].logical_max - map->meta[AXIS_RY].neutral;
map->meta[AXIS_RY].abs_min = map->meta[AXIS_RY].neutral - report->usages[i].logical_min;
map->meta[AXIS_RY].polarity = 1;
}
else {
Expand Down

0 comments on commit 6e06026

Please sign in to comment.