From f08d5e7c09879889797ebf0eb2de562dac111737 Mon Sep 17 00:00:00 2001 From: Daniel Kao Date: Sun, 3 Jul 2022 18:27:55 -0700 Subject: [PATCH] pointing device gestures: div0 checks --- drivers/sensors/cirque_pinnacle_gestures.c | 10 ++++++++-- quantum/pointing_device_gestures.c | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/sensors/cirque_pinnacle_gestures.c b/drivers/sensors/cirque_pinnacle_gestures.c index b1042079df34..7182fa2b97af 100644 --- a/drivers/sensors/cirque_pinnacle_gestures.c +++ b/drivers/sensors/cirque_pinnacle_gestures.c @@ -83,12 +83,18 @@ static circular_scroll_t circular_scroll(pinnacle_data_t touchData) { int8_t x, y, wheel_clicks; uint8_t center = 256 / 2, mag; int16_t ang, dot, det, opposite_side, adjacent_side; + uint16_t scale = cirque_pinnacle_get_scale(); if (touchData.zValue) { // place origin at center of trackpad, treat coordinates as vectors // scale to fixed int8_t size, angles are independent of resolution - x = (int8_t)((int32_t)touchData.xValue * 256 / cirque_pinnacle_get_scale() - center); - y = (int8_t)((int32_t)touchData.yValue * 256 / cirque_pinnacle_get_scale() - center); + if (scale) { + x = (int8_t)((int32_t)touchData.xValue * 256 / scale - center); + y = (int8_t)((int32_t)touchData.yValue * 256 / scale - center); + } else { + x = 0; + y = 0; + } // check if first touch if (!scroll.z) { diff --git a/quantum/pointing_device_gestures.c b/quantum/pointing_device_gestures.c index 7f0eecced929..78ed63b57523 100644 --- a/quantum/pointing_device_gestures.c +++ b/quantum/pointing_device_gestures.c @@ -26,6 +26,15 @@ static cursor_glide_t cursor_glide(cursor_glide_context_t* glide) { int32_t p; int32_t x, y; + if (glide->v0 == 0) { + report.dx = 0; + report.dy = 0; + report.valid = false; + glide->dx0 = 0; + glide->dy0 = 0; + goto exit; + } + glide->counter++; // calculate current 1D position p = glide->v0 * glide->counter - (int32_t)glide->coef * glide->counter * glide->counter / 2; @@ -44,6 +53,7 @@ static cursor_glide_t cursor_glide(cursor_glide_context_t* glide) { glide->y = y; glide->timer = timer_read(); +exit: return report; }