From 90b94b72ffb6b309ef3f23273083456e7e27455b Mon Sep 17 00:00:00 2001 From: Jack Wu Date: Mon, 27 Sep 2021 17:47:36 +0800 Subject: [PATCH] minui: add hall sensor event Bug: 191831427 Bug: 200907986 Test: manual test Signed-off-by: Jack Wu Change-Id: Ibb6f1e13344d33586398ac2e09430281bbe6d718 --- minui/events.cpp | 29 +++++++++++++++++++++++++++++ minui/include/minui/minui.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/minui/events.cpp b/minui/events.cpp index 863ac747..b307a497 100644 --- a/minui/events.cpp +++ b/minui/events.cpp @@ -267,6 +267,35 @@ int ev_get_input(int fd, uint32_t epevents, input_event* ev) { return -1; } +int ev_sync_sw_state(const ev_set_sw_callback& set_sw_cb) { + // Use unsigned long to match ioctl's parameter type. + unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT + unsigned long sw_bits[BITS_TO_LONGS(SW_MAX)]; // NOLINT + + for (size_t i = 0; i < g_ev_dev_count; ++i) { + memset(ev_bits, 0, sizeof(ev_bits)); + memset(sw_bits, 0, sizeof(sw_bits)); + + if (ioctl(ev_fdinfo[i].fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) == -1) { + continue; + } + if (!test_bit(EV_SW, ev_bits)) { + continue; + } + if (ioctl(ev_fdinfo[i].fd, EVIOCGSW(sizeof(sw_bits)), sw_bits) == -1) { + continue; + } + + for (int code = 0; code <= SW_MAX; code++) { + if (test_bit(code, sw_bits)) { + set_sw_cb(code, 1); + } + } + } + + return 0; +} + int ev_sync_key_state(const ev_set_key_callback& set_key_cb) { // Use unsigned long to match ioctl's parameter type. unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h index 6a762b6a..a2f62f0a 100644 --- a/minui/include/minui/minui.h +++ b/minui/include/minui/minui.h @@ -162,6 +162,7 @@ struct input_event; using ev_callback = std::function; using ev_set_key_callback = std::function; +using ev_set_sw_callback = std::function; int ev_init(ev_callback input_cb, bool allow_touch_inputs = false); void ev_exit(); @@ -169,6 +170,7 @@ int ev_add_fd(android::base::unique_fd&& fd, ev_callback cb); void ev_iterate_available_keys(const std::function& f); void ev_iterate_touch_inputs(const std::function& action); int ev_sync_key_state(const ev_set_key_callback& set_key_cb); +int ev_sync_sw_state(const ev_set_sw_callback& set_sw_cb); // 'timeout' has the same semantics as poll(2). // 0 : don't block