Skip to content

Commit 8958010

Browse files
joevtdingusdev
authored andcommitted
adbmouse: Fix bug with 5 or more buttons.
1 parent ae60515 commit 8958010

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

devices/common/adb/adbmouse.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
7676
static const uint8_t buttons_to_bits[] = {0, 7, 7, 10, 10, 13, 13, 16, 16};
7777
static const uint8_t bits_to_bits[] = {0, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 13, 13, 13, 16, 16, 16};
7878
int total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[this->num_bits]);
79+
uint8_t buttons_state = ~this->buttons_state;
7980

8081
for (int axis = 0; axis < 2; axis++) {
8182
int bits = this->num_bits;
@@ -91,7 +92,7 @@ bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
9192
bits = 7;
9293

9394
while (bits_remaining > 0) {
94-
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) ^ 1) << bits) | (*p << (bits + 1));
95+
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) & 1) << bits) | (*p << (bits + 1));
9596
val >>= bits;
9697
bits_remaining -= bits;
9798
p = bits == 7 ? &out_buf[2] : p + 1;

0 commit comments

Comments
 (0)