Skip to content

Commit 43a48ec

Browse files
committed
Input: zforce_ts - make parsing of contacts less confusing
Zforce touch data packet consists of a byte representing number of contacts followed by several chunks with length of 9 bytes representing each contact. Instead of accounting for the leading byte by increasing offset of each field in contacts by one introduce a pointer to contact data and point it appropriately. This avoids awkward constructs like: point.prblty = payload[9 * i + 9]; which makes it seem like there is off-by-one error, in favor of more straightforward: point.prblty = p[8]; Tested-by: Andreas Kemnade <[email protected]> # Tolino Shine2HD Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 83b6549 commit 43a48ec

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

drivers/input/touchscreen/zforce_ts.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ static int zforce_touch_event(struct zforce_ts *ts, u8 *payload)
318318
struct i2c_client *client = ts->client;
319319
struct zforce_point point;
320320
int count, i, num = 0;
321+
u8 *p;
321322

322323
count = payload[0];
323324
if (count > ZFORCE_REPORT_POINTS) {
@@ -328,8 +329,10 @@ static int zforce_touch_event(struct zforce_ts *ts, u8 *payload)
328329
}
329330

330331
for (i = 0; i < count; i++) {
331-
point.coord_x = get_unaligned_le16(&payload[9 * i + 1]);
332-
point.coord_y = get_unaligned_le16(&payload[9 * i + 3]);
332+
p = &payload[i * 9 + 1];
333+
334+
point.coord_x = get_unaligned_le16(&p[0]);
335+
point.coord_y = get_unaligned_le16(&p[2]);
333336

334337
if (point.coord_x > ts->prop.max_x ||
335338
point.coord_y > ts->prop.max_y) {
@@ -338,18 +341,16 @@ static int zforce_touch_event(struct zforce_ts *ts, u8 *payload)
338341
point.coord_x = point.coord_y = 0;
339342
}
340343

341-
point.state = payload[9 * i + 5] & 0x0f;
342-
point.id = (payload[9 * i + 5] & 0xf0) >> 4;
344+
point.state = p[4] & 0x0f;
345+
point.id = (p[4] & 0xf0) >> 4;
343346

344347
/* determine touch major, minor and orientation */
345-
point.area_major = max(payload[9 * i + 6],
346-
payload[9 * i + 7]);
347-
point.area_minor = min(payload[9 * i + 6],
348-
payload[9 * i + 7]);
349-
point.orientation = payload[9 * i + 6] > payload[9 * i + 7];
350-
351-
point.pressure = payload[9 * i + 8];
352-
point.prblty = payload[9 * i + 9];
348+
point.area_major = max(p[5], p[6]);
349+
point.area_minor = min(p[5], p[6]);
350+
point.orientation = p[5] > p[6];
351+
352+
point.pressure = p[7];
353+
point.prblty = p[8];
353354

354355
dev_dbg(&client->dev,
355356
"point %d/%d: state %d, id %d, pressure %d, prblty %d, x %d, y %d, amajor %d, aminor %d, ori %d\n",

0 commit comments

Comments
 (0)