#include #include #include #include #include #include #include #include #include "scode.h" #include "config.h" #include "log.h" #include "msg_queue.h" #include "gpio.h" #include "time_func.h" #define INPUT_EVENT_BATCH 16 PMSG_QUEUE Sys_Queue = NULL; static pthread_t ithread; static volatile sig_atomic_t running = 1; static int ts_fd = 0; static UINT32 last_bstate = 0; static TIMESTAMP button_event_ok[GPIO_BUTTON_COUNT]; static UINT_PTR touch_x = 0; static UINT_PTR touch_y = 0; static UINT32 touch_nextmsg = WM_TOUCHMOVE; static void poll_buttons(void) { UINT32 st, down, up, mask; UINT_PTR attr; TIMESTAMP now; /* poll hardware buttons */ st = Gpio_read_buttons(); if (st != last_bstate) { now = Time_since_start(); up = last_bstate & ~st; down = st & ~last_bstate; for (attr = 1, mask = GRB_STATE_BUTTON1; attr <= GPIO_BUTTON_COUNT; attr++, mask <<= 1) { if (now < button_event_ok[attr - 1]) continue; if (up & mask) { button_event_ok[attr - 1] = now + Gconfig.button_debounce; Mq_post1(Sys_Queue, 0, WM_HWBUTTONUP, attr); } else if (down & mask) Mq_post1(Sys_Queue, 0, WM_HWBUTTONDOWN, attr); } last_bstate = st; } } static void poll_touchscreen(void) { int nb, nev, xerrno, i; struct input_event buffer[INPUT_EVENT_BATCH]; nb = read(ts_fd, buffer, INPUT_EVENT_BATCH * sizeof(struct input_event)); if (nb == -1) { xerrno = errno; if ((xerrno != EAGAIN) && (xerrno != EWOULDBLOCK)) Log(LERROR, "Error reading from touchscreen device (%d)", xerrno); return; } else if (nb == 0) { Log(LERROR, "Unexpected end of file reading from touchscreen device"); return; } nev = nb / sizeof(struct input_event); xerrno = nev * sizeof(struct input_event); if (nb > xerrno) Log(LERROR, "read %d bytes from touchscreen but we can only use %d", nb, xerrno); for (i=0; i