Skip to content

Commit

Permalink
Merge branch 'asymmetric-scroll-amount-443' into kaoriya
Browse files Browse the repository at this point in the history
  • Loading branch information
koron committed Mar 21, 2024
2 parents 9bfcf87 + 10ec302 commit 38efc58
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions keyboards/keyball/lib/keyball/keyball.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ static int16_t add16(int16_t a, int16_t b) {
return r;
}

// divmod16 divides *v by div, returns the quotient, and assigns the remainder
// to *v.
static int16_t divmod16(int16_t *v, int16_t div) {
int16_t r = *v / div;
*v -= r * div;
return r;
}

// clip2int8 clips an integer fit into int8_t.
static inline int8_t clip2int8(int16_t v) {
return (v) < -127 ? -127 : (v) > 127 ? 127 : (int8_t)v;
Expand Down Expand Up @@ -171,11 +179,9 @@ static void motion_to_mouse_move(keyball_motion_t *m, report_mouse_t *r, bool is

static void motion_to_mouse_scroll(keyball_motion_t *m, report_mouse_t *r, bool is_left) {
// consume motion of trackball.
uint8_t div = keyball_get_scroll_div() - 1;
int16_t x = m->x >> div;
m->x -= x << div;
int16_t y = m->y >> div;
m->y -= y << div;
int16_t div = 1 << (keyball_get_scroll_div() - 1);
int16_t x = divmod16(&m->x, div);
int16_t y = divmod16(&m->y, div);

// apply to mouse report.
#if KEYBALL_MODEL == 61 || KEYBALL_MODEL == 39 || KEYBALL_MODEL == 147 || KEYBALL_MODEL == 44
Expand Down

0 comments on commit 38efc58

Please sign in to comment.