Skip to content

Commit 15893fa

Browse files
skomraJiri Kosina
authored andcommitted
HID: wacom: generic: read the number of expected touches on a per collection basis
Bluetooth connections may contain more than one set of touches, or a partial set of touches, in one report. Set the number of expected touches when reading a collection instead of once per report (in the pre-report function). Accordingly, reset the number of touches expected after each sync. Signed-off-by: Aaron Armstrong Skomra <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent f4e11d5 commit 15893fa

File tree

1 file changed

+63
-16
lines changed

1 file changed

+63
-16
lines changed

drivers/hid/wacom_wac.c

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,25 +2563,9 @@ static void wacom_wac_finger_pre_report(struct hid_device *hdev,
25632563
case HID_DG_TIPSWITCH:
25642564
hid_data->last_slot_field = equivalent_usage;
25652565
break;
2566-
case HID_DG_CONTACTCOUNT:
2567-
hid_data->cc_report = report->id;
2568-
hid_data->cc_index = i;
2569-
hid_data->cc_value_index = j;
2570-
break;
25712566
}
25722567
}
25732568
}
2574-
2575-
if (hid_data->cc_report != 0 &&
2576-
hid_data->cc_index >= 0) {
2577-
struct hid_field *field = report->field[hid_data->cc_index];
2578-
int value = field->value[hid_data->cc_value_index];
2579-
if (value)
2580-
hid_data->num_expected = value;
2581-
}
2582-
else {
2583-
hid_data->num_expected = wacom_wac->features.touch_max;
2584-
}
25852569
}
25862570

25872571
static void wacom_wac_finger_report(struct hid_device *hdev,
@@ -2591,6 +2575,7 @@ static void wacom_wac_finger_report(struct hid_device *hdev,
25912575
struct wacom_wac *wacom_wac = &wacom->wacom_wac;
25922576
struct input_dev *input = wacom_wac->touch_input;
25932577
unsigned touch_max = wacom_wac->features.touch_max;
2578+
struct hid_data *hid_data = &wacom_wac->hid_data;
25942579

25952580
/* If more packets of data are expected, give us a chance to
25962581
* process them rather than immediately syncing a partial
@@ -2604,6 +2589,7 @@ static void wacom_wac_finger_report(struct hid_device *hdev,
26042589

26052590
input_sync(input);
26062591
wacom_wac->hid_data.num_received = 0;
2592+
hid_data->num_expected = 0;
26072593

26082594
/* keep touch state for pen event */
26092595
wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
@@ -2678,12 +2664,73 @@ static void wacom_report_events(struct hid_device *hdev,
26782664
}
26792665
}
26802666

2667+
static void wacom_set_num_expected(struct hid_device *hdev,
2668+
struct hid_report *report,
2669+
int collection_index,
2670+
struct hid_field *field,
2671+
int field_index)
2672+
{
2673+
struct wacom *wacom = hid_get_drvdata(hdev);
2674+
struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2675+
struct hid_data *hid_data = &wacom_wac->hid_data;
2676+
unsigned int original_collection_level =
2677+
hdev->collection[collection_index].level;
2678+
bool end_collection = false;
2679+
int i;
2680+
2681+
if (hid_data->num_expected)
2682+
return;
2683+
2684+
// find the contact count value for this segment
2685+
for (i = field_index; i < report->maxfield && !end_collection; i++) {
2686+
struct hid_field *field = report->field[i];
2687+
unsigned int field_level =
2688+
hdev->collection[field->usage[0].collection_index].level;
2689+
unsigned int j;
2690+
2691+
if (field_level != original_collection_level)
2692+
continue;
2693+
2694+
for (j = 0; j < field->maxusage; j++) {
2695+
struct hid_usage *usage = &field->usage[j];
2696+
2697+
if (usage->collection_index != collection_index) {
2698+
end_collection = true;
2699+
break;
2700+
}
2701+
if (wacom_equivalent_usage(usage->hid) == HID_DG_CONTACTCOUNT) {
2702+
hid_data->cc_report = report->id;
2703+
hid_data->cc_index = i;
2704+
hid_data->cc_value_index = j;
2705+
2706+
if (hid_data->cc_report != 0 &&
2707+
hid_data->cc_index >= 0) {
2708+
2709+
struct hid_field *field =
2710+
report->field[hid_data->cc_index];
2711+
int value =
2712+
field->value[hid_data->cc_value_index];
2713+
2714+
if (value)
2715+
hid_data->num_expected = value;
2716+
}
2717+
}
2718+
}
2719+
}
2720+
2721+
if (hid_data->cc_report == 0 || hid_data->cc_index < 0)
2722+
hid_data->num_expected = wacom_wac->features.touch_max;
2723+
}
2724+
26812725
static int wacom_wac_collection(struct hid_device *hdev, struct hid_report *report,
26822726
int collection_index, struct hid_field *field,
26832727
int field_index)
26842728
{
26852729
struct wacom *wacom = hid_get_drvdata(hdev);
26862730

2731+
if (WACOM_FINGER_FIELD(field))
2732+
wacom_set_num_expected(hdev, report, collection_index, field,
2733+
field_index);
26872734
wacom_report_events(hdev, report, collection_index, field_index);
26882735

26892736
/*

0 commit comments

Comments
 (0)