diff --git a/src/sysinput.c b/src/sysinput.c index 8f45b37..c45d6f7 100644 --- a/src/sysinput.c +++ b/src/sysinput.c @@ -13,7 +13,7 @@ static int last_bstate = 0; static void *input_thread(void *arg) { - int st, tmp, mask; + int st, down, up, mask; uintptr_t attr; while (running) @@ -22,19 +22,16 @@ static void *input_thread(void *arg) st = Gpio_read_buttons(); if (st != last_bstate) { - tmp = last_bstate & ~st; + up = last_bstate & ~st; + down = st & ~last_bstate; for (attr = 1, mask = 1; attr <= 4; attr++, mask <<= 1) { - if (tmp & mask) + if (up & mask) { Log(LDEBUG, "posting WM_HWBUTTONUP(%d)", (int)attr); MqPost1(Sys_Queue, 0, WM_HWBUTTONUP, attr); } - } - tmp = st & ~last_bstate; - for (attr = 1, mask = 1; attr <= 4; attr++, mask <<= 1) - { - if (tmp & mask) + else if (down & mask) { Log(LDEBUG, "posting WM_HWBUTTONDOWN(%d)", (int)attr); MqPost1(Sys_Queue, 0, WM_HWBUTTONDOWN, attr);